Search in sources :

Example 16 with MessageStore

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

the class AbstractVirtualHostTest method testActivateInErrorStateAfterOpen.

public void testActivateInErrorStateAfterOpen() 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.setAttributes(Collections.<String, Object>singletonMap(VirtualHost.DESIRED_STATE, State.ACTIVE));
    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 17 with MessageStore

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

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

Example 19 with MessageStore

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

the class VirtualHostPropertiesNodeTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    VirtualHost vhost = mock(VirtualHost.class);
    MessageStore messageStore = new TestMemoryMessageStore();
    when(vhost.getMessageStore()).thenReturn(messageStore);
    _virtualHostPropertiesNode = new VirtualHostPropertiesNode(vhost);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) TestMemoryMessageStore(org.apache.qpid.server.store.TestMemoryMessageStore) VirtualHost(org.apache.qpid.server.model.VirtualHost) TestMemoryMessageStore(org.apache.qpid.server.store.TestMemoryMessageStore)

Example 20 with MessageStore

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

the class TrustStoreMessageSourceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    VirtualHost vhost = mock(VirtualHost.class);
    MessageStore messageStore = new TestMemoryMessageStore();
    TrustStore trustStore = mock(TrustStore.class);
    Certificate certificate = mock(Certificate.class);
    _certificates = new Certificate[] { certificate };
    when(vhost.getMessageStore()).thenReturn(messageStore);
    when(trustStore.getState()).thenReturn(State.ACTIVE);
    when(trustStore.getCertificates()).thenReturn(_certificates);
    when(certificate.getEncoded()).thenReturn("my certificate".getBytes());
    _trustStoreMessageSource = new TrustStoreMessageSource(trustStore, vhost);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) TestMemoryMessageStore(org.apache.qpid.server.store.TestMemoryMessageStore) VirtualHost(org.apache.qpid.server.model.VirtualHost) TrustStore(org.apache.qpid.server.model.TrustStore) TestMemoryMessageStore(org.apache.qpid.server.store.TestMemoryMessageStore) Certificate(java.security.cert.Certificate)

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