Search in sources :

Example 1 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class ReportRunnerTest method createMockQueue.

private Queue createMockQueue(final ServerMessage<?>... messages) {
    final Queue<?> queue = mock(Queue.class);
    final ArgumentCaptor<QueueEntryVisitor> captor = ArgumentCaptor.forClass(QueueEntryVisitor.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            QueueEntryVisitor visitor = captor.getValue();
            for (ServerMessage<?> message : messages) {
                if (visitor.visit(makeEntry(queue, message))) {
                    break;
                }
            }
            return null;
        }
    }).when(queue).visit(captor.capture());
    return queue;
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) QueueEntryVisitor(org.apache.qpid.server.queue.QueueEntryVisitor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 2 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class ReportRunner method convertMessage.

private static ReportableMessage convertMessage(QueueEntry entry) {
    final MessageInfoImpl messageInfo = new MessageInfoImpl(entry, true);
    ServerMessage message = entry.getMessage();
    byte[] content;
    try (QpidByteBuffer contentBuffer = message.getContent()) {
        content = new byte[contentBuffer.remaining()];
        contentBuffer.get(content);
    }
    return new ReportableMessage() {

        @Override
        public String getInitialRoutingAddress() {
            return messageInfo.getInitialRoutingAddress();
        }

        @Override
        public ReportableMessageHeader getMessageHeader() {
            return convertMessageHeader(messageInfo);
        }

        @Override
        public ByteBuffer getContent() {
            return ByteBuffer.wrap(content).asReadOnlyBuffer();
        }

        @Override
        public boolean isPersistent() {
            return messageInfo.isPersistent();
        }

        @Override
        public long getSize() {
            return messageInfo.getSize();
        }

        @Override
        public Date getExpiration() {
            return messageInfo.getExpirationTime();
        }

        @Override
        public long getMessageNumber() {
            return messageInfo.getId();
        }

        @Override
        public Date getArrivalTime() {
            return messageInfo.getArrivalTime();
        }
    };
}
Also used : MessageInfoImpl(org.apache.qpid.server.message.MessageInfoImpl) ServerMessage(org.apache.qpid.server.message.ServerMessage) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 3 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class HeadersExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering.

public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering() {
    String bindingKey = "key1";
    String replacementKey = "key2";
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, getTestName() + "_via_exch");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.TOPIC_EXCHANGE_CLASS);
    Exchange via = _virtualHost.createChild(Exchange.class, viaExchangeArguments);
    Queue<?> queue = _virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    Map<String, Object> exchToViaBindArguments = new HashMap<>();
    exchToViaBindArguments.put(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey);
    exchToViaBindArguments.put(JMS_SELECTOR.toString(), "prop = True");
    boolean exchToViaBind = _exchange.bind(via.getName(), bindingKey, exchToViaBindArguments, false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), replacementKey, Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(createTestMessage(Collections.singletonMap("prop", true)), bindingKey, _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
    result = _exchange.route(createTestMessage(Collections.singletonMap("prop", false)), bindingKey, _instanceProperties);
    assertFalse("Message unexpectedly routed to queue", result.hasRoutes());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 4 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class TopicExchangeTest method testUpdateBindingRemovingSelector.

public void testUpdateBindingRemovingSelector() throws Exception {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> message = createTestMessage(Collections.singletonMap("prop", false));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(message, bindingKey, instanceProperties);
    assertFalse("Message that does not match selector routed to queue", result.hasRoutes());
    _exchange.replaceBinding(bindingKey, queue, Collections.emptyMap());
    result = _exchange.route(message, bindingKey, instanceProperties);
    assertTrue("Message not routed to queue after rebind", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 5 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class TopicExchangeTest method testUpdateBindingReplacingSelector.

public void testUpdateBindingReplacingSelector() throws Exception {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> matchingMessage = createTestMessage(Collections.singletonMap("prop", true));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    _exchange.replaceBinding(bindingKey, queue, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = False"));
    result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertFalse("Message unexpectedly routed to queue after rebind", result.hasRoutes());
    result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertFalse(result.hasRoutes());
    matchingMessage = createTestMessage(Collections.singletonMap("prop", false));
    result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertTrue("Message not routed to queue", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Aggregations

ServerMessage (org.apache.qpid.server.message.ServerMessage)103 HashMap (java.util.HashMap)26 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)16 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)16 Exchange (org.apache.qpid.server.model.Exchange)14 MessageReference (org.apache.qpid.server.message.MessageReference)13 ArrayList (java.util.ArrayList)9 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)7 Queue (org.apache.qpid.server.model.Queue)7 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 PrivilegedAction (java.security.PrivilegedAction)2 UUID (java.util.UUID)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2