use of org.apache.tez.dag.app.MockClock in project tez by apache.
the class TestDagAwareYarnTaskScheduler method testIdleContainerAssignment.
@Test(timeout = 50000)
public void testIdleContainerAssignment() throws Exception {
AMRMClientAsyncWrapperForTest mockRMClient = spy(new AMRMClientAsyncWrapperForTest());
String appHost = "host";
int appPort = 0;
String appUrl = "url";
Configuration conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 100);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, false);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, false);
conf.setInt(TezConfiguration.TEZ_AM_RM_HEARTBEAT_INTERVAL_MS_MAX, 100);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MIN_MILLIS, 4000);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MAX_MILLIS, 5000);
conf.setInt(TezConfiguration.TEZ_AM_SESSION_MIN_HELD_CONTAINERS, 5);
DagInfo mockDagInfo = mock(DagInfo.class);
when(mockDagInfo.getTotalVertices()).thenReturn(10);
when(mockDagInfo.getVertexDescendants(anyInt())).thenReturn(new BitSet());
TaskSchedulerContext mockApp = setupMockTaskSchedulerContext(appHost, appPort, appUrl, conf);
when(mockApp.getCurrentDagInfo()).thenReturn(mockDagInfo);
when(mockApp.isSession()).thenReturn(true);
TaskSchedulerContextDrainable drainableAppCallback = createDrainableContext(mockApp);
MockClock clock = new MockClock(1000);
NewTaskSchedulerForTest scheduler = new NewTaskSchedulerForTest(drainableAppCallback, mockRMClient, clock);
scheduler.initialize();
drainableAppCallback.drain();
scheduler.start();
drainableAppCallback.drain();
verify(mockRMClient).start();
verify(mockRMClient).registerApplicationMaster(appHost, appPort, appUrl);
RegisterApplicationMasterResponse regResponse = mockRMClient.getRegistrationResponse();
verify(mockApp).setApplicationRegistrationData(regResponse.getMaximumResourceCapability(), regResponse.getApplicationACLs(), regResponse.getClientToAMTokenMasterKey(), regResponse.getQueue());
assertEquals(scheduler.getClusterNodeCount(), mockRMClient.getClusterNodeCount());
final String rack1 = "/r1";
final String rack2 = "/r2";
final String node1Rack1 = "n1r1";
final String node2Rack1 = "n2r1";
final String node1Rack2 = "n1r2";
MockDNSToSwitchMapping.addRackMapping(node1Rack1, rack1);
MockDNSToSwitchMapping.addRackMapping(node2Rack1, rack1);
MockDNSToSwitchMapping.addRackMapping(node1Rack2, rack2);
Priority priorityv0 = Priority.newInstance(1);
MockTaskInfo taskv0t0 = new MockTaskInfo("taskv0t0", priorityv0, node1Rack1, rack1);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 1), 1);
ContainerId cid1 = ContainerId.newContainerId(attemptId, 1);
NodeId n2r1 = NodeId.newInstance(node2Rack1, 1);
Container container1 = Container.newInstance(cid1, n2r1, null, taskv0t0.capability, priorityv0, null);
// verify idle container is kept for now
scheduler.onContainersAllocated(Collections.singletonList(container1));
clock.incrementTime(2000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(cid1);
verify(mockRMClient, never()).releaseAssignedContainer(cid1);
// verify idle container is released without being assigned to a task because rack-local reuse is
// disabled
TaskRequestCaptor taskRequestCaptor = new TaskRequestCaptor(mockRMClient, scheduler, drainableAppCallback);
TaskRequest reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0);
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).taskAllocated(taskv0t0.task, taskv0t0.cookie, container1);
verify(mockRMClient, never()).removeContainerRequest(reqv0t0);
verify(mockApp, never()).containerBeingReleased(cid1);
verify(mockRMClient).releaseAssignedContainer(cid1);
// cancel the task request
assertFalse(scheduler.deallocateTask(taskv0t0.task, false, null, null));
// allocate another container that's node-local
ContainerId cid2 = ContainerId.newContainerId(attemptId, 2);
NodeId n1r1 = NodeId.newInstance(node1Rack1, 1);
Container container2 = Container.newInstance(cid2, n1r1, null, taskv0t0.capability, priorityv0, null);
scheduler.onContainersAllocated(Collections.singletonList(container2));
clock.incrementTime(2000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(cid2);
verify(mockRMClient, never()).releaseAssignedContainer(cid2);
// reschedule the task, verify it's now scheduled without a container request
// since node-local idle container is available
reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0, false);
verify(mockApp).taskAllocated(taskv0t0.task, taskv0t0.cookie, container2);
verify(mockRMClient).removeContainerRequest(reqv0t0);
}
use of org.apache.tez.dag.app.MockClock in project tez by apache.
the class TestDagAwareYarnTaskScheduler method testSimpleReuseLocalMatching.
@Test(timeout = 30000)
public void testSimpleReuseLocalMatching() throws Exception {
AMRMClientAsyncWrapperForTest mockRMClient = spy(new AMRMClientAsyncWrapperForTest());
String appHost = "host";
int appPort = 0;
String appUrl = "url";
Configuration conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 100);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, false);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, false);
conf.setInt(TezConfiguration.TEZ_AM_RM_HEARTBEAT_INTERVAL_MS_MAX, 100);
DagInfo mockDagInfo = mock(DagInfo.class);
when(mockDagInfo.getTotalVertices()).thenReturn(10);
when(mockDagInfo.getVertexDescendants(anyInt())).thenReturn(new BitSet());
TaskSchedulerContext mockApp = setupMockTaskSchedulerContext(appHost, appPort, appUrl, conf);
when(mockApp.getCurrentDagInfo()).thenReturn(mockDagInfo);
TaskSchedulerContextDrainable drainableAppCallback = createDrainableContext(mockApp);
MockClock clock = new MockClock(1000);
NewTaskSchedulerForTest scheduler = new NewTaskSchedulerForTest(drainableAppCallback, mockRMClient, clock);
scheduler.initialize();
drainableAppCallback.drain();
scheduler.start();
drainableAppCallback.drain();
verify(mockRMClient).start();
verify(mockRMClient).registerApplicationMaster(appHost, appPort, appUrl);
RegisterApplicationMasterResponse regResponse = mockRMClient.getRegistrationResponse();
verify(mockApp).setApplicationRegistrationData(regResponse.getMaximumResourceCapability(), regResponse.getApplicationACLs(), regResponse.getClientToAMTokenMasterKey(), regResponse.getQueue());
assertEquals(scheduler.getClusterNodeCount(), mockRMClient.getClusterNodeCount());
Priority priorityv0 = Priority.newInstance(1);
Priority priorityv1 = Priority.newInstance(2);
String[] hostsv0t0 = { "host1", "host2" };
MockTaskInfo taskv0t0 = new MockTaskInfo("taskv0t0", priorityv0, hostsv0t0);
MockTaskInfo taskv0t1 = new MockTaskInfo("taskv0t1", priorityv0, "host3");
MockTaskInfo taskv0t2 = new MockTaskInfo("taskv0t2", priorityv0, hostsv0t0);
MockTaskInfo taskv1t0 = new MockTaskInfo("taskv1t0", priorityv1, hostsv0t0);
MockTaskInfo taskv1t1 = new MockTaskInfo("taskv1t1", priorityv1, hostsv0t0);
TaskRequestCaptor taskRequestCaptor = new TaskRequestCaptor(mockRMClient, scheduler, drainableAppCallback);
TaskRequest reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0);
taskRequestCaptor.scheduleTask(taskv0t1);
TaskRequest reqv0t2 = taskRequestCaptor.scheduleTask(taskv0t2);
TaskRequest reqv1t0 = taskRequestCaptor.scheduleTask(taskv1t0);
taskRequestCaptor.scheduleTask(taskv1t1);
NodeId host1 = NodeId.newInstance("host1", 1);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 1), 1);
ContainerId cid1 = ContainerId.newContainerId(attemptId, 1);
Container container1 = Container.newInstance(cid1, host1, null, taskv0t0.capability, priorityv0, null);
// allocate one container at v0 priority
scheduler.onContainersAllocated(Collections.singletonList(container1));
drainableAppCallback.drain();
verify(mockApp).taskAllocated(taskv0t0.task, taskv0t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t0);
// finish v0t0 successfully, verify v0t1 is skipped and v0t2 instead is assigned to the container
assertTrue(scheduler.deallocateTask(taskv0t0.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv0t2.task, taskv0t2.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t2);
// finish v0t2 successfully, verify v1t0 is assigned to the same container
assertTrue(scheduler.deallocateTask(taskv0t2.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv1t0.task, taskv1t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv1t0);
// fail v1t0 and verify container is released instead of reused for v1t1
assertTrue(scheduler.deallocateTask(taskv1t0.task, false, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp).containerBeingReleased(cid1);
verify(mockRMClient).releaseAssignedContainer(cid1);
String appMsg = "success";
AppFinalStatus finalStatus = new AppFinalStatus(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
when(mockApp.getFinalAppStatus()).thenReturn(finalStatus);
scheduler.shutdown();
drainableAppCallback.drain();
verify(mockRMClient).unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
verify(mockRMClient).stop();
}
use of org.apache.tez.dag.app.MockClock in project tez by apache.
the class TestDagAwareYarnTaskScheduler method testSimpleReuseRackMatching.
@Test(timeout = 30000)
public void testSimpleReuseRackMatching() throws Exception {
AMRMClientAsyncWrapperForTest mockRMClient = spy(new AMRMClientAsyncWrapperForTest());
String appHost = "host";
int appPort = 0;
String appUrl = "url";
Configuration conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 100);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, true);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, false);
conf.setInt(TezConfiguration.TEZ_AM_RM_HEARTBEAT_INTERVAL_MS_MAX, 100);
DagInfo mockDagInfo = mock(DagInfo.class);
when(mockDagInfo.getTotalVertices()).thenReturn(10);
when(mockDagInfo.getVertexDescendants(anyInt())).thenReturn(new BitSet());
TaskSchedulerContext mockApp = setupMockTaskSchedulerContext(appHost, appPort, appUrl, conf);
when(mockApp.getCurrentDagInfo()).thenReturn(mockDagInfo);
TaskSchedulerContextDrainable drainableAppCallback = createDrainableContext(mockApp);
MockClock clock = new MockClock(1000);
NewTaskSchedulerForTest scheduler = new NewTaskSchedulerForTest(drainableAppCallback, mockRMClient, clock);
scheduler.initialize();
drainableAppCallback.drain();
scheduler.start();
drainableAppCallback.drain();
verify(mockRMClient).start();
verify(mockRMClient).registerApplicationMaster(appHost, appPort, appUrl);
RegisterApplicationMasterResponse regResponse = mockRMClient.getRegistrationResponse();
verify(mockApp).setApplicationRegistrationData(regResponse.getMaximumResourceCapability(), regResponse.getApplicationACLs(), regResponse.getClientToAMTokenMasterKey(), regResponse.getQueue());
assertEquals(scheduler.getClusterNodeCount(), mockRMClient.getClusterNodeCount());
Priority priorityv0 = Priority.newInstance(1);
Priority priorityv1 = Priority.newInstance(2);
String[] hostsv0t0 = { "host1", "host2" };
MockTaskInfo taskv0t0 = new MockTaskInfo("taskv0t0", priorityv0, hostsv0t0);
MockTaskInfo taskv0t1 = new MockTaskInfo("taskv0t1", priorityv0, "host2");
MockTaskInfo taskv0t2 = new MockTaskInfo("taskv0t2", priorityv0, "host4", "/somerack");
MockTaskInfo taskv1t0 = new MockTaskInfo("taskv1t0", priorityv1, "host1");
MockTaskInfo taskv1t1 = new MockTaskInfo("taskv1t1", priorityv1, "host5");
TaskRequestCaptor taskRequestCaptor = new TaskRequestCaptor(mockRMClient, scheduler, drainableAppCallback);
TaskRequest reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0);
TaskRequest reqv0t1 = taskRequestCaptor.scheduleTask(taskv0t1);
taskRequestCaptor.scheduleTask(taskv0t2);
TaskRequest reqv1t0 = taskRequestCaptor.scheduleTask(taskv1t0);
taskRequestCaptor.scheduleTask(taskv1t1);
NodeId host1 = NodeId.newInstance("host1", 1);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 1), 1);
ContainerId cid1 = ContainerId.newContainerId(attemptId, 1);
Container container1 = Container.newInstance(cid1, host1, null, taskv0t0.capability, priorityv0, null);
// allocate one container at v0 priority
scheduler.onContainersAllocated(Collections.singletonList(container1));
drainableAppCallback.drain();
verify(mockApp).taskAllocated(taskv0t0.task, taskv0t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t0);
// finish v0t0 successfully, verify v0t1 is skipped and v1t0 assigned instead
// since host locality is preferred to rack locality and lower priority vertex
// is not blocked by higher priority vertex
assertTrue(scheduler.deallocateTask(taskv0t0.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv1t0.task, taskv1t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv1t0);
// finish v1t0 successfully, verify v0t1 is assigned
assertTrue(scheduler.deallocateTask(taskv1t0.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv0t1.task, taskv0t1.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t1);
// fail v0t1 and verify container is released instead of reused for v1t1
assertTrue(scheduler.deallocateTask(taskv0t1.task, false, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp).containerBeingReleased(cid1);
verify(mockRMClient).releaseAssignedContainer(cid1);
String appMsg = "success";
AppFinalStatus finalStatus = new AppFinalStatus(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
when(mockApp.getFinalAppStatus()).thenReturn(finalStatus);
scheduler.shutdown();
drainableAppCallback.drain();
verify(mockRMClient).unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
verify(mockRMClient).stop();
}
use of org.apache.tez.dag.app.MockClock in project tez by apache.
the class TestDagAwareYarnTaskScheduler method testSimpleReuseAnyMatching.
@Test(timeout = 30000)
public void testSimpleReuseAnyMatching() throws Exception {
AMRMClientAsyncWrapperForTest mockRMClient = spy(new AMRMClientAsyncWrapperForTest());
String appHost = "host";
int appPort = 0;
String appUrl = "url";
Configuration conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 100);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, true);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_RM_HEARTBEAT_INTERVAL_MS_MAX, 100);
DagInfo mockDagInfo = mock(DagInfo.class);
when(mockDagInfo.getTotalVertices()).thenReturn(10);
when(mockDagInfo.getVertexDescendants(anyInt())).thenReturn(new BitSet());
TaskSchedulerContext mockApp = setupMockTaskSchedulerContext(appHost, appPort, appUrl, conf);
when(mockApp.getCurrentDagInfo()).thenReturn(mockDagInfo);
TaskSchedulerContextDrainable drainableAppCallback = createDrainableContext(mockApp);
MockClock clock = new MockClock(1000);
NewTaskSchedulerForTest scheduler = new NewTaskSchedulerForTest(drainableAppCallback, mockRMClient, clock);
scheduler.initialize();
drainableAppCallback.drain();
scheduler.start();
drainableAppCallback.drain();
verify(mockRMClient).start();
verify(mockRMClient).registerApplicationMaster(appHost, appPort, appUrl);
RegisterApplicationMasterResponse regResponse = mockRMClient.getRegistrationResponse();
verify(mockApp).setApplicationRegistrationData(regResponse.getMaximumResourceCapability(), regResponse.getApplicationACLs(), regResponse.getClientToAMTokenMasterKey(), regResponse.getQueue());
assertEquals(scheduler.getClusterNodeCount(), mockRMClient.getClusterNodeCount());
Priority priorityv0 = Priority.newInstance(1);
Priority priorityv1 = Priority.newInstance(2);
String[] hostsv0t0 = { "host1", "host2" };
MockTaskInfo taskv0t0 = new MockTaskInfo("taskv0t0", priorityv0, hostsv0t0);
MockTaskInfo taskv0t1 = new MockTaskInfo("taskv0t1", priorityv0, "host2");
MockTaskInfo taskv0t2 = new MockTaskInfo("taskv0t2", priorityv0, "host4", "/rack4");
MockTaskInfo taskv1t0 = new MockTaskInfo("taskv1t0", priorityv1, "host1");
MockTaskInfo taskv1t1 = new MockTaskInfo("taskv1t1", priorityv1, "host6", "/rack6");
TaskRequestCaptor taskRequestCaptor = new TaskRequestCaptor(mockRMClient, scheduler, drainableAppCallback);
TaskRequest reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0);
TaskRequest reqv0t1 = taskRequestCaptor.scheduleTask(taskv0t1);
TaskRequest reqv0t2 = taskRequestCaptor.scheduleTask(taskv0t2);
TaskRequest reqv1t0 = taskRequestCaptor.scheduleTask(taskv1t0);
taskRequestCaptor.scheduleTask(taskv1t1);
NodeId host1 = NodeId.newInstance("host1", 1);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 1), 1);
ContainerId cid1 = ContainerId.newContainerId(attemptId, 1);
Container container1 = Container.newInstance(cid1, host1, null, taskv0t0.capability, priorityv0, null);
// allocate one container at v0 priority
scheduler.onContainersAllocated(Collections.singletonList(container1));
drainableAppCallback.drain();
verify(mockApp).taskAllocated(taskv0t0.task, taskv0t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t0);
// finish v0t0 successfully, verify v0t1 is skipped and v1t0 assigned instead
// since host locality is preferred to rack locality and lower priority vertex
// is not blocked by higher priority vertex
assertTrue(scheduler.deallocateTask(taskv0t0.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv1t0.task, taskv1t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv1t0);
// finish v1t0 successfully, verify v0t1 is assigned
assertTrue(scheduler.deallocateTask(taskv1t0.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv0t1.task, taskv0t1.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t1);
// finish v0t1 successfully, verify v0t2 is assigned
assertTrue(scheduler.deallocateTask(taskv0t1.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv0t2.task, taskv0t2.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t2);
// fail v0t2 and verify container is released instead of reused for v1t1
assertTrue(scheduler.deallocateTask(taskv0t2.task, false, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp).containerBeingReleased(cid1);
verify(mockRMClient).releaseAssignedContainer(cid1);
String appMsg = "success";
AppFinalStatus finalStatus = new AppFinalStatus(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
when(mockApp.getFinalAppStatus()).thenReturn(finalStatus);
scheduler.shutdown();
drainableAppCallback.drain();
verify(mockRMClient).unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
verify(mockRMClient).stop();
}
use of org.apache.tez.dag.app.MockClock in project tez by apache.
the class TestDagAwareYarnTaskScheduler method testReuseWithAffinity.
@Test(timeout = 30000)
public void testReuseWithAffinity() throws Exception {
AMRMClientAsyncWrapperForTest mockRMClient = spy(new AMRMClientAsyncWrapperForTest());
String appHost = "host";
int appPort = 0;
String appUrl = "url";
Configuration conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 100);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, true);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, false);
conf.setInt(TezConfiguration.TEZ_AM_RM_HEARTBEAT_INTERVAL_MS_MAX, 100);
DagInfo mockDagInfo = mock(DagInfo.class);
when(mockDagInfo.getTotalVertices()).thenReturn(10);
when(mockDagInfo.getVertexDescendants(anyInt())).thenReturn(new BitSet());
TaskSchedulerContext mockApp = setupMockTaskSchedulerContext(appHost, appPort, appUrl, conf);
when(mockApp.getCurrentDagInfo()).thenReturn(mockDagInfo);
TaskSchedulerContextDrainable drainableAppCallback = createDrainableContext(mockApp);
MockClock clock = new MockClock(1000);
NewTaskSchedulerForTest scheduler = new NewTaskSchedulerForTest(drainableAppCallback, mockRMClient, clock);
scheduler.initialize();
drainableAppCallback.drain();
scheduler.start();
drainableAppCallback.drain();
verify(mockRMClient).start();
verify(mockRMClient).registerApplicationMaster(appHost, appPort, appUrl);
RegisterApplicationMasterResponse regResponse = mockRMClient.getRegistrationResponse();
verify(mockApp).setApplicationRegistrationData(regResponse.getMaximumResourceCapability(), regResponse.getApplicationACLs(), regResponse.getClientToAMTokenMasterKey(), regResponse.getQueue());
assertEquals(scheduler.getClusterNodeCount(), mockRMClient.getClusterNodeCount());
Priority priorityv0 = Priority.newInstance(1);
Priority priorityv1 = Priority.newInstance(2);
String[] hostsv0t0 = { "host1", "host2" };
MockTaskInfo taskv0t0 = new MockTaskInfo("taskv0t0", priorityv0, hostsv0t0);
MockTaskInfo taskv0t1 = new MockTaskInfo("taskv0t1", priorityv0, hostsv0t0);
TaskRequestCaptor taskRequestCaptor = new TaskRequestCaptor(mockRMClient, scheduler, drainableAppCallback);
TaskRequest reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0);
taskRequestCaptor.scheduleTask(taskv0t1);
NodeId host1 = NodeId.newInstance("host1", 1);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 1), 1);
ContainerId cid1 = ContainerId.newContainerId(attemptId, 1);
Container container1 = Container.newInstance(cid1, host1, null, taskv0t0.capability, priorityv0, null);
// allocate one container at v0 priority
scheduler.onContainersAllocated(Collections.singletonList(container1));
drainableAppCallback.drain();
verify(mockApp).taskAllocated(taskv0t0.task, taskv0t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t0);
// add a new request for this container
MockTaskInfo taskv1t0 = new MockTaskInfo("taskv1t0", priorityv1, "host1");
TaskRequest reqv1t0 = taskRequestCaptor.scheduleTask(taskv1t0, cid1);
// finish v0t0 successfully, verify v0t1 is skipped even though it is node-local
// and v1t0 assigned instead for affinity
assertTrue(scheduler.deallocateTask(taskv0t0.task, true, null, null));
clock.incrementTime(10000);
drainableAppCallback.drain();
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
verify(mockApp).taskAllocated(taskv1t0.task, taskv1t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv1t0);
String appMsg = "success";
AppFinalStatus finalStatus = new AppFinalStatus(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
when(mockApp.getFinalAppStatus()).thenReturn(finalStatus);
scheduler.shutdown();
drainableAppCallback.drain();
verify(mockRMClient).unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
verify(mockRMClient).stop();
}
Aggregations