@Test public void testDuplicateCompletedEvents() { WrappedContainer wc = new WrappedContainer(); wc.launchContainer(); wc.containerLaunched(); wc.assignTaskAttempt(wc.taskAttemptID); wc.pullTaskToRun(); wc.taskAttemptSucceeded(wc.taskAttemptID); TezTaskAttemptID taID2 = TezTaskAttemptID.getInstance(wc.taskID, 2); wc.assignTaskAttempt(taID2); wc.pullTaskToRun(); wc.taskAttemptSucceeded(taID2); wc.stopRequest(); wc.nmStopSent(); wc.containerCompleted(false); wc.verifyState(AMContainerState.COMPLETED); wc.verifyNoOutgoingEvents(); wc.containerCompleted(false); wc.verifyNoOutgoingEvents(); wc.verifyHistoryStopEvent(); }
@Test // Assign before launch. public void tetSingleSuccessfulTaskFlow() { WrappedContainer wc = new WrappedContainer(); wc.verifyState(AMContainerState.ALLOCATED); // Launch request. wc.launchContainer(); wc.verifyState(AMContainerState.LAUNCHING); // 1 Launch request. wc.verifyCountAndGetOutgoingEvents(1); // Assign task. wc.assignTaskAttempt(wc.taskAttemptID); wc.verifyState(AMContainerState.LAUNCHING); wc.verifyNoOutgoingEvents(); assertEquals(wc.taskAttemptID, wc.amContainer.getQueuedTaskAttempts().get(0)); // Container Launched wc.containerLaunched(); wc.verifyState(AMContainerState.IDLE); wc.verifyNoOutgoingEvents(); assertEquals(wc.taskAttemptID, wc.amContainer.getQueuedTaskAttempts().get(0)); assertNull(wc.amContainer.getRunningTaskAttempt()); verify(wc.tal).registerRunningContainer(wc.containerID); verify(wc.chh).register(wc.containerID); // Pull TA AMContainerTask pulledTask = wc.pullTaskToRun(); wc.verifyState(AMContainerState.RUNNING); wc.verifyNoOutgoingEvents(); assertFalse(pulledTask.shouldDie()); assertEquals(wc.taskSpec.getTaskAttemptID(), pulledTask.getTask().getTaskAttemptID()); assertEquals(wc.taskAttemptID, wc.amContainer.getRunningTaskAttempt()); assertEquals(0, wc.amContainer.getQueuedTaskAttempts().size()); wc.taskAttemptSucceeded(wc.taskAttemptID); wc.verifyState(AMContainerState.IDLE); wc.verifyNoOutgoingEvents(); assertNull(wc.amContainer.getRunningTaskAttempt()); verify(wc.tal).unregisterTaskAttempt(wc.taskAttemptID); wc.containerCompleted(false); wc.verifyHistoryStopEvent(); wc.verifyState(AMContainerState.COMPLETED); wc.verifyNoOutgoingEvents(); verify(wc.tal).unregisterRunningContainer(wc.containerID); verify(wc.chh).unregister(wc.containerID); assertEquals(1, wc.amContainer.getAllTaskAttempts().size()); assertFalse(wc.amContainer.isInErrorState()); }
@SuppressWarnings("rawtypes") @Test public void testContainerDiskFailedAtRunning() { WrappedContainer wc = new WrappedContainer(); List<Event> outgoingEvents; wc.launchContainer(); wc.assignTaskAttempt(wc.taskAttemptID); wc.containerLaunched(); wc.pullTaskToRun(); wc.verifyState(AMContainerState.RUNNING); wc.containerCompleted(ContainerExitStatus.DISKS_FAILED); wc.verifyState(AMContainerState.COMPLETED); verify(wc.tal).registerRunningContainer(wc.containerID); verify(wc.tal).unregisterRunningContainer(wc.containerID); verify(wc.chh).register(wc.containerID); verify(wc.chh).unregister(wc.containerID); outgoingEvents = wc.verifyCountAndGetOutgoingEvents(1); verifyUnOrderedOutgoingEventTypes( outgoingEvents, TaskAttemptEventType.TA_CONTAINER_TERMINATED_BY_SYSTEM); assertFalse(wc.amContainer.isInErrorState()); // Pending task complete. (Ideally, container should be dead at this point // and this event should not be generated. Network timeout on NM-RM heartbeat // can cause it to be genreated) wc.taskAttemptSucceeded(wc.taskAttemptID); wc.verifyNoOutgoingEvents(); wc.verifyHistoryStopEvent(); assertFalse(wc.amContainer.isInErrorState()); }
@SuppressWarnings("rawtypes") @Test // Verify that incoming NM launched events to COMPLETED containers are // handled. public void testContainerCompletedAtLaunching() { WrappedContainer wc = new WrappedContainer(); List<Event> outgoingEvents; wc.launchContainer(); wc.assignTaskAttempt(wc.taskAttemptID); wc.containerCompleted(false); wc.verifyState(AMContainerState.COMPLETED); verify(wc.tal).registerRunningContainer(wc.containerID); verify(wc.tal).unregisterRunningContainer(wc.containerID); outgoingEvents = wc.verifyCountAndGetOutgoingEvents(1); verifyUnOrderedOutgoingEventTypes(outgoingEvents, TaskAttemptEventType.TA_CONTAINER_TERMINATED); assertFalse(wc.amContainer.isInErrorState()); // Container launched generated by NM call. wc.containerLaunched(); wc.verifyNoOutgoingEvents(); assertFalse(wc.amContainer.isInErrorState()); }
@Test public void testTaskPullAtLaunching() { WrappedContainer wc = new WrappedContainer(); wc.launchContainer(); AMContainerTask pulledTask = wc.pullTaskToRun(); wc.verifyState(AMContainerState.LAUNCHING); wc.verifyNoOutgoingEvents(); assertFalse(pulledTask.shouldDie()); assertNull(pulledTask.getTask()); }
@Test public void testContainerCompletedAtAllocated() { WrappedContainer wc = new WrappedContainer(); wc.verifyState(AMContainerState.ALLOCATED); wc.containerCompleted(false); wc.verifyState(AMContainerState.COMPLETED); wc.verifyNoOutgoingEvents(); assertFalse(wc.amContainer.isInErrorState()); }
@Test public void testSingleSuccessfulTaskFlowStopRequest() { WrappedContainer wc = new WrappedContainer(); wc.verifyState(AMContainerState.ALLOCATED); wc.launchContainer(); wc.assignTaskAttempt(wc.taskAttemptID); wc.containerLaunched(); wc.pullTaskToRun(); wc.taskAttemptSucceeded(wc.taskAttemptID); wc.stopRequest(); wc.verifyState(AMContainerState.STOP_REQUESTED); // Event to NM to stop the container. wc.verifyCountAndGetOutgoingEvents(1); assertTrue( wc.verifyCountAndGetOutgoingEvents(1).get(0).getType() == NMCommunicatorEventType.CONTAINER_STOP_REQUEST); wc.nmStopSent(); wc.verifyState(AMContainerState.STOPPING); wc.verifyNoOutgoingEvents(); wc.containerCompleted(false); wc.verifyHistoryStopEvent(); wc.verifyState(AMContainerState.COMPLETED); wc.verifyNoOutgoingEvents(); verify(wc.tal).unregisterRunningContainer(wc.containerID); verify(wc.chh).unregister(wc.containerID); assertEquals(0, wc.amContainer.getQueuedTaskAttempts().size()); assertNull(wc.amContainer.getRunningTaskAttempt()); assertEquals(1, wc.amContainer.getAllTaskAttempts().size()); assertFalse(wc.amContainer.isInErrorState()); }
@SuppressWarnings("rawtypes") @Test public void testNodeFailedAtIdleMultipleAttempts() { WrappedContainer wc = new WrappedContainer(); List<Event> outgoingEvents; wc.launchContainer(); wc.containerLaunched(); wc.assignTaskAttempt(wc.taskAttemptID); wc.pullTaskToRun(); wc.taskAttemptSucceeded(wc.taskAttemptID); wc.verifyState(AMContainerState.IDLE); TezTaskAttemptID taID2 = TezTaskAttemptID.getInstance(wc.taskID, 2); wc.assignTaskAttempt(taID2); wc.pullTaskToRun(); wc.taskAttemptSucceeded(taID2); wc.verifyState(AMContainerState.IDLE); wc.nodeFailed(); // Expecting a complete event from the RM wc.verifyState(AMContainerState.STOPPING); outgoingEvents = wc.verifyCountAndGetOutgoingEvents(3); verifyUnOrderedOutgoingEventTypes( outgoingEvents, TaskAttemptEventType.TA_NODE_FAILED, TaskAttemptEventType.TA_NODE_FAILED, AMSchedulerEventType.S_CONTAINER_DEALLOCATE); for (Event event : outgoingEvents) { if (event.getType() == TaskAttemptEventType.TA_NODE_FAILED) { TaskAttemptEventNodeFailed nfEvent = (TaskAttemptEventNodeFailed) event; assertEquals("nodeFailed", nfEvent.getDiagnosticInfo()); } } assertFalse(wc.amContainer.isInErrorState()); wc.containerCompleted(false); wc.verifyNoOutgoingEvents(); wc.verifyHistoryStopEvent(); assertNull(wc.amContainer.getRunningTaskAttempt()); assertEquals(0, wc.amContainer.getQueuedTaskAttempts().size()); assertEquals(2, wc.amContainer.getAllTaskAttempts().size()); }