Search in sources :

Example 36 with ServerMessage

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

the class QueueEntryImplTestBase method testGetNext.

/**
 * Tests if entries in DEQUEUED or DELETED state are not returned by getNext method.
 */
public void testGetNext() throws Exception {
    int numberOfEntries = 5;
    QueueEntryImpl[] entries = new QueueEntryImpl[numberOfEntries];
    Map<String, Object> queueAttributes = new HashMap<String, Object>();
    queueAttributes.put(Queue.ID, UUID.randomUUID());
    queueAttributes.put(Queue.NAME, getName());
    final QueueManagingVirtualHost virtualHost = BrokerTestHelper.createVirtualHost("testVH");
    StandardQueueImpl queue = new StandardQueueImpl(queueAttributes, virtualHost);
    queue.open();
    OrderedQueueEntryList queueEntryList = queue.getEntries();
    // create test entries
    for (int i = 0; i < numberOfEntries; i++) {
        ServerMessage message = mock(ServerMessage.class);
        when(message.getMessageNumber()).thenReturn((long) i);
        final MessageReference reference = mock(MessageReference.class);
        when(reference.getMessage()).thenReturn(message);
        when(message.newReference()).thenReturn(reference);
        when(message.newReference(any(TransactionLogResource.class))).thenReturn(reference);
        QueueEntryImpl entry = (QueueEntryImpl) queueEntryList.add(message, null);
        entries[i] = entry;
    }
    // test getNext for not acquired entries
    for (int i = 0; i < numberOfEntries; i++) {
        QueueEntryImpl queueEntry = entries[i];
        QueueEntry next = queueEntry.getNextValidEntry();
        if (i < numberOfEntries - 1) {
            assertEquals("Unexpected entry from QueueEntryImpl#getNext()", entries[i + 1], next);
        } else {
            assertNull("The next entry after the last should be null", next);
        }
    }
    // discard second
    entries[1].acquire();
    entries[1].delete();
    // discard third
    entries[2].acquire();
    entries[2].delete();
    QueueEntry next = entries[0].getNextValidEntry();
    assertEquals("expected forth entry", entries[3], next);
    next = next.getNextValidEntry();
    assertEquals("expected fifth entry", entries[4], next);
    next = next.getNextValidEntry();
    assertNull("The next entry after the last should be null", next);
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 37 with ServerMessage

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

the class RejectPolicyHandlerTest method testOverfullMessages.

public void testOverfullMessages() throws Exception {
    ServerMessage incomingMessage = createIncomingMessage(5);
    when(_queue.getMaximumQueueDepthMessages()).thenReturn(7L);
    when(_queue.getQueueDepthMessages()).thenReturn(7);
    when(_queue.getQueueDepthBytes()).thenReturn(10L);
    try {
        _rejectOverflowPolicyHandler.checkReject(incomingMessage);
        fail("Exception expected");
    } catch (MessageUnacceptableException e) {
    // pass
    }
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 38 with ServerMessage

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

the class RejectPolicyHandlerTest method testIncomingMessageDeleted.

public void testIncomingMessageDeleted() throws Exception {
    when(_queue.getMaximumQueueDepthMessages()).thenReturn(1L);
    ServerMessage incomingMessage1 = createIncomingMessage(2);
    ServerMessage incomingMessage2 = createIncomingMessage(2);
    _rejectOverflowPolicyHandler.checkReject(incomingMessage1);
    _rejectOverflowPolicyHandler.messageDeleted(incomingMessage1.getStoredMessage());
    _rejectOverflowPolicyHandler.checkReject(incomingMessage2);
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 39 with ServerMessage

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

the class RejectPolicyHandlerTest method testOverfullBytes.

public void testOverfullBytes() throws Exception {
    ServerMessage incomingMessage = createIncomingMessage(6);
    when(_queue.getQueueDepthBytes()).thenReturn(5L);
    when(_queue.getMaximumQueueDepthBytes()).thenReturn(10L);
    when(_queue.getQueueDepthMessages()).thenReturn(1);
    try {
        _rejectOverflowPolicyHandler.checkReject(incomingMessage);
        fail("Exception expected");
    } catch (MessageUnacceptableException e) {
    // pass
    }
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 40 with ServerMessage

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

the class RingOverflowPolicyHandlerTest method createLastEntry.

private QueueEntry createLastEntry() {
    AMQMessageHeader oldestMessageHeader = mock(AMQMessageHeader.class);
    ServerMessage oldestMessage = mock(ServerMessage.class);
    when(oldestMessage.getMessageHeader()).thenReturn(oldestMessageHeader);
    QueueEntry oldestEntry = mock(QueueEntry.class);
    when(oldestEntry.getMessage()).thenReturn(oldestMessage);
    return oldestEntry;
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

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