ProportionalCapacityPreemptionPolicy implements SchedulingEditPolicy { @Override public void editSchedule(){ CSQueue root = scheduler.getRootQueue(); Resource clusterResources = Resources.clone(scheduler.getClusterResource()); containerBasedPreemptOrKill(root, clusterResources); } ProportionalCapacityPreemptionPolicy();  ProportionalCapacityPreemptionPolicy(Configuration config,
      EventHandler<ContainerPreemptEvent> dispatcher,
      CapacityScheduler scheduler);  ProportionalCapacityPreemptionPolicy(Configuration config,
      EventHandler<ContainerPreemptEvent> dispatcher,
      CapacityScheduler scheduler, Clock clock); void init(Configuration config,
      EventHandler<ContainerPreemptEvent> disp,
      PreemptableResourceScheduler sched); @VisibleForTesting ResourceCalculator getResourceCalculator(); @Override void editSchedule(); @Override long getMonitoringInterval(); @Override String getPolicyName(); static final String OBSERVE_ONLY; static final String MONITORING_INTERVAL; static final String WAIT_TIME_BEFORE_KILL; static final String TOTAL_PREEMPTION_PER_ROUND; static final String MAX_IGNORED_OVER_CAPACITY; static final String NATURAL_TERMINATION_FACTOR; public EventHandler<ContainerPreemptEvent> dispatcher; }
@Test public void testZeroGuarOverCap() { int[][] qData = new int[][] { { 200, 100, 0, 99, 0, 100, 100 }, { 200, 200, 200, 200, 200, 200, 200 }, { 170, 170, 60, 20, 90, 0, 0 }, { 85, 50, 30, 10, 10, 20, 20 }, { 0, 0, 0, 0, 0, 0, 0 }, { 4, 3, 1, 1, 1, 1, 1 }, { -1, -1, 1, 1, 1, -1, 1 }, { 2, 3, 0, 0, 0, 1, 0 }, }; ProportionalCapacityPreemptionPolicy policy = buildPolicy(qData); policy.editSchedule(); verify(mDisp, times(15)).handle(argThat(new IsPreemptionRequestFor(appC))); }
@Test public void testHierarchicalLarge() { int[][] qData = new int[][] { { 400, 200, 60, 140, 100, 70, 30, 100, 10, 90 }, { 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, }, { 400, 210, 70,140, 100, 50, 50, 90, 90, 0 }, { 10, 0, 0, 0, 0, 0, 0, 0, 0, 15 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 6, 2, 1, 1, 2, 1, 1, 2, 1, 1 }, { -1, -1, 1, 1, -1, 1, 1, -1, 1, 1 }, { 3, 2, 0, 0, 2, 0, 0, 2, 0, 0 }, }; ProportionalCapacityPreemptionPolicy policy = buildPolicy(qData); policy.editSchedule(); verify(mDisp, times(10)).handle(argThat(new IsPreemptionRequestFor(appA))); verify(mDisp, times(5)).handle(argThat(new IsPreemptionRequestFor(appE))); }
@Test public void testPreemptionWithVCoreResource() { int[][] qData = new int[][] { { 100, 100, 100 }, { 5, 1, 1 }, { 2, 0, 0 }, }; String[][] resData = new String[][] { { "100:100", "50:50", "50:50" }, { "10:100", "10:100", "0" }, { "70:20", "70:20", "10:100" }, { "0", "0", "0" }, { "-1", "1:10", "1:10" }, }; ProportionalCapacityPreemptionPolicy policy = buildPolicy(qData, resData, true); policy.editSchedule(); verify(mDisp, times(5)).handle(argThat(new IsPreemptionRequestFor(appA))); }