FairOrderingPolicy extends AbstractComparatorOrderingPolicy<S> { @VisibleForTesting public void setSizeBasedWeight(boolean sizeBasedWeight) { this.sizeBasedWeight = sizeBasedWeight; } FairOrderingPolicy(); @VisibleForTesting boolean getSizeBasedWeight(); @VisibleForTesting void setSizeBasedWeight(boolean sizeBasedWeight); @Override void configure(Map<String, String> conf); @Override void containerAllocated(S schedulableEntity,
    RMContainer r); @Override void containerReleased(S schedulableEntity,
    RMContainer r); @Override void demandUpdated(S schedulableEntity); @Override String getInfo(); @Override String getConfigName(); static final String ENABLE_SIZE_BASED_WEIGHT; }
@Test public void testSizeBasedWeight() { FairOrderingPolicy<MockSchedulableEntity> policy = new FairOrderingPolicy<MockSchedulableEntity>(); policy.setSizeBasedWeight(true); MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r2 = new MockSchedulableEntity(); assertEquals("Comparator Output", 0, policy.getComparator().compare(r1, r2)); r1.setUsed(Resources.createResource(4 * GB)); r2.setUsed(Resources.createResource(4 * GB)); r1.setPending(Resources.createResource(4 * GB)); r2.setPending(Resources.createResource(4 * GB)); AbstractComparatorOrderingPolicy.updateSchedulingResourceUsage( r1.getSchedulingResourceUsage()); AbstractComparatorOrderingPolicy.updateSchedulingResourceUsage( r2.getSchedulingResourceUsage()); assertEquals("Comparator Output", 0, policy.getComparator().compare(r1, r2)); r2.setUsed(Resources.createResource(5 * GB)); r2.setPending(Resources.createResource(5 * GB)); AbstractComparatorOrderingPolicy.updateSchedulingResourceUsage( r2.getSchedulingResourceUsage()); Assert.assertTrue(policy.getComparator().compare(r1, r2) < 0); r2.setPending(Resources.createResource(100 * GB)); AbstractComparatorOrderingPolicy.updateSchedulingResourceUsage( r2.getSchedulingResourceUsage()); Assert.assertTrue(policy.getComparator().compare(r1, r2) > 0); }
@Test public void testOrderingUsingUsedAndPendingResources() { FairOrderingPolicy<MockSchedulableEntity> policy = new FairOrderingPolicy<>(); policy.setSizeBasedWeight(true); MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r2 = new MockSchedulableEntity(); r1.setUsed(Resources.createResource(4 * GB)); r2.setUsed(Resources.createResource(4 * GB)); r1.setPending(Resources.createResource(4 * GB)); r2.setPending(Resources.createResource(4 * GB)); AbstractComparatorOrderingPolicy .updateSchedulingResourceUsage(r1.getSchedulingResourceUsage()); AbstractComparatorOrderingPolicy .updateSchedulingResourceUsage(r2.getSchedulingResourceUsage()); assertEquals("Comparator Output", 0, policy.getComparator().compare(r1, r2)); r1.setUsed(Resources.createResource(4 * GB)); r2.setUsed(Resources.createResource(8 * GB)); r1.setPending(Resources.createResource(4 * GB)); r2.setPending(Resources.createResource(8 * GB)); AbstractComparatorOrderingPolicy .updateSchedulingResourceUsage(r1.getSchedulingResourceUsage()); AbstractComparatorOrderingPolicy .updateSchedulingResourceUsage(r2.getSchedulingResourceUsage()); Assert.assertTrue(policy.getComparator().compare(r1, r2) < 0); }
@Test public void testOrderingUsingAppSubmitTime() { FairOrderingPolicy<MockSchedulableEntity> policy = new FairOrderingPolicy<>(); policy.setSizeBasedWeight(true); MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r2 = new MockSchedulableEntity(); assertEquals(r1.getStartTime(), r2.getStartTime()); assertEquals("Comparator Output", 0, policy.getComparator().compare(r1, r2)); r1.setStartTime(5); r2.setStartTime(10); Assert.assertTrue(policy.getComparator().compare(r1, r2) < 0); r1.setStartTime(10); r2.setStartTime(5); Assert.assertTrue(policy.getComparator().compare(r1, r2) > 0); }