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;
}
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();
}
};
}
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());
}
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());
}
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());
}
Aggregations