private static void waitForContainerAllocation(Collection<MockNM> nodes, MockAM am, List<Container> allocatedContainers, List<RejectedSchedulingRequest> rejectedRequests, int containerNum) throws Exception { int attemptCount = 10; while (allocatedContainers.size() < containerNum && attemptCount > 0) { for (MockNM node : nodes) { node.nodeHeartbeat(true); } LOG.info("Waiting for containers to be created for " + am.getApplicationAttemptId().getApplicationId() + "..."); sleep(1000); AllocateResponse allocResponse = am.schedule(); allocatedContainers.addAll(allocResponse.getAllocatedContainers()); rejectedRequests.addAll(allocResponse.getRejectedSchedulingRequests()); attemptCount--; } }
private List<Container> waitForAllocation(int allocNum, int timeout, MockAM am, MockNM... nms) throws Exception { final List<Container> result = new ArrayList<>(); GenericTestUtils.waitFor(() -> { try { AllocateResponse response = am.schedule(); List<Container> allocated = response.getAllocatedContainers(); System.out.println("Expecting allocation: " + allocNum + ", actual allocation: " + allocated.size()); for (Container c : allocated) { System.out.println("Container " + c.getId().toString() + " is allocated on node: " + c.getNodeId().toString() + ", allocation tags: " + String.join(",", c.getAllocationTags())); } result.addAll(allocated); if (result.size() == allocNum) { return true; } doNodeHeartbeat(nms); } catch (Exception e) { e.printStackTrace(); } return false; }, 500, timeout); return result; }
AllocateResponse allocResponse = am1.schedule(); // send the request List<Container> allocatedContainers = new ArrayList<>(); List<RejectedSchedulingRequest> rejectedReqs = new ArrayList<>(); LOG.info("Waiting for containers to be created for app 1..."); sleep(1000); allocResponse = am1.schedule(); allocatedContainers.addAll(allocResponse.getAllocatedContainers()); rejectedReqs.addAll(allocResponse.getRejectedSchedulingRequests());
AllocateResponse alloc1Response = am1.schedule(); // send the request LOG.info("Waiting for containers to be created for app 1..."); sleep(1000); alloc1Response = am1.schedule(); am2.addContainerToBeReleased(cId); try { am2.schedule(); fail("Exception was expected!!"); } catch (InvalidContainerReleaseException e) {
schedulingRequest(1, 4, 1, 512, "foo"), schedulingRequest(1, 5, 1, 512, "foo"))); AllocateResponse allocResponse = am1.schedule(); // send the request List<Container> allocatedContainers = new ArrayList<>(); allocatedContainers.addAll(allocResponse.getAllocatedContainers());
schedulingRequest(1, 5, 1, 512, "foo"), schedulingRequest(1, 6, 1, 512, "foo"))); AllocateResponse allocResponse = am1.schedule(); // send the request List<Container> allocatedContainers = new ArrayList<>(); allocatedContainers.addAll(allocResponse.getAllocatedContainers());
AllocateResponse alloc1Response = am1.schedule(); // send the request LOG.info("Waiting for containers to be created for app 1..."); sleep(1000); alloc1Response = am1.schedule(); am2.addContainerToBeReleased(cId); try { am2.schedule(); Assert.fail("Exception was expected!!"); } catch (InvalidContainerReleaseException e) {
schedulingRequest(1, 3, 1, 512, "foo"), schedulingRequest(1, 5, 1, 512, "foo"))); AllocateResponse allocResponse = am1.schedule(); // send the request List<Container> allocatedContainers = new ArrayList<>(); allocatedContainers.addAll(allocResponse.getAllocatedContainers());
schedulingRequest(1, 4, 1, 512, "foo"), schedulingRequest(1, 5, 1, 512, "foo"))); AllocateResponse allocResponse = am1.schedule(); // send the request List<Container> allocatedContainers = new ArrayList<>(); allocatedContainers.addAll(allocResponse.getAllocatedContainers());
schedulingRequest(1, 7, 1, 512, "foo"), schedulingRequest(1, 8, 1, 512, "foo"))); AllocateResponse allocResponse = am1.schedule(); // send the request List<Container> allocatedContainers = new ArrayList<>(); allocatedContainers.addAll(allocResponse.getAllocatedContainers());
@Test(timeout=1200000) public void testAllocateAfterUnregister() throws Exception { MockRM rm = new MockRM(conf); rm.start(); // Register node1 MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB); // Submit an application RMApp app1 = rm.submitApp(2048); nm1.nodeHeartbeat(true); RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); am1.registerAppAttempt(); // unregister app attempt FinishApplicationMasterRequest req = FinishApplicationMasterRequest.newInstance( FinalApplicationStatus.KILLED, "", ""); am1.unregisterAppAttempt(req, false); // request container after unregister am1.addRequests(new String[] { "127.0.0.1" }, GB, 1, 1); AllocateResponse alloc1Response = am1.schedule(); nm1.nodeHeartbeat(true); rm.drainEvents(); alloc1Response = am1.schedule(); Assert.assertEquals(0, alloc1Response.getAllocatedContainers().size()); }
@Test(timeout = 3000000) public void testAllocateResponseIdOverflow() throws Exception { MockRM rm = new MockRM(conf); try { rm.start(); // Register node1 MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB); // Submit an application RMApp app1 = rm.submitApp(2048); // kick the scheduling nm1.nodeHeartbeat(true); RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); am1.registerAppAttempt(); // Set the last reponseId to be MAX_INT Assert.assertTrue(am1.setApplicationLastResponseId(Integer.MAX_VALUE)); // Both allocate should succeed am1.schedule(); // send allocate with reponseId = MAX_INT Assert.assertEquals(0, am1.getResponseId()); am1.schedule(); // send allocate with reponseId = 0 Assert.assertEquals(1, am1.getResponseId()); } finally { if (rm != null) { rm.stop(); } } }
@Test(timeout = 3000000) public void testQueueLevelContainerAllocationFail() throws Exception { MockRM rm = new MockRM(configuration); rm.start(); // Register node1 MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB); // Submit an application RMApp app1 = rm.submitApp(2 * GB, "queueA"); // kick the scheduling nm1.nodeHeartbeat(true); RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); am1.registerAppAttempt(); am1.addRequests(new String[] { "127.0.0.1" }, MEMORY_ALLOCATION, 1, 1); try { allocateResponse = am1.schedule(); // send the request Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof InvalidResourceRequestException); Assert.assertEquals( InvalidResourceRequestException.InvalidResourceType.GREATER_THEN_MAX_ALLOCATION, ((InvalidResourceRequestException) e).getInvalidResourceType()); } finally { rm.stop(); } }
final MockAM am = MockRM.launchAndRegisterAM(app, rm, nm1); am.addRequests(new String[] {"*"}, 5 * GB, 1, 1, 2); am.schedule();