use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.
the class QueueImplTest method testaddHeadadd.
@Test
public void testaddHeadadd() throws Exception {
QueueImpl queue = getTemporaryQueue();
final int numMessages = 10;
List<MessageReference> refs1 = new ArrayList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i);
refs1.add(ref);
queue.addTail(ref);
}
LinkedList<MessageReference> refs2 = new LinkedList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i + numMessages);
refs2.addFirst(ref);
queue.addHead(ref, false);
}
List<MessageReference> refs3 = new ArrayList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i + 2 * numMessages);
refs3.add(ref);
queue.addTail(ref);
}
FakeConsumer consumer = new FakeConsumer();
queue.addConsumer(consumer);
queue.deliverNow();
List<MessageReference> allRefs = new ArrayList<>();
allRefs.addAll(refs2);
allRefs.addAll(refs1);
allRefs.addAll(refs3);
assertRefListsIdenticalRefs(allRefs, consumer.getReferences());
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.
the class QueueImplTest method testBusyConsumerWithFilterFirstCallBusy.
@Test
public void testBusyConsumerWithFilterFirstCallBusy() 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", "green");
refs.add(ref);
queue.addTail(ref);
}
Assert.assertEquals(10, getMessageCount(queue));
Assert.assertEquals(0, queue.getScheduledCount());
Assert.assertEquals(0, queue.getDeliveringCount());
queue.deliverNow();
consumer.setStatusImmediate(null);
queue.deliverNow();
List<MessageReference> receeivedRefs = consumer.getReferences();
int currId = 0;
for (MessageReference receeivedRef : receeivedRefs) {
Assert.assertEquals("messages received out of order", receeivedRef.getMessage().getMessageID(), currId++);
}
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer in project activemq-artemis by apache.
the class QueueImplTest method testConsumerWithFilterAddAndRemove.
@Test
public void testConsumerWithFilterAddAndRemove() {
QueueImpl queue = getTemporaryQueue();
Filter filter = new FakeFilter("fruit", "orange");
FakeConsumer consumer = new FakeConsumer(filter);
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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.tests.unit.core.server.impl.fakes.FakeConsumer 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());
}
Aggregations