Search in sources :

Example 51 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference 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 52 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference 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)

Example 53 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImplTest method testPauseAndResumeWithDirect.

/**
 * Test the paused and resumed states with direct deliveries.
 *
 * @throws Exception
 */
@Test
public void testPauseAndResumeWithDirect() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    // Now add a consumer
    FakeConsumer consumer = new FakeConsumer();
    queue.addConsumer(consumer);
    // brings to queue to paused state
    queue.pause();
    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);
    }
    // the queue even if it's paused will receive the message but won't forward
    // directly to the consumer until resumed.
    Assert.assertEquals(numMessages, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    Assert.assertTrue(consumer.getReferences().isEmpty());
    // brings the queue to resumed state.
    queue.resume();
    awaitExecution();
    // resuming delivery of messages
    assertRefListsIdenticalRefs(refs, consumer.getReferences());
    Assert.assertEquals(numMessages, getMessageCount(queue));
    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)

Example 54 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImplTest method testChangeConsumersAndDeliver.

@Test
public void testChangeConsumersAndDeliver() 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(numMessages, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(0, queue.getDeliveringCount());
    FakeConsumer cons1 = new FakeConsumer();
    queue.addConsumer(cons1);
    queue.deliverNow();
    Assert.assertEquals(numMessages, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(numMessages, queue.getDeliveringCount());
    assertRefListsIdenticalRefs(refs, cons1.getReferences());
    FakeConsumer cons2 = new FakeConsumer();
    queue.addConsumer(cons2);
    Assert.assertEquals(2, queue.getConsumerCount());
    cons1.getReferences().clear();
    for (MessageReference ref : refs) {
        queue.acknowledge(ref);
    }
    refs.clear();
    for (int i = 0; i < 2 * numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    queue.deliverNow();
    Assert.assertEquals(numMessages * 2, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(numMessages * 2, queue.getDeliveringCount());
    Assert.assertEquals(numMessages, cons1.getReferences().size());
    Assert.assertEquals(numMessages, cons2.getReferences().size());
    cons1.getReferences().clear();
    cons2.getReferences().clear();
    for (MessageReference ref : refs) {
        queue.acknowledge(ref);
    }
    refs.clear();
    FakeConsumer cons3 = new FakeConsumer();
    queue.addConsumer(cons3);
    Assert.assertEquals(3, queue.getConsumerCount());
    for (int i = 0; i < 3 * numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    queue.deliverNow();
    Assert.assertEquals(numMessages * 3, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(numMessages * 3, queue.getDeliveringCount());
    Assert.assertEquals(numMessages, cons1.getReferences().size());
    Assert.assertEquals(numMessages, cons2.getReferences().size());
    Assert.assertEquals(numMessages, cons3.getReferences().size());
    queue.removeConsumer(cons1);
    cons3.getReferences().clear();
    cons2.getReferences().clear();
    for (MessageReference ref : refs) {
        queue.acknowledge(ref);
    }
    refs.clear();
    for (int i = 0; i < 2 * numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    queue.deliverNow();
    Assert.assertEquals(numMessages * 2, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(numMessages * 2, queue.getDeliveringCount());
    Assert.assertEquals(numMessages, cons2.getReferences().size());
    Assert.assertEquals(numMessages, cons3.getReferences().size());
    queue.removeConsumer(cons3);
    cons2.getReferences().clear();
    for (MessageReference ref : refs) {
        queue.acknowledge(ref);
    }
    refs.clear();
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        refs.add(ref);
        queue.addTail(ref);
    }
    queue.deliverNow();
    Assert.assertEquals(numMessages, getMessageCount(queue));
    Assert.assertEquals(0, queue.getScheduledCount());
    Assert.assertEquals(numMessages, queue.getDeliveringCount());
    Assert.assertEquals(numMessages, cons2.getReferences().size());
}
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 55 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImplTest method testGetNonExistentReference.

@Test
public void testGetNonExistentReference() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    MessageReference messageReference = generateReference(queue, 1);
    MessageReference messageReference2 = generateReference(queue, 2);
    MessageReference messageReference3 = generateReference(queue, 3);
    queue.addHead(messageReference, false);
    queue.addHead(messageReference2, false);
    queue.addHead(messageReference3, false);
    Assert.assertNull(queue.getReference(5));
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Aggregations

MessageReference (org.apache.activemq.artemis.core.server.MessageReference)82 ArrayList (java.util.ArrayList)29 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)26 Test (org.junit.Test)26 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)18 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)14 Message (org.apache.activemq.artemis.api.core.Message)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)11 Queue (org.apache.activemq.artemis.core.server.Queue)10 HashMap (java.util.HashMap)9 NoSuchElementException (java.util.NoSuchElementException)9 Map (java.util.Map)8 Filter (org.apache.activemq.artemis.core.filter.Filter)7 LinkedList (java.util.LinkedList)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)5 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)4 BindingsTransactionImpl (org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl)4 HashSet (java.util.HashSet)3