Search in sources :

Example 31 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl 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 32 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl 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 33 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl 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 34 with QueueImpl

use of org.apache.activemq.artemis.core.server.impl.QueueImpl 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 35 with QueueImpl

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

QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)48 Test (org.junit.Test)41 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)26 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)21 ArrayList (java.util.ArrayList)17 MessageConsumer (javax.jms.MessageConsumer)6 MessageProducer (javax.jms.MessageProducer)6 Session (javax.jms.Session)6 Filter (org.apache.activemq.artemis.core.filter.Filter)6 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)5 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)4 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)4 FakeFilter (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Connection (javax.jms.Connection)3 Queue (javax.jms.Queue)3