DominantResourceFairnessPolicy extends SchedulingPolicy { @Override public String getName() { return NAME; }  @Override String getName(); @Override Comparator<Schedulable> getComparator(); @Override ResourceCalculator getResourceCalculator(); @Override void computeShares(Collection<? extends Schedulable> schedulables,
      Resource totalResources); @Override void computeSteadyShares(Collection<? extends FSQueue> queues,
      Resource totalResources); @Override boolean checkIfUsageOverFairShare(Resource usage, Resource fairShare); @Override Resource getHeadroom(Resource queueFairShare, Resource queueUsage,
                              Resource maxAvailable); @Override void initialize(FSContext fsContext); static final String NAME; }
@Test public void testCalculateClusterAndFairRatios() { Map<String, Integer> index = ResourceUtils.getResourceTypeIndex(); Resource used = Resources.createResource(10, 5); Resource capacity = Resources.createResource(100, 10); float[][] shares = new float[3][2]; DominantResourceFairnessComparatorN comparator = new DominantResourceFairnessComparatorN(); used.setResourceValue("test", 2L); capacity.setResourceValue("test", 5L); int dominant = comparator.calculateClusterAndFairRatios(used, capacity, shares, 1.0f); assertEquals("Calculated usage ratio for memory (10MB out of 100MB) is " + "incorrect", 0.1, shares[index.get(ResourceInformation.MEMORY_MB.getName())][0], .00001); assertEquals("Calculated usage ratio for vcores (5 out of 10) is " + "incorrect", 0.5, shares[index.get(ResourceInformation.VCORES.getName())][0], .00001); assertEquals("Calculated usage ratio for test resource (2 out of 5) is " + "incorrect", 0.4, shares[index.get("test")][0], .00001); assertEquals("The wrong dominant resource index was returned", index.get(ResourceInformation.VCORES.getName()).intValue(), dominant); }
@Test public void testCalculateMinShareRatios() { Map<String, Integer> index = ResourceUtils.getResourceTypeIndex(); Resource used = Resources.createResource(10, 5); Resource minShares = Resources.createResource(5, 10); float[][] ratios = new float[3][3]; DominantResourceFairnessComparatorN comparator = new DominantResourceFairnessComparatorN(); used.setResourceValue("test", 2L); minShares.setResourceValue("test", 0L); comparator.calculateMinShareRatios(used, minShares, ratios); assertEquals("Calculated min share ratio for memory (10MB out of 5MB) is " + "incorrect", 2.0, ratios[index.get(ResourceInformation.MEMORY_MB.getName())][2], .00001f); assertEquals("Calculated min share ratio for vcores (5 out of 10) is " + "incorrect", 0.5, ratios[index.get(ResourceInformation.VCORES.getName())][2], .00001f); assertEquals("Calculated min share ratio for test resource (0 out of 5) is " + "incorrect", Float.POSITIVE_INFINITY, ratios[index.get("test")][2], 0.00001f); }