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);
BlockingQueueWrapper wrapper = new BlockingQueueWrapper(200L);
wrapper.init(queue);
int numOfEntries = 2;
List<I_Entry> ret = wrapper.blockingPeek(numOfEntries, 1000L);
assertEquals("Wrong number of entries found", 2, ret.size());
queue.removeNum(2);
numOfEntries = 2;
ret = wrapper.blockingPeek(numOfEntries, 1000L);
assertEquals("Wrong number of entries found", 1, ret.size());
queue.clear();
ret = wrapper.blockingPeek(numOfEntries, 1000L);
assertEquals("Wrong number of entries found", 0, ret.size());
// and now making asynchronous putting with events
numOfEntries = 3;
long delay = 500L;
boolean inhibitEvents = false;
QueuePutter putter = new QueuePutter(this.queue, delay, numOfEntries, inhibitEvents);
putter.start();
long t0 = System.currentTimeMillis();
ret = wrapper.blockingPeek(numOfEntries, 10000L);
assertEquals("Wrong number of entries when blocking with events", numOfEntries, ret.size());
long delta = System.currentTimeMillis() - t0;
log.info("The blocking request with events took '" + delta + "' milliseconds");
assertTrue("The method was blocking too long (did probably not wake up correctly", delta < 7000L);
queue.clear();
// and now making asynchronous putting without events (polling should detect it)
numOfEntries = 3;
delay = 500L;
inhibitEvents = true;
putter = new QueuePutter(this.queue, delay, numOfEntries, inhibitEvents);
putter.start();
t0 = System.currentTimeMillis();
ret = wrapper.blockingPeek(numOfEntries, 10000L);
assertEquals("Wrong number of entries when blocking with events", numOfEntries, ret.size());
delta = System.currentTimeMillis() - t0;
log.info("The blocking request without events took '" + delta + "' milliseconds");
assertTrue("The method was blocking too long (did probably not wake up correctly", delta < 7000L);
queue.clear();