YARN-9431. Fix flaky junit test fair.TestAppRunnability after YARN-8967. Contributed by Wilfred Spiegelenburg.

This commit is contained in:
Giovanni Matteo Fumarola 2019-04-01 11:21:31 -07:00
parent 332cab5518
commit da7f8c244d
2 changed files with 14 additions and 9 deletions

View File

@ -293,11 +293,16 @@ private void createApplicationWithAMResourceInternal(
Resource amResource, List<ResourceRequest> amReqs) { Resource amResource, List<ResourceRequest> amReqs) {
RMContext rmContext = resourceManager.getRMContext(); RMContext rmContext = resourceManager.getRMContext();
ApplicationId appId = attId.getApplicationId(); ApplicationId appId = attId.getApplicationId();
// This fakes the placement which is not part of the scheduler anymore
ApplicationPlacementContext placementCtx =
new ApplicationPlacementContext(queue);
// Set the placement in the app and not just in the event in the next call
// otherwise with out of order event processing we might remove the app.
RMApp rmApp = new RMAppImpl(appId, rmContext, conf, null, user, null, RMApp rmApp = new RMAppImpl(appId, rmContext, conf, null, user, null,
ApplicationSubmissionContext.newInstance(appId, null, queue, null, ApplicationSubmissionContext.newInstance(appId, null, queue, null,
mock(ContainerLaunchContext.class), false, false, 0, amResource, mock(ContainerLaunchContext.class), false, false, 0, amResource,
null), null),
scheduler, null, 0, null, null, amReqs); scheduler, null, 0, null, null, amReqs, placementCtx, -1);
rmContext.getRMApps().put(appId, rmApp); rmContext.getRMApps().put(appId, rmApp);
} }

View File

@ -89,27 +89,27 @@ public void testUserAsDefaultQueue() throws Exception {
} }
@Test @Test
public void testNotUserAsDefaultQueue() throws Exception { public void testNotUserAsDefaultQueue() {
// Restarting resource manager since the Conf object is changed changed. // We need a new scheduler since we want to change the conf object. This
resourceManager.stop(); // requires a new RM to propagate it . Do a proper teardown to not leak
tearDown();
// Create a new one with the amended config.
conf.set(FairSchedulerConfiguration.USER_AS_DEFAULT_QUEUE, "false"); conf.set(FairSchedulerConfiguration.USER_AS_DEFAULT_QUEUE, "false");
resourceManager = new MockRM(conf); resourceManager = new MockRM(conf);
resourceManager.start(); resourceManager.start();
scheduler = (FairScheduler) resourceManager.getResourceScheduler(); scheduler = (FairScheduler) resourceManager.getResourceScheduler();
ApplicationAttemptId appAttemptId = createAppAttemptId(1, 1); ApplicationAttemptId appAttemptId = createAppAttemptId(1, 1);
createApplicationWithAMResource(appAttemptId, "default", "user2", null); createApplicationWithAMResource(appAttemptId, "default", "user1", null);
assertEquals(0, scheduler.getQueueManager().getLeafQueue("user1", true)
.getNumRunnableApps());
assertEquals(1, scheduler.getQueueManager().getLeafQueue("default", true) assertEquals(1, scheduler.getQueueManager().getLeafQueue("default", true)
.getNumRunnableApps()); .getNumRunnableApps());
assertEquals(0, scheduler.getQueueManager().getLeafQueue("user2", true) assertEquals(0, scheduler.getQueueManager().getLeafQueue("user1", true)
.getNumRunnableApps()); .getNumRunnableApps());
} }
@Test @Test
public void testAppAdditionAndRemoval() throws Exception { public void testAppAdditionAndRemoval() {
ApplicationAttemptId attemptId = createAppAttemptId(1, 1); ApplicationAttemptId attemptId = createAppAttemptId(1, 1);
ApplicationPlacementContext apc = ApplicationPlacementContext apc =
new ApplicationPlacementContext("user1"); new ApplicationPlacementContext("user1");