use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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());
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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());
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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));
}
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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());
}
use of org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer 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++);
}
}
Aggregations