use of org.apache.tez.serviceplugins.api.TaskCommunicator in project tez by apache.
the class TaskCommunicatorManager method createCustomTaskCommunicator.
@VisibleForTesting
TaskCommunicator createCustomTaskCommunicator(TaskCommunicatorContext taskCommunicatorContext, NamedEntityDescriptor taskCommDescriptor) throws TezException {
LOG.info("Creating TaskCommunicator {}:{} " + taskCommDescriptor.getEntityName(), taskCommDescriptor.getClassName());
Class<? extends TaskCommunicator> taskCommClazz = (Class<? extends TaskCommunicator>) ReflectionUtils.getClazz(taskCommDescriptor.getClassName());
try {
Constructor<? extends TaskCommunicator> ctor = taskCommClazz.getConstructor(TaskCommunicatorContext.class);
return ctor.newInstance(taskCommunicatorContext);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new TezUncheckedException(e);
}
}
use of org.apache.tez.serviceplugins.api.TaskCommunicator in project tez by apache.
the class TestTaskAttempt method createMockTaskAttemptListener.
private TaskCommunicatorManagerInterface createMockTaskAttemptListener() throws ServicePluginException {
TaskCommunicatorManagerInterface taListener = mock(TaskCommunicatorManagerInterface.class);
TaskCommunicator taskComm = mock(TaskCommunicator.class);
doReturn(new InetSocketAddress("localhost", 0)).when(taskComm).getAddress();
doReturn(new TaskCommunicatorWrapper(taskComm)).when(taListener).getTaskCommunicator(0);
return taListener;
}
use of org.apache.tez.serviceplugins.api.TaskCommunicator in project tez by apache.
the class TestTaskCommunicatorManager method testTaskCommunicatorUserError.
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testTaskCommunicatorUserError() {
TaskCommunicatorContextImpl taskCommContext = mock(TaskCommunicatorContextImpl.class);
TaskCommunicator taskCommunicator = mock(TaskCommunicator.class, new ExceptionAnswer());
doReturn(taskCommContext).when(taskCommunicator).getContext();
EventHandler eventHandler = mock(EventHandler.class);
AppContext appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
when(appContext.getEventHandler()).thenReturn(eventHandler);
doReturn("testTaskCommunicator").when(appContext).getTaskCommunicatorName(0);
String expectedId = "[0:testTaskCommunicator]";
Configuration conf = new Configuration(false);
TaskCommunicatorManager taskCommunicatorManager = new TaskCommunicatorManager(taskCommunicator, appContext, mock(TaskHeartbeatHandler.class), mock(ContainerHeartbeatHandler.class));
try {
taskCommunicatorManager.init(conf);
taskCommunicatorManager.start();
// Invoking a couple of random methods.
DAG mockDag = mock(DAG.class, RETURNS_DEEP_STUBS);
when(mockDag.getID().getId()).thenReturn(1);
taskCommunicatorManager.dagComplete(mockDag);
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_COMMUNICATOR_SERVICE_FATAL_ERROR, event.getType());
assertTrue(event.getError().getMessage().contains("TestException_" + "dagComplete"));
assertTrue(event.getDiagnosticInfo().contains("DAG completion"));
assertTrue(event.getDiagnosticInfo().contains(expectedId));
when(appContext.getAllContainers().get(any(ContainerId.class)).getContainer().getNodeId()).thenReturn(mock(NodeId.class));
taskCommunicatorManager.registerRunningContainer(mock(ContainerId.class), 0);
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_COMMUNICATOR_SERVICE_FATAL_ERROR, event.getType());
assertTrue(event.getError().getMessage().contains("TestException_" + "registerRunningContainer"));
assertTrue(event.getDiagnosticInfo().contains("registering running Container"));
assertTrue(event.getDiagnosticInfo().contains(expectedId));
} finally {
taskCommunicatorManager.stop();
}
}
Aggregations