Search in sources :

Example 46 with ServerMessage

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

the class SortedQueueEntryListTest method testInsertBefore.

public void testInsertBefore() throws Exception {
    _sqel = new SelfValidatingSortedQueueEntryList(_testQueue);
    ServerMessage msg = generateTestMessage(1, "B");
    _sqel.add(msg, null);
    SortedQueueEntry entry = _sqel.next(_sqel.getHead());
    validateEntry(entry, "B", 1);
    msg = generateTestMessage(2, "A");
    _sqel.add(msg, null);
    entry = _sqel.next(_sqel.getHead());
    validateEntry(entry, "A", 2);
    entry = _sqel.next(entry);
    validateEntry(entry, "B", 1);
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 47 with ServerMessage

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

the class SortedQueueEntryListTest method testNonUniqueSortKeys.

public void testNonUniqueSortKeys() throws Exception {
    _sqel = new SelfValidatingSortedQueueEntryList(_testQueue);
    // Build test list
    long messageId = 0L;
    while (messageId < 200) {
        final ServerMessage msg = generateTestMessage(messageId++, "samekey");
        _sqel.add(msg, null);
    }
    final QueueEntryIterator iter = getTestList().iterator();
    int count = 0;
    while (iter.advance()) {
        assertEquals("Sorted queue entry value is not as expected", "samekey", getSortedKeyValue(iter));
        assertEquals("Message id not as expected", Long.valueOf(count++), getMessageId(iter));
    }
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 48 with ServerMessage

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

the class SortedQueueEntryTest method getQueueEntryImpl.

@Override
public QueueEntryImpl getQueueEntryImpl(int msgId) {
    final ServerMessage message = mock(ServerMessage.class);
    AMQMessageHeader hdr = mock(AMQMessageHeader.class);
    when(message.getMessageHeader()).thenReturn(hdr);
    when(hdr.getHeader(eq("KEY"))).thenReturn(keys[msgId - 1]);
    when(hdr.containsHeader(eq("KEY"))).thenReturn(true);
    when(hdr.getHeaderNames()).thenReturn(Collections.singleton("KEY"));
    final MessageReference reference = mock(MessageReference.class);
    when(reference.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(reference);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(reference);
    return _queueEntryList.add(message, null);
}
Also used : 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 49 with ServerMessage

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

the class StandardQueueEntryListTest method createServerMessage.

private ServerMessage createServerMessage(final long id) {
    ServerMessage message = mock(ServerMessage.class);
    when(message.getMessageNumber()).thenReturn(id);
    final MessageReference reference = mock(MessageReference.class);
    when(reference.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(reference);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(reference);
    return message;
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 50 with ServerMessage

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

the class StandardQueueTest method testAutoDeleteQueue.

public void testAutoDeleteQueue() throws Exception {
    getQueue().close();
    getQueue().delete();
    Map<String, Object> queueAttributes = new HashMap<>();
    queueAttributes.put(Queue.NAME, getQname());
    queueAttributes.put(Queue.LIFETIME_POLICY, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
    final StandardQueueImpl queue = new StandardQueueImpl(queueAttributes, getVirtualHost());
    queue.open();
    setQueue(queue);
    ServerMessage message = createMessage(25l);
    QueueConsumer consumer = (QueueConsumer) getQueue().addConsumer(getConsumerTarget(), null, message.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    getQueue().enqueue(message, null, null);
    consumer.close();
    assertTrue("Queue was not deleted when consumer was removed", getQueue().isDeleted());
}
Also used : 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