diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/scheduler/TestOpportunisticContainerAllocator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/scheduler/TestOpportunisticContainerAllocator.java index 2d3b09914c6..060893a6e08 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/scheduler/TestOpportunisticContainerAllocator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/scheduler/TestOpportunisticContainerAllocator.java @@ -37,6 +37,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -47,6 +49,8 @@ public class TestOpportunisticContainerAllocator { + private static final Logger LOG = + LoggerFactory.getLogger(TestOpportunisticContainerAllocator.class); private static final int GB = 1024; private OpportunisticContainerAllocator allocator = null; private OpportunisticContainerContext oppCntxt = null; @@ -174,7 +178,7 @@ public void testRoundRobinSimpleAllocation() throws Exception { List containers = allocator.allocateContainers( blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser"); - System.out.println(containers); + LOG.info(containers.toString()); Set allocatedHosts = new HashSet<>(); for (Container c : containers) { allocatedHosts.add(c.getNodeHttpAddress()); @@ -242,7 +246,7 @@ public void testNodeLocalAllocation() throws Exception { List containers = allocator.allocateContainers( blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser"); - System.out.println(containers); + LOG.info(containers.toString()); Set allocatedHosts = new HashSet<>(); for (Container c : containers) { allocatedHosts.add(c.getNodeHttpAddress()); @@ -295,7 +299,7 @@ public void testNodeLocalAllocationSameSchedKey() throws Exception { List containers = allocator.allocateContainers( blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser"); - System.out.println(containers); + LOG.info(containers.toString()); Set allocatedHosts = new HashSet<>(); for (Container c : containers) { allocatedHosts.add(c.getNodeHttpAddress()); @@ -412,7 +416,7 @@ public void testRoundRobinRackLocalAllocation() throws Exception { for (Container c : containers) { allocatedHosts.add(c.getNodeHttpAddress()); } - System.out.println(containers); + LOG.info(containers.toString()); Assert.assertTrue(allocatedHosts.contains("h2:1234")); Assert.assertTrue(allocatedHosts.contains("h5:1234")); Assert.assertFalse(allocatedHosts.contains("h3:1234")); @@ -459,7 +463,7 @@ public void testRoundRobinRackLocalAllocationSameSchedKey() throws Exception { for (Container c : containers) { allocatedHosts.add(c.getNodeHttpAddress()); } - System.out.println(containers); + LOG.info(containers.toString()); Assert.assertTrue(allocatedHosts.contains("h2:1234")); Assert.assertTrue(allocatedHosts.contains("h5:1234")); Assert.assertFalse(allocatedHosts.contains("h3:1234")); @@ -502,7 +506,7 @@ public void testOffSwitchAllocationWhenNoNodeOrRack() throws Exception { List containers = allocator.allocateContainers( blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser"); - System.out.println(containers); + LOG.info(containers.toString()); Assert.assertEquals(2, containers.size()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java index 9a8c02bf486..33c23837b4d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java @@ -223,7 +223,15 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception nm3.nodeHeartbeat(true); nm4.nodeHeartbeat(true); - Thread.sleep(1000); + try { + GenericTestUtils.waitFor(new Supplier() { + @Override public Boolean get() { + return amservice.getLeastLoadedNodes().size() == 4; + } + }, 10, 10 * 100); + }catch (TimeoutException e) { + fail("timed out while waiting for scheduler to add nodes."); + } QueueMetrics metrics = ((CapacityScheduler) scheduler).getRootQueue() .getMetrics(); @@ -388,7 +396,15 @@ public void testContainerPromoteAfterContainerStart() throws Exception { nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(true); - Thread.sleep(1000); + try { + GenericTestUtils.waitFor(new Supplier() { + @Override public Boolean get() { + return amservice.getLeastLoadedNodes().size() == 2; + } + }, 10, 10 * 100); + }catch (TimeoutException e) { + fail("timed out while waiting for scheduler to add nodes."); + } QueueMetrics metrics = ((CapacityScheduler) scheduler).getRootQueue() .getMetrics(); @@ -513,7 +529,15 @@ public void testContainerPromoteAfterContainerComplete() throws Exception { nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(true); - Thread.sleep(1000); + try { + GenericTestUtils.waitFor(new Supplier() { + @Override public Boolean get() { + return amservice.getLeastLoadedNodes().size() == 2; + } + }, 10, 10 * 100); + }catch (TimeoutException e) { + fail("timed out while waiting for scheduler to add nodes."); + } QueueMetrics metrics = ((CapacityScheduler) scheduler).getRootQueue() .getMetrics(); @@ -618,7 +642,16 @@ public void testContainerAutoUpdateContainer() throws Exception { amservice.handle(new NodeUpdateSchedulerEvent(rmNode1)); nm1.nodeHeartbeat(true); - Thread.sleep(1000); + + try { + GenericTestUtils.waitFor(new Supplier() { + @Override public Boolean get() { + return amservice.getLeastLoadedNodes().size() == 1; + } + }, 10, 10 * 100); + }catch (TimeoutException e) { + fail("timed out while waiting for scheduler to add nodes."); + } AllocateResponse allocateResponse = am1.allocate(Arrays.asList( ResourceRequest.newInstance(Priority.newInstance(1), "*", @@ -801,6 +834,16 @@ public void testOpportunisticSchedulerMetrics() throws Exception { nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(true); + try { + GenericTestUtils.waitFor(new Supplier() { + @Override public Boolean get() { + return amservice.getLeastLoadedNodes().size() == 2; + } + }, 10, 10 * 100); + }catch (TimeoutException e) { + fail("timed out while waiting for scheduler to add nodes."); + } + AllocateResponse allocateResponse = am1.allocate(Arrays.asList( ResourceRequest.newInstance(Priority.newInstance(1), "*", Resources.createResource(1 * GB), 2, true, null,