Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RabbitMQ: add vhost parameter for policies #1701

Merged
merged 1 commit into from Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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