/** * MAPREDUCE-6771. Test if RMContainerAllocator generates the events in the * right order while processing finished containers. */ @Test public void testHandlingFinishedContainers() { EventHandler eventHandler = mock(EventHandler.class); AppContext context = mock(MRAppMaster.RunningAppContext.class); when(context.getClock()).thenReturn(new ControlledClock()); when(context.getClusterInfo()).thenReturn( new ClusterInfo(Resource.newInstance(10240, 1))); when(context.getEventHandler()).thenReturn(eventHandler); RMContainerAllocator containerAllocator = new RMContainerAllocatorForFinishedContainer(null, context); ContainerStatus finishedContainer = ContainerStatus.newInstance( mock(ContainerId.class), ContainerState.COMPLETE, "", 0); containerAllocator.processFinishedContainer(finishedContainer); InOrder inOrder = inOrder(eventHandler); inOrder.verify(eventHandler).handle( isA(TaskAttemptDiagnosticsUpdateEvent.class)); inOrder.verify(eventHandler).handle(isA(TaskAttemptEvent.class)); inOrder.verifyNoMoreInteractions(); }
/** * Verifies that the class was loaded by the job classloader if it is in the * context of the MRAppMaster, and if not throws an exception to fail the * job. */ private void verifyClassLoader(Class<?> cls) { // to detect that it is instantiated in the context of the MRAppMaster, we // inspect the stack trace and determine a caller is MRAppMaster for (StackTraceElement e: new Throwable().getStackTrace()) { if (e.getClassName().equals(MRAppMaster.class.getName()) && !(cls.getClassLoader() instanceof ApplicationClassLoader)) { throw new ExceptionInInitializerError("incorrect classloader used"); } } }