Search in sources :

Example 6 with MessageReference

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

the class SortedQueueEntryListTest method generateTestMessage.

private ServerMessage generateTestMessage(final long id, final String keyValue) {
    final ServerMessage message = mock(ServerMessage.class);
    AMQMessageHeader hdr = mock(AMQMessageHeader.class);
    when(message.getMessageHeader()).thenReturn(hdr);
    when(hdr.getHeader(eq("KEY"))).thenReturn(keyValue);
    when(hdr.containsHeader(eq("KEY"))).thenReturn(true);
    when(hdr.getHeaderNames()).thenReturn(Collections.singleton("KEY"));
    MessageReference ref = mock(MessageReference.class);
    when(ref.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(ref);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
    when(message.getMessageNumber()).thenReturn(id);
    return message;
}
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 7 with MessageReference

use of org.apache.qpid.server.message.MessageReference 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 8 with MessageReference

use of org.apache.qpid.server.message.MessageReference 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 9 with MessageReference

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

the class ReferenceCountingTest method testMessageGetsRemoved.

/**
 * Check that when the reference count is decremented the message removes itself from the store
 */
public void testMessageGetsRemoved() throws QpidException {
    ContentHeaderBody chb = createPersistentContentHeader();
    MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
    final MessageMetaData mmd = new MessageMetaData(info, chb);
    StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
    Transaction txn = _store.newTransaction();
    txn.enqueueMessage(createTransactionLogResource("dummyQ"), createEnqueueableMessage(storedMessage));
    txn.commitTran();
    AMQMessage message = new AMQMessage(storedMessage);
    MessageReference ref = message.newReference();
    assertEquals(1, getStoreMessageCount());
    ref.release();
    assertEquals(0, getStoreMessageCount());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) StoredMessage(org.apache.qpid.server.store.StoredMessage) Transaction(org.apache.qpid.server.store.Transaction) MessageReference(org.apache.qpid.server.message.MessageReference)

Example 10 with MessageReference

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

the class ReferenceCountingTest method testMessageRemains.

public void testMessageRemains() throws QpidException {
    MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
    final ContentHeaderBody chb = createPersistentContentHeader();
    final MessageMetaData mmd = new MessageMetaData(info, chb);
    StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
    Transaction txn = _store.newTransaction();
    txn.enqueueMessage(createTransactionLogResource("dummyQ"), createEnqueueableMessage(storedMessage));
    txn.commitTran();
    AMQMessage message = new AMQMessage(storedMessage);
    MessageReference ref = message.newReference();
    assertEquals(1, getStoreMessageCount());
    MessageReference ref2 = message.newReference();
    ref.release();
    assertEquals(1, getStoreMessageCount());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) StoredMessage(org.apache.qpid.server.store.StoredMessage) Transaction(org.apache.qpid.server.store.Transaction) MessageReference(org.apache.qpid.server.message.MessageReference)

Aggregations

MessageReference (org.apache.qpid.server.message.MessageReference)20 ServerMessage (org.apache.qpid.server.message.ServerMessage)13 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)10 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)5 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 AccessControlException (java.security.AccessControlException)2 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 Transaction (org.apache.qpid.server.store.Transaction)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 MessageContainer (org.apache.qpid.server.message.MessageContainer)1 RoutingResult (org.apache.qpid.server.message.RoutingResult)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1