Search in sources :

Example 1 with AllocatorRunnable

use of org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable in project hadoop by apache.

the class TestRMCommunicator method testRMContainerAllocatorYarnRuntimeExceptionIsHandled.

@Test(timeout = 2000)
public void testRMContainerAllocatorYarnRuntimeExceptionIsHandled() throws Exception {
    ClientService mockClientService = mock(ClientService.class);
    AppContext mockContext = mock(AppContext.class);
    MockRMCommunicator mockRMCommunicator = new MockRMCommunicator(mockClientService, mockContext);
    final RMCommunicator communicator = spy(mockRMCommunicator);
    Clock mockClock = mock(Clock.class);
    when(mockContext.getClock()).thenReturn(mockClock);
    doThrow(new YarnRuntimeException("Test")).doNothing().when(communicator).heartbeat();
    when(mockClock.getTime()).thenReturn(1L).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            communicator.stop();
            return 2;
        }
    }).thenThrow(new AssertionError("GetClock called second time, when it should not have since the thread " + "should have quit"));
    AllocatorRunnable testRunnable = communicator.new AllocatorRunnable();
    testRunnable.run();
    verify(mockClock, times(2)).getTime();
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) Answer(org.mockito.stubbing.Answer) ClientService(org.apache.hadoop.mapreduce.v2.app.client.ClientService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AllocatorRunnable(org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable) AppContext(org.apache.hadoop.mapreduce.v2.app.AppContext) Clock(org.apache.hadoop.yarn.util.Clock) Test(org.junit.Test)

Example 2 with AllocatorRunnable

use of org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable in project hadoop by apache.

the class TestRMCommunicator method testRMContainerAllocatorExceptionIsHandled.

@Test(timeout = 2000)
public void testRMContainerAllocatorExceptionIsHandled() throws Exception {
    ClientService mockClientService = mock(ClientService.class);
    AppContext mockContext = mock(AppContext.class);
    MockRMCommunicator mockRMCommunicator = new MockRMCommunicator(mockClientService, mockContext);
    RMCommunicator communicator = spy(mockRMCommunicator);
    Clock mockClock = mock(Clock.class);
    when(mockContext.getClock()).thenReturn(mockClock);
    doThrow(new RMContainerAllocationException("Test")).doNothing().when(communicator).heartbeat();
    when(mockClock.getTime()).thenReturn(1L).thenThrow(new AssertionError("GetClock called second time, when it should not have since the " + "thread should have quit"));
    AllocatorRunnable testRunnable = communicator.new AllocatorRunnable();
    testRunnable.run();
}
Also used : ClientService(org.apache.hadoop.mapreduce.v2.app.client.ClientService) AllocatorRunnable(org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable) AppContext(org.apache.hadoop.mapreduce.v2.app.AppContext) Clock(org.apache.hadoop.yarn.util.Clock) Test(org.junit.Test)

Aggregations

AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)2 ClientService (org.apache.hadoop.mapreduce.v2.app.client.ClientService)2 AllocatorRunnable (org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable)2 Clock (org.apache.hadoop.yarn.util.Clock)2 Test (org.junit.Test)2 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1