use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImplTest method testRoundRobinWithQueueing.
@Test
public void testRoundRobinWithQueueing() throws Exception {
QueueImpl queue = getTemporaryQueue();
final int numMessages = 10;
List<MessageReference> refs = new ArrayList<>();
queue.pause();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
FakeConsumer cons1 = new FakeConsumer();
FakeConsumer cons2 = new FakeConsumer();
queue.addConsumer(cons1);
queue.addConsumer(cons2);
queue.resume();
// Need to make sure the consumers will receive the messages before we do these assertions
long timeout = System.currentTimeMillis() + 5000;
while (cons1.getReferences().size() != numMessages / 2 && timeout > System.currentTimeMillis()) {
Thread.sleep(1);
}
while (cons2.getReferences().size() != numMessages / 2 && timeout > System.currentTimeMillis()) {
Thread.sleep(1);
}
Assert.assertEquals(numMessages / 2, cons1.getReferences().size());
Assert.assertEquals(numMessages / 2, cons2.getReferences().size());
for (int i = 0; i < numMessages; i++) {
MessageReference ref;
ref = i % 2 == 0 ? cons1.getReferences().get(i / 2) : cons2.getReferences().get(i / 2);
Assert.assertEquals(refs.get(i), ref);
}
}
use of org.apache.activemq.artemis.core.server.MessageReference 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.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImplTest method testIterator.
@Test
public void testIterator() {
QueueImpl queue = getTemporaryQueue();
final int numMessages = 20;
List<MessageReference> refs = new ArrayList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i);
queue.addTail(ref);
refs.add(ref);
}
Assert.assertEquals(numMessages, getMessageCount(queue));
Iterator<MessageReference> iterator = queue.iterator();
List<MessageReference> list = new ArrayList<>();
while (iterator.hasNext()) {
list.add(iterator.next());
}
assertRefListsIdenticalRefs(refs, list);
}
use of org.apache.activemq.artemis.core.server.MessageReference 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.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImplTest method testTotalIteratorOrder.
@Test
public void testTotalIteratorOrder() throws Exception {
final String MY_ADDRESS = "myAddress";
final String MY_QUEUE = "myQueue";
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), true));
AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
server.getAddressSettingsRepository().addMatch("#", defaultSetting);
server.start();
ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
ClientSessionFactory factory = createSessionFactory(locator);
ClientSession session = addClientSession(factory.createSession(false, true, true));
session.createQueue(MY_ADDRESS, MY_QUEUE, true);
ClientProducer producer = addClientProducer(session.createProducer(MY_ADDRESS));
for (int i = 0; i < 50; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[1024]);
message.putIntProperty("order", i);
producer.send(message);
}
producer.close();
session.close();
factory.close();
locator.close();
Queue queue = ((LocalQueueBinding) server.getPostOffice().getBinding(new SimpleString(MY_QUEUE))).getQueue();
LinkedListIterator<MessageReference> totalIterator = queue.browserIterator();
try {
int i = 0;
while (totalIterator.hasNext()) {
MessageReference ref = totalIterator.next();
Assert.assertEquals(i++, ref.getMessage().getIntProperty("order").intValue());
}
} finally {
totalIterator.close();
server.stop();
}
}
Aggregations