// Private ------------------------------------------------------------------------------
private void testConsumerWithFilters(final boolean direct) throws Exception
{
QueueImpl queue = new QueueImpl(1,
QueueImplTest.address1,
QueueImplTest.queue1,
null,
false,
true,
scheduledExecutor,
new FakePostOffice(),
null,
null,
executor);
Filter filter = new FakeFilter("fruit", "orange");
FakeConsumer consumer = new FakeConsumer(filter);
if (direct)
{
queue.addConsumer(consumer);
}
List<MessageReference> refs = new ArrayList<MessageReference>();
MessageReference ref1 = generateReference(queue, 1);
ref1.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));
queue.addTail(ref1);
MessageReference ref2 = generateReference(queue, 2);
ref2.getMessage().putStringProperty(new SimpleString("cheese"), new SimpleString("stilton"));
queue.addTail(ref2);
MessageReference ref3 = generateReference(queue, 3);
ref3.getMessage().putStringProperty(new SimpleString("cake"), new SimpleString("sponge"));
queue.addTail(ref3);
MessageReference ref4 = generateReference(queue, 4);
ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
refs.add(ref4);
queue.addTail(ref4);
MessageReference ref5 = generateReference(queue, 5);
ref5.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("apple"));
queue.addTail(ref5);
MessageReference ref6 = generateReference(queue, 6);
ref6.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
refs.add(ref6);
queue.addTail(ref6);
if (!direct)
{
queue.addConsumer(consumer);
queue.deliverNow();
}
Assert.assertEquals(6, queue.getMessageCount());
awaitExecution();;
Assert.assertEquals(2, consumer.getReferences().size());
Assert.assertEquals(2, queue.getDeliveringCount());
assertRefListsIdenticalRefs(refs, consumer.getReferences());
queue.acknowledge(ref5);
queue.acknowledge(ref6);
queue.removeConsumer(consumer);
consumer = new FakeConsumer();
queue.addConsumer(consumer);
queue.deliverNow();
Assert.assertEquals(4, queue.getMessageCount());
Assert.assertEquals(4, consumer.getReferences().size());
Assert.assertEquals(4, queue.getDeliveringCount());
}