From 2c35d9b2f0597289e526c615c720431314b25f43 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Tue, 22 Aug 2017 11:10:25 +0200 Subject: SONAR-9738 Fail if the cluster name differs from node to node --- .../java/org/sonarqube/tests/cluster/Cluster.java | 8 ++++++-- .../tests/cluster/DataCenterEditionTest.java | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'tests') 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... 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); } -- cgit v1.2.3