Search in sources :

Example 6 with MessageHandler

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

the class MessageStoreTestCase method testVisitMessagesAborted.

public void testVisitMessagesAborted() throws Exception {
    int contentSize = 0;
    for (int i = 0; i < 3; i++) {
        final MessageHandle<TestMessageMetaData> message = _store.addMessage(new TestMessageMetaData(i + 1, contentSize));
        enqueueMessage(message.allContentAdded(), "dummyQ");
    }
    MessageHandler handler = mock(MessageHandler.class);
    when(handler.handle(any(StoredMessage.class))).thenReturn(true, false);
    _storeReader.visitMessages(handler);
    verify(handler, times(2)).handle(any(StoredMessage.class));
}
Also used : MessageHandler(org.apache.qpid.server.store.handler.MessageHandler)

Example 7 with MessageHandler

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

the class MessageStoreTestCase method testVisitMessages.

public void testVisitMessages() throws Exception {
    long messageId = 1;
    int contentSize = 0;
    final MessageHandle<TestMessageMetaData> message = _store.addMessage(new TestMessageMetaData(messageId, contentSize));
    enqueueMessage(message.allContentAdded(), "dummyQ");
    MessageHandler handler = mock(MessageHandler.class);
    _storeReader.visitMessages(handler);
    verify(handler, times(1)).handle(argThat(new MessageMetaDataMatcher(messageId)));
}
Also used : MessageHandler(org.apache.qpid.server.store.handler.MessageHandler)

Example 8 with MessageHandler

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

the class TestMemoryMessageStore method getMessageCount.

public int getMessageCount() {
    final AtomicInteger counter = new AtomicInteger();
    newMessageStoreReader().visitMessages(new MessageHandler() {

        @Override
        public boolean handle(StoredMessage<?> storedMessage) {
            counter.incrementAndGet();
            return true;
        }
    });
    return counter.get();
}
Also used : MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 9 with MessageHandler

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfMessageInstanceForNonExistingMessage.

@SuppressWarnings("unchecked")
public void testRecoveryOfMessageInstanceForNonExistingMessage() {
    final Queue<?> queue = createRegisteredMockQueue();
    final long messageId = 1;
    final Transaction transaction = mock(Transaction.class);
    MessageStore store = new NullMessageStore() {

        @Override
        public void visitMessages(MessageHandler handler) throws StoreException {
        // no message to visit
        }

        @Override
        public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
            handler.handle(new TestMessageEnqueueRecord(queue.getId(), messageId));
        }

        @Override
        public Transaction newTransaction() {
            return transaction;
        }
    };
    when(_virtualHost.getMessageStore()).thenReturn(store);
    SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
    recoverer.recover(_virtualHost);
    verify(queue, never()).enqueue(any(ServerMessage.class), any(Action.class), any(MessageEnqueueRecord.class));
    verify(transaction).dequeueMessage(argThat(new MessageEnqueueRecordMatcher(queue.getId(), messageId)));
    verify(transaction, times(1)).commitTranAsync((Void) null);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) Action(org.apache.qpid.server.util.Action) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) ServerMessage(org.apache.qpid.server.message.ServerMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Transaction(org.apache.qpid.server.store.Transaction) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler)

Example 10 with MessageHandler

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleEnqueueWithDistributedTransaction.

@SuppressWarnings("unchecked")
public void testRecoveryOfSingleEnqueueWithDistributedTransaction() {
    Queue<?> queue = createRegisteredMockQueue();
    final Transaction transaction = mock(Transaction.class);
    final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(1);
    long messageId = storedMessage.getMessageNumber();
    EnqueueableMessage enqueueableMessage = createMockEnqueueableMessage(messageId, storedMessage);
    EnqueueRecord enqueueRecord = createMockRecord(queue, enqueueableMessage);
    final long format = 1;
    final byte[] globalId = new byte[] { 0 };
    final byte[] branchId = new byte[] { 0 };
    final EnqueueRecord[] enqueues = { enqueueRecord };
    final Transaction.DequeueRecord[] dequeues = {};
    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
        }

        @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();
    ServerMessage<?> message = storedMessage.getMetaData().getType().createMessage(storedMessage);
    verify(queue, times(1)).enqueue(eq(message), (Action<? super MessageInstance>) isNull(), any(MessageEnqueueRecord.class));
    verify(transaction).commitTran();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) DistributedTransactionHandler(org.apache.qpid.server.store.handler.DistributedTransactionHandler) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) EnqueueRecord(org.apache.qpid.server.store.Transaction.EnqueueRecord) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Xid(org.apache.qpid.server.txn.Xid) Transaction(org.apache.qpid.server.store.Transaction) DtxRegistry(org.apache.qpid.server.txn.DtxRegistry) EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) DtxBranch(org.apache.qpid.server.txn.DtxBranch)

Aggregations

MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)10 MessageStore (org.apache.qpid.server.store.MessageStore)6 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)6 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)6 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)5 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 Transaction (org.apache.qpid.server.store.Transaction)4 UUID (java.util.UUID)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 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 QueueEntry (org.apache.qpid.server.queue.QueueEntry)1 Action (org.apache.qpid.server.util.Action)1