FSLeafQueue extends FSQueue { public boolean canRunAppAM(Resource amResource) { if (Math.abs(maxAMShare - -1.0f) < 0.0001) { return true; } Resource maxAMResource = computeMaxAMResource(); getMetrics().setMaxAMShare(maxAMResource); Resource ifRunAMResource = Resources.add(amResourceUsage, amResource); return Resources.fitsIn(ifRunAMResource, maxAMResource); } FSLeafQueue(String name, FairScheduler scheduler,
      FSParentQueue parent); @Override void collectSchedulerApplications(
      Collection<ApplicationAttemptId> apps); @Override Resource getDemand(); @Override void updateDemand(); @Override Resource assignContainer(FSSchedulerNode node); @Override List<FSQueue> getChildQueues(); @Override List<QueueUserACLInfo> getQueueUserAclInfo(UserGroupInformation user); @Override int getNumRunnableApps(); int getNumPendingApps(); int getNumAssignedApps(); @Override boolean isEmpty(); int getNumActiveApps(); @Override ActiveUsersManager getAbstractUsersManager(); boolean canRunAppAM(Resource amResource); @Override void recoverContainer(Resource clusterResource,
      SchedulerApplicationAttempt schedulerAttempt, RMContainer rmContainer); void setWeights(float weight); @Override Resource getMaximumContainerAllocation(); void addAssignedApp(ApplicationId applicationId); void removeAssignedApp(ApplicationId applicationId);  }
@Test public void testCanRunAppAMReturnsTrue() { conf.set(YarnConfiguration.RESOURCE_TYPES, CUSTOM_RESOURCE); ResourceUtils.resetResourceTypes(conf); resourceManager = new MockRM(conf); resourceManager.start(); scheduler = (FairScheduler) resourceManager.getResourceScheduler(); Resource maxShare = Resource.newInstance(1024 * 8, 4, ImmutableMap.of(CUSTOM_RESOURCE, 10L)); addNodeToScheduler(Resource.newInstance(4096, 10, ImmutableMap.of(CUSTOM_RESOURCE, 25L))); FSLeafQueue queue = setupQueue(maxShare); Resource expectedAMShare = Resource.newInstance(2048, 2, ImmutableMap.of(CUSTOM_RESOURCE, 5L)); Resource appAMResource = Resource.newInstance(2048, 2, ImmutableMap.of(CUSTOM_RESOURCE, 3L)); Map<String, Long> customResourceValues = verifyQueueMetricsForCustomResources(queue); boolean result = queue.canRunAppAM(appAMResource); assertTrue("AM should have been allocated!", result); verifyAMShare(queue, expectedAMShare, customResourceValues); }
@Test public void testCanRunAppAMReturnsFalse() { conf.set(YarnConfiguration.RESOURCE_TYPES, CUSTOM_RESOURCE); ResourceUtils.resetResourceTypes(conf); resourceManager = new MockRM(conf); resourceManager.start(); scheduler = (FairScheduler) resourceManager.getResourceScheduler(); Resource maxShare = Resource.newInstance(1024 * 8, 4, ImmutableMap.of(CUSTOM_RESOURCE, 10L)); addNodeToScheduler(Resource.newInstance(4096, 10, ImmutableMap.of(CUSTOM_RESOURCE, 25L))); FSLeafQueue queue = setupQueue(maxShare); Resource expectedAMShare = Resource.newInstance(2048, 2, ImmutableMap.of(CUSTOM_RESOURCE, 5L)); Resource appAMResource = Resource.newInstance(2048, 2, ImmutableMap.of(CUSTOM_RESOURCE, 6L)); Map<String, Long> customResourceValues = verifyQueueMetricsForCustomResources(queue); boolean result = queue.canRunAppAM(appAMResource); assertFalse("AM should not have been allocated!", result); verifyAMShare(queue, expectedAMShare, customResourceValues); }