// The tests ----------------------------------------------------------------
public void testScheduledNoConsumer() throws Exception
{
QueueImpl queue = new QueueImpl(1,
new SimpleString("address1"),
new SimpleString("queue1"),
null,
false,
true,
scheduledExecutor,
null,
null,
null,
Executors.newSingleThreadExecutor());
// Send one scheduled
long now = System.currentTimeMillis();
MessageReference ref1 = generateReference(queue, 1);
ref1.setScheduledDeliveryTime(now + 7000);
queue.addLast(ref1);
// Send some non scheduled messages
MessageReference ref2 = generateReference(queue, 2);
queue.addLast(ref2);
MessageReference ref3 = generateReference(queue, 3);
queue.addLast(ref3);
MessageReference ref4 = generateReference(queue, 4);
queue.addLast(ref4);
// Now send some more scheduled messages
MessageReference ref5 = generateReference(queue, 5);
ref5.setScheduledDeliveryTime(now + 5000);
queue.addLast(ref5);
MessageReference ref6 = generateReference(queue, 6);
ref6.setScheduledDeliveryTime(now + 4000);
queue.addLast(ref6);
MessageReference ref7 = generateReference(queue, 7);
ref7.setScheduledDeliveryTime(now + 3000);
queue.addLast(ref7);
MessageReference ref8 = generateReference(queue, 8);
ref8.setScheduledDeliveryTime(now + 6000);
queue.addLast(ref8);
List<MessageReference> refs = new ArrayList<MessageReference>();
// Scheduled refs are added back to *FRONT* of queue - otherwise if there were many messages in the queue
// They may get stranded behind a big backlog
refs.add(ref1);
refs.add(ref8);
refs.add(ref5);
refs.add(ref6);
refs.add(ref7);
refs.add(ref2);
refs.add(ref3);
refs.add(ref4);
Thread.sleep(7500);
FakeConsumer consumer = new FakeConsumer();
queue.addConsumer(consumer);
queue.deliverNow();
assertRefListsIdenticalRefs(refs, consumer.getReferences());
}