Search in sources :

Example 81 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueueTestBase method createMessage.

protected ServerMessage createMessage(Long id, final int headerSize, final int payloadSize) {
    ServerMessage message = createMessage(id);
    when(message.getSizeIncludingHeader()).thenReturn(new Long(headerSize + payloadSize));
    return message;
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 82 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueueTestBase method putGivenNumberOfMessages.

/**
 * A helper method to put given number of messages into queue
 * <p>
 * Queue is not checked if messages are added into queue
 *
 * @param queue
 *            queue to put messages into
 * @param messageNumber
 *            number of messages to put into queue
 * @param queue
 * @param messageNumber
 */
protected void putGivenNumberOfMessages(Queue<?> queue, int messageNumber) {
    for (int i = 0; i < messageNumber; i++) {
        // Create message
        ServerMessage message = null;
        message = createMessage((long) i);
        // Put message on queue
        queue.enqueue(message, null, null);
    }
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 83 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueueTestBase method createMessage.

protected ServerMessage createMessage(Long id, byte priority, final Map<String, Object> arguments, long arrivalTime) {
    ServerMessage message = createMessage(id);
    AMQMessageHeader hdr = message.getMessageHeader();
    when(hdr.getPriority()).thenReturn(priority);
    when(message.getArrivalTime()).thenReturn(arrivalTime);
    when(hdr.getHeaderNames()).thenReturn(arguments.keySet());
    final ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
    when(hdr.containsHeader(nameCaptor.capture())).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
            return arguments.containsKey(nameCaptor.getValue());
        }
    });
    final ArgumentCaptor<Set> namesCaptor = ArgumentCaptor.forClass(Set.class);
    when(hdr.containsHeaders(namesCaptor.capture())).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
            return arguments.keySet().containsAll(namesCaptor.getValue());
        }
    });
    final ArgumentCaptor<String> nameCaptor2 = ArgumentCaptor.forClass(String.class);
    when(hdr.getHeader(nameCaptor2.capture())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
            return arguments.get(nameCaptor2.getValue());
        }
    });
    return message;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 84 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueueTestBase method testReleasedOutOfComparableOrderAreRedelivered.

/**
 * Tests that if a client releases entries 'out of order' (the order
 * used by QueueEntryImpl.compareTo) that messages are still resent
 * successfully.  Specifically this test ensures the {@see AbstractQueue#requeue()}
 * can correctly move the _releasedEntry to an earlier position in the QueueEntry list.
 */
public void testReleasedOutOfComparableOrderAreRedelivered() throws Exception {
    ServerMessage messageA = createMessage(new Long(24));
    ServerMessage messageB = createMessage(new Long(25));
    ServerMessage messageC = createMessage(new Long(26));
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    final ArrayList<QueueEntry> queueEntries = new ArrayList<QueueEntry>();
    EntryListAddingAction postEnqueueAction = new EntryListAddingAction(queueEntries);
    /* Enqueue three messages */
    _queue.enqueue(messageA, postEnqueueAction, null);
    _queue.enqueue(messageB, postEnqueueAction, null);
    _queue.enqueue(messageC, postEnqueueAction, null);
    while (_consumerTarget.processPending()) ;
    assertEquals("Unexpected total number of messages sent to consumer", 3, _consumerTarget.getMessages().size());
    assertFalse("Redelivery flag should not be set", queueEntries.get(0).isRedelivered());
    assertFalse("Redelivery flag should not be set", queueEntries.get(1).isRedelivered());
    assertFalse("Redelivery flag should not be set", queueEntries.get(2).isRedelivered());
    /* Now release the third and first message only, causing it to be requeued */
    queueEntries.get(2).release();
    queueEntries.get(0).release();
    while (_consumerTarget.processPending()) ;
    assertEquals("Unexpected total number of messages sent to consumer", 5, _consumerTarget.getMessages().size());
    assertTrue("Redelivery flag should now be set", queueEntries.get(0).isRedelivered());
    assertFalse("Redelivery flag should remain be unset", queueEntries.get(1).isRedelivered());
    assertTrue("Redelivery flag should now be set", queueEntries.get(2).isRedelivered());
    assertNull("releasedEntry should be cleared after requeue processed", _consumer.getQueueContext().getReleasedEntry());
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) ArrayList(java.util.ArrayList)

Example 85 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueueTestBase method testMessageHeldIfNotYetValidWhenConsumerAdded.

public void testMessageHeldIfNotYetValidWhenConsumerAdded() throws Exception {
    _queue.close();
    Map<String, Object> attributes = new HashMap<>(_arguments);
    attributes.put(Queue.NAME, _qname);
    attributes.put(Queue.OWNER, _owner);
    attributes.put(Queue.HOLD_ON_PUBLISH_ENABLED, Boolean.TRUE);
    _queue = _virtualHost.createChild(Queue.class, attributes);
    ServerMessage messageA = createMessage(new Long(24));
    AMQMessageHeader messageHeader = messageA.getMessageHeader();
    when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() + 20000L);
    _queue.enqueue(messageA, null, null);
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    while (_consumerTarget.processPending()) ;
    assertEquals("Message which was not yet valid was received", 0, _consumerTarget.getMessages().size());
    when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() - 100L);
    _queue.checkMessageStatus();
    while (_consumerTarget.processPending()) ;
    assertEquals("Message which was valid was not received", 1, _consumerTarget.getMessages().size());
}
Also used : HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Queue(org.apache.qpid.server.model.Queue)

Aggregations

ServerMessage (org.apache.qpid.server.message.ServerMessage)103 HashMap (java.util.HashMap)26 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)16 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)16 Exchange (org.apache.qpid.server.model.Exchange)14 MessageReference (org.apache.qpid.server.message.MessageReference)13 ArrayList (java.util.ArrayList)9 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)7 Queue (org.apache.qpid.server.model.Queue)7 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 PrivilegedAction (java.security.PrivilegedAction)2 UUID (java.util.UUID)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2