use of org.apache.tez.common.TezTaskUmbilicalProtocol in project tez by apache.
the class TestTaskCommunicatorManager1 method testGetTask.
@Test(timeout = 5000)
public void testGetTask() throws IOException {
TezTaskCommunicatorImpl taskCommunicator = (TezTaskCommunicatorImpl) taskAttemptListener.getTaskCommunicator(0).getTaskCommunicator();
TezTaskUmbilicalProtocol tezUmbilical = taskCommunicator.getUmbilical();
ContainerId containerId1 = createContainerId(appId, 1);
ContainerContext containerContext1 = new ContainerContext(containerId1.toString());
containerTask = tezUmbilical.getTask(containerContext1);
assertTrue(containerTask.shouldDie());
ContainerId containerId2 = createContainerId(appId, 2);
ContainerContext containerContext2 = new ContainerContext(containerId2.toString());
taskAttemptListener.registerRunningContainer(containerId2, 0);
containerTask = tezUmbilical.getTask(containerContext2);
assertNull(containerTask);
// Valid task registered
taskAttemptListener.registerTaskAttempt(amContainerTask, containerId2, 0);
containerTask = tezUmbilical.getTask(containerContext2);
assertFalse(containerTask.shouldDie());
assertEquals(taskSpec, containerTask.getTaskSpec());
// Task unregistered. Should respond to heartbeats
taskAttemptListener.unregisterTaskAttempt(taskAttemptID, 0, TaskAttemptEndReason.OTHER, null);
containerTask = tezUmbilical.getTask(containerContext2);
assertNull(containerTask);
// Container unregistered. Should send a shouldDie = true
taskAttemptListener.unregisterRunningContainer(containerId2, 0, ContainerEndReason.OTHER, null);
containerTask = tezUmbilical.getTask(containerContext2);
assertTrue(containerTask.shouldDie());
ContainerId containerId3 = createContainerId(appId, 3);
ContainerContext containerContext3 = new ContainerContext(containerId3.toString());
taskAttemptListener.registerRunningContainer(containerId3, 0);
// Register task to container3, followed by unregistering container 3 all together
TaskSpec taskSpec2 = mock(TaskSpec.class);
TezTaskAttemptID taskAttemptId2 = mock(TezTaskAttemptID.class);
doReturn(taskAttemptId2).when(taskSpec2).getTaskAttemptID();
AMContainerTask amContainerTask2 = new AMContainerTask(taskSpec, null, null, false, 0);
taskAttemptListener.registerTaskAttempt(amContainerTask2, containerId3, 0);
taskAttemptListener.unregisterRunningContainer(containerId3, 0, ContainerEndReason.OTHER, null);
containerTask = tezUmbilical.getTask(containerContext3);
assertTrue(containerTask.shouldDie());
}
use of org.apache.tez.common.TezTaskUmbilicalProtocol in project tez by apache.
the class TestTaskCommunicatorManager1 method testGetTaskMultiplePulls.
@Test(timeout = 5000)
public void testGetTaskMultiplePulls() throws IOException {
TezTaskCommunicatorImpl taskCommunicator = (TezTaskCommunicatorImpl) taskAttemptListener.getTaskCommunicator(0).getTaskCommunicator();
TezTaskUmbilicalProtocol tezUmbilical = taskCommunicator.getUmbilical();
ContainerId containerId1 = createContainerId(appId, 1);
ContainerContext containerContext1 = new ContainerContext(containerId1.toString());
taskAttemptListener.registerRunningContainer(containerId1, 0);
containerTask = tezUmbilical.getTask(containerContext1);
assertNull(containerTask);
// Register task
taskAttemptListener.registerTaskAttempt(amContainerTask, containerId1, 0);
containerTask = tezUmbilical.getTask(containerContext1);
assertFalse(containerTask.shouldDie());
assertEquals(taskSpec, containerTask.getTaskSpec());
// Try pulling again - simulates re-use pull
containerTask = tezUmbilical.getTask(containerContext1);
assertNull(containerTask);
}
use of org.apache.tez.common.TezTaskUmbilicalProtocol in project tez by apache.
the class TestTaskReporter method testContinuousHeartbeatsOnMaxEvents.
@Test(timeout = 10000)
public void testContinuousHeartbeatsOnMaxEvents() throws Exception {
final Object lock = new Object();
final AtomicBoolean hb2Done = new AtomicBoolean(false);
TezTaskUmbilicalProtocol mockUmbilical = mock(TezTaskUmbilicalProtocol.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
TezHeartbeatRequest request = (TezHeartbeatRequest) args[0];
if (request.getRequestId() == 1 || request.getRequestId() == 2) {
TezHeartbeatResponse response = new TezHeartbeatResponse(createEvents(5));
response.setLastRequestId(request.getRequestId());
return response;
} else if (request.getRequestId() == 3) {
TezHeartbeatResponse response = new TezHeartbeatResponse(createEvents(1));
response.setLastRequestId(request.getRequestId());
synchronized (lock) {
hb2Done.set(true);
lock.notify();
}
return response;
} else {
throw new TezUncheckedException("Invalid request id for test: " + request.getRequestId());
}
}
}).when(mockUmbilical).heartbeat(any(TezHeartbeatRequest.class));
TezTaskAttemptID mockTaskAttemptId = mock(TezTaskAttemptID.class);
LogicalIOProcessorRuntimeTask mockTask = mock(LogicalIOProcessorRuntimeTask.class);
doReturn("vertexName").when(mockTask).getVertexName();
doReturn(mockTaskAttemptId).when(mockTask).getTaskAttemptID();
// Setup the sleep time to be way higher than the test timeout
TaskReporter.HeartbeatCallable heartbeatCallable = new TaskReporter.HeartbeatCallable(mockTask, mockUmbilical, 100000, 100000, 5, new AtomicLong(0), "containerIdStr");
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(heartbeatCallable);
try {
synchronized (lock) {
if (!hb2Done.get()) {
lock.wait();
}
}
verify(mockUmbilical, times(3)).heartbeat(any(TezHeartbeatRequest.class));
Thread.sleep(2000l);
// Sleep for 2 seconds, less than the callable sleep time. No more invocations.
verify(mockUmbilical, times(3)).heartbeat(any(TezHeartbeatRequest.class));
} finally {
executor.shutdownNow();
}
}
use of org.apache.tez.common.TezTaskUmbilicalProtocol in project tez by apache.
the class TestTaskReporter method testEventThrottling.
@Test(timeout = 10000)
public void testEventThrottling() throws Exception {
TezTaskAttemptID mockTaskAttemptId = mock(TezTaskAttemptID.class);
LogicalIOProcessorRuntimeTask mockTask = mock(LogicalIOProcessorRuntimeTask.class);
when(mockTask.getMaxEventsToHandle()).thenReturn(10000, 1);
when(mockTask.getVertexName()).thenReturn("vertexName");
when(mockTask.getTaskAttemptID()).thenReturn(mockTaskAttemptId);
TezTaskUmbilicalProtocol mockUmbilical = mock(TezTaskUmbilicalProtocol.class);
TezHeartbeatResponse resp1 = new TezHeartbeatResponse(createEvents(5));
resp1.setLastRequestId(1);
TezHeartbeatResponse resp2 = new TezHeartbeatResponse(createEvents(1));
resp2.setLastRequestId(2);
resp2.setShouldDie();
when(mockUmbilical.heartbeat(isA(TezHeartbeatRequest.class))).thenReturn(resp1, resp2);
// Setup the sleep time to be way higher than the test timeout
TaskReporter.HeartbeatCallable heartbeatCallable = new TaskReporter.HeartbeatCallable(mockTask, mockUmbilical, 100000, 100000, 5, new AtomicLong(0), "containerIdStr");
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Future<Boolean> result = executor.submit(heartbeatCallable);
Assert.assertFalse(result.get());
} finally {
executor.shutdownNow();
}
ArgumentCaptor<TezHeartbeatRequest> captor = ArgumentCaptor.forClass(TezHeartbeatRequest.class);
verify(mockUmbilical, times(2)).heartbeat(captor.capture());
TezHeartbeatRequest req = captor.getValue();
Assert.assertEquals(2, req.getRequestId());
Assert.assertEquals(1, req.getMaxEvents());
}
use of org.apache.tez.common.TezTaskUmbilicalProtocol in project tez by apache.
the class TestTaskReporter method testStatusUpdateAfterInitializationAndCounterFlag.
@Test(timeout = 5000)
public void testStatusUpdateAfterInitializationAndCounterFlag() {
TezTaskAttemptID mockTaskAttemptId = mock(TezTaskAttemptID.class);
LogicalIOProcessorRuntimeTask mockTask = mock(LogicalIOProcessorRuntimeTask.class);
doReturn("vertexName").when(mockTask).getVertexName();
doReturn(mockTaskAttemptId).when(mockTask).getTaskAttemptID();
boolean progressNotified = false;
doReturn(progressNotified).when(mockTask).getAndClearProgressNotification();
TezTaskUmbilicalProtocol mockUmbilical = mock(TezTaskUmbilicalProtocol.class);
float progress = 0.5f;
TaskStatistics stats = new TaskStatistics();
TezCounters counters = new TezCounters();
doReturn(progress).when(mockTask).getProgress();
doReturn(stats).when(mockTask).getTaskStatistics();
doReturn(counters).when(mockTask).getCounters();
// Setup the sleep time to be way higher than the test timeout
TaskReporter.HeartbeatCallable heartbeatCallable = new TaskReporter.HeartbeatCallable(mockTask, mockUmbilical, 100000, 100000, 5, new AtomicLong(0), "containerIdStr");
// task not initialized - nothing obtained from task
doReturn(false).when(mockTask).hasInitialized();
TaskStatusUpdateEvent event = heartbeatCallable.getStatusUpdateEvent(true);
verify(mockTask, times(1)).hasInitialized();
verify(mockTask, times(0)).getProgress();
verify(mockTask, times(0)).getAndClearProgressNotification();
verify(mockTask, times(0)).getTaskStatistics();
verify(mockTask, times(0)).getCounters();
Assert.assertEquals(0, event.getProgress(), 0);
Assert.assertEquals(false, event.getProgressNotified());
Assert.assertNull(event.getCounters());
Assert.assertNull(event.getStatistics());
// task is initialized - progress obtained but not counters since flag is false
doReturn(true).when(mockTask).hasInitialized();
event = heartbeatCallable.getStatusUpdateEvent(false);
verify(mockTask, times(2)).hasInitialized();
verify(mockTask, times(1)).getProgress();
verify(mockTask, times(1)).getAndClearProgressNotification();
verify(mockTask, times(0)).getTaskStatistics();
verify(mockTask, times(0)).getCounters();
Assert.assertEquals(progress, event.getProgress(), 0);
Assert.assertEquals(progressNotified, event.getProgressNotified());
Assert.assertNull(event.getCounters());
Assert.assertNull(event.getStatistics());
// task is initialized - progress obtained and also counters since flag is true
progressNotified = true;
doReturn(progressNotified).when(mockTask).getAndClearProgressNotification();
doReturn(true).when(mockTask).hasInitialized();
event = heartbeatCallable.getStatusUpdateEvent(true);
verify(mockTask, times(3)).hasInitialized();
verify(mockTask, times(2)).getProgress();
verify(mockTask, times(2)).getAndClearProgressNotification();
verify(mockTask, times(1)).getTaskStatistics();
verify(mockTask, times(1)).getCounters();
Assert.assertEquals(progress, event.getProgress(), 0);
Assert.assertEquals(progressNotified, event.getProgressNotified());
Assert.assertEquals(counters, event.getCounters());
Assert.assertEquals(stats, event.getStatistics());
}
Aggregations