Search in sources :

Example 26 with ServerMessage

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

the class AbstractQueueTestBase method testNoneOverflowPolicy.

public void testNoneOverflowPolicy() {
    Map<String, Object> attributes = new HashMap<>(_arguments);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_MESSAGES, 2);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_BYTES, 100);
    Queue<?> queue = getQueue();
    queue.setAttributes(attributes);
    ServerMessage message = createMessage(new Long(24), 50, 50);
    when(message.getArrivalTime()).thenReturn(10l);
    queue.enqueue(message, null, null);
    message = createMessage(new Long(25), 50, 50);
    when(message.getArrivalTime()).thenReturn(50l);
    queue.enqueue(message, null, null);
    message = createMessage(new Long(26), 50, 50);
    when(message.getArrivalTime()).thenReturn(200l);
    queue.enqueue(message, null, null);
    assertEquals("Wrong number of messages in queue", 3, queue.getQueueDepthMessages());
    assertEquals("Wrong size of messages in queue", 300, queue.getQueueDepthBytes());
    assertEquals("Wrong oldest message", 10l, ((AbstractQueue) queue).getEntries().getOldestEntry().getMessage().getArrivalTime());
}
Also used : HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 27 with ServerMessage

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

the class AbstractQueueTestBase method testReleasedMessageIsResentToSubscriber.

/**
 * Tests that a released queue entry is resent to the subscriber.  Verifies also that the
 * QueueContext._releasedEntry is reset to null after the entry has been reset.
 */
public void testReleasedMessageIsResentToSubscriber() 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 first message only, causing it to be requeued */
    queueEntries.get(0).release();
    while (_consumerTarget.processPending()) ;
    assertEquals("Unexpected total number of messages sent to consumer", 4, _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());
    assertFalse("Redelivery flag should remain be unset", 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 28 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) {
    AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getMessageId()).thenReturn(String.valueOf(id));
    ServerMessage message = mock(ServerMessage.class);
    when(message.getMessageNumber()).thenReturn(id);
    when(message.getMessageHeader()).thenReturn(header);
    StoredMessage storedMessage = mock(StoredMessage.class);
    when(message.getStoredMessage()).thenReturn(storedMessage);
    MessageReference ref = mock(MessageReference.class);
    when(ref.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(ref);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
    return message;
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 29 with ServerMessage

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

the class AbstractQueueTestBase method testEnqueueTwoMessagesThenRegisterConsumer.

/**
 * Tests enqueuing two messages.
 */
public void testEnqueueTwoMessagesThenRegisterConsumer() throws Exception {
    ServerMessage messageA = createMessage(new Long(24));
    ServerMessage messageB = createMessage(new Long(25));
    _queue.enqueue(messageA, null, null);
    _queue.enqueue(messageB, null, null);
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    while (_consumerTarget.processPending()) ;
    assertEquals(messageB, _consumer.getQueueContext().getLastSeenEntry().getMessage());
    assertNull("There should be no releasedEntry after enqueues", _consumer.getQueueContext().getReleasedEntry());
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 30 with ServerMessage

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

the class FlowToDiskOverflowPolicyHandlerTest method createMessage.

private ServerMessage createMessage(long size) {
    ServerMessage message = mock(ServerMessage.class);
    when(message.getSizeIncludingHeader()).thenReturn(size);
    StoredMessage storedMessage = mock(StoredMessage.class);
    when(message.getStoredMessage()).thenReturn(storedMessage);
    MessageReference ref = mock(MessageReference.class);
    when(ref.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(ref);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
    return message;
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

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