|
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
|
|
|
|
|
|
public class TestPriorityUtilizationQueueOrderingPolicy {
|
|
public class TestPriorityUtilizationQueueOrderingPolicy {
|
|
private List<CSQueue> mockCSQueues(String[] queueNames, int[] priorities,
|
|
private List<CSQueue> mockCSQueues(String[] queueNames, int[] priorities,
|
|
- float[] utilizations, String partition) {
|
|
|
|
|
|
+ float[] utilizations, float[] absCapacities, String partition) {
|
|
// sanity check
|
|
// sanity check
|
|
assert queueNames != null && priorities != null && utilizations != null
|
|
assert queueNames != null && priorities != null && utilizations != null
|
|
&& queueNames.length > 0 && queueNames.length == priorities.length
|
|
&& queueNames.length > 0 && queueNames.length == priorities.length
|
|
@@ -48,6 +48,7 @@ public class TestPriorityUtilizationQueueOrderingPolicy {
|
|
when(q.getQueueName()).thenReturn(queueNames[i]);
|
|
when(q.getQueueName()).thenReturn(queueNames[i]);
|
|
|
|
|
|
QueueCapacities qc = new QueueCapacities(false);
|
|
QueueCapacities qc = new QueueCapacities(false);
|
|
|
|
+ qc.setAbsoluteCapacity(partition, absCapacities[i]);
|
|
qc.setUsedCapacity(partition, utilizations[i]);
|
|
qc.setUsedCapacity(partition, utilizations[i]);
|
|
|
|
|
|
when(q.getQueueCapacities()).thenReturn(qc);
|
|
when(q.getQueueCapacities()).thenReturn(qc);
|
|
@@ -81,41 +82,45 @@ public class TestPriorityUtilizationQueueOrderingPolicy {
|
|
|
|
|
|
// Case 1, one queue
|
|
// Case 1, one queue
|
|
policy.setQueues(mockCSQueues(new String[] { "a" }, new int[] { 0 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a" }, new int[] { 0 },
|
|
- new float[] { 0.1f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f }, new float[] {0.2f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a" });
|
|
verifyOrder(policy, "", new String[] { "a" });
|
|
|
|
|
|
// Case 2, 2 queues
|
|
// Case 2, 2 queues
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 0, 0 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 0, 0 },
|
|
- new float[] { 0.1f, 0.0f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 0.0f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
|
|
|
|
// Case 3, 3 queues
|
|
// Case 3, 3 queues
|
|
policy.setQueues(
|
|
policy.setQueues(
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 0, 0, 0 },
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 0, 0, 0 },
|
|
- new float[] { 0.1f, 0.0f, 0.2f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f},
|
|
|
|
+ ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a", "c" });
|
|
verifyOrder(policy, "", new String[] { "b", "a", "c" });
|
|
|
|
|
|
// Case 4, 3 queues, ignore priority
|
|
// Case 4, 3 queues, ignore priority
|
|
policy.setQueues(
|
|
policy.setQueues(
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
- new float[] { 0.1f, 0.0f, 0.2f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f},
|
|
|
|
+ ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a", "c" });
|
|
verifyOrder(policy, "", new String[] { "b", "a", "c" });
|
|
|
|
|
|
// Case 5, 3 queues, look at partition (default)
|
|
// Case 5, 3 queues, look at partition (default)
|
|
policy.setQueues(
|
|
policy.setQueues(
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
- new float[] { 0.1f, 0.0f, 0.2f }, "x"));
|
|
|
|
|
|
+ new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f},
|
|
|
|
+ "x"));
|
|
verifyOrder(policy, "", new String[] { "a", "b", "c" });
|
|
verifyOrder(policy, "", new String[] { "a", "b", "c" });
|
|
|
|
|
|
// Case 5, 3 queues, look at partition (x)
|
|
// Case 5, 3 queues, look at partition (x)
|
|
policy.setQueues(
|
|
policy.setQueues(
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
- new float[] { 0.1f, 0.0f, 0.2f }, "x"));
|
|
|
|
|
|
+ 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" });
|
|
verifyOrder(policy, "x", new String[] { "b", "a", "c" });
|
|
|
|
|
|
// Case 6, 3 queues, with different accessibility to partition
|
|
// Case 6, 3 queues, with different accessibility to partition
|
|
List<CSQueue> queues = mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
List<CSQueue> queues = mockCSQueues(new String[] { "a", "b", "c" }, new int[] { 2, 1, 0 },
|
|
- new float[] { 0.1f, 0.0f, 0.2f }, "x");
|
|
|
|
|
|
+ new float[] { 0.1f, 0.0f, 0.2f }, new float[] {0.2f, 0.3f, 0.4f}, "x");
|
|
// a can access "x"
|
|
// a can access "x"
|
|
when(queues.get(0).getAccessibleNodeLabels()).thenReturn(ImmutableSet.of("x", "y"));
|
|
when(queues.get(0).getAccessibleNodeLabels()).thenReturn(ImmutableSet.of("x", "y"));
|
|
// c can access "x"
|
|
// c can access "x"
|
|
@@ -131,89 +136,94 @@ public class TestPriorityUtilizationQueueOrderingPolicy {
|
|
|
|
|
|
// Case 1, one queue
|
|
// Case 1, one queue
|
|
policy.setQueues(mockCSQueues(new String[] { "a" }, new int[] { 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a" }, new int[] { 1 },
|
|
- new float[] { 0.1f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f }, new float[] {0.2f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a" });
|
|
verifyOrder(policy, "", new String[] { "a" });
|
|
|
|
|
|
// Case 2, 2 queues, both under utilized, same priority
|
|
// Case 2, 2 queues, both under utilized, same priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
- new float[] { 0.2f, 0.1f }, ""));
|
|
|
|
|
|
+ new float[] { 0.2f, 0.1f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
|
|
|
|
// Case 3, 2 queues, both over utilized, same priority
|
|
// Case 3, 2 queues, both over utilized, same priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
- new float[] { 1.1f, 1.2f }, ""));
|
|
|
|
|
|
+ new float[] { 1.1f, 1.2f },new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 4, 2 queues, one under and one over, same priority
|
|
// Case 4, 2 queues, one under and one over, same priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
- new float[] { 0.1f, 1.2f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 1.2f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 5, 2 queues, both over utilized, different priority
|
|
// Case 5, 2 queues, both over utilized, different priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
- new float[] { 1.1f, 1.2f }, ""));
|
|
|
|
|
|
+ new float[] { 1.1f, 1.2f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
|
|
|
|
// Case 6, 2 queues, both under utilized, different priority
|
|
// Case 6, 2 queues, both under utilized, different priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
- new float[] { 0.1f, 0.2f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 0.2f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
|
|
|
|
// Case 7, 2 queues, one under utilized and one over utilized,
|
|
// Case 7, 2 queues, one under utilized and one over utilized,
|
|
// different priority (1)
|
|
// different priority (1)
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
- new float[] { 0.1f, 1.2f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 1.2f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 8, 2 queues, one under utilized and one over utilized,
|
|
// Case 8, 2 queues, one under utilized and one over utilized,
|
|
// different priority (1)
|
|
// different priority (1)
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 2, 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 2, 1 },
|
|
- new float[] { 0.1f, 1.2f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 1.2f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 9, 2 queues, one under utilized and one meet, different priority (1)
|
|
// Case 9, 2 queues, one under utilized and one meet, different priority (1)
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
- new float[] { 0.1f, 1.0f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 1.0f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 10, 2 queues, one under utilized and one meet, different priority (2)
|
|
// Case 10, 2 queues, one under utilized and one meet, different priority (2)
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 2, 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 2, 1 },
|
|
- new float[] { 0.1f, 1.0f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 1.0f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 11, 2 queues, one under utilized and one meet, same priority
|
|
// Case 11, 2 queues, one under utilized and one meet, same priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 1 },
|
|
- new float[] { 0.1f, 1.0f }, ""));
|
|
|
|
|
|
+ new float[] { 0.1f, 1.0f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
verifyOrder(policy, "", new String[] { "a", "b" });
|
|
|
|
|
|
// Case 12, 2 queues, both meet, different priority
|
|
// Case 12, 2 queues, both meet, different priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b" }, new int[] { 1, 2 },
|
|
- new float[] { 1.0f, 1.0f }, ""));
|
|
|
|
|
|
+ new float[] { 1.0f, 1.0f }, new float[] {0.2f, 0.3f}, ""));
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
verifyOrder(policy, "", new String[] { "b", "a" });
|
|
|
|
|
|
// Case 13, 5 queues, different priority
|
|
// Case 13, 5 queues, different priority
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
- new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, ""));
|
|
|
|
|
|
+ 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" });
|
|
verifyOrder(policy, "", new String[] { "e", "c", "b", "a", "d" });
|
|
|
|
|
|
- // Case 14, 5 queues, different priority, partition default;
|
|
|
|
|
|
+ // Case 14, 5 queues, different priority,
|
|
|
|
+ // partition default - abs capacity is 0;
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
- new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, "x"));
|
|
|
|
|
|
+ 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" });
|
|
verifyOrder(policy, "", new String[] { "e", "b", "a", "c", "d" });
|
|
|
|
|
|
// Case 15, 5 queues, different priority, partition x;
|
|
// Case 15, 5 queues, different priority, partition x;
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
policy.setQueues(mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
- new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, "x"));
|
|
|
|
|
|
+ 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" });
|
|
verifyOrder(policy, "x", new String[] { "e", "c", "b", "a", "d" });
|
|
|
|
|
|
// Case 16, 5 queues, different priority, partition x; and different
|
|
// Case 16, 5 queues, different priority, partition x; and different
|
|
// accessibility
|
|
// accessibility
|
|
List<CSQueue> queues = mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
List<CSQueue> queues = mockCSQueues(new String[] { "a", "b", "c", "d", "e" },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
new int[] { 1, 2, 0, 0, 3 },
|
|
- new float[] { 1.2f, 1.0f, 0.2f, 1.1f, 0.2f }, "x");
|
|
|
|
|
|
+ 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");
|
|
// Only a/d has access to x
|
|
// Only a/d has access to x
|
|
when(queues.get(0).getAccessibleNodeLabels()).thenReturn(
|
|
when(queues.get(0).getAccessibleNodeLabels()).thenReturn(
|
|
ImmutableSet.of("x"));
|
|
ImmutableSet.of("x"));
|
|
@@ -221,5 +231,23 @@ public class TestPriorityUtilizationQueueOrderingPolicy {
|
|
ImmutableSet.of("x"));
|
|
ImmutableSet.of("x"));
|
|
policy.setQueues(queues);
|
|
policy.setQueues(queues);
|
|
verifyOrder(policy, "x", new String[] { "a", "d", "e", "c", "b" });
|
|
verifyOrder(policy, "x", new String[] { "a", "d", "e", "c", "b" });
|
|
|
|
+
|
|
|
|
+ // Case 17, 2 queues, one's abs capacity is 0
|
|
|
|
+ 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" });
|
|
|
|
+
|
|
|
|
+ // Case 18, 2 queues, one's abs capacity is 0
|
|
|
|
+ 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" });
|
|
|
|
+
|
|
|
|
+ //Case 19, 5 queues with 2 having abs capacity 0 are prioritized last
|
|
|
|
+ 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" });
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|