diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java index 742a43a12078..9bebe10e2bad 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java @@ -584,6 +584,81 @@ public void testAMRMClientMatchingFitInferredRack() } } + @Test(timeout = 60000) + public void testAsksWithifferentResourceSize() + throws YarnException, IOException { + AMRMClientImpl amClient = null; + try { + // start am rm client + amClient = (AMRMClientImpl) AMRMClient + . createAMRMClient(); + amClient.init(conf); + amClient.start(); + amClient.registerApplicationMaster("Host", 10000, ""); + + Resource capability1 = Resource.newInstance(1024, 1); + Resource capability2 = Resource.newInstance(2048, 1); + + ContainerRequest storedContainer1 = + new ContainerRequest(capability1, nodes, racks, priority); + ContainerRequest storedContainer2 = + new ContainerRequest(capability2, nodes, racks, priority); + + // go through an exemplary allocation, matching and release cycle + amClient.addContainerRequest(storedContainer1); + amClient.addContainerRequest(storedContainer2); + // RM should allocate container within 2 calls to allocate() + int allocatedContainerCount = 0; + int iterationsLeft = 3; + while (allocatedContainerCount < 2 && iterationsLeft-- > 0) { + Log.getLog().info("Allocated " + allocatedContainerCount + " containers" + + " with " + iterationsLeft + " iterations left"); + AllocateResponse allocResponse = amClient.allocate(0.1f); + assertEquals(0, amClient.ask.size()); + assertEquals(0, amClient.release.size()); + + assertEquals(nodeCount, amClient.getClusterNodeCount()); + allocatedContainerCount += + allocResponse.getAllocatedContainers().size(); + for (Container container : allocResponse.getAllocatedContainers()) { + ContainerRequest expectedRequest = + container.getPriority().equals(storedContainer1.getPriority()) + ? storedContainer1 : storedContainer2; + List> matches = + amClient.getMatchingRequests(container.getPriority(), + ResourceRequest.ANY, container.getResource()); + Log.getLog().info( + "allocated container of resource " + container.getResource()); + // test correct matched container is returned + // verifyMatches(matches, 1); + ContainerRequest matchedRequest = matches.get(0).iterator().next(); + // assertEquals(matchedRequest, expectedRequest); + amClient.removeContainerRequest(matchedRequest); + // assign this container, use it and release it + amClient.releaseAssignedContainer(container.getId()); + } + // let NM heartbeat to RM and trigger allocations + triggerSchedulingWithNMHeartBeat(); + } + + assertEquals(2, allocatedContainerCount); + AllocateResponse allocResponse = amClient.allocate(0.1f); + assertEquals(0, amClient.release.size()); + assertEquals(0, amClient.ask.size()); + assertEquals(0, allocResponse.getAllocatedContainers().size()); + // 0 requests left. everything got cleaned up + assertTrue(amClient.getTable(0).isEmpty()); + + amClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, + null, null); + + } finally { + if (amClient != null && amClient.getServiceState() == STATE.STARTED) { + amClient.stop(); + } + } + } + @Test //(timeout=60000) public void testAMRMClientMatchStorage() throws YarnException, IOException { AMRMClientImpl amClient = null;