Search in sources :

Example 1 with ContainerLauncher

use of org.apache.tez.serviceplugins.api.ContainerLauncher in project tez by apache.

the class TestContainerLauncherManager method testContainerLauncherUserError.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testContainerLauncherUserError() throws ServicePluginException {
    ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class);
    doReturn(eventHandler).when(appContext).getEventHandler();
    doReturn("testlauncher").when(appContext).getContainerLauncherName(0);
    Configuration conf = new Configuration(false);
    ContainerLauncherManager containerLauncherManager = new ContainerLauncherManager(appContext);
    containerLauncherManager.setContainerLauncher(containerLauncher);
    try {
        containerLauncherManager.init(conf);
        containerLauncherManager.start();
        // launch container
        doThrow(new RuntimeException("testexception")).when(containerLauncher).launchContainer(any(ContainerLaunchRequest.class));
        ContainerLaunchContext clc1 = mock(ContainerLaunchContext.class);
        Container container1 = mock(Container.class);
        ContainerLauncherLaunchRequestEvent launchRequestEvent = new ContainerLauncherLaunchRequestEvent(clc1, container1, 0, 0, 0);
        containerLauncherManager.handle(launchRequestEvent);
        ArgumentCaptor<Event> argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        Event rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        DAGAppMasterEventUserServiceFatalError event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertEquals(DAGAppMasterEventType.CONTAINER_LAUNCHER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("testexception"));
        assertTrue(event.getDiagnosticInfo().contains("launching container"));
        assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
        reset(eventHandler);
        // stop container
        doThrow(new RuntimeException("teststopexception")).when(containerLauncher).stopContainer(any(ContainerStopRequest.class));
        ContainerId containerId2 = mock(ContainerId.class);
        NodeId nodeId2 = mock(NodeId.class);
        ContainerLauncherStopRequestEvent stopRequestEvent = new ContainerLauncherStopRequestEvent(containerId2, nodeId2, null, 0, 0, 0);
        argumentCaptor = ArgumentCaptor.forClass(Event.class);
        containerLauncherManager.handle(stopRequestEvent);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertTrue(event.getError().getMessage().contains("teststopexception"));
        assertTrue(event.getDiagnosticInfo().contains("stopping container"));
        assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
    } finally {
        containerLauncherManager.stop();
    }
}
Also used : DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) Configuration(org.apache.hadoop.conf.Configuration) AppContext(org.apache.tez.dag.app.AppContext) EventHandler(org.apache.hadoop.yarn.event.EventHandler) ContainerStopRequest(org.apache.tez.serviceplugins.api.ContainerStopRequest) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) ContainerLauncherLaunchRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent) ContainerLauncher(org.apache.tez.serviceplugins.api.ContainerLauncher) Container(org.apache.hadoop.yarn.api.records.Container) ContainerLaunchRequest(org.apache.tez.serviceplugins.api.ContainerLaunchRequest) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ContainerLauncherLaunchRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent) Event(org.apache.hadoop.yarn.event.Event) ContainerLauncherStopRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherStopRequestEvent) ContainerLauncherStopRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherStopRequestEvent) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)1 Container (org.apache.hadoop.yarn.api.records.Container)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 Event (org.apache.hadoop.yarn.event.Event)1 EventHandler (org.apache.hadoop.yarn.event.EventHandler)1 AppContext (org.apache.tez.dag.app.AppContext)1 DAGAppMasterEventUserServiceFatalError (org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError)1 ContainerLauncherLaunchRequestEvent (org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent)1 ContainerLauncherStopRequestEvent (org.apache.tez.dag.app.rm.ContainerLauncherStopRequestEvent)1 DagInfoImplForTest (org.apache.tez.dag.helpers.DagInfoImplForTest)1 ContainerLaunchRequest (org.apache.tez.serviceplugins.api.ContainerLaunchRequest)1 ContainerLauncher (org.apache.tez.serviceplugins.api.ContainerLauncher)1 ContainerStopRequest (org.apache.tez.serviceplugins.api.ContainerStopRequest)1 Test (org.junit.Test)1