Search in sources :

Example 1 with StorableMessageMetaData

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

the class UpgradeFrom4To5 method upgradeMetaData.

private void upgradeMetaData(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
    LOGGER.info("Message MetaData");
    if (environment.getDatabaseNames().contains(OLD_METADATA_DB_NAME)) {
        final MessageMetaDataBinding binding = new MessageMetaDataBinding();
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                StorableMessageMetaData metaData = binding.entryToObject(value);
                // get message id
                Long messageId = LongBinding.entryToLong(key);
                // ONLY copy data if message is delivered to existing queue
                if (messagesToDiscard.contains(messageId)) {
                    return;
                }
                DatabaseEntry newValue = new DatabaseEntry();
                binding.objectToEntry(metaData, newValue);
                targetDatabase.put(transaction, key, newValue);
                targetDatabase.put(transaction, key, newValue);
                deleteCurrent();
            }
        };
        new DatabaseTemplate(environment, OLD_METADATA_DB_NAME, NEW_METADATA_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_METADATA_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Message MetaData entries");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 2 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleMessageOnSingleQueue.

@SuppressWarnings("unchecked")
@Test
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) Test(org.junit.Test)

Example 3 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method testRecoveryDeletesOrphanMessages.

@Test
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) Test(org.junit.Test)

Example 4 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 5 with StorableMessageMetaData

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfMessageInstanceForNonExistingQueue.

@Test
public void testRecoveryOfMessageInstanceForNonExistingQueue() {
    final UUID queueId = UUID.randomUUID();
    final Transaction transaction = mock(Transaction.class);
    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(queueId, messageId));
        }

        @Override
        public Transaction newTransaction() {
            return transaction;
        }
    };
    when(_virtualHost.getMessageStore()).thenReturn(store);
    SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
    recoverer.recover(_virtualHost);
    verify(transaction).dequeueMessage(argThat(new MessageEnqueueRecordMatcher(queueId, messageId)));
    verify(transaction, times(1)).commitTranAsync((Void) null);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) Transaction(org.apache.qpid.server.store.Transaction) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) UUID(java.util.UUID) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) Test(org.junit.Test)

Aggregations

StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)14 Test (org.junit.Test)6 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 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)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