ResourceCalculatorUtils { public static int computeAvailableContainers(Resource available, Resource required, EnumSet<SchedulerResourceTypes> resourceTypes) { if (resourceTypes.contains(SchedulerResourceTypes.CPU)) { return Math.min( calculateRatioOrMaxValue(available.getMemory(), required.getMemory()), calculateRatioOrMaxValue(available.getVirtualCores(), required .getVirtualCores())); } return calculateRatioOrMaxValue( available.getMemory(), required.getMemory()); }  static int divideAndCeil(int a, int b); static int computeAvailableContainers(Resource available,
      Resource required, EnumSet<SchedulerResourceTypes> resourceTypes); static int divideAndCeilContainers(Resource required, Resource factor,
      EnumSet<SchedulerResourceTypes> resourceTypes);  }
@Test public void testComputeAvailableContainers() throws Exception { Resource clusterAvailableResources = Resource.newInstance(81920, 40); Resource nonZeroResource = Resource.newInstance(1024, 2); int expectedNumberOfContainersForMemory = 80; int expectedNumberOfContainersForCPU = 20; verifyDifferentResourceTypes(clusterAvailableResources, nonZeroResource, expectedNumberOfContainersForMemory, expectedNumberOfContainersForCPU); Resource zeroMemoryResource = Resource.newInstance(0, nonZeroResource.getVirtualCores()); verifyDifferentResourceTypes(clusterAvailableResources, zeroMemoryResource, Integer.MAX_VALUE, expectedNumberOfContainersForCPU); Resource zeroCpuResource = Resource.newInstance(nonZeroResource.getMemory(), 0); verifyDifferentResourceTypes(clusterAvailableResources, zeroCpuResource, expectedNumberOfContainersForMemory, expectedNumberOfContainersForMemory); }