use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class StandardQueueTest method testEnqueueDequeuedEntry.
/**
* Tests that entry in dequeued state are not enqueued and not delivered to consumer
*/
public void testEnqueueDequeuedEntry() throws Exception {
// create a queue where each even entry is considered a dequeued
AbstractQueue queue = new DequeuedQueue(getVirtualHost());
queue.create();
// create a consumer
TestConsumerTarget consumer = new TestConsumerTarget();
// register consumer
queue.addConsumer(consumer, null, createMessage(-1l).getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
// put test messages into a queue
putGivenNumberOfMessages(queue, 4);
while (consumer.processPending()) ;
// assert received messages
List<MessageInstance> messages = consumer.getMessages();
assertEquals("Only 2 messages should be returned", (long) 2, (long) messages.size());
assertEquals("ID of first message should be 1", 1l, (messages.get(0).getMessage()).getMessageNumber());
assertEquals("ID of second message should be 3", 3l, (messages.get(1).getMessage()).getMessageNumber());
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class PriorityQueueTest method changeMessagePriorityForNonExistingMessageId.
@Test
public void changeMessagePriorityForNonExistingMessageId() throws Exception {
final PriorityQueue<?> queue = (PriorityQueue<?>) getQueue();
final InternalMessage internalMessage1 = createInternalMessage((byte) 3, 0);
final InternalMessage internalMessage2 = createInternalMessage((byte) 5, 1);
final InternalMessage internalMessage3 = createInternalMessage((byte) 4, 2);
queue.enqueue(internalMessage1, null, null);
queue.enqueue(internalMessage2, null, null);
queue.enqueue(internalMessage3, null, null);
final long result = queue.reenqueueMessageForPriorityChange(internalMessage3.getMessageNumber() + 1, (byte) 6);
assertEquals("Unexpected operation result", -1, result);
final List<MessageInstance> msgs = consumeMessages(queue);
try {
assertEquals(internalMessage2.getMessageNumber(), msgs.get(0).getMessage().getMessageNumber());
assertEquals(internalMessage3.getMessageNumber(), msgs.get(1).getMessage().getMessageNumber());
assertEquals(internalMessage1.getMessageNumber(), msgs.get(2).getMessage().getMessageNumber());
} catch (AssertionFailedError afe) {
showMessageOrderOnFailure(msgs, afe);
}
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class PriorityQueueTest method showMessageOrderOnFailure.
private void showMessageOrderOnFailure(final List<MessageInstance> msgs, final AssertionFailedError afe) {
int index = 1;
for (MessageInstance qe : msgs) {
System.err.println(index + ":" + qe.getMessage().getMessageNumber());
index++;
}
throw afe;
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class PriorityQueueTest method changeMessagePriority.
@Test
public void changeMessagePriority() throws Exception {
final PriorityQueue<?> queue = (PriorityQueue<?>) getQueue();
final InternalMessage internalMessage1 = createInternalMessage((byte) 3, 0);
final InternalMessage internalMessage2 = createInternalMessage((byte) 3, 1);
final InternalMessage internalMessage3 = createInternalMessage((byte) 4, 2);
queue.enqueue(internalMessage1, null, null);
queue.enqueue(internalMessage2, null, null);
queue.enqueue(internalMessage3, null, null);
final long result = queue.reenqueueMessageForPriorityChange(internalMessage2.getMessageNumber(), (byte) 5);
assertEquals("Unexpected operation result", internalMessage3.getMessageNumber() + 1, result);
final List<MessageInstance> msgs = consumeMessages(queue);
try {
assertEquals(internalMessage3.getMessageNumber() + 1, msgs.get(0).getMessage().getMessageNumber());
assertEquals(internalMessage3.getMessageNumber(), msgs.get(1).getMessage().getMessageNumber());
assertEquals(internalMessage1.getMessageNumber(), msgs.get(2).getMessage().getMessageNumber());
} catch (AssertionFailedError afe) {
showMessageOrderOnFailure(msgs, afe);
}
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class RingOverflowPolicyTest method testEnqueueWithOverflowWhenLeastSignificantEntryIsAcquiredByConsumer.
@Test
public void testEnqueueWithOverflowWhenLeastSignificantEntryIsAcquiredByConsumer() throws Exception {
final Queue<?> queue = createTestRingQueue(2);
final ServerMessage<?> message1 = enqueueTestMessage(queue);
final TestConsumerTarget consumerTarget = createTestConsumerTargetAndConsumer(queue);
final boolean received = consumerTarget.processPending();
assertThat(received, is(true));
final MessageInstance receivedMessage = consumerTarget.getMessages().remove(0);
assertThat(receivedMessage, is(notNullValue()));
assertThat(receivedMessage.isAcquired(), is(true));
assertThat(receivedMessage.getMessage(), is(message1));
final ServerMessage<?> message2 = enqueueTestMessage(queue);
assertThat(queue.getQueueDepthMessages(), is(equalTo(2)));
final ServerMessage<?> message3 = enqueueTestMessage(queue);
assertThat(queue.getQueueDepthMessages(), is(equalTo(2)));
assertThat(message2.isReferenced(queue), is(equalTo(false)));
assertThat(message3.isReferenced(queue), is(equalTo(true)));
}
Aggregations