use of org.apache.tez.dag.app.rm.AMSchedulerEventTALaunchRequest in project tez by apache.
the class TestTaskAttempt method testRetriesAtSamePriorityConfig.
@Test(timeout = 5000)
public void testRetriesAtSamePriorityConfig() {
// Override the test defaults to setup the config change
TezConfiguration vertexConf = new TezConfiguration();
vertexConf.setBoolean(TezConfiguration.TEZ_AM_TASK_RESCHEDULE_HIGHER_PRIORITY, false);
vertexConf.setBoolean(TezConfiguration.TEZ_AM_TASK_RESCHEDULE_RELAXED_LOCALITY, true);
when(mockVertex.getVertexConfig()).thenReturn(new VertexImpl.VertexConfigImpl(vertexConf));
// set locality
Set<String> hosts = new TreeSet<String>();
hosts.add("host1");
locationHint = TaskLocationHint.createTaskLocationHint(hosts, null);
TaskAttemptImpl.ScheduleTaskattemptTransition sta = new TaskAttemptImpl.ScheduleTaskattemptTransition();
EventHandler eventHandler = mock(EventHandler.class);
TezTaskID taskID = TezTaskID.getInstance(TezVertexID.getInstance(TezDAGID.getInstance("1", 1, 1), 1), 1);
TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, mock(TaskCommunicatorManagerInterface.class), new Configuration(), new SystemClock(), mock(TaskHeartbeatHandler.class), appCtx, false, Resource.newInstance(1024, 1), createFakeContainerContext(), false);
TaskAttemptImpl taImplReScheduled = new MockTaskAttemptImpl(taskID, 1, eventHandler, mock(TaskCommunicatorManagerInterface.class), new Configuration(), new SystemClock(), mock(TaskHeartbeatHandler.class), appCtx, true, Resource.newInstance(1024, 1), createFakeContainerContext(), false);
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
TaskAttemptEventSchedule sEvent = mock(TaskAttemptEventSchedule.class);
when(sEvent.getPriorityLowLimit()).thenReturn(3);
when(sEvent.getPriorityHighLimit()).thenReturn(1);
// Verify priority for a non-retried attempt
sta.transition(taImpl, sEvent);
verify(eventHandler, times(1)).handle(arg.capture());
AMSchedulerEventTALaunchRequest launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(2, launchEvent.getPriority());
Assert.assertEquals(1, launchEvent.getLocationHint().getHosts().size());
Assert.assertTrue(launchEvent.getLocationHint().getHosts().contains("host1"));
// Verify priority for a retried attempt is the same
sta.transition(taImplReScheduled, sEvent);
verify(eventHandler, times(2)).handle(arg.capture());
launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(2, launchEvent.getPriority());
Assert.assertNull(launchEvent.getLocationHint());
}
use of org.apache.tez.dag.app.rm.AMSchedulerEventTALaunchRequest in project tez by apache.
the class TestTaskAttempt method testLocalityRequest.
@Test(timeout = 5000)
public void testLocalityRequest() {
TaskAttemptImpl.ScheduleTaskattemptTransition sta = new TaskAttemptImpl.ScheduleTaskattemptTransition();
EventHandler eventHandler = mock(EventHandler.class);
Set<String> hosts = new TreeSet<String>();
hosts.add("host1");
hosts.add("host2");
hosts.add("host3");
locationHint = TaskLocationHint.createTaskLocationHint(hosts, null);
TezTaskID taskID = TezTaskID.getInstance(TezVertexID.getInstance(TezDAGID.getInstance("1", 1, 1), 1), 1);
TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, mock(TaskCommunicatorManagerInterface.class), new Configuration(), new SystemClock(), mock(TaskHeartbeatHandler.class), appCtx, false, Resource.newInstance(1024, 1), createFakeContainerContext(), false);
TaskAttemptEventSchedule sEvent = mock(TaskAttemptEventSchedule.class);
sta.transition(taImpl, sEvent);
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(1)).handle(arg.capture());
if (!(arg.getAllValues().get(0) instanceof AMSchedulerEventTALaunchRequest)) {
fail("Second event not of type " + AMSchedulerEventTALaunchRequest.class.getName());
}
// TODO Move the Rack request check to the client after TEZ-125 is fixed.
Set<String> requestedRacks = taImpl.taskRacks;
assertEquals(1, requestedRacks.size());
assertEquals(3, taImpl.taskHosts.size());
for (int i = 0; i < 3; i++) {
String host = ("host" + (i + 1));
assertEquals(host, true, taImpl.taskHosts.contains(host));
}
}
use of org.apache.tez.dag.app.rm.AMSchedulerEventTALaunchRequest in project tez by apache.
the class TestVertexImpl method testPickupDagLocalResourceOnScheduleTask.
@Test(timeout = 5000)
public void testPickupDagLocalResourceOnScheduleTask() {
initAllVertices(VertexState.INITED);
VertexImpl v1 = vertices.get("vertex1");
startVertex(v1);
TezTaskAttemptID taskAttemptId0 = TezTaskAttemptID.getInstance(v1.getTask(0).getTaskId(), 0);
TaskAttemptImpl ta0 = (TaskAttemptImpl) v1.getTask(0).getAttempt(taskAttemptId0);
ta0.handle(new TaskAttemptEventSchedule(taskAttemptId0, 1, 1));
dispatcher.await();
Assert.assertEquals(1, amSchedulerEventDispatcher.events.size());
AMSchedulerEventTALaunchRequest launchRequestEvent = (AMSchedulerEventTALaunchRequest) amSchedulerEventDispatcher.events.get(0);
Map<String, LocalResource> localResourceMap = launchRequestEvent.getContainerContext().getLocalResources();
Assert.assertTrue(localResourceMap.containsKey("dag lr"));
Assert.assertTrue(localResourceMap.containsKey("vertex lr"));
}
use of org.apache.tez.dag.app.rm.AMSchedulerEventTALaunchRequest in project tez by apache.
the class TestTaskAttempt method testPriority.
@Test(timeout = 5000)
public void testPriority() {
TaskAttemptImpl.ScheduleTaskattemptTransition sta = new TaskAttemptImpl.ScheduleTaskattemptTransition();
EventHandler eventHandler = mock(EventHandler.class);
TezTaskID taskID = TezTaskID.getInstance(TezVertexID.getInstance(TezDAGID.getInstance("1", 1, 1), 1), 1);
TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, mock(TaskCommunicatorManagerInterface.class), new Configuration(), new SystemClock(), mock(TaskHeartbeatHandler.class), appCtx, false, Resource.newInstance(1024, 1), createFakeContainerContext(), false);
TaskAttemptImpl taImplReScheduled = new MockTaskAttemptImpl(taskID, 1, eventHandler, mock(TaskCommunicatorManagerInterface.class), new Configuration(), new SystemClock(), mock(TaskHeartbeatHandler.class), appCtx, true, Resource.newInstance(1024, 1), createFakeContainerContext(), false);
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
TaskAttemptEventSchedule sEvent = mock(TaskAttemptEventSchedule.class);
when(sEvent.getPriorityLowLimit()).thenReturn(3);
when(sEvent.getPriorityHighLimit()).thenReturn(1);
sta.transition(taImpl, sEvent);
verify(eventHandler, times(1)).handle(arg.capture());
AMSchedulerEventTALaunchRequest launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(2, launchEvent.getPriority());
sta.transition(taImplReScheduled, sEvent);
verify(eventHandler, times(2)).handle(arg.capture());
launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(1, launchEvent.getPriority());
when(sEvent.getPriorityLowLimit()).thenReturn(6);
when(sEvent.getPriorityHighLimit()).thenReturn(4);
sta.transition(taImpl, sEvent);
verify(eventHandler, times(3)).handle(arg.capture());
launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(5, launchEvent.getPriority());
sta.transition(taImplReScheduled, sEvent);
verify(eventHandler, times(4)).handle(arg.capture());
launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(4, launchEvent.getPriority());
when(sEvent.getPriorityLowLimit()).thenReturn(5);
when(sEvent.getPriorityHighLimit()).thenReturn(5);
sta.transition(taImpl, sEvent);
verify(eventHandler, times(5)).handle(arg.capture());
launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(5, launchEvent.getPriority());
sta.transition(taImplReScheduled, sEvent);
verify(eventHandler, times(6)).handle(arg.capture());
launchEvent = (AMSchedulerEventTALaunchRequest) arg.getValue();
Assert.assertEquals(5, launchEvent.getPriority());
}
use of org.apache.tez.dag.app.rm.AMSchedulerEventTALaunchRequest in project tez by apache.
the class TestTaskAttempt method testHostResolveAttempt.
@Test(timeout = 5000)
public // TODO Move to the client post TEZ-125.
void testHostResolveAttempt() throws Exception {
TaskAttemptImpl.ScheduleTaskattemptTransition sta = new TaskAttemptImpl.ScheduleTaskattemptTransition();
EventHandler eventHandler = mock(EventHandler.class);
String[] hosts = new String[] { "127.0.0.1", "host2", "host3" };
Set<String> resolved = new TreeSet<String>(Arrays.asList(new String[] { "host1", "host2", "host3" }));
locationHint = TaskLocationHint.createTaskLocationHint(new TreeSet<String>(Arrays.asList(hosts)), null);
TezTaskID taskID = TezTaskID.getInstance(TezVertexID.getInstance(TezDAGID.getInstance("1", 1, 1), 1), 1);
TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, mock(TaskCommunicatorManagerInterface.class), new Configuration(), new SystemClock(), mock(TaskHeartbeatHandler.class), appCtx, false, Resource.newInstance(1024, 1), createFakeContainerContext(), false);
TaskAttemptImpl spyTa = spy(taImpl);
when(spyTa.resolveHosts(hosts)).thenReturn(resolved.toArray(new String[3]));
TaskAttemptEventSchedule mockTAEvent = mock(TaskAttemptEventSchedule.class);
sta.transition(spyTa, mockTAEvent);
verify(spyTa).resolveHosts(hosts);
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(1)).handle(arg.capture());
if (!(arg.getAllValues().get(0) instanceof AMSchedulerEventTALaunchRequest)) {
fail("Second Event not of type ContainerRequestEvent");
}
Map<String, Boolean> expected = new HashMap<String, Boolean>();
expected.put("host1", true);
expected.put("host2", true);
expected.put("host3", true);
Set<String> requestedHosts = spyTa.taskHosts;
for (String h : requestedHosts) {
expected.remove(h);
}
assertEquals(0, expected.size());
}
Aggregations