diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java index 7a85bfab44e..fe2e0e1681d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java @@ -331,15 +331,18 @@ public static void waitForContainerState( ContainerStatus containerStatus = null; HashSet fStates = new HashSet<>(finalStates); + timeOutMax *= 10; int timeoutSecs = 0; do { - Thread.sleep(1000); + Thread.sleep(100); containerStatus = containerManager.getContainerStatuses(request) .getContainerStatuses().get(0); - LOG.info("Waiting for container to get into one of states " + fStates - + ". Current state is " + containerStatus.getState()); timeoutSecs += 1; + if (timeoutSecs % 10 == 0) { + LOG.info("Waiting for container to get into one of states " + fStates + + ". Current state is " + containerStatus.getState()); + } } while (!fStates.contains(containerStatus.getState()) && timeoutSecs < timeOutMax); LOG.info("Container state is " + containerStatus.getState()); @@ -371,7 +374,7 @@ public static void waitForNMContainerState(ContainerManagerImpl containerManager, ContainerId containerID, org.apache.hadoop.yarn.server.nodemanager.containermanager .container.ContainerState finalState) - throws InterruptedException, YarnException, IOException { + throws InterruptedException { waitForNMContainerState(containerManager, containerID, finalState, 20); } @@ -379,7 +382,7 @@ public static void waitForNMContainerState(ContainerManagerImpl containerManager, ContainerId containerID, org.apache.hadoop.yarn.server.nodemanager.containermanager .container.ContainerState finalState, int timeOutMax) - throws InterruptedException, YarnException, IOException { + throws InterruptedException { waitForNMContainerState(containerManager, containerID, Arrays.asList(finalState), timeOutMax); } @@ -388,23 +391,24 @@ public static void waitForNMContainerState(ContainerManagerImpl containerManager, ContainerId containerID, List finalStates, int timeOutMax) - throws InterruptedException, YarnException, IOException { + throws InterruptedException { Container container = null; + timeOutMax *= 10; org.apache.hadoop.yarn.server.nodemanager .containermanager.container.ContainerState currentState = null; int timeoutSecs = 0; do { - Thread.sleep(1000); + Thread.sleep(100); container = containerManager.getContext().getContainers().get(containerID); if (container != null) { currentState = container.getContainerState(); } - if (currentState != null) { + timeoutSecs += 1; + if (currentState != null && timeoutSecs % 10 == 0) { LOG.info("Waiting for NM container to get into one of the following " + "states: " + finalStates + ". Current state is " + currentState); } - timeoutSecs += 1; } while (!finalStates.contains(currentState) && timeoutSecs < timeOutMax); LOG.info("Container state is " + currentState); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java index 05360aba2d4..f5d8df01200 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java @@ -859,21 +859,15 @@ public void testContainerDeQueuedAfterAMKill() throws Exception { ContainerScheduler containerScheduler = containerManager.getContainerScheduler(); // Ensure both containers are properly queued. - int numTries = 30; - while ((containerScheduler.getNumQueuedContainers() < 2) && - (numTries-- > 0)) { - Thread.sleep(100); - } + GenericTestUtils.waitFor( + () -> containerScheduler.getNumQueuedContainers() >= 2, 50, 3000); Assert.assertEquals(2, containerScheduler.getNumQueuedContainers()); containerManager.stopContainers( StopContainersRequest.newInstance(Arrays.asList(createContainerId(2)))); - numTries = 30; - while ((containerScheduler.getNumQueuedContainers() > 1) && - (numTries-- > 0)) { - Thread.sleep(100); - } + GenericTestUtils.waitFor( + () -> containerScheduler.getNumQueuedContainers() <= 1, 50, 3000); Assert.assertEquals(1, containerScheduler.getNumQueuedContainers()); } @@ -996,16 +990,14 @@ public void testKillOnlyRequiredOpportunisticContainers() throws Exception { allRequests = StartContainersRequest.newInstance(list); containerManager.startContainers(allRequests); - BaseContainerManagerTest.waitForNMContainerState(containerManager, - createContainerId(0), ContainerState.DONE, 40); - Thread.sleep(5000); - // Get container statuses. Container 0 should be killed, container 1 // should be queued and container 2 should be running. int killedContainers = 0; List statList = new ArrayList(); for (int i = 0; i < 6; i++) { statList.add(createContainerId(i)); + BaseContainerManagerTest.waitForNMContainerState(containerManager, + statList.get(i), ContainerState.DONE, 40); } GetContainerStatusesRequest statRequest = GetContainerStatusesRequest.newInstance(statList);