amNodeMap.handle(new AMNodeEventContainerAllocated(nodeId, cId1));
amNodeMap.handle(new AMNodeEventContainerAllocated(nodeId, cId2));
amNodeMap.handle(new AMNodeEventContainerAllocated(nodeId, cId3));
assertEquals(3, node.containers.size());
TezTaskAttemptID ta1 = mock(TezTaskAttemptID.class);
TezTaskAttemptID ta2 = mock(TezTaskAttemptID.class);
TezTaskAttemptID ta3 = mock(TezTaskAttemptID.class);
amNodeMap.handle(new AMNodeEventTaskAttemptSucceeded(nodeId, cId1, ta1));
assertEquals(1, node.numSuccessfulTAs);
amNodeMap.handle(new AMNodeEventTaskAttemptEnded(nodeId, cId2, ta2, true));
assertEquals(1, node.numSuccessfulTAs);
assertEquals(1, node.numFailedTAs);
assertEquals(AMNodeState.ACTIVE, node.getState());
// duplicate should not affect anything
amNodeMap.handle(new AMNodeEventTaskAttemptEnded(nodeId, cId2, ta2, true));
assertEquals(1, node.numSuccessfulTAs);
assertEquals(1, node.numFailedTAs);
assertEquals(AMNodeState.ACTIVE, node.getState());
amNodeMap.handle(new AMNodeEventTaskAttemptEnded(nodeId, cId3, ta3, true));
dispatcher.await();
assertEquals(1, node.numSuccessfulTAs);
assertEquals(2, node.numFailedTAs);
assertEquals(AMNodeState.BLACKLISTED, node.getState());
assertEquals(5, handler.events.size());
assertEquals(AMContainerEventType.C_NODE_FAILED, handler.events.get(0).getType());
assertEquals(cId1, ((AMContainerEventNodeFailed)handler.events.get(0)).getContainerId());
assertEquals(AMContainerEventType.C_NODE_FAILED, handler.events.get(1).getType());
assertEquals(cId2, ((AMContainerEventNodeFailed)handler.events.get(1)).getContainerId());
assertEquals(AMContainerEventType.C_NODE_FAILED, handler.events.get(2).getType());
assertEquals(cId3, ((AMContainerEventNodeFailed)handler.events.get(2)).getContainerId());
assertEquals(AMNodeEventType.N_NODE_WAS_BLACKLISTED, handler.events.get(3).getType());
assertEquals(node.getNodeId(), ((AMNodeEvent)handler.events.get(3)).getNodeId());
assertEquals(AMSchedulerEventType.S_NODE_BLACKLISTED, handler.events.get(4).getType());
assertEquals(node.getNodeId(), ((AMSchedulerEventNodeBlacklistUpdate)handler.events.get(4)).getNodeId());
ContainerId cId4 = mock(ContainerId.class);
ContainerId cId5 = mock(ContainerId.class);
TezTaskAttemptID ta4 = mock(TezTaskAttemptID.class);
TezTaskAttemptID ta5 = mock(TezTaskAttemptID.class);
AMNodeImpl node2 = (AMNodeImpl) amNodeMap.get(nodeId2);
amNodeMap.handle(new AMNodeEventContainerAllocated(nodeId2, cId4));
amNodeMap.handle(new AMNodeEventContainerAllocated(nodeId2, cId5));
amNodeMap.handle(new AMNodeEventTaskAttemptEnded(nodeId2, cId4, ta4, true));