PriorityUtilizationQueueOrderingPolicy implements QueueOrderingPolicy { @Override public void setQueues(List<CSQueue> queues) { this.queues = queues; } PriorityUtilizationQueueOrderingPolicy(boolean respectPriority); static int compare(double relativeAssigned1, double relativeAssigned2,
      int priority1, int priority2); @Override void setQueues(List<CSQueue> queues); @Override Iterator<CSQueue> getAssignmentIterator(String partition); @Override String getConfigName(); @VisibleForTesting List<CSQueue> getQueues();  }
@Test public void testUtilizationOrdering() { PriorityUtilizationQueueOrderingPolicy policy = new PriorityUtilizationQueueOrderingPolicy(false); policy.setQueues(mockCSQueues(new String[] { "a" }, new int[] { 0 }, new float[] { 0.1f }, new float[] {0.2f}, "")); verifyOrder(policy, "", new String[] { "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 0, 0 }, new float[] { 0.1f, 0.0f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "b", "a" }); policy.setQueues( mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 0, 0, 0 }, new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f}, "")); verifyOrder(policy, "", new String[] { "b", "a", "c" }); policy.setQueues( mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 }, new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f}, "")); verifyOrder(policy, "", new String[] { "b", "a", "c" }); policy.setQueues( mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 }, new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f}, "x")); verifyOrder(policy, "", new String[] { "a", "b", "c" }); policy.setQueues( mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 }, new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f}, "x")); verifyOrder(policy, "x", new String[] { "b", "a", "c" }); List<CSQueue> queues = mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 }, new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f}, "x"); when(queues.get(0).getAccessibleNodeLabels()).thenReturn(ImmutableSet.of("x", "y")); when(queues.get(2).getAccessibleNodeLabels()).thenReturn(ImmutableSet.of("x", "y")); policy.setQueues(queues); verifyOrder(policy, "x", new String[] { "a", "c", "b" }); }
@Test public void testPriorityUtilizationOrdering() { PriorityUtilizationQueueOrderingPolicy policy = new PriorityUtilizationQueueOrderingPolicy(true); policy.setQueues(mockCSQueues(new String[] { "a" }, new int[] { 1 }, new float[] { 0.1f }, new float[] {0.2f}, "")); verifyOrder(policy, "", new String[] { "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 }, new float[] { 0.2f, 0.1f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "b", "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 }, new float[] { 1.1f, 1.2f },new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 }, new float[] { 0.1f, 1.2f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 }, new float[] { 1.1f, 1.2f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "b", "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 }, new float[] { 0.1f, 0.2f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "b", "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 }, new float[] { 0.1f, 1.2f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 2, 1 }, new float[] { 0.1f, 1.2f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 }, new float[] { 0.1f, 1.0f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 2, 1 }, new float[] { 0.1f, 1.0f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 }, new float[] { 0.1f, 1.0f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 }, new float[] { 1.0f, 1.0f }, new float[] {0.2f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "b", "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" }, new int[] { 1, 2, 0, 0, 3 }, new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, new float[] { 0.2f, 0.1f, 0.1f, 0.3f, 0.3f }, "")); verifyOrder(policy, "", new String[] { "e", "c", "b", "a", "d" }); policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" }, new int[] { 1, 2, 0, 0, 3 }, new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, new float[] { 0.2f, 0.1f, 0.1f, 0.3f, 0.3f }, "x")); verifyOrder(policy, "", new String[] { "e", "b", "a", "c", "d" }); policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" }, new int[] { 1, 2, 0, 0, 3 }, new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, new float[] { 0.2f, 0.1f, 0.1f, 0.3f, 0.3f }, "x")); verifyOrder(policy, "x", new String[] { "e", "c", "b", "a", "d" }); List<CSQueue> queues = mockCSQueues(new String[] { "a", "b", "c", "d", "e" }, new int[] { 1, 2, 0, 0, 3 }, new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, new float[] { 0.2f, 0.1f, 0.1f, 0.3f, 0.3f }, "x"); when(queues.get(0).getAccessibleNodeLabels()).thenReturn( ImmutableSet.of("x")); when(queues.get(3).getAccessibleNodeLabels()).thenReturn( ImmutableSet.of("x")); policy.setQueues(queues); verifyOrder(policy, "x", new String[] { "a", "d", "e", "c", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 }, new float[] { 0.1f, 1.2f }, new float[] {0.0f, 0.3f}, "")); verifyOrder(policy, "", new String[] { "b", "a" }); policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 }, new float[] { 0.1f, 1.2f }, new float[] {0.3f, 0.0f}, "")); verifyOrder(policy, "", new String[] { "a", "b" }); policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" }, new int[] { 1, 2, 0, 0, 3 }, new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, new float[] { 0.0f, 0.0f, 0.1f, 0.3f, 0.3f }, "x")); verifyOrder(policy, "x", new String[] { "e", "c", "d", "b", "a" }); }