Search in sources :

Example 1 with FakeFilter

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());
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Filter(org.apache.activemq.artemis.core.filter.Filter) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) Test(org.junit.Test)

Example 2 with FakeFilter

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());
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Filter(org.apache.activemq.artemis.core.filter.Filter) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter)

Example 3 with FakeFilter

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);
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Filter(org.apache.activemq.artemis.core.filter.Filter) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) Test(org.junit.Test)

Aggregations

Filter (org.apache.activemq.artemis.core.filter.Filter)3 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)3 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)3 FakeFilter (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter)3 ArrayList (java.util.ArrayList)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)2 Test (org.junit.Test)2