Search in sources :

Example 6 with MessageStore

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

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

the class AbstractVirtualHostTest method testStartInErrorStateAfterOpen.

public void testStartInErrorStateAfterOpen() throws Exception {
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
    final MessageStore store = mock(MessageStore.class);
    doThrow(new RuntimeException("Cannot open store")).when(store).openMessageStore(any(ConfiguredObject.class));
    AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) {

        @Override
        protected MessageStore createMessageStore() {
            return store;
        }
    };
    host.open();
    assertEquals("Unexpected state", State.ERRORED, host.getState());
    doNothing().when(store).openMessageStore(any(ConfiguredObject.class));
    when(store.newMessageStoreReader()).thenReturn(mock(MessageStore.MessageStoreReader.class));
    host.start();
    assertEquals("Unexpected state", State.ACTIVE, host.getState());
    host.close();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 8 with MessageStore

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

the class AbstractVirtualHostTest method testValidateMessageStoreCreationSucceeds.

public void testValidateMessageStoreCreationSucceeds() {
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
    final MessageStore store = mock(MessageStore.class);
    AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) {

        @Override
        protected MessageStore createMessageStore() {
            return store;
        }
    };
    host.validateMessageStoreCreation();
    verify(store).openMessageStore(host);
    verify(store).closeMessageStore();
    host.close();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 9 with MessageStore

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

the class JDBCMessageStoreTest method testEnqueueTransactionCommitAsync.

public void testEnqueueTransactionCommitAsync() throws Exception {
    final String queueName = getTestName();
    final UUID transactionalLogId = UUID.randomUUID();
    final MessageStore store = getStore();
    final TransactionLogResource transactionalLog = mockTransactionLogResource(transactionalLogId, queueName);
    final InternalMessage message = addTestMessage(store, queueName, "test");
    final Transaction transaction = store.newTransaction();
    final MessageEnqueueRecord record = transaction.enqueueMessage(transactionalLog, message);
    assertNotNull("Message enqueue record should not be null", record);
    assertEquals("Unexpected queue id", transactionalLogId, record.getQueueId());
    assertEquals("Unexpected message number", message.getMessageNumber(), record.getMessageNumber());
    final ListenableFuture<Void> future = transaction.commitTranAsync(null);
    future.get(1000, TimeUnit.MILLISECONDS);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Transaction(org.apache.qpid.server.store.Transaction) UUID(java.util.UUID) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 10 with MessageStore

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

the class JDBCMessageStoreTest method testDequeueTransactionCommitAsync.

public void testDequeueTransactionCommitAsync() throws Exception {
    final String queueName = getTestName();
    final UUID transactionalLogId = UUID.randomUUID();
    final MessageStore store = getStore();
    final TransactionLogResource transactionalLog = mockTransactionLogResource(transactionalLogId, queueName);
    final InternalMessage message = addTestMessage(store, queueName, "test2");
    final Transaction enqueueTransaction = store.newTransaction();
    MessageEnqueueRecord record = enqueueTransaction.enqueueMessage(transactionalLog, message);
    enqueueTransaction.commitTran();
    final Transaction dequeueTransaction = store.newTransaction();
    dequeueTransaction.dequeueMessage(record);
    final ListenableFuture<Void> future = dequeueTransaction.commitTranAsync(null);
    future.get(1000, TimeUnit.MILLISECONDS);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Transaction(org.apache.qpid.server.store.Transaction) UUID(java.util.UUID) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Aggregations

MessageStore (org.apache.qpid.server.store.MessageStore)20 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)7 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)6 Transaction (org.apache.qpid.server.store.Transaction)6 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)6 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)6 UUID (java.util.UUID)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)3 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)2 VirtualHost (org.apache.qpid.server.model.VirtualHost)2 QueueEntry (org.apache.qpid.server.queue.QueueEntry)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 TestMemoryMessageStore (org.apache.qpid.server.store.TestMemoryMessageStore)2 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)2 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)2 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)2 File (java.io.File)1 AccessControlException (java.security.AccessControlException)1