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));
}
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());
}
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());
}
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());
}
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));
}
Aggregations