Skip to content

Commit f7c4834

Browse files
author
Simon MacMullen
committed
Test removal of policies
1 parent 7966d45 commit f7c4834

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
import java.io.IOException;
99
import java.util.HashMap;
10+
import java.util.HashSet;
1011
import java.util.Map;
12+
import java.util.Set;
1113

1214
/**
1315
*
1416
*/
1517
public class Policies extends BrokerTestCase {
1618
@Override protected void createResources() throws IOException {
17-
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\\\"}");
19+
setAE();
20+
setDLX();
1921
channel.exchangeDeclare("has-ae", "fanout");
2022
Map<String, Object> args = new HashMap<String, Object>();
2123
args.put("alternate-exchange", "ae2");
@@ -28,6 +30,9 @@ public void testAlternateExchange() throws IOException {
2830
channel.queueBind(q, "ae", "");
2931
channel.basicPublish("has-ae", "", MessageProperties.BASIC, "".getBytes());
3032
assertDelivered(q, 1);
33+
clearPolicies();
34+
channel.basicPublish("has-ae", "", MessageProperties.BASIC, "".getBytes());
35+
assertDelivered(q, 0);
3136
}
3237

3338
// i.e. the argument takes priority over the policy
@@ -50,6 +55,10 @@ public void testDeadLetterExchange() throws IOException, InterruptedException {
5055
Thread.sleep(10);
5156
GetResponse resp = channel.basicGet(dest, true);
5257
assertEquals("rk", resp.getEnvelope().getRoutingKey());
58+
clearPolicies();
59+
channel.basicPublish("", src, MessageProperties.BASIC, "".getBytes());
60+
Thread.sleep(10);
61+
assertDelivered(dest, 0);
5362
}
5463

5564
// again the argument takes priority over the policy
@@ -69,9 +78,30 @@ public void testDeadLetterExchangeArgs() throws IOException, InterruptedExceptio
6978
}
7079

7180
@Override protected void releaseResources() throws IOException {
72-
Host.rabbitmqctl("clear_policy AE");
73-
Host.rabbitmqctl("clear_policy DLX");
81+
clearPolicies();
7482
channel.exchangeDelete("has-ae");
7583
channel.exchangeDelete("has-ae-args");
7684
}
85+
86+
private Set<String> policies = new HashSet<String>();
87+
88+
private void setAE() throws IOException {
89+
setPolicy("AE", "^has-ae", "{\\\"alternate-exchange\\\":\\\"ae\\\"}");
90+
}
91+
92+
private void setDLX() throws IOException {
93+
setPolicy("DLX", "^has-dlx", "{\\\"dead-letter-exchange\\\":\\\"dlx\\\"\\,\\\"dead-letter-routing-key\\\":\\\"rk\\\"}");
94+
}
95+
96+
private void setPolicy(String name, String pattern, String definition) throws IOException {
97+
Host.rabbitmqctl("set_policy " + name + " " + pattern + " " + definition);
98+
policies.add(name);
99+
}
100+
101+
private void clearPolicies() throws IOException {
102+
for (String policy : policies) {
103+
Host.rabbitmqctl("clear_policy " + policy);
104+
}
105+
policies.clear();
106+
}
77107
}

0 commit comments

Comments
 (0)