Skip to content

Commit a96d6c0

Browse files
author
Simon MacMullen
committed
Don't conflict with HATests, remove pointless sleeps, clean up escaping a little.
1 parent 167e016 commit a96d6c0

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.rabbitmq.client.Channel;
2020
import com.rabbitmq.client.GetResponse;
2121
import com.rabbitmq.client.test.BrokerTestCase;
22+
import com.rabbitmq.client.test.server.HATests;
2223
import com.rabbitmq.tools.Host;
2324

2425
import java.io.IOException;
@@ -31,11 +32,11 @@ public class Policies extends BrokerTestCase {
3132
private static final int DELAY = 100; // MILLIS
3233

3334
@Override protected void createResources() throws IOException {
34-
setPolicy("AE", "^has-ae", "{\\\"alternate-exchange\\\":\\\"ae\\\"}");
35-
setPolicy("DLX", "^has-dlx", "{\\\"dead-letter-exchange\\\":\\\"dlx\\\"\\,\\\"dead-letter-routing-key\\\":\\\"rk\\\"}");
36-
setPolicy("TTL", "^has-ttl", "{\\\"message-ttl\\\":" + DELAY + "}");
37-
setPolicy("Expires", "^has-expires", "{\\\"expires\\\":" + DELAY + "}");
38-
setPolicy("MaxLength", "^has-max-length", "{\\\"max-length\\\":1}");
35+
setPolicy("AE", "^has-ae", "\"alternate-exchange\":\"ae\"");
36+
setPolicy("DLX", "^has-dlx", "\"dead-letter-exchange\":\"dlx\",\"dead-letter-routing-key\":\"rk\"");
37+
setPolicy("TTL", "^has-ttl", "\"message-ttl\":" + DELAY);
38+
setPolicy("Expires", "^has-expires", "\"expires\":" + DELAY);
39+
setPolicy("MaxLength", "^has-max-length", "\"max-length\":1");
3940
channel.exchangeDeclare("has-ae", "fanout");
4041
Map<String, Object> args = new HashMap<String, Object>();
4142
args.put("alternate-exchange", "ae2");
@@ -46,9 +47,7 @@ public void testAlternateExchange() throws IOException, InterruptedException {
4647
String q = declareQueue();
4748
channel.exchangeDeclare("ae", "fanout", false, true, null);
4849
channel.queueBind(q, "ae", "");
49-
Thread.sleep(DELAY); // TODO do we need this?
5050
basicPublishVolatile("has-ae", "");
51-
Thread.sleep(DELAY); // TODO do we need this?
5251
assertDelivered(q, 1);
5352
clearPolicies();
5453

@@ -177,10 +176,21 @@ public void testMaxLengthArgs() throws IOException, InterruptedException {
177176
private Set<String> policies = new HashSet<String>();
178177

179178
private void setPolicy(String name, String pattern, String definition) throws IOException {
180-
Host.rabbitmqctl("set_policy " + name + " " + pattern + " " + definition);
179+
// We need to override the HA policy that we use in HATests, so
180+
// priority 1. But we still want a valid test of HA, so add the
181+
// ha-mode definition.
182+
if (HATests.HA_TESTS_RUNNING) {
183+
definition += ",\"ha-mode\":\"all\"";
184+
}
185+
Host.rabbitmqctl("set_policy --priority 1 " + name + " " + pattern +
186+
" {" + escapeDefinition(definition) + "}");
181187
policies.add(name);
182188
}
183189

190+
private String escapeDefinition(String definition) {
191+
return definition.replaceAll(",", "\\\\,").replaceAll("\"", "\\\\\\\"");
192+
}
193+
184194
private void clearPolicies() throws IOException {
185195
for (String policy : policies) {
186196
Host.rabbitmqctl("clear_policy " + policy);

0 commit comments

Comments
 (0)