* Test the paused and resumed states with async deliveries.
* @throws Exception
*/
public void testPauseAndResumeWithAsync() throws Exception
{
QueueImpl queue = new QueueImpl(1,
QueueImplTest.address1,
QueueImplTest.queue1,
null,
false,
true,
scheduledExecutor,
null,
null,
null,
executor);
// pauses the queue
queue.pause();
final int numMessages = 10;
List<MessageReference> refs = new ArrayList<MessageReference>();
for (int i = 0; i < numMessages; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addLast(ref);
}
// even as this queue is paused, it will receive the messages anyway
Assert.assertEquals(10, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
// Now add a consumer
FakeConsumer consumer = new FakeConsumer();
queue.addConsumer(consumer);
Assert.assertTrue(consumer.getReferences().isEmpty());
Assert.assertEquals(10, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
// explicit order of delivery
queue.deliverNow();
// As the queue is paused, even an explicit order of delivery will not work.
Assert.assertEquals(0, consumer.getReferences().size());
Assert.assertEquals(numMessages, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
// resuming work
queue.resume();
awaitExecution();;
// after resuming the delivery begins.
assertRefListsIdenticalRefs(refs, consumer.getReferences());
Assert.assertEquals(numMessages, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages, queue.getDeliveringCount());
}