use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class TopicExchangeTest 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 = _vhost.createChild(Exchange.class, viaExchangeArguments);
Queue<?> queue = _vhost.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 testRouteToQueueWithSelector.
public void testRouteToQueueWithSelector() {
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));
ServerMessage<?> unmatchingMessage = 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(matchingMessage, "mybinding", instanceProperties);
assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
result = _exchange.route(unmatchingMessage, "mybinding", instanceProperties);
assertFalse("Message without matching selector unexpectedly routed to queue", result.hasRoutes());
boolean unbind = _exchange.unbind(queue.getName(), bindingKey);
assertTrue("Unbind operation should be successful", unbind);
result = _exchange.route(matchingMessage, "mybinding", instanceProperties);
assertFalse("Message with matching selector unexpectedly routed to queue after unbind", result.hasRoutes());
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class TopicExchangeTest method testUpdateBindingChangeReplacementKey.
public void testUpdateBindingChangeReplacementKey() throws Exception {
String bindingKey = "mybinding";
String replacementKey = "key1";
String replacementKey2 = "key2";
Map<String, Object> attributes = new HashMap<>();
attributes.put(Exchange.NAME, getTestName());
attributes.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
Exchange via = _vhost.createChild(Exchange.class, attributes);
Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
boolean exchToViaBind = _exchange.bind(via.getName(), bindingKey, Collections.emptyMap(), 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(_messageWithNoHeaders, bindingKey, _instanceProperties);
assertFalse("Message unexpectedly routed to queue", result.hasRoutes());
_exchange.bind(via.getName(), bindingKey, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey), true);
result = _exchange.route(_messageWithNoHeaders, bindingKey, _instanceProperties);
assertTrue("Message was not routed", result.hasRoutes());
assertTrue("Message was not routed to queue", result.getRoutes().contains(queue));
Queue<?> queue2 = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue2"));
assertTrue("Binding of queue2 failed", via.bind(queue2.getName(), replacementKey2, Collections.emptyMap(), false));
_exchange.bind(via.getName(), bindingKey, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey2), true);
result = _exchange.route(_messageWithNoHeaders, bindingKey, _instanceProperties);
assertTrue("Message was not routed", result.hasRoutes());
assertTrue("Message was not routed to queue2", result.getRoutes().contains(queue2));
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class TopicExchangeTest method testUpdateBindingAddingSelector.
public void testUpdateBindingAddingSelector() 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.emptyMap(), false);
assertTrue("Bind operation should be successful", bind);
RoutingResult<ServerMessage<?>> result = _exchange.route(message, bindingKey, instanceProperties);
assertTrue("Message not routed to queue", result.hasRoutes());
_exchange.replaceBinding(bindingKey, queue, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = false"));
result = _exchange.route(message, bindingKey, instanceProperties);
assertTrue("Message that matches selector not routed to queue after rebind", result.hasRoutes());
result = _exchange.route(message = createTestMessage(Collections.singletonMap("prop", true)), bindingKey, instanceProperties);
assertFalse("Message that does not match selector routed to queue after rebind", result.hasRoutes());
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class LocalTransactionTest method createTestQueueEntries.
private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
for (int i = 0; i < queueDurableFlags.length; i++) {
final TransactionLogResource queue = createQueue(queueDurableFlags[i]);
final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
queueEntries.add(new MockMessageInstance() {
@Override
public ServerMessage getMessage() {
return message;
}
@Override
public TransactionLogResource getOwningResource() {
return queue;
}
@Override
public MessageEnqueueRecord getEnqueueRecord() {
return hasRecord ? mock(MessageEnqueueRecord.class) : null;
}
});
}
return queueEntries;
}
Aggregations