use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter in project activemq-artemis by apache.
the class QueueImplTest method testConsumeWithFiltersAddAndRemoveConsumer.
@Test
public void testConsumeWithFiltersAddAndRemoveConsumer() throws Exception {
QueueImpl queue = getTemporaryQueue();
Filter filter = new FakeFilter("fruit", "orange");
FakeConsumer consumer = new FakeConsumer(filter);
queue.addConsumer(consumer);
List<MessageReference> refs = new ArrayList<>();
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("fruit"), new SimpleString("orange"));
queue.addTail(ref2);
refs.add(ref2);
Assert.assertEquals(2, getMessageCount(queue));
awaitExecution();
Assert.assertEquals(1, consumer.getReferences().size());
Assert.assertEquals(1, queue.getDeliveringCount());
assertRefListsIdenticalRefs(refs, consumer.getReferences());
queue.acknowledge(ref2);
queue.removeConsumer(consumer);
queue.addConsumer(consumer);
queue.deliverNow();
refs.clear();
consumer.clearReferences();
MessageReference ref3 = generateReference(queue, 3);
ref3.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));
queue.addTail(ref3);
MessageReference ref4 = generateReference(queue, 4);
ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
queue.addTail(ref4);
refs.add(ref4);
Assert.assertEquals(3, getMessageCount(queue));
awaitExecution();
Assert.assertEquals(1, consumer.getReferences().size());
Assert.assertEquals(1, queue.getDeliveringCount());
assertRefListsIdenticalRefs(refs, consumer.getReferences());
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter in project activemq-artemis by apache.
the class QueueImplTest method testConsumerWithFilters.
// Private ------------------------------------------------------------------------------
private void testConsumerWithFilters(final boolean direct) throws Exception {
QueueImpl queue = getTemporaryQueue();
Filter filter = new FakeFilter("fruit", "orange");
FakeConsumer consumer = new FakeConsumer(filter);
if (direct) {
queue.addConsumer(consumer);
}
List<MessageReference> refs = new ArrayList<>();
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, getMessageCount(queue));
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, getMessageCount(queue));
Assert.assertEquals(4, consumer.getReferences().size());
Assert.assertEquals(4, queue.getDeliveringCount());
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter in project activemq-artemis by apache.
the class QueueImplTest method testConsumerWithFilterAddAndRemove.
@Test
public void testConsumerWithFilterAddAndRemove() {
QueueImpl queue = getTemporaryQueue();
Filter filter = new FakeFilter("fruit", "orange");
FakeConsumer consumer = new FakeConsumer(filter);
}
Aggregations