Search in sources :

Example 1 with FakeConsumer

use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.

the class QueueImplTest method testBusyConsumer.

@Test
public void testBusyConsumer() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    FakeConsumer consumer = new FakeConsumer();
    consumer.setStatusImmediate(HandleStatus.BUSY);
    queue.addConsumer(consumer);
    final int numMessages = 10;
    List<MessageReference> refs = new ArrayList<>();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    queue.deliverNow();
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    Assert.assertTrue(consumer.getReferences().isEmpty());
    consumer.setStatusImmediate(HandleStatus.HANDLED);
    queue.deliverNow();
    assertRefListsIdenticalRefs(refs, consumer.getReferences());
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(10, queue.getDeliveringCount());
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 2 with FakeConsumer

use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.

the class QueueImplTest method testBusyConsumerThenAddMoreMessages.

@Test
public void testBusyConsumerThenAddMoreMessages() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    FakeConsumer consumer = new FakeConsumer();
    consumer.setStatusImmediate(HandleStatus.BUSY);
    queue.addConsumer(consumer);
    final int numMessages = 10;
    List<MessageReference> refs = new ArrayList<>();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    queue.deliverNow();
    Assert.assertEquals(10, getMessageCount(queue));
    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);
        queue.addTail(ref);
    }
    Assert.assertEquals(20, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    Assert.assertTrue(consumer.getReferences().isEmpty());
    consumer.setStatusImmediate(HandleStatus.HANDLED);
    for (int i = numMessages * 2; i < numMessages * 3; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    queue.deliverNow();
    assertRefListsIdenticalRefs(refs, consumer.getReferences());
    Assert.assertEquals(30, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(30, queue.getDeliveringCount());
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 3 with FakeConsumer

use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.

the class QueueImplTest method testWithPriorities.

@Test
public void testWithPriorities() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    final int numMessages = 10;
    List<MessageReference> refs = new ArrayList<>();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        ref.getMessage().setPriority((byte) i);
        refs.add(ref);
        queue.addTail(ref);
    }
    queue.deliverNow();
    FakeConsumer consumer = new FakeConsumer();
    queue.addConsumer(consumer);
    queue.deliverNow();
    List<MessageReference> receivedRefs = consumer.getReferences();
    // Should be in reverse order
    Assert.assertEquals(refs.size(), receivedRefs.size());
    for (int i = 0; i < numMessages; i++) {
        Assert.assertEquals(refs.get(i), receivedRefs.get(9 - i));
    }
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 4 with FakeConsumer

use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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 5 with FakeConsumer

use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.

the class QueueImplTest method testBusyConsumerWithFilterThenAddMoreMessages.

@Test
public void testBusyConsumerWithFilterThenAddMoreMessages() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    FakeConsumer consumer = new FakeConsumer(FilterImpl.createFilter("color = 'green'"));
    consumer.setStatusImmediate(HandleStatus.BUSY);
    queue.addConsumer(consumer);
    final int numMessages = 10;
    List<MessageReference> refs = new ArrayList<>();
    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, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    queue.deliverNow();
    Assert.assertEquals(10, getMessageCount(queue));
    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, getMessageCount(queue));
    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, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(10, queue.getDeliveringCount());
    List<MessageReference> receeivedRefs = consumer.getReferences();
    int currId = 10;
    for (MessageReference receeivedRef : receeivedRefs) {
        Assert.assertEquals("messages received out of order", receeivedRef.getMessage().getMessageID(), currId++);
    }
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Aggregations

QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)21 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)21 Test (org.junit.Test)20 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)18 ArrayList (java.util.ArrayList)16 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 Filter (org.apache.activemq.artemis.core.filter.Filter)3 FakeFilter (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter)3 Consumer (org.apache.activemq.artemis.core.server.Consumer)2 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1