diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-08-22 11:10:25 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-05 14:24:13 +0200 |
commit | 2c35d9b2f0597289e526c615c720431314b25f43 (patch) | |
tree | 18c47db5a61a842746fdadae4c5b96598419fd41 /tests | |
parent | 3ad9508d1ffa61cd9361f3af24aaeb1da5b0f38a (diff) | |
download | sonarqube-2c35d9b2f0597289e526c615c720431314b25f43.tar.gz sonarqube-2c35d9b2f0597289e526c615c720431314b25f43.zip |
SONAR-9738 Fail if the cluster name differs from node to node
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java | 8 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java | 20 |
2 files changed, 26 insertions, 2 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java b/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java index cf81dd3342c..6c8416cbc8d 100644 --- a/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java +++ b/tests/src/test/java/org/sonarqube/tests/cluster/Cluster.java @@ -29,6 +29,7 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.Enumeration; @@ -36,6 +37,7 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; import javax.annotation.CheckForNull; @@ -218,8 +220,10 @@ public class Cluster { return new Cluster(nodes); } - public Builder addNode(NodeType type) { - nodes.add(new Node(type)); + public Builder addNode(NodeType type, Consumer<Node>... consumers) { + Node node = new Node(type); + Arrays.stream(consumers).forEach(c -> c.accept(node)); + nodes.add(node); return this; } } diff --git a/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java b/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java index 2a52d6f7818..52f7930e434 100644 --- a/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java +++ b/tests/src/test/java/org/sonarqube/tests/cluster/DataCenterEditionTest.java @@ -91,6 +91,26 @@ public class DataCenterEditionTest { dce.stop(); } + @Test + public void using_different_cluster_names_should_fail() throws ExecutionException, InterruptedException, SQLException { + Cluster cluster = Cluster.builder() + .addNode(SEARCH, n -> n.getProperties().setProperty(Cluster.CLUSTER_NAME, "goodClusterName")) + .addNode(SEARCH, n -> n.getProperties().setProperty(Cluster.CLUSTER_NAME, "goodClusterName")) + .addNode(SEARCH, n -> n.getProperties().setProperty(Cluster.CLUSTER_NAME, "goodClusterName")) + .addNode(APPLICATION, n -> n.getProperties().setProperty(Cluster.CLUSTER_NAME, "goodClusterName")) + .addNode(APPLICATION, n -> n.getProperties().setProperty(Cluster.CLUSTER_NAME, "badClusterName")) + .build(); + cluster.startAll(n -> "goodClusterName".equals(n.getProperties().getProperty(Cluster.CLUSTER_NAME))); + + try { + cluster.startAll(n -> "badClusterName".equals(n.getProperties().getProperty(Cluster.CLUSTER_NAME))); + fail("A node with a bad cluster name was able to join the cluster"); + } catch (Exception e) { + // we expect, that joining the cluster fails + System.out.println(e); + } + } + private void assertDatabaseInitialized(Database database) { assertThat(countRowsOfMigration(database)).isGreaterThan(0); } |