use of org.apache.tez.runtime.api.impl.TezEvent in project tez by apache.
the class TestVertexImpl method testVertexGetTAAttemptsObsoletionWithPendingRoutes.
@Test(timeout = 5000)
public void testVertexGetTAAttemptsObsoletionWithPendingRoutes() throws Exception {
initAllVertices(VertexState.INITED);
VertexImpl v1 = vertices.get("vertex1");
startVertex(v1);
VertexImpl v2 = vertices.get("vertex2");
startVertex(v2);
VertexImpl v3 = vertices.get("vertex3");
VertexImpl v4 = vertices.get("vertex4");
List<ScheduleTaskRequest> taskList = new LinkedList<VertexManagerPluginContext.ScheduleTaskRequest>();
// scheduling start to trigger edge routing to begin
for (int i = 0; i < v4.getTotalTasks(); ++i) {
taskList.add(ScheduleTaskRequest.create(i, null));
}
v4.scheduleTasks(taskList);
Assert.assertEquals(VertexState.RUNNING, v4.getState());
Assert.assertEquals(1, v4.sourceVertices.size());
Edge e = v4.sourceVertices.get(v3);
TezTaskAttemptID v3TaId = TezTaskAttemptID.getInstance(TezTaskID.getInstance(v3.getVertexId(), 0), 0);
TezTaskAttemptID v4TaId = TezTaskAttemptID.getInstance(TezTaskID.getInstance(v4.getVertexId(), 0), 0);
for (int i = 0; i < 11; ++i) {
v4.handle(new VertexEventRouteEvent(v4.getVertexId(), Collections.singletonList(new TezEvent(DataMovementEvent.create(0, null), new EventMetaData(EventProducerConsumerType.OUTPUT, v3.getName(), v3.getName(), v3TaId)))));
}
dispatcher.await();
// verify all events have been are in taskEvents
Assert.assertEquals(11, v4.getOnDemandRouteEvents().size());
TaskAttemptEventInfo eventInfo;
EdgeManagerPluginOnDemand mockPlugin = mock(EdgeManagerPluginOnDemand.class);
EventRouteMetadata mockFailedRoute = EventRouteMetadata.create(1, new int[] { 0 });
e.edgeManager = mockPlugin;
when(mockPlugin.routeInputSourceTaskFailedEventToDestination(anyInt(), anyInt())).thenReturn(mockFailedRoute);
// return more events that dont evenly fit in max size
EventRouteMetadata mockRoute = EventRouteMetadata.create(2, new int[] { 0, 0 });
when(mockPlugin.routeDataMovementEventToDestination(anyInt(), anyInt(), anyInt())).thenReturn(mockRoute);
int fromEventId = 0;
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 5);
fromEventId = eventInfo.getNextFromEventId();
// 0-1 events expanded and fit, 2nd event has pending routes
Assert.assertEquals(2, fromEventId);
Assert.assertEquals(5, eventInfo.getEvents().size());
// send an input failed event
v4.handle(new VertexEventRouteEvent(v4.getVertexId(), Collections.singletonList(new TezEvent(InputFailedEvent.create(0, 0), new EventMetaData(EventProducerConsumerType.OUTPUT, v3.getName(), v3.getName(), v3TaId)))));
// get only input failed event. all DM events obsoleted
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 5);
fromEventId = eventInfo.getNextFromEventId();
Assert.assertEquals(12, fromEventId);
Assert.assertEquals(1, eventInfo.getEvents().size());
Assert.assertEquals(EventType.INPUT_FAILED_EVENT, eventInfo.getEvents().get(0).getEventType());
}
use of org.apache.tez.runtime.api.impl.TezEvent in project tez by apache.
the class TestVertexImpl method testVertexGetTAAttempts.
@Test(timeout = 5000)
public void testVertexGetTAAttempts() throws Exception {
initAllVertices(VertexState.INITED);
VertexImpl v1 = vertices.get("vertex1");
startVertex(v1);
VertexImpl v2 = vertices.get("vertex2");
startVertex(v2);
VertexImpl v3 = vertices.get("vertex3");
VertexImpl v4 = vertices.get("vertex4");
Assert.assertEquals(VertexState.RUNNING, v4.getState());
Assert.assertEquals(1, v4.sourceVertices.size());
Edge e = v4.sourceVertices.get(v3);
TezTaskAttemptID v3TaId = TezTaskAttemptID.getInstance(TezTaskID.getInstance(v3.getVertexId(), 0), 0);
TezTaskAttemptID v4TaId = TezTaskAttemptID.getInstance(TezTaskID.getInstance(v4.getVertexId(), 0), 0);
for (int i = 0; i < 5; ++i) {
v4.handle(new VertexEventRouteEvent(v4.getVertexId(), Collections.singletonList(new TezEvent(DataMovementEvent.create(0, null), new EventMetaData(EventProducerConsumerType.OUTPUT, v3.getName(), v3.getName(), v3TaId)))));
}
dispatcher.await();
// verify all events have been put in pending.
// this is not necessary after legacy routing has been removed
Assert.assertEquals(5, v4.pendingTaskEvents.size());
List<ScheduleTaskRequest> taskList = new LinkedList<VertexManagerPluginContext.ScheduleTaskRequest>();
// scheduling start to trigger edge routing to begin
for (int i = 0; i < v4.getTotalTasks(); ++i) {
taskList.add(ScheduleTaskRequest.create(i, null));
}
v4.scheduleTasks(taskList);
dispatcher.await();
// verify all events have been moved to taskEvents
Assert.assertEquals(5, v4.getOnDemandRouteEvents().size());
for (int i = 5; i < 11; ++i) {
v4.handle(new VertexEventRouteEvent(v4.getVertexId(), Collections.singletonList(new TezEvent(DataMovementEvent.create(0, null), new EventMetaData(EventProducerConsumerType.OUTPUT, v3.getName(), v3.getName(), v3TaId)))));
}
dispatcher.await();
// verify all events have been are in taskEvents
Assert.assertEquals(11, v4.getOnDemandRouteEvents().size());
TaskAttemptEventInfo eventInfo;
EdgeManagerPluginOnDemand mockPlugin = mock(EdgeManagerPluginOnDemand.class);
EventRouteMetadata mockRoute = EventRouteMetadata.create(1, new int[] { 0 });
e.edgeManager = mockPlugin;
// source task id will not match. all events will return null
when(mockPlugin.routeDataMovementEventToDestination(1, 0, 0)).thenReturn(mockRoute);
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, 0, 0, 1);
// all events traversed
Assert.assertEquals(11, eventInfo.getNextFromEventId());
// no events
Assert.assertEquals(0, eventInfo.getEvents().size());
int fromEventId = 0;
// source task id will match. all events will be returned
// max events is respected.
when(mockPlugin.routeDataMovementEventToDestination(anyInt(), anyInt(), anyInt())).thenReturn(mockRoute);
for (int i = 0; i < 11; ++i) {
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 1);
fromEventId = eventInfo.getNextFromEventId();
Assert.assertEquals((i + 1), fromEventId);
Assert.assertEquals(1, eventInfo.getEvents().size());
}
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 1);
// all events traversed
Assert.assertEquals(11, eventInfo.getNextFromEventId());
// no events
Assert.assertEquals(0, eventInfo.getEvents().size());
// ask for events with sufficient buffer. get all events in a single shot.
fromEventId = 0;
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 100);
fromEventId = eventInfo.getNextFromEventId();
Assert.assertEquals(11, fromEventId);
Assert.assertEquals(11, eventInfo.getEvents().size());
// change max events to larger value. max events does not evenly divide total events
fromEventId = 0;
for (int i = 1; i <= 2; ++i) {
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 5);
fromEventId = eventInfo.getNextFromEventId();
Assert.assertEquals((i * 5), fromEventId);
Assert.assertEquals(5, eventInfo.getEvents().size());
}
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 5);
// all events traversed
Assert.assertEquals(11, eventInfo.getNextFromEventId());
// remainder events
Assert.assertEquals(1, eventInfo.getEvents().size());
// return more events that dont evenly fit in max size
mockRoute = EventRouteMetadata.create(2, new int[] { 0, 0 });
when(mockPlugin.routeDataMovementEventToDestination(anyInt(), anyInt(), anyInt())).thenReturn(mockRoute);
fromEventId = 0;
int lastFromEventId = 0;
for (int i = 1; i <= 4; ++i) {
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 5);
fromEventId = eventInfo.getNextFromEventId();
Assert.assertEquals((i % 2 > 0 ? (lastFromEventId += 2) : (lastFromEventId += 3)), fromEventId);
Assert.assertEquals(5, eventInfo.getEvents().size());
}
eventInfo = v4.getTaskAttemptTezEvents(v4TaId, fromEventId, 0, 5);
// all events traversed
Assert.assertEquals(11, eventInfo.getNextFromEventId());
// remainder events
Assert.assertEquals(2, eventInfo.getEvents().size());
}
use of org.apache.tez.runtime.api.impl.TezEvent in project tez by apache.
the class TestVertexManager method testOnRootVertexInitialized2.
/**
* TEZ-1647
* custom vertex manager generates events only when both i1 and i2 are initialized.
* @throws Exception
*/
@Test(timeout = 5000)
public void testOnRootVertexInitialized2() throws Exception {
VertexManager vm = new VertexManager(VertexManagerPluginDescriptor.create(CustomVertexManager.class.getName()), UserGroupInformation.getCurrentUser(), mockVertex, mockAppContext, mock(StateChangeNotifier.class));
vm.initialize();
InputDescriptor id1 = mock(InputDescriptor.class);
List<Event> events1 = new LinkedList<Event>();
InputDataInformationEvent diEvent1 = InputDataInformationEvent.createWithSerializedPayload(0, null);
events1.add(diEvent1);
// do not call context.addRootInputEvents, just cache the TezEvent
vm.onRootVertexInitialized("input1", id1, events1);
verify(mockHandler, times(1)).handle(requestCaptor.capture());
List<TezEvent> tezEventsAfterInput1 = requestCaptor.getValue().getEvents();
assertEquals(0, tezEventsAfterInput1.size());
InputDescriptor id2 = mock(InputDescriptor.class);
List<Event> events2 = new LinkedList<Event>();
InputDataInformationEvent diEvent2 = InputDataInformationEvent.createWithSerializedPayload(0, null);
events2.add(diEvent2);
// call context.addRootInputEvents(input1), context.addRootInputEvents(input2)
vm.onRootVertexInitialized("input2", id2, events2);
verify(mockHandler, times(2)).handle(requestCaptor.capture());
List<TezEvent> tezEventsAfterInput2 = requestCaptor.getValue().getEvents();
assertEquals(2, tezEventsAfterInput2.size());
// also verify the EventMetaData
Set<String> edgeVertexSet = new HashSet<String>();
for (TezEvent tezEvent : tezEventsAfterInput2) {
edgeVertexSet.add(tezEvent.getDestinationInfo().getEdgeVertexName());
}
assertEquals(Sets.newHashSet("input1", "input2"), edgeVertexSet);
}
use of org.apache.tez.runtime.api.impl.TezEvent in project tez by apache.
the class TestVertexManager method testOnRootVertexInitialized.
@Test(timeout = 5000)
public void testOnRootVertexInitialized() throws Exception {
Configuration conf = new Configuration();
VertexManager vm = new VertexManager(RootInputVertexManager.createConfigBuilder(conf).build(), UserGroupInformation.getCurrentUser(), mockVertex, mockAppContext, mock(StateChangeNotifier.class));
vm.initialize();
InputDescriptor id1 = mock(InputDescriptor.class);
List<Event> events1 = new LinkedList<Event>();
InputDataInformationEvent diEvent1 = InputDataInformationEvent.createWithSerializedPayload(0, null);
events1.add(diEvent1);
vm.onRootVertexInitialized("input1", id1, events1);
verify(mockHandler, times(1)).handle(requestCaptor.capture());
List<TezEvent> tezEvents1 = requestCaptor.getValue().getEvents();
assertEquals(1, tezEvents1.size());
assertEquals(diEvent1, tezEvents1.get(0).getEvent());
InputDescriptor id2 = mock(InputDescriptor.class);
List<Event> events2 = new LinkedList<Event>();
InputDataInformationEvent diEvent2 = InputDataInformationEvent.createWithSerializedPayload(0, null);
events2.add(diEvent2);
vm.onRootVertexInitialized("input1", id2, events2);
verify(mockHandler, times(2)).handle(requestCaptor.capture());
List<TezEvent> tezEvents2 = requestCaptor.getValue().getEvents();
assertEquals(tezEvents2.size(), 1);
assertEquals(diEvent2, tezEvents2.get(0).getEvent());
}
use of org.apache.tez.runtime.api.impl.TezEvent in project tez by apache.
the class TestTaskImpl method testTaskSucceedAndRetroActiveFailure.
@SuppressWarnings("rawtypes")
@Test(timeout = 5000)
public void testTaskSucceedAndRetroActiveFailure() {
TezTaskID taskId = getNewTaskID();
scheduleTaskAttempt(taskId);
launchTaskAttempt(mockTask.getLastAttempt().getTaskAttemptID());
updateAttemptState(mockTask.getLastAttempt(), TaskAttemptState.RUNNING);
mockTask.handle(createTaskTASucceededEvent(mockTask.getLastAttempt().getTaskAttemptID()));
// The task should now have succeeded
assertTaskSucceededState();
verify(mockTask.stateChangeNotifier).taskSucceeded(any(String.class), eq(taskId), eq(mockTask.getLastAttempt().getTaskAttemptID().getId()));
ArgumentCaptor<DAGHistoryEvent> argumentCaptor = ArgumentCaptor.forClass(DAGHistoryEvent.class);
verify(mockHistoryHandler).handle(argumentCaptor.capture());
DAGHistoryEvent dagHistoryEvent = argumentCaptor.getValue();
HistoryEvent historyEvent = dagHistoryEvent.getHistoryEvent();
assertTrue(historyEvent instanceof TaskFinishedEvent);
TaskFinishedEvent taskFinishedEvent = (TaskFinishedEvent) historyEvent;
assertEquals(taskFinishedEvent.getFinishTime(), mockTask.getFinishTime());
eventHandler.events.clear();
// Now fail the attempt after it has succeeded
TezTaskAttemptID mockDestId = mock(TezTaskAttemptID.class);
TezEvent mockTezEvent = mock(TezEvent.class);
EventMetaData meta = new EventMetaData(EventProducerConsumerType.INPUT, "Vertex", "Edge", mockDestId);
when(mockTezEvent.getSourceInfo()).thenReturn(meta);
TaskAttemptEventOutputFailed outputFailedEvent = new TaskAttemptEventOutputFailed(mockDestId, mockTezEvent, 1);
mockTask.handle(createTaskTAFailedEvent(mockTask.getLastAttempt().getTaskAttemptID(), TaskFailureType.NON_FATAL, outputFailedEvent));
// The task should still be in the scheduled state
assertTaskScheduledState();
Event event = eventHandler.events.get(0);
Assert.assertEquals(AMNodeEventType.N_TA_ENDED, event.getType());
event = eventHandler.events.get(eventHandler.events.size() - 1);
Assert.assertEquals(VertexEventType.V_TASK_RESCHEDULED, event.getType());
// report of output read error should be the causal TA
List<MockTaskAttemptImpl> attempts = mockTask.getAttemptList();
Assert.assertEquals(2, attempts.size());
MockTaskAttemptImpl newAttempt = attempts.get(1);
Assert.assertEquals(mockDestId, newAttempt.getSchedulingCausalTA());
}
Aggregations