Search in sources :

Example 76 with ServerMessage

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

the class AbstractQueueTestBase method testRingOverflowPolicyMaxCount.

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

Example 77 with ServerMessage

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

the class AbstractQueueTestBase method testRegisterConsumerThenEnqueueMessage.

public void testRegisterConsumerThenEnqueueMessage() throws Exception {
    ServerMessage messageA = createMessage(new Long(24));
    // Check adding a consumer adds it to the queue
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    assertEquals("Queue does not have consumer", 1, _queue.getConsumerCount());
    assertEquals("Queue does not have active consumer", 1, _queue.getConsumerCountWithCredit());
    // Check sending a message ends up with the subscriber
    _queue.enqueue(messageA, null, null);
    while (_consumerTarget.processPending()) ;
    assertEquals(messageA, _consumer.getQueueContext().getLastSeenEntry().getMessage());
    assertNull(_consumer.getQueueContext().getReleasedEntry());
    // Check removing the consumer removes it's information from the queue
    _consumer.close();
    assertTrue("Consumer still had queue", _consumerTarget.isClosed());
    assertFalse("Queue still has consumer", 1 == _queue.getConsumerCount());
    assertFalse("Queue still has active consumer", 1 == _queue.getConsumerCountWithCredit());
    ServerMessage messageB = createMessage(new Long(25));
    _queue.enqueue(messageB, null, null);
    assertNull(_consumer.getQueueContext());
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 78 with ServerMessage

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

the class AbstractQueueTestBase method testReleaseForQueueWithMultipleConsumers.

/**
 * Tests that a release requeues an entry for a queue with multiple consumers.  Verifies that a
 * requeue resends a message to a <i>single</i> subscriber.
 */
public void testReleaseForQueueWithMultipleConsumers() throws Exception {
    ServerMessage messageA = createMessage(new Long(24));
    ServerMessage messageB = createMessage(new Long(25));
    TestConsumerTarget target1 = new TestConsumerTarget();
    TestConsumerTarget target2 = new TestConsumerTarget();
    QueueConsumer consumer1 = (QueueConsumer) _queue.addConsumer(target1, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    QueueConsumer consumer2 = (QueueConsumer) _queue.addConsumer(target2, 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 two messages */
    _queue.enqueue(messageA, postEnqueueAction, null);
    _queue.enqueue(messageB, postEnqueueAction, null);
    while (target1.processPending()) ;
    while (target2.processPending()) ;
    assertEquals("Unexpected total number of messages sent to both after enqueue", 2, target1.getMessages().size() + target2.getMessages().size());
    /* Now release the first message only, causing it to be requeued */
    queueEntries.get(0).release();
    while (target1.processPending()) ;
    while (target2.processPending()) ;
    assertEquals("Unexpected total number of messages sent to both consumers after release", 3, target1.getMessages().size() + target2.getMessages().size());
    assertNull("releasedEntry should be cleared after requeue processed", consumer1.getQueueContext().getReleasedEntry());
    assertNull("releasedEntry should be cleared after requeue processed", consumer2.getQueueContext().getReleasedEntry());
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) ArrayList(java.util.ArrayList) TestConsumerTarget(org.apache.qpid.server.consumer.TestConsumerTarget)

Example 79 with ServerMessage

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

the class AbstractQueueTestBase method getExpirationOnQueue.

private long getExpirationOnQueue(final Queue<?> queue, long arrivalTime, long expiration) {
    final List<QueueEntry> entries = new ArrayList<>();
    ServerMessage message = createMessage(1l);
    when(message.getArrivalTime()).thenReturn(arrivalTime);
    when(message.getExpiration()).thenReturn(expiration);
    queue.enqueue(message, null, null);
    queue.visit(new QueueEntryVisitor() {

        @Override
        public boolean visit(final QueueEntry entry) {
            entries.add(entry);
            return true;
        }
    });
    assertEquals("Expected only one entry in the queue", 1, entries.size());
    Long entryExpiration = (Long) entries.get(0).getInstanceProperties().getProperty(InstanceProperties.Property.EXPIRATION);
    queue.clearQueue();
    entries.clear();
    return entryExpiration;
}
Also used : ArrayList(java.util.ArrayList) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 80 with ServerMessage

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

the class AbstractQueueTestBase method testRingOverflowPolicyMessagesRejected.

public void testRingOverflowPolicyMessagesRejected() {
    Map<String, Object> attributes = new HashMap<>(_arguments);
    attributes.put(Queue.OVERFLOW_POLICY, OverflowPolicy.RING);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_MESSAGES, 0);
    Queue<?> queue = getQueue();
    queue.setAttributes(attributes);
    ServerMessage message;
    RoutingResult result;
    message = createMessage(new Long(27), 20, 10);
    result = queue.route(message, message.getInitialRoutingAddress(), null);
    assertTrue("Result should include not accepting route", result.isRejected());
    int headerSize = 20;
    int payloadSize = 10;
    int id = 28;
    attributes = new HashMap<>(_arguments);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_MESSAGES, 10);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_BYTES, 10);
    queue.setAttributes(attributes);
    message = createMessage(new Long(id), headerSize, payloadSize);
    result = queue.route(message, message.getInitialRoutingAddress(), null);
    assertTrue("Result should include not accepting route", result.isRejected());
}
Also used : RoutingResult(org.apache.qpid.server.message.RoutingResult) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

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