Skip to content

Commit f5543e8

Browse files
author
Simon MacMullen
committed
Tests for DLX policy
1 parent 7b43cbb commit f5543e8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/src/com/rabbitmq/client/test/functional/Policies.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.rabbitmq.client.test.functional;
22

3+
import com.rabbitmq.client.GetResponse;
34
import com.rabbitmq.client.MessageProperties;
45
import com.rabbitmq.client.test.BrokerTestCase;
56
import com.rabbitmq.tools.Host;
@@ -14,6 +15,7 @@
1415
public class Policies extends BrokerTestCase {
1516
@Override protected void createResources() throws IOException {
1617
Host.rabbitmqctl("set_policy AE ^has-ae {\\\"alternate-exchange\\\":\\\"ae\\\"}");
18+
Host.rabbitmqctl("set_policy DLX ^has-dlx {\\\"dead-letter-exchange\\\":\\\"dlx\\\",\\\"dead-letter-routing-key\\\":\\\"rk\\\"}");
1719
channel.exchangeDeclare("has-ae", "fanout");
1820
Map<String, Object> args = new HashMap<String, Object>();
1921
args.put("alternate-exchange", "ae2");
@@ -37,8 +39,39 @@ public void testAlternateExchangeArgs() throws IOException {
3739
assertDelivered(q, 1);
3840
}
3941

42+
public void testDeadLetterExchange() throws IOException, InterruptedException {
43+
Map<String, Object> args = new HashMap<String, Object>();
44+
args.put("x-message-ttl", 0);
45+
String src = channel.queueDeclare("has-dlx", false, true, false, args).getQueue();
46+
String dest = channel.queueDeclare().getQueue();
47+
channel.exchangeDeclare("dlx", "fanout", false, true, null);
48+
channel.queueBind(dest, "dlx", "");
49+
channel.basicPublish("", src, MessageProperties.BASIC, "".getBytes());
50+
Thread.sleep(10);
51+
GetResponse resp = channel.basicGet(dest, true);
52+
assertEquals("rk", resp.getEnvelope().getRoutingKey());
53+
}
54+
55+
// again the argument takes priority over the policy
56+
public void testDeadLetterExchangeArgs() throws IOException, InterruptedException {
57+
Map<String, Object> args = new HashMap<String, Object>();
58+
args.put("x-message-ttl", 0);
59+
args.put("x-dead-letter-exchange", "dlx2");
60+
args.put("x-dead-letter-routing-key", "rk2");
61+
String src = channel.queueDeclare("has-dlx-args", false, true, false, args).getQueue();
62+
String dest = channel.queueDeclare().getQueue();
63+
channel.exchangeDeclare("dlx2", "fanout", false, true, null);
64+
channel.queueBind(dest, "dlx2", "");
65+
channel.basicPublish("", src, MessageProperties.BASIC, "".getBytes());
66+
Thread.sleep(10);
67+
GetResponse resp = channel.basicGet(dest, true);
68+
assertEquals("rk2", resp.getEnvelope().getRoutingKey());
69+
}
70+
4071
@Override protected void releaseResources() throws IOException {
4172
Host.rabbitmqctl("clear_policy AE");
73+
Host.rabbitmqctl("clear_policy DLX");
4274
channel.exchangeDelete("has-ae");
75+
channel.exchangeDelete("has-ae-args");
4376
}
4477
}

0 commit comments

Comments
 (0)