### Question:
ResourceTrackerService extends AbstractService implements
    ResourceTracker { @SuppressWarnings("unchecked") @VisibleForTesting void handleContainerStatus(ContainerStatus containerStatus) { ApplicationAttemptId appAttemptId = containerStatus.getContainerId().getApplicationAttemptId(); RMApp rmApp = rmContext.getRMApps().get(appAttemptId.getApplicationId()); if (rmApp == null) { LOG.error("Received finished container : " + containerStatus.getContainerId() + "for unknown application " + appAttemptId.getApplicationId() + " Skipping."); return; } if (rmApp.getApplicationSubmissionContext().getUnmanagedAM()) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring container completion status for unmanaged AM" + rmApp.getApplicationId()); } return; } RMAppAttempt rmAppAttempt = rmApp.getRMAppAttempt(appAttemptId); Container masterContainer = rmAppAttempt.getMasterContainer(); if (masterContainer.getId().equals(containerStatus.getContainerId()) && containerStatus.getState() == ContainerState.COMPLETE) { RMAppAttemptContainerFinishedEvent evt = new RMAppAttemptContainerFinishedEvent(appAttemptId, containerStatus); rmContext.getDispatcher().getEventHandler().handle(evt); } } ResourceTrackerService(RMContext rmContext,
      NodesListManager nodesListManager,
      NMLivelinessMonitor nmLivelinessMonitor,
      RMContainerTokenSecretManager containerTokenSecretManager,
      NMTokenSecretManagerInRM nmTokenSecretManager); @SuppressWarnings("unchecked") @Override RegisterNodeManagerResponse registerNodeManager(
      RegisterNodeManagerRequest request); @SuppressWarnings("unchecked") @Override NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request); static Node resolve(String hostName); @VisibleForTesting Server getServer();  }### Answer:
@SuppressWarnings("unchecked") @Test public void testHandleContainerStatusInvalidCompletions() throws Exception { rm = new MockRM(new YarnConfiguration()); rm.start(); EventHandler handler = spy(rm.getRMContext().getDispatcher().getEventHandler()); RMApp app = rm.submitApp(1024, true); ContainerStatus status = ContainerStatus.newInstance( ContainerId.newInstance(ApplicationAttemptId.newInstance( app.getApplicationId(), 2), 1), ContainerState.COMPLETE, "Dummy Completed", 0); rm.getResourceTrackerService().handleContainerStatus(status); verify(handler, never()).handle((Event) any()); RMAppAttemptImpl currentAttempt = (RMAppAttemptImpl) app.getCurrentAppAttempt(); currentAttempt.setMasterContainer(null); status = ContainerStatus.newInstance( ContainerId.newInstance(currentAttempt.getAppAttemptId(), 0), ContainerState.COMPLETE, "Dummy Completed", 0); rm.getResourceTrackerService().handleContainerStatus(status); verify(handler, never()).handle((Event)any()); app = rm.submitApp(1024); status = ContainerStatus.newInstance( ContainerId.newInstance(ApplicationAttemptId.newInstance( app.getApplicationId(), 2), 1), ContainerState.COMPLETE, "Dummy Completed", 0); try { rm.getResourceTrackerService().handleContainerStatus(status); } catch (Exception e) { } verify(handler, never()).handle((Event)any()); currentAttempt = (RMAppAttemptImpl) app.getCurrentAppAttempt(); currentAttempt.setMasterContainer(null); status = ContainerStatus.newInstance( ContainerId.newInstance(currentAttempt.getAppAttemptId(), 0), ContainerState.COMPLETE, "Dummy Completed", 0); try { rm.getResourceTrackerService().handleContainerStatus(status); } catch (Exception e) { } verify(handler, never()).handle((Event)any()); }