Search in sources :

Example 6 with ContainerRemoteLaunchEvent

use of org.apache.hadoop.mapreduce.v2.app.launcher.ContainerRemoteLaunchEvent in project hadoop by apache.

the class TestContainerLauncherImpl method testMyShutdown.

@Test(timeout = 5000)
public void testMyShutdown() throws Exception {
    LOG.info("in test Shutdown");
    AppContext mockContext = mock(AppContext.class);
    @SuppressWarnings("unchecked") EventHandler<Event> mockEventHandler = mock(EventHandler.class);
    when(mockContext.getEventHandler()).thenReturn(mockEventHandler);
    ContainerManagementProtocolClient mockCM = mock(ContainerManagementProtocolClient.class);
    ContainerLauncherImplUnderTest ut = new ContainerLauncherImplUnderTest(mockContext, mockCM);
    Configuration conf = new Configuration();
    ut.init(conf);
    ut.start();
    try {
        ContainerId contId = makeContainerId(0l, 0, 0, 1);
        TaskAttemptId taskAttemptId = makeTaskAttemptId(0l, 0, 0, TaskType.MAP, 0);
        String cmAddress = "127.0.0.1:8000";
        StartContainersResponse startResp = recordFactory.newRecordInstance(StartContainersResponse.class);
        startResp.setAllServicesMetaData(serviceResponse);
        LOG.info("inserting launch event");
        ContainerRemoteLaunchEvent mockLaunchEvent = mock(ContainerRemoteLaunchEvent.class);
        when(mockLaunchEvent.getType()).thenReturn(EventType.CONTAINER_REMOTE_LAUNCH);
        when(mockLaunchEvent.getContainerID()).thenReturn(contId);
        when(mockLaunchEvent.getTaskAttemptID()).thenReturn(taskAttemptId);
        when(mockLaunchEvent.getContainerMgrAddress()).thenReturn(cmAddress);
        when(mockCM.startContainers(any(StartContainersRequest.class))).thenReturn(startResp);
        when(mockLaunchEvent.getContainerToken()).thenReturn(createNewContainerToken(contId, cmAddress));
        ut.handle(mockLaunchEvent);
        ut.waitForPoolToIdle();
        verify(mockCM).startContainers(any(StartContainersRequest.class));
    // skip cleanup and make sure stop kills the container
    } finally {
        ut.stop();
        verify(mockCM).stopContainers(any(StopContainersRequest.class));
    }
}
Also used : StartContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest) Configuration(org.apache.hadoop.conf.Configuration) StartContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse) TaskAttemptId(org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId) AppContext(org.apache.hadoop.mapreduce.v2.app.AppContext) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Event(org.apache.hadoop.yarn.event.Event) StopContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Configuration (org.apache.hadoop.conf.Configuration)5 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)5 AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)5 Event (org.apache.hadoop.yarn.event.Event)5 StartContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)3 StopContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest)3 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)2 ContainerLauncherEvent (org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherEvent)2 ContainerRemoteLaunchEvent (org.apache.hadoop.mapreduce.v2.app.launcher.ContainerRemoteLaunchEvent)2 EventHandler (org.apache.hadoop.yarn.event.EventHandler)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)1 TaskId (org.apache.hadoop.mapreduce.v2.api.records.TaskId)1 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)1 TaskAttempt (org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt)1