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));
}
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));
}
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;
}
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() {
}
};
}
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;
}
Aggregations