Search in sources :

Example 6 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class FlowToDiskTransactionObserverTest method testOnMessageEnqueue.

public void testOnMessageEnqueue() throws Exception {
    EnqueueableMessage<?> message1 = createMessage(MAX_UNCOMMITTED_IN_MEMORY_SIZE);
    EnqueueableMessage<?> message2 = createMessage(1);
    EnqueueableMessage<?> message3 = createMessage(1);
    _flowToDiskMessageObserver.onMessageEnqueue(_transaction, message1);
    StoredMessage handle1 = message1.getStoredMessage();
    verify(handle1, never()).flowToDisk();
    verify(_eventLogger, never()).message(same(_logSubject), any(LogMessage.class));
    _flowToDiskMessageObserver.onMessageEnqueue(_transaction, message2);
    StoredMessage handle2 = message2.getStoredMessage();
    verify(handle1).flowToDisk();
    verify(handle2).flowToDisk();
    verify(_eventLogger).message(same(_logSubject), any(LogMessage.class));
    final ServerTransaction transaction2 = mock(ServerTransaction.class);
    _flowToDiskMessageObserver.onMessageEnqueue(transaction2, message3);
    StoredMessage handle3 = message2.getStoredMessage();
    verify(handle1).flowToDisk();
    verify(handle2).flowToDisk();
    verify(handle3).flowToDisk();
    verify(_eventLogger).message(same(_logSubject), any(LogMessage.class));
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) LogMessage(org.apache.qpid.server.logging.LogMessage)

Example 7 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class FlowToDiskTransactionObserverTest method testOnDischarge.

public void testOnDischarge() throws Exception {
    EnqueueableMessage<?> message1 = createMessage(MAX_UNCOMMITTED_IN_MEMORY_SIZE - 1);
    EnqueueableMessage<?> message2 = createMessage(1);
    EnqueueableMessage<?> message3 = createMessage(1);
    _flowToDiskMessageObserver.onMessageEnqueue(_transaction, message1);
    final ServerTransaction transaction2 = mock(ServerTransaction.class);
    _flowToDiskMessageObserver.onMessageEnqueue(transaction2, message2);
    _flowToDiskMessageObserver.onDischarge(_transaction);
    _flowToDiskMessageObserver.onMessageEnqueue(transaction2, message3);
    StoredMessage handle1 = message1.getStoredMessage();
    StoredMessage handle2 = message2.getStoredMessage();
    StoredMessage handle3 = message2.getStoredMessage();
    verify(handle1, never()).flowToDisk();
    verify(handle2, never()).flowToDisk();
    verify(handle3, never()).flowToDisk();
    verify(_eventLogger, never()).message(same(_logSubject), any(LogMessage.class));
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) LogMessage(org.apache.qpid.server.logging.LogMessage)

Example 8 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class FlowToDiskTransactionObserverTest method createMessage.

private EnqueueableMessage<?> createMessage(int size) {
    EnqueueableMessage message = mock(EnqueueableMessage.class);
    StoredMessage handle = mock(StoredMessage.class);
    when(message.getStoredMessage()).thenReturn(handle);
    when(handle.getContentSize()).thenReturn(size);
    final StorableMessageMetaData metadata = mock(StorableMessageMetaData.class);
    when(metadata.getStorableSize()).thenReturn(0);
    when(metadata.getContentSize()).thenReturn(size);
    when(handle.getMetaData()).thenReturn(metadata);
    return message;
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 9 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v0_10 method convertToStoredMessage.

private StoredMessage<MessageMetaData_0_10> convertToStoredMessage(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
    Object messageBody = serverMsg.getMessageBody();
    ObjectToMimeContentConverter converter = MimeContentConverterRegistry.getBestFitObjectToMimeContentConverter(messageBody);
    final byte[] messageContent = converter == null ? new byte[] {} : converter.toMimeContent(messageBody);
    String mimeType = converter == null ? null : converter.getMimeType();
    mimeType = improveMimeType(serverMsg, mimeType);
    final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(serverMsg, addressSpace, mimeType, messageContent.length);
    final int metadataSize = messageMetaData_0_10.getStorableSize();
    return new StoredMessage<MessageMetaData_0_10>() {

        @Override
        public MessageMetaData_0_10 getMetaData() {
            return messageMetaData_0_10;
        }

        @Override
        public long getMessageNumber() {
            return serverMsg.getMessageNumber();
        }

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return QpidByteBuffer.wrap(messageContent, offset, length);
        }

        @Override
        public int getContentSize() {
            return messageContent.length;
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInMemory() {
            return true;
        }

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : ObjectToMimeContentConverter(org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter) StoredMessage(org.apache.qpid.server.store.StoredMessage)

Example 10 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage 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)

Aggregations

StoredMessage (org.apache.qpid.server.store.StoredMessage)23 MessageReference (org.apache.qpid.server.message.MessageReference)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)4 Transaction (org.apache.qpid.server.store.Transaction)4 UUID (java.util.UUID)3 LogMessage (org.apache.qpid.server.logging.LogMessage)3 HashMap (java.util.HashMap)2 ObjectToMimeContentConverter (org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter)2 Queue (org.apache.qpid.server.model.Queue)2 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)2 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 ConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType)2 MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)2 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)2 MessageStore (org.apache.qpid.server.store.MessageStore)2 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)2 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1