}
}
public void testBusyConsumerWithFilterThenAddMoreMessages() throws Exception
{
QueueImpl queue = new QueueImpl(1,
QueueImplTest.address1,
QueueImplTest.queue1,
null,
false,
true,
scheduledExecutor,
null,
null,
null,
executor);
FakeConsumer consumer = new FakeConsumer(FilterImpl.createFilter("color = 'green'"));
consumer.setStatusImmediate(HandleStatus.BUSY);
queue.addConsumer(consumer);
final int numMessages = 10;
List<MessageReference> refs = new ArrayList<MessageReference>();
for (int i = 0; i < numMessages; i++)
{
MessageReference ref = generateReference(queue, i);
ref.getMessage().putStringProperty("color", "red");
refs.add(ref);
queue.addTail(ref);
}
Assert.assertEquals(10, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
queue.deliverNow();
Assert.assertEquals(10, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
Assert.assertTrue(consumer.getReferences().isEmpty());
for (int i = numMessages; i < numMessages * 2; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
ref.getMessage().putStringProperty("color", "green");
queue.addTail(ref);
}
Assert.assertEquals(20, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
Assert.assertTrue(consumer.getReferences().isEmpty());
consumer.setStatusImmediate(null);
for (int i = numMessages * 2; i < numMessages * 3; i++)
{
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
queue.deliverNow();
Assert.assertEquals(numMessages, consumer.getReferences().size());
Assert.assertEquals(30, queue.getMessageCount());
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(10, queue.getDeliveringCount());
List<MessageReference> receeivedRefs = consumer.getReferences();
int currId = 10;
for (MessageReference receeivedRef : receeivedRefs)
{