From da7f8c244d9ff3a3616f6b1dd4ebe3f35bfd3bbe Mon Sep 17 00:00:00 2001 From: Giovanni Matteo Fumarola Date: Mon, 1 Apr 2019 11:21:31 -0700 Subject: [PATCH] YARN-9431. Fix flaky junit test fair.TestAppRunnability after YARN-8967. Contributed by Wilfred Spiegelenburg. --- .../scheduler/fair/FairSchedulerTestBase.java | 7 ++++++- .../scheduler/fair/TestAppRunnability.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerTestBase.java index f149cb0de5..b931618172 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerTestBase.java @@ -293,11 +293,16 @@ private void createApplicationWithAMResourceInternal( Resource amResource, List amReqs) { RMContext rmContext = resourceManager.getRMContext(); 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, ApplicationSubmissionContext.newInstance(appId, null, queue, null, mock(ContainerLaunchContext.class), false, false, 0, amResource, null), - scheduler, null, 0, null, null, amReqs); + scheduler, null, 0, null, null, amReqs, placementCtx, -1); rmContext.getRMApps().put(appId, rmApp); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAppRunnability.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAppRunnability.java index 03338f49c9..b7ef471381 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAppRunnability.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestAppRunnability.java @@ -89,27 +89,27 @@ public void testUserAsDefaultQueue() throws Exception { } @Test - public void testNotUserAsDefaultQueue() throws Exception { + public void testNotUserAsDefaultQueue() { - // Restarting resource manager since the Conf object is changed changed. - resourceManager.stop(); + // We need a new scheduler since we want to change the conf object. This + // 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"); resourceManager = new MockRM(conf); resourceManager.start(); scheduler = (FairScheduler) resourceManager.getResourceScheduler(); ApplicationAttemptId appAttemptId = createAppAttemptId(1, 1); - createApplicationWithAMResource(appAttemptId, "default", "user2", null); - assertEquals(0, scheduler.getQueueManager().getLeafQueue("user1", true) - .getNumRunnableApps()); + createApplicationWithAMResource(appAttemptId, "default", "user1", null); assertEquals(1, scheduler.getQueueManager().getLeafQueue("default", true) .getNumRunnableApps()); - assertEquals(0, scheduler.getQueueManager().getLeafQueue("user2", true) + assertEquals(0, scheduler.getQueueManager().getLeafQueue("user1", true) .getNumRunnableApps()); } @Test - public void testAppAdditionAndRemoval() throws Exception { + public void testAppAdditionAndRemoval() { ApplicationAttemptId attemptId = createAppAttemptId(1, 1); ApplicationPlacementContext apc = new ApplicationPlacementContext("user1");