Skip to content

Commit

Permalink
closes #1697: add vhost parameter for policies (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
twillouer authored and rnorth committed Dec 23, 2019
1 parent e7e05d2 commit 08234f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
Expand Up @@ -263,6 +263,15 @@ public RabbitMQContainer withPolicy(String name, String pattern, Map<String, Obj
return self();
}

public RabbitMQContainer withPolicy(String vhost, String name, String pattern, Map<String, Object> definition) {
values.add(asList("rabbitmqadmin", "declare", "policy",
"--vhost=" + vhost,
"name=" + name,
"pattern=" + pattern,
"definition=" + toJson(definition)));
return self();
}

public RabbitMQContainer withPolicy(String name, String pattern, Map<String, Object> definition, int priority, String applyTo) {
values.add(asList("rabbitmqadmin", "declare", "policy",
"name=" + name,
Expand Down
Expand Up @@ -154,21 +154,22 @@ public void shouldStartTheWholeEnchilada() throws IOException, InterruptedExcept
{
try (RabbitMQContainer container = new RabbitMQContainer()) {
container
.withVhost("vhost1")
.withVhostLimit("vhost1", "max-connections", 1)
.withVhost("vhost2", true)
.withExchange("direct-exchange", "direct")
.withExchange("topic-exchange", "topic")
.withQueue("queue1")
.withQueue("queue2", true, false, ImmutableMap.of("x-message-ttl", 1000))
.withBinding("direct-exchange", "queue1")
.withUser("user1", "password1")
.withUser("user2", "password2", ImmutableSet.of("administrator"))
.withPermission("vhost1", "user1", ".*", ".*", ".*")
.withPolicy("max length policy", "^dog", ImmutableMap.of("max-length", 1), 1, "queues")
.withPolicy("alternate exchange policy", "^direct-exchange", ImmutableMap.of("alternate-exchange", "amq.direct"))
.withOperatorPolicy("operator policy 1", "^queue1", ImmutableMap.of("message-ttl", 1000), 1, "queues")
.withPluginsEnabled("rabbitmq_shovel", "rabbitmq_random_exchange");
.withVhost("vhost1")
.withVhostLimit("vhost1", "max-connections", 1)
.withVhost("vhost2", true)
.withExchange("direct-exchange", "direct")
.withExchange("topic-exchange", "topic")
.withQueue("queue1")
.withQueue("queue2", true, false, ImmutableMap.of("x-message-ttl", 1000))
.withBinding("direct-exchange", "queue1")
.withUser("user1", "password1")
.withUser("user2", "password2", ImmutableSet.of("administrator"))
.withPermission("vhost1", "user1", ".*", ".*", ".*")
.withPolicy("max length policy", "^dog", ImmutableMap.of("max-length", 1), 1, "queues")
.withPolicy("alternate exchange policy", "^direct-exchange", ImmutableMap.of("alternate-exchange", "amq.direct"))
.withPolicy("vhost2", "ha-all", ".*", ImmutableMap.of("ha-mode", "all", "ha-sync-mode", "automatic"))
.withOperatorPolicy("operator policy 1", "^queue1", ImmutableMap.of("message-ttl", 1000), 1, "queues")
.withPluginsEnabled("rabbitmq_shovel", "rabbitmq_random_exchange");

container.start();

Expand All @@ -192,6 +193,10 @@ public void shouldStartTheWholeEnchilada() throws IOException, InterruptedExcept
.getStdout())
.contains("max length policy", "alternate exchange policy");

assertThat(container.execInContainer("rabbitmqadmin", "list", "policies", "--vhost=vhost2")
.getStdout())
.contains("ha-all", "ha-sync-mode");

assertThat(container.execInContainer("rabbitmqadmin", "list", "operator_policies")
.getStdout())
.contains("operator policy 1");
Expand Down

0 comments on commit 08234f8

Please sign in to comment.