use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testGetReference.
@Test
public void testGetReference() 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.assertEquals(queue.getReference(2), messageReference2);
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testConsumerWithFilters.
// Private ------------------------------------------------------------------------------
private void testConsumerWithFilters(final boolean direct) throws Exception {
QueueImpl queue = getTemporaryQueue();
Filter filter = new FakeFilter("fruit", "orange");
FakeConsumer consumer = new FakeConsumer(filter);
if (direct) {
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("cheese"), new SimpleString("stilton"));
queue.addTail(ref2);
MessageReference ref3 = generateReference(queue, 3);
ref3.getMessage().putStringProperty(new SimpleString("cake"), new SimpleString("sponge"));
queue.addTail(ref3);
MessageReference ref4 = generateReference(queue, 4);
ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
refs.add(ref4);
queue.addTail(ref4);
MessageReference ref5 = generateReference(queue, 5);
ref5.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("apple"));
queue.addTail(ref5);
MessageReference ref6 = generateReference(queue, 6);
ref6.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
refs.add(ref6);
queue.addTail(ref6);
if (!direct) {
queue.addConsumer(consumer);
queue.deliverNow();
}
Assert.assertEquals(6, getMessageCount(queue));
awaitExecution();
Assert.assertEquals(2, consumer.getReferences().size());
Assert.assertEquals(2, queue.getDeliveringCount());
assertRefListsIdenticalRefs(refs, consumer.getReferences());
queue.acknowledge(ref5);
queue.acknowledge(ref6);
queue.removeConsumer(consumer);
consumer = new FakeConsumer();
queue.addConsumer(consumer);
queue.deliverNow();
Assert.assertEquals(4, getMessageCount(queue));
Assert.assertEquals(4, consumer.getReferences().size());
Assert.assertEquals(4, queue.getDeliveringCount());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testPauseAndResumeWithAsync.
/**
* Test the paused and resumed states with async deliveries.
*
* @throws Exception
*/
@Test
public void testPauseAndResumeWithAsync() throws Exception {
QueueImpl queue = getTemporaryQueue();
// pauses the queue
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);
}
// even as this queue is paused, it will receive the messages anyway
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());
// explicit order of delivery
queue.deliverNow();
// As the queue is paused, even an explicit order of delivery will not work.
Assert.assertEquals(0, consumer.getReferences().size());
Assert.assertEquals(numMessages, getMessageCount(queue));
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
// resuming work
queue.resume();
awaitExecution();
// after resuming the delivery begins.
assertRefListsIdenticalRefs(refs, consumer.getReferences());
Assert.assertEquals(numMessages, getMessageCount(queue));
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(numMessages, queue.getDeliveringCount());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testConsumerWithFilterThenAddMoreMessages.
@Test
public void testConsumerWithFilterThenAddMoreMessages() 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().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());
for (int i = numMessages; i < numMessages * 2; i++) {
MessageReference ref = generateReference(queue, i);
refs.add(ref);
ref.getMessage().putStringProperty("color", "green");
queue.addTail(ref);
}
FakeConsumer consumer = new FakeConsumer(FilterImpl.createFilter("color = 'green'"));
queue.addConsumer(consumer);
queue.deliverNow();
Assert.assertEquals(20, getMessageCount(queue));
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(10, queue.getDeliveringCount());
for (int i = numMessages * 2; i < numMessages * 3; i++) {
MessageReference ref = generateReference(queue, i);
refs.add(ref);
ref.getMessage().putStringProperty("color", "green");
queue.addTail(ref);
}
queue.deliverNow();
Assert.assertEquals(20, consumer.getReferences().size());
Assert.assertEquals(30, getMessageCount(queue));
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(20, queue.getDeliveringCount());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testMessagesAdded.
@Test
public void testMessagesAdded() throws Exception {
QueueImpl queue = getTemporaryQueue();
MessageReference messageReference = generateReference(queue, 1);
MessageReference messageReference2 = generateReference(queue, 2);
MessageReference messageReference3 = generateReference(queue, 3);
queue.addTail(messageReference);
queue.addTail(messageReference2);
queue.addTail(messageReference3);
Assert.assertEquals(getMessagesAdded(queue), 3);
}
Aggregations