Search in sources :

Example 1 with MessageInstance

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());
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) TestConsumerTarget(org.apache.qpid.server.consumer.TestConsumerTarget)

Example 2 with MessageInstance

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);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 3 with MessageInstance

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;
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance)

Example 4 with MessageInstance

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);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 5 with MessageInstance

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)));
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) TestConsumerTarget(org.apache.qpid.server.consumer.TestConsumerTarget) Test(org.junit.Test)

Aggregations

MessageInstance (org.apache.qpid.server.message.MessageInstance)31 Test (org.junit.Test)10 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)8 ServerMessage (org.apache.qpid.server.message.ServerMessage)8 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)5 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)5 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 AssertionFailedError (junit.framework.AssertionFailedError)4 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)4 Map (java.util.Map)3 Action (org.apache.qpid.server.util.Action)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageSource (org.apache.qpid.server.message.MessageSource)2 Queue (org.apache.qpid.server.model.Queue)2 Visitor (org.apache.qpid.server.protocol.v0_8.UnacknowledgedMessageMap.Visitor)2 MockMessageInstance (org.apache.qpid.server.queue.MockMessageInstance)2