Search in sources :

Example 6 with NullMessageStore

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

the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationSucceeds.

public void testPublishContentHeaderWhenMessageAuthorizationSucceeds() throws Exception {
    when(_virtualHost.getDefaultDestination()).thenReturn(_messageDestination);
    when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {

        @Override
        public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
            MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
            return messageHandle;
        }
    });
    final ArgumentCaptor<ServerMessage> messageCaptor = ArgumentCaptor.forClass(ServerMessage.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            ServerMessage message = messageCaptor.getValue();
            return new RoutingResult(message);
        }
    }).when(_messageDestination).route(messageCaptor.capture(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
    AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
    BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
    properties.setUserId(_amqConnection.getAuthorizedPrincipal().getName());
    channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, ROUTING_KEY, false, false);
    channel.receiveMessageHeader(properties, 0);
    verify(_messageDestination).route((ServerMessage) any(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage) StoredMemoryMessage(org.apache.qpid.server.store.StoredMemoryMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) RoutingResult(org.apache.qpid.server.message.RoutingResult) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) MessageHandle(org.apache.qpid.server.store.MessageHandle) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 7 with NullMessageStore

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

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

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

the class AbstractStandardVirtualHostNodeTest method testActivateVHNWithVHBlueprint_StoreHasNoVH.

/**
 *  Tests activating a virtualhostnode with a blueprint context variable.  Config store
 *  does not specify a virtualhost.  Checks virtualhost is created from the blueprint.
 */
public void testActivateVHNWithVHBlueprint_StoreHasNoVH() throws Exception {
    DurableConfigurationStore configStore = new NullMessageStore() {
    };
    String vhBlueprint = String.format("{ \"type\" : \"%s\", \"name\" : \"%s\"}", TestMemoryVirtualHost.VIRTUAL_HOST_TYPE, TEST_VIRTUAL_HOST_NAME);
    Map<String, String> context = Collections.singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, vhBlueprint);
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    nodeAttributes.put(VirtualHostNode.CONTEXT, context);
    VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.open();
    node.start();
    VirtualHost<?> virtualHost = node.getVirtualHost();
    assertNotNull("Virtual host should be created by blueprint", virtualHost);
    assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NAME, virtualHost.getName());
    assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
    assertNotNull("Unexpected virtual host id", virtualHost.getId());
    assertEquals("Initial configuration should be empty", "{}", node.getVirtualHostInitialConfiguration());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Aggregations

NullMessageStore (org.apache.qpid.server.store.NullMessageStore)9 MessageStore (org.apache.qpid.server.store.MessageStore)6 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)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 ServerMessage (org.apache.qpid.server.message.ServerMessage)2 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 MessageHandle (org.apache.qpid.server.store.MessageHandle)2 StoredMemoryMessage (org.apache.qpid.server.store.StoredMemoryMessage)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 AccessControlException (java.security.AccessControlException)1 HashMap (java.util.HashMap)1 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)1