Search in sources :

Example 1 with TaskScheduler

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

the class TestTaskSchedulerManager method testTaskSchedulerUserError.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testTaskSchedulerUserError() {
    TaskScheduler taskScheduler = mock(TaskScheduler.class, new ExceptionAnswer());
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
    when(appContext.getEventHandler()).thenReturn(eventHandler);
    doReturn("testTaskScheduler").when(appContext).getTaskSchedulerName(0);
    String expectedId = "[0:testTaskScheduler]";
    Configuration conf = new Configuration(false);
    InetSocketAddress address = new InetSocketAddress(15222);
    DAGClientServer mockClientService = mock(DAGClientServer.class);
    doReturn(address).when(mockClientService).getBindAddress();
    TaskSchedulerManager taskSchedulerManager = new TaskSchedulerManager(taskScheduler, appContext, mock(ContainerSignatureMatcher.class), mockClientService, Executors.newFixedThreadPool(1)) {

        @Override
        protected void instantiateSchedulers(String host, int port, String trackingUrl, AppContext appContext) throws TezException {
        // Stubbed out since these are setup up front in the constructor used for testing
        }
    };
    try {
        taskSchedulerManager.init(conf);
        taskSchedulerManager.start();
        // Invoking a couple of random methods
        AMSchedulerEventTALaunchRequest launchRequest = new AMSchedulerEventTALaunchRequest(mock(TezTaskAttemptID.class), mock(Resource.class), mock(TaskSpec.class), mock(TaskAttempt.class), mock(TaskLocationHint.class), 0, mock(ContainerContext.class), 0, 0, 0);
        taskSchedulerManager.handleEvent(launchRequest);
        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.TASK_SCHEDULER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("TestException_" + "allocateTask"));
        assertTrue(event.getDiagnosticInfo().contains("Task Allocation"));
        assertTrue(event.getDiagnosticInfo().contains(expectedId));
        taskSchedulerManager.dagCompleted();
        argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(2)).handle(argumentCaptor.capture());
        rawEvent = argumentCaptor.getAllValues().get(1);
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertEquals(DAGAppMasterEventType.TASK_SCHEDULER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("TestException_" + "dagComplete"));
        assertTrue(event.getDiagnosticInfo().contains("Dag Completion"));
        assertTrue(event.getDiagnosticInfo().contains(expectedId));
    } finally {
        taskSchedulerManager.stop();
    }
}
Also used : DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) InetSocketAddress(java.net.InetSocketAddress) AppContext(org.apache.tez.dag.app.AppContext) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) ContainerSignatureMatcher(org.apache.tez.common.ContainerSignatureMatcher) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) EventHandler(org.apache.hadoop.yarn.event.EventHandler) TaskScheduler(org.apache.tez.serviceplugins.api.TaskScheduler) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) ContainerContext(org.apache.tez.dag.app.ContainerContext) Event(org.apache.hadoop.yarn.event.Event) DAGClientServer(org.apache.tez.dag.api.client.DAGClientServer) TaskAttempt(org.apache.tez.dag.app.dag.TaskAttempt) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 Configuration (org.apache.hadoop.conf.Configuration)1 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)1 Resource (org.apache.hadoop.yarn.api.records.Resource)1 Event (org.apache.hadoop.yarn.event.Event)1 EventHandler (org.apache.hadoop.yarn.event.EventHandler)1 ContainerSignatureMatcher (org.apache.tez.common.ContainerSignatureMatcher)1 TaskLocationHint (org.apache.tez.dag.api.TaskLocationHint)1 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)1 DAGClientServer (org.apache.tez.dag.api.client.DAGClientServer)1 AppContext (org.apache.tez.dag.app.AppContext)1 ContainerContext (org.apache.tez.dag.app.ContainerContext)1 TaskAttempt (org.apache.tez.dag.app.dag.TaskAttempt)1 DAGAppMasterEventUserServiceFatalError (org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError)1 DagInfoImplForTest (org.apache.tez.dag.helpers.DagInfoImplForTest)1 TezTaskAttemptID (org.apache.tez.dag.records.TezTaskAttemptID)1 TaskSpec (org.apache.tez.runtime.api.impl.TaskSpec)1 TaskScheduler (org.apache.tez.serviceplugins.api.TaskScheduler)1 Test (org.junit.Test)1