Search in sources :

Example 11 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 testaddHeadadd.

@Test
public void testaddHeadadd() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    final int numMessages = 10;
    List<MessageReference> refs1 = new ArrayList<>();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs1.add(ref);
        queue.addTail(ref);
    }
    LinkedList<MessageReference> refs2 = new LinkedList<>();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i + numMessages);
        refs2.addFirst(ref);
        queue.addHead(ref, false);
    }
    List<MessageReference> refs3 = new ArrayList<>();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i + 2 * numMessages);
        refs3.add(ref);
        queue.addTail(ref);
    }
    FakeConsumer consumer = new FakeConsumer();
    queue.addConsumer(consumer);
    queue.deliverNow();
    List<MessageReference> allRefs = new ArrayList<>();
    allRefs.addAll(refs2);
    allRefs.addAll(refs1);
    allRefs.addAll(refs3);
    assertRefListsIdenticalRefs(allRefs, consumer.getReferences());
}
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) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 12 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 testBusyConsumerWithFilterFirstCallBusy.

@Test
public void testBusyConsumerWithFilterFirstCallBusy() 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", "green");
        refs.add(ref);
        queue.addTail(ref);
    }
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    queue.deliverNow();
    consumer.setStatusImmediate(null);
    queue.deliverNow();
    List<MessageReference> receeivedRefs = consumer.getReferences();
    int currId = 0;
    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)

Example 13 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 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)

Example 14 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 testMessageOrder.

@Test
public void testMessageOrder() throws Exception {
    FakeConsumer consumer = new FakeConsumer();
    QueueImpl queue = getTemporaryQueue();
    MessageReference messageReference = generateReference(queue, 1);
    MessageReference messageReference2 = generateReference(queue, 2);
    MessageReference messageReference3 = generateReference(queue, 3);
    queue.addHead(messageReference, false);
    queue.addTail(messageReference2);
    queue.addHead(messageReference3, false);
    Assert.assertEquals(0, consumer.getReferences().size());
    queue.addConsumer(consumer);
    queue.deliverNow();
    Assert.assertEquals(3, consumer.getReferences().size());
    Assert.assertEquals(messageReference3, consumer.getReferences().get(0));
    Assert.assertEquals(messageReference, consumer.getReferences().get(1));
    Assert.assertEquals(messageReference2, consumer.getReferences().get(2));
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 15 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 testSimpleNonDirectDelivery.

@Test
public void testSimpleNonDirectDelivery() 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);
        refs.add(ref);
        queue.addTail(ref);
    }
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    // Now add a consumer
    FakeConsumer consumer = new FakeConsumer();
    queue.addConsumer(consumer);
    Assert.assertTrue(consumer.getReferences().isEmpty());
    Assert.assertEquals(10, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    queue.deliverNow();
    assertRefListsIdenticalRefs(refs, consumer.getReferences());
    Assert.assertEquals(numMessages, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(numMessages, 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)

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