FSLeafQueue extends FSQueue { @Override public void updateDemand() { Resource tmpDemand = Resources.createResource(0); readLock.lock(); try { for (FSAppAttempt sched : runnableApps) { sched.updateDemand(); Resources.addTo(tmpDemand, sched.getDemand()); } for (FSAppAttempt sched : nonRunnableApps) { sched.updateDemand(); Resources.addTo(tmpDemand, sched.getDemand()); } } finally { readLock.unlock(); } demand = Resources.componentwiseMin(tmpDemand, getMaxShare()); if (LOG.isDebugEnabled()) { LOG.debug("The updated demand for " + getName() + " is " + demand + "; the max is " + getMaxShare()); LOG.debug("The updated fairshare for " + getName() + " is " + getFairShare()); } } 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 testUpdateDemand() { conf.set(FairSchedulerConfiguration.ASSIGN_MULTIPLE, "false"); resourceManager = new MockRM(conf); resourceManager.start(); scheduler = (FairScheduler) resourceManager.getResourceScheduler(); String queueName = "root.queue1"; FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null); schedulable.setMaxShare(new ConfigurableResource(maxResource)); assertThat(schedulable.getMetrics().getMaxApps()). isEqualTo(Integer.MAX_VALUE); assertThat(schedulable.getMetrics().getSchedulingPolicy()).isEqualTo( SchedulingPolicy.DEFAULT_POLICY.getName()); FSAppAttempt app = mock(FSAppAttempt.class); Mockito.when(app.getDemand()).thenReturn(maxResource); Mockito.when(app.getResourceUsage()).thenReturn(Resources.none()); schedulable.addApp(app, true); schedulable.addApp(app, true); schedulable.updateDemand(); assertTrue("Demand is greater than max allowed ", Resources.equals(schedulable.getDemand(), maxResource)); }