System.out.println("***" + ME);
try {
//========== Test 1: peek()
{
DummyEntry[] queueEntries = {
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true)
};
queue.put(queueEntries, false);
for (int ii=0; ii<10; ii++) {
I_QueueEntry result = queue.peek();
assertTrue("Missing entry", result != null);
assertEquals(ME+": Wrong result", queueEntries[0].getUniqueId(), result.getUniqueId());
}
queue.remove(); // Remove one
for (int ii=0; ii<10; ii++) {
I_QueueEntry result = queue.peek();
assertTrue("Missing entry", result != null);
assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), result.getUniqueId());
}
queue.remove(); // Remove one
for (int ii=0; ii<10; ii++) {
I_QueueEntry result = queue.peek();
assertTrue("Missing entry", result != null);
assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), result.getUniqueId());
}
queue.remove(); // Remove one
for (int ii=0; ii<10; ii++) {
I_QueueEntry result = queue.peek();
assertTrue("Unexpected entry", result == null);
}
log.info("#1 Success, peek()");
}
//========== Test 2: peek(num)
{
DummyEntry[] queueEntries = {
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true)
};
queue.put(queueEntries, false);
for (int ii=-1; ii<100; ii++) {
List<I_Entry> results = queue.peek(ii, -1L); // does no remove
assertTrue("Missing entry", results != null);
int expected = ii;
if (ii == -1 || ii >= queueEntries.length)
expected = queueEntries.length;
assertEquals(ME+": Wrong number of entries returned ii=" + ii, expected, results.size());
}
queue.clear();
log.info("#2 Success, peek(int)");
}
//========== Test 3: peekSamePriority(-1)
{
DummyEntry[] queueEntries = {
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true)
};
queue.put(queueEntries, false);
int[] prios = { 9, 7, 5 };
for (int j=0; j<prios.length; j++) {
for (int ii=0; ii<10; ii++) {
List<I_Entry> results = queue.peekSamePriority(-1, -1L); // does no remove
assertTrue("Expected results", results != null);
assertEquals(ME+": Wrong number of 9 priorities", 4, results.size());
for (int k=0; k<results.size(); ++k)
assertEquals(ME+": Wrong priority returned", prios[j], ((I_QueueEntry)results.get(k)).getPriority());
}
for (int ii=0; ii<4; ii++) {
int num = queue.remove();
assertEquals(ME+": Expected remove", 1, num);
}
}
assertEquals(ME+": Expected empty queue", 0, queue.getNumOfEntries());
log.info("#3 Success, peekSamePriority()");
}
//========== Test 4: peekWithPriority(-1,7,9)
{
DummyEntry[] queueEntries = {
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.LOW_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MIN_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), true),
new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, queue.getStorageId(), true)
};
queue.put(queueEntries, false);
for (int ii=0; ii<10; ii++) {
List<I_Entry> results = queue.peekWithPriority(-1, -1L, 7, 9); // does no remove
assertTrue("Expected results", results != null);
assertEquals(ME+": Wrong number of 9 priorities", 8, results.size());
for (int k=0; k<results.size(); ++k) {
assertEquals(ME+": Wrong priority returned", (k<4)?9L:7L, ((I_QueueEntry)results.get(k)).getPriority());
}
}
queue.clear();
assertEquals(ME+": Expected empty queue", 0, queue.getNumOfEntries());
log.info("#4 Success, peekWithPriority()");
}
//========== Test 5: peek(100, 60)
{
DummyEntry[] queueEntries = {
new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), 80, true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), 80, true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), 80, true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), 80, true),
new DummyEntry(glob, PriorityEnum.HIGH_PRIORITY, queue.getStorageId(), 80, true),
};
queue.put(queueEntries, false);
try {
List<I_Entry> results = queue.peek(100, 60); // does no remove