assertRefListsIdenticalRefs(allRefs, consumer.getReferences());
}
public void testChangeConsumersAndDeliver() throws Exception
{
QueueImpl queue = new QueueImpl(1,
QueueImplTest.address1,
QueueImplTest.queue1,
null,
false,
true,
scheduledExecutor,
new FakePostOffice(),
null,
null,
executor);
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.addTail(ref);
}
Assert.assertEquals(numMessages, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
FakeConsumer cons1 = new FakeConsumer();
queue.addConsumer(cons1);
queue.deliverNow();
Assert.assertEquals(numMessages, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages, queue.getDeliveringCount());
assertRefListsIdenticalRefs(refs, cons1.getReferences());
FakeConsumer cons2 = new FakeConsumer();
queue.addConsumer(cons2);
Assert.assertEquals(2, queue.getConsumerCount());
cons1.getReferences().clear();
for (MessageReference ref : refs)
{
queue.acknowledge(ref);
}
refs.clear();
for (int i = 0; i < 2 * numMessages; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
queue.deliverNow();
Assert.assertEquals(numMessages * 2, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages * 2, queue.getDeliveringCount());
Assert.assertEquals(numMessages, cons1.getReferences().size());
Assert.assertEquals(numMessages, cons2.getReferences().size());
cons1.getReferences().clear();
cons2.getReferences().clear();
for (MessageReference ref : refs)
{
queue.acknowledge(ref);
}
refs.clear();
FakeConsumer cons3 = new FakeConsumer();
queue.addConsumer(cons3);
Assert.assertEquals(3, queue.getConsumerCount());
for (int i = 0; i < 3 * numMessages; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
queue.deliverNow();
Assert.assertEquals(numMessages * 3, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages * 3, queue.getDeliveringCount());
Assert.assertEquals(numMessages, cons1.getReferences().size());
Assert.assertEquals(numMessages, cons2.getReferences().size());
Assert.assertEquals(numMessages, cons3.getReferences().size());
queue.removeConsumer(cons1);
cons3.getReferences().clear();
cons2.getReferences().clear();
for (MessageReference ref : refs)
{
queue.acknowledge(ref);
}
refs.clear();
for (int i = 0; i < 2 * numMessages; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
queue.deliverNow();
Assert.assertEquals(numMessages * 2, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages * 2, queue.getDeliveringCount());
Assert.assertEquals(numMessages, cons2.getReferences().size());
Assert.assertEquals(numMessages, cons3.getReferences().size());
queue.removeConsumer(cons3);
cons2.getReferences().clear();
for (MessageReference ref : refs)
{
queue.acknowledge(ref);
}
refs.clear();
for (int i = 0; i < numMessages; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
queue.deliverNow();
Assert.assertEquals(numMessages, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages, queue.getDeliveringCount());
Assert.assertEquals(numMessages, cons2.getReferences().size());
}