use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestTaskAttempt method testCompletedAtSubmitted.
@Test(timeout = 5000)
public void testCompletedAtSubmitted() throws ServicePluginException {
ApplicationId appId = ApplicationId.newInstance(1, 2);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 0);
TezDAGID dagID = TezDAGID.getInstance(appId, 1);
TezVertexID vertexID = TezVertexID.getInstance(dagID, 1);
TezTaskID taskID = TezTaskID.getInstance(vertexID, 1);
MockEventHandler eventHandler = spy(new MockEventHandler());
TaskCommunicatorManagerInterface taListener = createMockTaskAttemptListener();
Configuration taskConf = new Configuration();
taskConf.setClass("fs.file.impl", StubbedFS.class, FileSystem.class);
taskConf.setBoolean("fs.file.impl.disable.cache", true);
locationHint = TaskLocationHint.createTaskLocationHint(new HashSet<String>(Arrays.asList(new String[] { "127.0.0.1" })), null);
Resource resource = Resource.newInstance(1024, 1);
NodeId nid = NodeId.newInstance("127.0.0.1", 0);
@SuppressWarnings("deprecation") ContainerId contId = ContainerId.newInstance(appAttemptId, 3);
Container container = mock(Container.class);
when(container.getId()).thenReturn(contId);
when(container.getNodeId()).thenReturn(nid);
when(container.getNodeHttpAddress()).thenReturn("localhost:0");
AMContainerMap containers = new AMContainerMap(mock(ContainerHeartbeatHandler.class), mock(TaskCommunicatorManagerInterface.class), new ContainerContextMatcher(), appCtx);
containers.addContainerIfNew(container, 0, 0, 0);
doReturn(new ClusterInfo()).when(appCtx).getClusterInfo();
doReturn(containers).when(appCtx).getAllContainers();
TaskHeartbeatHandler mockHeartbeatHandler = mock(TaskHeartbeatHandler.class);
TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, taListener, taskConf, new SystemClock(), mockHeartbeatHandler, appCtx, false, resource, createFakeContainerContext(), false);
TezTaskAttemptID taskAttemptID = taImpl.getID();
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
taImpl.handle(new TaskAttemptEventSchedule(taskAttemptID, 0, 0));
taImpl.handle(new TaskAttemptEventSubmitted(taskAttemptID, contId));
assertEquals("Task attempt is not in the RUNNING state", taImpl.getState(), TaskAttemptState.STARTING);
verify(mockHeartbeatHandler).register(taskAttemptID);
int expectedEventsAtStarting = 4;
verify(eventHandler, times(expectedEventsAtStarting)).handle(arg.capture());
// Ensure status_updates are handled in the submitted state.
taImpl.handle(new TaskAttemptEventStatusUpdate(taskAttemptID, new TaskStatusUpdateEvent(null, 0.1f, null, false)));
taImpl.handle(new TaskAttemptEvent(taskAttemptID, TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt is not in the SUCCEEDED state", taImpl.getState(), TaskAttemptState.SUCCEEDED);
verify(mockHeartbeatHandler).unregister(taskAttemptID);
assertEquals(0, taImpl.getDiagnostics().size());
int expectedEvenstAfterTerminating = expectedEventsAtStarting + 3;
arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(expectedEvenstAfterTerminating)).handle(arg.capture());
Event e = verifyEventType(arg.getAllValues().subList(expectedEventsAtStarting, expectedEvenstAfterTerminating), TaskEventTASucceeded.class, 1);
assertEquals(TaskEventType.T_ATTEMPT_SUCCEEDED, e.getType());
verifyEventType(arg.getAllValues().subList(expectedEventsAtStarting, expectedEvenstAfterTerminating), AMSchedulerEventTAEnded.class, 1);
verifyEventType(arg.getAllValues().subList(expectedEventsAtStarting, expectedEvenstAfterTerminating), DAGEventCounterUpdate.class, 1);
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGImpl method testDAGStart.
@Test(timeout = 5000)
public void testDAGStart() {
initDAG(dag);
startDAG(dag);
dispatcher.await();
for (int i = 0; i < 6; ++i) {
TezVertexID vId = TezVertexID.getInstance(dagId, i);
Vertex v = dag.getVertex(vId);
Assert.assertEquals(VertexState.RUNNING, v.getState());
if (i < 2) {
Assert.assertEquals(0, v.getDistanceFromRoot());
} else if (i == 2) {
Assert.assertEquals(1, v.getDistanceFromRoot());
} else if (i > 2 && i < 5) {
Assert.assertEquals(2, v.getDistanceFromRoot());
} else if (i == 5) {
Assert.assertEquals(3, v.getDistanceFromRoot());
}
}
for (int i = 0; i < 6; ++i) {
TezVertexID vId = TezVertexID.getInstance(dagId, i);
LOG.info("Distance from root: v" + i + ":" + dag.getVertex(vId).getDistanceFromRoot());
}
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGImpl method testVertexReRunning.
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testVertexReRunning() {
initDAG(dag);
dag.dagScheduler = mock(DAGScheduler.class);
startDAG(dag);
dispatcher.await();
TezVertexID vId = TezVertexID.getInstance(dagId, 1);
Vertex v = dag.getVertex(vId);
dispatcher.getEventHandler().handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId, 0), TaskState.SUCCEEDED));
dispatcher.getEventHandler().handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId, 1), TaskState.SUCCEEDED));
dispatcher.await();
Assert.assertEquals(VertexState.SUCCEEDED, v.getState());
Assert.assertEquals(1, dag.getSuccessfulVertices());
Assert.assertEquals(1, dag.numCompletedVertices);
dispatcher.getEventHandler().handle(new VertexEventTaskReschedule(TezTaskID.getInstance(vId, 0)));
dispatcher.await();
Assert.assertEquals(VertexState.RUNNING, v.getState());
Assert.assertEquals(0, dag.getSuccessfulVertices());
Assert.assertEquals(0, dag.numCompletedVertices);
dispatcher.getEventHandler().handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId, 0), TaskState.SUCCEEDED));
dispatcher.await();
Assert.assertEquals(VertexState.SUCCEEDED, v.getState());
Assert.assertEquals(1, dag.getSuccessfulVertices());
Assert.assertEquals(1, dag.numCompletedVertices);
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGImpl method _testDAGKillVertexSuccessAfterTerminated.
// Vertices succeed after a DAG kill has been processed. Should be ignored.
@SuppressWarnings("unchecked")
private void _testDAGKillVertexSuccessAfterTerminated(DAGTerminationCause terminationCause) {
initDAG(dag);
startDAG(dag);
dispatcher.await();
dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 0), VertexState.SUCCEEDED));
dispatcher.await();
Assert.assertEquals(DAGState.RUNNING, dag.getState());
dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 1), VertexState.SUCCEEDED));
dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, terminationCause, null));
dispatcher.await();
Assert.assertEquals(terminationCause.getFinishedState(), dag.getState());
// Vertex SUCCESS gets processed after the DAG has reached the KILLED state. Should be ignored.
for (int i = 2; i < 6; ++i) {
dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, i), VertexState.SUCCEEDED));
}
dispatcher.await();
int killedCount = 0;
for (Map.Entry<TezVertexID, Vertex> vEntry : dag.getVertices().entrySet()) {
if (vEntry.getValue().getState() == VertexState.KILLED) {
killedCount++;
}
}
Assert.assertEquals(4, killedCount);
Assert.assertEquals(terminationCause, dag.getTerminationCause());
Assert.assertEquals(2, dag.getSuccessfulVertices());
for (Vertex v : dag.getVertices().values()) {
Assert.assertEquals(VertexTerminationCause.DAG_TERMINATED, v.getTerminationCause());
}
Assert.assertEquals(1, dagFinishEventHandler.dagFinishEvents);
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGScheduler method testConcurrencyLimit.
@Test(timeout = 5000)
public void testConcurrencyLimit() {
MockEventHandler mockEventHandler = new MockEventHandler();
DAG mockDag = mock(DAG.class);
when(mockDag.getTotalVertices()).thenReturn(2);
TezVertexID vId0 = TezVertexID.fromString("vertex_1436907267600_195589_1_00");
TezVertexID vId1 = TezVertexID.fromString("vertex_1436907267600_195589_1_01");
TezTaskID tId0 = TezTaskID.getInstance(vId0, 0);
TezTaskID tId1 = TezTaskID.getInstance(vId1, 0);
TaskAttempt mockAttempt;
Vertex mockVertex = mock(Vertex.class);
when(mockDag.getVertex((TezVertexID) any())).thenReturn(mockVertex);
when(mockVertex.getDistanceFromRoot()).thenReturn(0);
when(mockVertex.getVertexId()).thenReturn(vId0);
DAGScheduler scheduler = new DAGSchedulerNaturalOrder(mockDag, mockEventHandler);
// not effective
scheduler.addVertexConcurrencyLimit(vId0, 0);
// schedule beyond limit and it gets scheduled
mockAttempt = mock(TaskAttempt.class);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId0, 0));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
Assert.assertEquals(1, mockEventHandler.events.size());
mockAttempt = mock(TaskAttempt.class);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId0, 1));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
Assert.assertEquals(2, mockEventHandler.events.size());
mockAttempt = mock(TaskAttempt.class);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId0, 2));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
Assert.assertEquals(3, mockEventHandler.events.size());
mockEventHandler.events.clear();
List<TaskAttempt> mockAttempts = Lists.newArrayList();
int completed = 0;
int requested = 0;
int scheduled = 0;
// effective
scheduler.addVertexConcurrencyLimit(vId1, 2);
// schedule beyond limit and it gets buffered
mockAttempt = mock(TaskAttempt.class);
mockAttempts.add(mockAttempt);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId1, requested++));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
// scheduled
Assert.assertEquals(scheduled + 1, mockEventHandler.events.size());
Assert.assertEquals(mockAttempts.get(scheduled).getID(), // matches order
mockEventHandler.events.get(scheduled).getTaskAttemptID());
scheduled++;
mockAttempt = mock(TaskAttempt.class);
mockAttempts.add(mockAttempt);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId1, requested++));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
// scheduled
Assert.assertEquals(scheduled + 1, mockEventHandler.events.size());
Assert.assertEquals(mockAttempts.get(scheduled).getID(), // matches order
mockEventHandler.events.get(scheduled).getTaskAttemptID());
scheduled++;
mockAttempt = mock(TaskAttempt.class);
mockAttempts.add(mockAttempt);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId1, requested++));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
// buffered
Assert.assertEquals(scheduled, mockEventHandler.events.size());
mockAttempt = mock(TaskAttempt.class);
mockAttempts.add(mockAttempt);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId1, requested++));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
// buffered
Assert.assertEquals(scheduled, mockEventHandler.events.size());
scheduler.taskCompleted(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_COMPLETED, mockAttempts.get(completed++)));
// scheduled
Assert.assertEquals(scheduled + 1, mockEventHandler.events.size());
Assert.assertEquals(mockAttempts.get(scheduled).getID(), // matches order
mockEventHandler.events.get(scheduled).getTaskAttemptID());
scheduled++;
scheduler.taskCompleted(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_COMPLETED, mockAttempts.get(completed++)));
// scheduled
Assert.assertEquals(scheduled + 1, mockEventHandler.events.size());
Assert.assertEquals(mockAttempts.get(scheduled).getID(), // matches order
mockEventHandler.events.get(scheduled).getTaskAttemptID());
scheduled++;
scheduler.taskCompleted(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_COMPLETED, mockAttempts.get(completed++)));
// no extra scheduling
Assert.assertEquals(scheduled, mockEventHandler.events.size());
mockAttempt = mock(TaskAttempt.class);
mockAttempts.add(mockAttempt);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId1, requested++));
scheduler.scheduleTask(new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt));
// scheduled
Assert.assertEquals(scheduled + 1, mockEventHandler.events.size());
Assert.assertEquals(mockAttempts.get(scheduled).getID(), // matches order
mockEventHandler.events.get(scheduled).getTaskAttemptID());
scheduled++;
}
Aggregations