|
@@ -176,6 +176,12 @@ public class TestCallQueueManager {
|
|
private static final Class<? extends RpcScheduler> schedulerClass
|
|
private static final Class<? extends RpcScheduler> schedulerClass
|
|
= CallQueueManager.convertSchedulerClass(DefaultRpcScheduler.class);
|
|
= CallQueueManager.convertSchedulerClass(DefaultRpcScheduler.class);
|
|
|
|
|
|
|
|
+ private static final Class<? extends BlockingQueue<FakeCall>> fcqueueClass
|
|
|
|
+ = CallQueueManager.convertQueueClass(FairCallQueue.class, FakeCall.class);
|
|
|
|
+
|
|
|
|
+ private static final Class<? extends RpcScheduler> rpcSchedulerClass
|
|
|
|
+ = CallQueueManager.convertSchedulerClass(DecayRpcScheduler.class);
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testCallQueueCapacity() throws InterruptedException {
|
|
public void testCallQueueCapacity() throws InterruptedException {
|
|
manager = new CallQueueManager<FakeCall>(queueClass, schedulerClass, false,
|
|
manager = new CallQueueManager<FakeCall>(queueClass, schedulerClass, false,
|
|
@@ -319,6 +325,55 @@ public class TestCallQueueManager {
|
|
assertEquals(totalCallsConsumed, totalCallsCreated);
|
|
assertEquals(totalCallsConsumed, totalCallsCreated);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testQueueCapacity() throws InterruptedException {
|
|
|
|
+ int capacity = 4;
|
|
|
|
+ String ns = "ipc.8020";
|
|
|
|
+ conf.setInt("ipc.8020.scheduler.priority.levels", 2);
|
|
|
|
+ conf.set("ipc.8020.callqueue.capacity.weights", "1,3");
|
|
|
|
+ manager = new CallQueueManager<>(fcqueueClass, rpcSchedulerClass, false,
|
|
|
|
+ capacity, ns, conf);
|
|
|
|
+
|
|
|
|
+ // insert 4 calls with 2 at each priority
|
|
|
|
+ // since the queue with priority 0 has only 1 capacity, the second call
|
|
|
|
+ // with p0 will be overflowed to queue with priority 1
|
|
|
|
+ for (int i = 0; i < capacity; i++) {
|
|
|
|
+ FakeCall fc = new FakeCall(i);
|
|
|
|
+ fc.setPriorityLevel(i%2);
|
|
|
|
+ manager.put(fc);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // get calls, the order should be
|
|
|
|
+ // call 0 with p0
|
|
|
|
+ // call 1 with p1
|
|
|
|
+ // call 2 with p0 since overflow
|
|
|
|
+ // call 3 with p1
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 0);
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 1);
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 0);
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 1);
|
|
|
|
+
|
|
|
|
+ conf.set("ipc.8020.callqueue.capacity.weights", "1,1");
|
|
|
|
+ manager = new CallQueueManager<>(fcqueueClass, rpcSchedulerClass, false,
|
|
|
|
+ capacity, ns, conf);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < capacity; i++) {
|
|
|
|
+ FakeCall fc = new FakeCall(i);
|
|
|
|
+ fc.setPriorityLevel(i%2);
|
|
|
|
+ manager.put(fc);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // get calls, the order should be
|
|
|
|
+ // call 0 with p0
|
|
|
|
+ // call 2 with p0
|
|
|
|
+ // call 1 with p1
|
|
|
|
+ // call 3 with p1
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 0);
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 0);
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 1);
|
|
|
|
+ assertEquals(manager.take().priorityLevel, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
public static class ExceptionFakeCall implements Schedulable {
|
|
public static class ExceptionFakeCall implements Schedulable {
|
|
public ExceptionFakeCall() {
|
|
public ExceptionFakeCall() {
|
|
throw new IllegalArgumentException("Exception caused by call queue " +
|
|
throw new IllegalArgumentException("Exception caused by call queue " +
|