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 67cb80357ba..4f4ee4c4508 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 @@ -310,15 +310,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()); @@ -350,7 +353,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); } @@ -358,7 +361,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); } @@ -367,23 +370,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 7eee8c984ae..a6594436773 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 @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.scheduler; +import com.google.common.base.Supplier; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -29,6 +30,7 @@ import org.apache.hadoop.fs.UnsupportedFileSystemException; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.api.protocolrecords.ContainerUpdateRequest; import org.apache.hadoop.yarn.api.protocolrecords.ContainerUpdateResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest; @@ -738,25 +740,30 @@ public void testQueueShedding() throws Exception { allRequests = StartContainersRequest.newInstance(list); containerManager.startContainers(allRequests); - ContainerScheduler containerScheduler = + final ContainerScheduler containerScheduler = containerManager.getContainerScheduler(); // Ensure all containers are properly queued. - int numTries = 30; - while ((containerScheduler.getNumQueuedContainers() < 6) && - (numTries-- > 0)) { - Thread.sleep(100); - } + GenericTestUtils.waitFor( + new Supplier() { + @Override + public Boolean get() { + return containerScheduler.getNumQueuedContainers() == 6; + } + }, 50, 3000); + Assert.assertEquals(6, containerScheduler.getNumQueuedContainers()); ContainerQueuingLimit containerQueuingLimit = ContainerQueuingLimit .newInstance(); containerQueuingLimit.setMaxQueueLength(2); containerScheduler.updateQueuingLimit(containerQueuingLimit); - numTries = 30; - while ((containerScheduler.getNumQueuedContainers() > 2) && - (numTries-- > 0)) { - Thread.sleep(100); - } + GenericTestUtils.waitFor( + new Supplier() { + @Override + public Boolean get() { + return containerScheduler.getNumQueuedContainers() <= 2; + } + }, 50, 3000); Assert.assertEquals(2, containerScheduler.getNumQueuedContainers()); List statList = new ArrayList(); @@ -832,24 +839,28 @@ public void testContainerDeQueuedAfterAMKill() throws Exception { allRequests = StartContainersRequest.newInstance(list); containerManager.startContainers(allRequests); - ContainerScheduler containerScheduler = + final ContainerScheduler containerScheduler = containerManager.getContainerScheduler(); // Ensure both containers are properly queued. - int numTries = 30; - while ((containerScheduler.getNumQueuedContainers() < 2) && - (numTries-- > 0)) { - Thread.sleep(100); - } + GenericTestUtils.waitFor( + new Supplier() { + @Override + public Boolean get() { + return 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( + new Supplier() { + @Override + public Boolean get() { + return containerScheduler.getNumQueuedContainers() <= 1; + } + }, 50, 3000); Assert.assertEquals(1, containerScheduler.getNumQueuedContainers()); } @@ -970,16 +981,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);