PriorityScheduler extends DuplicateRemovedScheduler implements MonitorableScheduler { @Override public synchronized Request poll(Task task) { Request poll = priorityQueuePlus.poll(); if (poll != null) { return poll; } poll = noPriorityQueue.poll(); if (poll != null) { return poll; } return priorityQueueMinus.poll(); }  @Override void pushWhenNoDuplicate(Request request, Task task); @Override synchronized Request poll(Task task); @Override int getLeftRequestsCount(Task task); @Override int getTotalRequestsCount(Task task); static final int INITIAL_CAPACITY; }
@Test public void testDifferentPriority() { Request request = new Request("a"); request.setPriority(100); priorityScheduler.push(request,task); request = new Request("b"); request.setPriority(900); priorityScheduler.push(request,task); request = new Request("c"); priorityScheduler.push(request,task); request = new Request("d"); request.setPriority(-900); priorityScheduler.push(request,task); Request poll = priorityScheduler.poll(task); Assert.assertEquals("b",poll.getUrl()); poll = priorityScheduler.poll(task); Assert.assertEquals("a",poll.getUrl()); poll = priorityScheduler.poll(task); Assert.assertEquals("c",poll.getUrl()); poll = priorityScheduler.poll(task); Assert.assertEquals("d",poll.getUrl()); }
@Test public void testNoPriority() { Request request = new Request("a"); priorityScheduler.push(request,task); request = new Request("b"); priorityScheduler.push(request,task); request = new Request("c"); priorityScheduler.push(request,task); Request poll = priorityScheduler.poll(task); Assert.assertEquals("a",poll.getUrl()); poll = priorityScheduler.poll(task); Assert.assertEquals("b",poll.getUrl()); poll = priorityScheduler.poll(task); Assert.assertEquals("c",poll.getUrl()); }