use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestTaskAttempt method testNodeFailedLeafVertex.
@Test(timeout = 5000)
public // Ensure node failure on Successful Leaf tasks do not cause them to be marked as KILLED
void testNodeFailedLeafVertex() throws Exception {
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(), true);
TezTaskAttemptID taskAttemptID = taImpl.getID();
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
taImpl.handle(new TaskAttemptEventSchedule(taskAttemptID, 0, 0));
taImpl.handle(new TaskAttemptEventSubmitted(taskAttemptID, contId));
taImpl.handle(new TaskAttemptEventStartedRemotely(taskAttemptID));
assertEquals("Task attempt is not in the RUNNING state", TaskAttemptState.RUNNING, taImpl.getState());
verify(mockHeartbeatHandler).register(taskAttemptID);
int expectedEventsAtRunning = 5;
verify(eventHandler, times(expectedEventsAtRunning)).handle(arg.capture());
taImpl.handle(new TaskAttemptEvent(taskAttemptID, TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt is not in the SUCCEEDED state", TaskAttemptState.SUCCEEDED, taImpl.getState());
verify(mockHeartbeatHandler).unregister(taskAttemptID);
assertEquals(0, taImpl.getDiagnostics().size());
int expectedEvenstAfterTerminating = expectedEventsAtRunning + 3;
arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(expectedEvenstAfterTerminating)).handle(arg.capture());
verifyEventType(arg.getAllValues().subList(expectedEventsAtRunning, expectedEvenstAfterTerminating), TaskEventTASucceeded.class, 1);
verifyEventType(arg.getAllValues().subList(expectedEventsAtRunning, expectedEvenstAfterTerminating), AMSchedulerEventTAEnded.class, 1);
verifyEventType(arg.getAllValues().subList(expectedEventsAtRunning, expectedEvenstAfterTerminating), DAGEventCounterUpdate.class, 1);
// Send out a Node Failure.
taImpl.handle(new TaskAttemptEventNodeFailed(taskAttemptID, "NodeDecomissioned", TaskAttemptTerminationCause.NODE_FAILED));
// Verify no additional events
int expectedEventsNodeFailure = expectedEvenstAfterTerminating + 0;
arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(expectedEventsNodeFailure)).handle(arg.capture());
// Verify still in SUCCEEDED state
assertEquals("Task attempt is not in the SUCCEEDED state", TaskAttemptState.SUCCEEDED, taImpl.getState());
// verify unregister is not invoked again
verify(mockHeartbeatHandler, times(1)).unregister(taskAttemptID);
// error cause remains as default value
assertEquals(TaskAttemptTerminationCause.UNKNOWN_ERROR, taImpl.getTerminationCause());
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGImpl method testVertexCompletion.
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testVertexCompletion() {
initDAG(dag);
Assert.assertTrue(0.0f == dag.getCompletedTaskProgress());
startDAG(dag);
Assert.assertTrue(0.0f == dag.getCompletedTaskProgress());
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());
// 2 tasks completed, total plan has 11 vertices
Assert.assertEquals((float) 2 / 11, dag.getCompletedTaskProgress(), 0.05);
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGScheduler method testConcurrencyLimitWithKilledNonRunningTask.
@Test(timeout = 5000)
public void testConcurrencyLimitWithKilledNonRunningTask() {
MockEventHandler mockEventHandler = new MockEventHandler();
DAG mockDag = mock(DAG.class);
when(mockDag.getTotalVertices()).thenReturn(2);
TezVertexID vId0 = TezVertexID.fromString("vertex_1436907267600_195589_1_00");
TezTaskID tId0 = TezTaskID.getInstance(vId0, 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);
List<TaskAttempt> mockAttempts = Lists.newArrayList();
int completed = 0;
int requested = 0;
int scheduled = 0;
// effective
scheduler.addVertexConcurrencyLimit(vId0, 1);
// schedule beyond limit and it gets buffered
mockAttempt = mock(TaskAttempt.class);
mockAttempts.add(mockAttempt);
when(mockAttempt.getID()).thenReturn(TezTaskAttemptID.getInstance(tId0, 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(tId0, 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(tId0, 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(1)));
// buffered
Assert.assertEquals(scheduled, mockEventHandler.events.size());
Assert.assertEquals(mockAttempts.get(0).getID(), // matches order
mockEventHandler.events.get(0).getTaskAttemptID());
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestDAGScheduler method testDAGSchedulerNaturalOrder.
@Test(timeout = 5000)
public void testDAGSchedulerNaturalOrder() {
MockEventHandler mockEventHandler = new MockEventHandler();
DAG mockDag = mock(DAG.class);
Vertex mockVertex = mock(Vertex.class);
TaskAttempt mockAttempt = mock(TaskAttempt.class);
when(mockDag.getVertex((TezVertexID) any())).thenReturn(mockVertex);
when(mockDag.getTotalVertices()).thenReturn(4);
when(mockVertex.getDistanceFromRoot()).thenReturn(0).thenReturn(1).thenReturn(2);
TezVertexID vId0 = TezVertexID.fromString("vertex_1436907267600_195589_1_00");
TezVertexID vId1 = TezVertexID.fromString("vertex_1436907267600_195589_1_01");
TezVertexID vId2 = TezVertexID.fromString("vertex_1436907267600_195589_1_02");
TezVertexID vId3 = TezVertexID.fromString("vertex_1436907267600_195589_1_03");
when(mockVertex.getVertexId()).thenReturn(vId0).thenReturn(vId1).thenReturn(vId2).thenReturn(vId3);
DAGEventSchedulerUpdate event = new DAGEventSchedulerUpdate(DAGEventSchedulerUpdate.UpdateType.TA_SCHEDULE, mockAttempt);
DAGScheduler scheduler = new DAGSchedulerNaturalOrder(mockDag, mockEventHandler);
scheduler.scheduleTaskEx(event);
Assert.assertEquals(10, mockEventHandler.event.getPriorityHighLimit());
Assert.assertEquals(12, mockEventHandler.event.getPriorityLowLimit());
scheduler.scheduleTaskEx(event);
Assert.assertEquals(25, mockEventHandler.event.getPriorityHighLimit());
Assert.assertEquals(27, mockEventHandler.event.getPriorityLowLimit());
scheduler.scheduleTaskEx(event);
Assert.assertEquals(40, mockEventHandler.event.getPriorityHighLimit());
Assert.assertEquals(42, mockEventHandler.event.getPriorityLowLimit());
scheduler.scheduleTaskEx(event);
Assert.assertEquals(43, mockEventHandler.event.getPriorityHighLimit());
Assert.assertEquals(45, mockEventHandler.event.getPriorityLowLimit());
}
use of org.apache.tez.dag.records.TezVertexID in project tez by apache.
the class TestEdge method testInvalidSourceTaskIndex.
@Test(timeout = 5000)
public void testInvalidSourceTaskIndex() throws Exception {
EventHandler mockEventHandler = mock(EventHandler.class);
Edge edge = new Edge(EdgeProperty.create(EdgeManagerPluginDescriptor.create(CustomEdgeManagerWithInvalidReturnValue.class.getName()).setUserPayload(new CustomEdgeManagerWithInvalidReturnValue.EdgeManagerConfig(1, 1, 1, -1).toUserPayload()), DataSourceType.PERSISTED, SchedulingType.SEQUENTIAL, OutputDescriptor.create(""), InputDescriptor.create("")), mockEventHandler, new TezConfiguration());
TezVertexID v1Id = createVertexID(1);
TezVertexID v2Id = createVertexID(2);
edge.setSourceVertex(mockVertex("v1", v1Id, new LinkedHashMap<TezTaskID, Task>()));
edge.setDestinationVertex(mockVertex("v2", v2Id, new LinkedHashMap<TezTaskID, Task>()));
edge.initialize();
try {
TezEvent ireEvent = new TezEvent(InputReadErrorEvent.create("diag", 0, 1), new EventMetaData(EventProducerConsumerType.INPUT, "v2", "v1", TezTaskAttemptID.getInstance(TezTaskID.getInstance(v2Id, 1), 1)));
edge.sendTezEventToSourceTasks(ireEvent);
Assert.fail();
} catch (AMUserCodeException e) {
e.printStackTrace();
assertTrue(e.getCause().getMessage().contains("SourceTaskIndex should not be negative"));
}
}
Aggregations