Search in sources :

Example 6 with QueueImpl

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

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

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

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

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