Search in sources :

Example 1 with EnqueueableMessage

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

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

the class MessageStoreQuotaEventsTestBase method testOverflow.

@Test
public void testOverflow() throws Exception {
    Transaction transaction = _store.newTransaction();
    List<EnqueueableMessage> messages = new ArrayList<EnqueueableMessage>();
    for (int i = 0; i < getNumberOfMessagesToFillStore(); i++) {
        EnqueueableMessage m = addMessage(i);
        messages.add(m);
        transaction.enqueueMessage(this, m);
    }
    transaction.commitTran();
    assertEvent(1, Event.PERSISTENT_MESSAGE_SIZE_OVERFULL);
    for (EnqueueableMessage m : messages) {
        m.getStoredMessage().remove();
    }
    assertEvent(2, Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL);
}
Also used : EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with EnqueueableMessage

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

the class MessageStoreTestCase method enqueueMessage.

private void enqueueMessage(final StoredMessage<TestMessageMetaData> message, final String queueName) {
    Transaction txn = _store.newTransaction();
    txn.enqueueMessage(new TransactionLogResource() {

        private final UUID _id = UUID.nameUUIDFromBytes(queueName.getBytes());

        @Override
        public String getName() {
            return queueName;
        }

        @Override
        public UUID getId() {
            return _id;
        }

        @Override
        public MessageDurability getMessageDurability() {
            return MessageDurability.DEFAULT;
        }
    }, new EnqueueableMessage() {

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

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

        @Override
        public StoredMessage getStoredMessage() {
            return message;
        }
    });
    txn.commitTran();
}
Also used : EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) UUID(java.util.UUID)

Example 4 with EnqueueableMessage

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

the class MessageStoreTestCase method getTestRecord.

private TestRecord getTestRecord(long messageNumber) {
    UUID queueId1 = UUIDGenerator.generateRandomUUID();
    TransactionLogResource queue1 = mock(TransactionLogResource.class);
    when(queue1.getId()).thenReturn(queueId1);
    EnqueueableMessage message1 = mock(EnqueueableMessage.class);
    when(message1.isPersistent()).thenReturn(true);
    when(message1.getMessageNumber()).thenReturn(messageNumber);
    final StoredMessage<?> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getMessageNumber()).thenReturn(messageNumber);
    when(message1.getStoredMessage()).thenReturn(storedMessage);
    TestRecord enqueueRecord = new TestRecord(queue1, message1);
    return enqueueRecord;
}
Also used : EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) UUID(java.util.UUID)

Example 5 with EnqueueableMessage

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

the class MessageStoreTestCase method testVisitMessageInstances.

@Test
public void testVisitMessageInstances() throws Exception {
    long messageId = 1;
    int contentSize = 0;
    final StoredMessage<TestMessageMetaData> message = _store.addMessage(new TestMessageMetaData(messageId, contentSize)).allContentAdded();
    EnqueueableMessage enqueueableMessage = createMockEnqueueableMessage(messageId, message);
    UUID queueId = UUID.randomUUID();
    TransactionLogResource queue = createTransactionLogResource(queueId);
    Transaction transaction = _store.newTransaction();
    transaction.enqueueMessage(queue, enqueueableMessage);
    transaction.commitTran();
    MessageInstanceHandler handler = mock(MessageInstanceHandler.class);
    _storeReader.visitMessageInstances(handler);
    verify(handler, times(1)).handle(argThat(new EnqueueRecordMatcher(queueId, messageId)));
}
Also used : EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)13 UUID (java.util.UUID)7 Test (org.junit.Test)6 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)2 Transaction (org.apache.qpid.server.store.Transaction)2 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)2 ArrayList (java.util.ArrayList)1 MessageDurability (org.apache.qpid.server.store.MessageDurability)1 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)1 MessageStore (org.apache.qpid.server.store.MessageStore)1 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)1 StoredMessage (org.apache.qpid.server.store.StoredMessage)1 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)1 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)1 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)1 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)1 DtxBranch (org.apache.qpid.server.txn.DtxBranch)1 DtxRegistry (org.apache.qpid.server.txn.DtxRegistry)1 Xid (org.apache.qpid.server.txn.Xid)1