Search in sources :

Example 6 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleMessageOnSingleQueue.

@SuppressWarnings("unchecked")
public void testRecoveryOfSingleMessageOnSingleQueue() {
    final Queue<?> queue = createRegisteredMockQueue();
    final long messageId = 1;
    final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(messageId);
    MessageStore store = new NullMessageStore() {

        @Override
        public void visitMessages(MessageHandler handler) throws StoreException {
            handler.handle(storedMessage);
        }

        @Override
        public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
            handler.handle(new TestMessageEnqueueRecord(queue.getId(), messageId));
        }
    };
    when(_virtualHost.getMessageStore()).thenReturn(store);
    SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
    recoverer.recover(_virtualHost);
    ServerMessage<?> message = storedMessage.getMetaData().getType().createMessage(storedMessage);
    verify(queue, times(1)).recover(eq(message), any(MessageEnqueueRecord.class));
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 7 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleDequeueWithDistributedTransaction.

public void testRecoveryOfSingleDequeueWithDistributedTransaction() {
    final UUID queueId = UUID.randomUUID();
    final Queue<?> queue = createRegisteredMockQueue(queueId);
    final Transaction transaction = mock(Transaction.class);
    final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(1);
    final long messageId = storedMessage.getMessageNumber();
    Transaction.DequeueRecord dequeueRecord = createMockDequeueRecord(queueId, messageId);
    QueueEntry queueEntry = mock(QueueEntry.class);
    when(queueEntry.acquire()).thenReturn(true);
    when(queue.getMessageOnTheQueue(messageId)).thenReturn(queueEntry);
    final long format = 1;
    final byte[] globalId = new byte[] { 0 };
    final byte[] branchId = new byte[] { 0 };
    final EnqueueRecord[] enqueues = {};
    final Transaction.DequeueRecord[] dequeues = { dequeueRecord };
    MessageStore store = new NullMessageStore() {

        @Override
        public void visitMessages(MessageHandler handler) throws StoreException {
            handler.handle(storedMessage);
        }

        @Override
        public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
            // We need the message to be enqueued onto the queue so that later the distributed transaction
            // can dequeue it.
            handler.handle(new TestMessageEnqueueRecord(queue.getId(), messageId));
        }

        @Override
        public void visitDistributedTransactions(DistributedTransactionHandler handler) throws StoreException {
            handler.handle(new Transaction.StoredXidRecord() {

                @Override
                public long getFormat() {
                    return format;
                }

                @Override
                public byte[] getGlobalId() {
                    return globalId;
                }

                @Override
                public byte[] getBranchId() {
                    return branchId;
                }
            }, enqueues, dequeues);
        }

        @Override
        public Transaction newTransaction() {
            return transaction;
        }
    };
    DtxRegistry dtxRegistry = new DtxRegistry(_virtualHost);
    when(_virtualHost.getMessageStore()).thenReturn(store);
    when(_virtualHost.getDtxRegistry()).thenReturn(dtxRegistry);
    SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
    recoverer.recover(_virtualHost);
    DtxBranch branch = dtxRegistry.getBranch(new Xid(format, globalId, branchId));
    assertNotNull("Expected dtx branch to be created", branch);
    branch.commit();
    verify(queueEntry, times(1)).delete();
    verify(transaction).commitTran();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) EnqueueRecord(org.apache.qpid.server.store.Transaction.EnqueueRecord) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) UUID(java.util.UUID) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) DistributedTransactionHandler(org.apache.qpid.server.store.handler.DistributedTransactionHandler) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) QueueEntry(org.apache.qpid.server.queue.QueueEntry) Xid(org.apache.qpid.server.txn.Xid) Transaction(org.apache.qpid.server.store.Transaction) DtxRegistry(org.apache.qpid.server.txn.DtxRegistry) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) DtxBranch(org.apache.qpid.server.txn.DtxBranch)

Example 8 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method createMockStoredMessage.

private StoredMessage<StorableMessageMetaData> createMockStoredMessage(final long messageId) {
    TestMessageMetaData metaData = new TestMessageMetaData(messageId, 0);
    @SuppressWarnings("unchecked") final StoredMessage<StorableMessageMetaData> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getMessageNumber()).thenReturn(messageId);
    when(storedMessage.getMetaData()).thenReturn(metaData);
    return storedMessage;
}
Also used : TestMessageMetaData(org.apache.qpid.server.store.TestMessageMetaData) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 9 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method testRecoveryDeletesOrphanMessages.

public void testRecoveryDeletesOrphanMessages() {
    final long messageId = 1;
    final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(messageId);
    MessageStore store = new NullMessageStore() {

        @Override
        public void visitMessages(MessageHandler handler) throws StoreException {
            handler.handle(storedMessage);
        }

        @Override
        public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
        // No messages instances
        }
    };
    when(_virtualHost.getMessageStore()).thenReturn(store);
    SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
    recoverer.recover(_virtualHost);
    verify(storedMessage, times(1)).remove();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 10 with StorableMessageMetaData

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

Aggregations

StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)14 MessageStore (org.apache.qpid.server.store.MessageStore)5 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)5 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)5 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)5 DatabaseEntry (com.sleepycat.je.DatabaseEntry)4 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)3 StoredMessage (org.apache.qpid.server.store.StoredMessage)3 Transaction (org.apache.qpid.server.store.Transaction)3 MessageMetaDataBinding (org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding)3 UUID (java.util.UUID)2 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)2 TestMessageMetaData (org.apache.qpid.server.store.TestMessageMetaData)2 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)2 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)2 DtxBranch (org.apache.qpid.server.txn.DtxBranch)2 DtxRegistry (org.apache.qpid.server.txn.DtxRegistry)2 Xid (org.apache.qpid.server.txn.Xid)2 Cursor (com.sleepycat.je.Cursor)1 Database (com.sleepycat.je.Database)1