aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce/src
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-08-22 11:10:25 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-05 14:24:13 +0200
commit2c35d9b2f0597289e526c615c720431314b25f43 (patch)
tree18c47db5a61a842746fdadae4c5b96598419fd41 /server/sonar-ce/src
parent3ad9508d1ffa61cd9361f3af24aaeb1da5b0f38a (diff)
downloadsonarqube-2c35d9b2f0597289e526c615c720431314b25f43.tar.gz
sonarqube-2c35d9b2f0597289e526c615c720431314b25f43.zip
SONAR-9738 Fail if the cluster name differs from node to node
Diffstat (limited to 'server/sonar-ce/src')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java5
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java52
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java8
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java4
4 files changed, 25 insertions, 44 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
index b913387c84a..a4b40580540 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
@@ -41,6 +41,7 @@ import static org.sonar.process.cluster.ClusterObjectKeys.CLIENT_UUIDS;
*/
public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWrapper {
+ private static final String HAZELCAST_CLUSTER_NAME = "sonarqube";
private final ClientConfig hzConfig;
@VisibleForTesting
@@ -48,15 +49,13 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
public HazelcastClientWrapperImpl(Configuration config) {
boolean clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
- String clusterName = config.get(ProcessProperties.CLUSTER_NAME).orElse(null);
String clusterLocalEndPoint = config.get(ProcessProperties.CLUSTER_LOCALENDPOINT).orElse(null);
checkState(clusterEnabled, "Cluster is not enabled");
checkState(isNotEmpty(clusterLocalEndPoint), "LocalEndPoint have not been set");
- checkState(isNotEmpty(clusterName), "sonar.cluster.name is missing");
hzConfig = new ClientConfig();
- hzConfig.getGroupConfig().setName(clusterName);
+ hzConfig.getGroupConfig().setName(HAZELCAST_CLUSTER_NAME);
hzConfig.getNetworkConfig().addAddress(clusterLocalEndPoint);
// Tweak HazelCast configuration
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
index 3c483a80f3e..58be787c69f 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
@@ -70,9 +70,9 @@ public class HazelcastClientWrapperImplTest {
@BeforeClass
public static void setupHazelcastClusterAndHazelcastClient() {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
- hzCluster = HazelcastTestHelper.createHazelcastCluster("cluster_with_client", port);
+ hzCluster = HazelcastTestHelper.createHazelcastCluster(port);
- MapSettings settings = createClusterSettings("cluster_with_client", "localhost:" + port);
+ MapSettings settings = createClusterSettings("localhost:" + port);
hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
}
@@ -92,7 +92,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void start_throws_ISE_if_LOCALENDPOINT_is_incorrect() {
- MapSettings settings = createClusterSettings("sonarqube", "\u4563\u1432\u1564");
+ MapSettings settings = createClusterSettings("\u4563\u1432\u1564");
HazelcastClientWrapperImpl hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
expectedException.expect(IllegalStateException.class);
@@ -103,7 +103,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_LOCALENDPOINT_is_empty() {
- MapSettings settings = createClusterSettings("sonarqube", "");
+ MapSettings settings = createClusterSettings("");
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("LocalEndPoint have not been set");
@@ -113,7 +113,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_CLUSTER_ENABLED_is_false() {
- MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("localhost:9003");
settings.setProperty(ProcessProperties.CLUSTER_ENABLED, false);
expectedException.expect(IllegalStateException.class);
@@ -124,7 +124,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_missing_CLUSTER_ENABLED() {
- MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("localhost:9003");
settings.removeProperty(ProcessProperties.CLUSTER_ENABLED);
expectedException.expect(IllegalStateException.class);
@@ -134,19 +134,8 @@ public class HazelcastClientWrapperImplTest {
}
@Test
- public void constructor_throws_ISE_if_missing_CLUSTER_NAME() {
- MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
- settings.removeProperty(ProcessProperties.CLUSTER_NAME);
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("sonar.cluster.name is missing");
-
- new HazelcastClientWrapperImpl(settings.asConfig());
- }
-
- @Test
public void constructor_throws_ISE_if_missing_CLUSTER_LOCALENDPOINT() {
- MapSettings settings = createClusterSettings("sonarqube", "localhost:9003");
+ MapSettings settings = createClusterSettings("localhost:9003");
settings.removeProperty(ProcessProperties.CLUSTER_LOCALENDPOINT);
expectedException.expect(IllegalStateException.class);
@@ -159,8 +148,8 @@ public class HazelcastClientWrapperImplTest {
public void client_must_connect_to_hazelcast() throws InterruptedException {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
// Launch a fake Hazelcast instance
- HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster("client_must_connect_to_hazelcast", port);
- MapSettings settings = createClusterSettings("client_must_connect_to_hazelcast", "localhost:" + port);
+ HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(port);
+ MapSettings settings = createClusterSettings("localhost:" + port);
HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings.asConfig());
ClientListenerImpl clientListener = new ClientListenerImpl();
@@ -177,8 +166,8 @@ public class HazelcastClientWrapperImplTest {
@Test
public void client_must_be_able_to_set_ReplicatedMap_objects() throws InterruptedException {
+ hzClient.start();
try {
- hzClient.start();
Set<String> setTest = new HashSet<>();
setTest.addAll(
@@ -196,8 +185,8 @@ public class HazelcastClientWrapperImplTest {
@Test
public void client_must_be_able_to_retrieve_Set_objects() {
+ hzClient.start();
try {
- hzClient.start();
// Set
Set<String> setTest = new HashSet<>();
@@ -211,8 +200,8 @@ public class HazelcastClientWrapperImplTest {
@Test
public void client_must_be_able_to_retrieve_List_objects() {
+ hzClient.start();
try {
- hzClient.start();
// List
List<String> listTest = Arrays.asList("1", "2");
@@ -225,9 +214,8 @@ public class HazelcastClientWrapperImplTest {
@Test
public void client_must_be_able_to_retrieve_Map_objects() {
+ hzClient.start();
try {
- hzClient.start();
-
Map mapTest = new HashMap<>();
mapTest.put("a", Arrays.asList("123", "456"));
hzCluster.getMap("TEST3").putAll(mapTest);
@@ -240,8 +228,8 @@ public class HazelcastClientWrapperImplTest {
@Test
public void configuration_tweaks_of_hazelcast_must_be_present() {
+ hzClient.start();
try {
- hzClient.start();
HazelcastClientInstanceImpl realClient = ((HazelcastClientProxy) hzClient.hzInstance).client;
assertThat(realClient.getClientConfig().getProperty("hazelcast.tcp.join.port.try.count")).isEqualTo("10");
assertThat(realClient.getClientConfig().getProperty("hazelcast.phone.home.enabled")).isEqualTo("false");
@@ -260,12 +248,9 @@ public class HazelcastClientWrapperImplTest {
memoryAppender.start();
lc.getLogger("com.hazelcast").addAppender(memoryAppender);
- try {
- hzClient.start();
- } finally {
- hzClient.stop();
- memoryAppender.stop();
- }
+ hzClient.start();
+ hzClient.stop();
+ memoryAppender.stop();
assertThat(memoryAppender.events).isNotEmpty();
memoryAppender.events.stream().forEach(
e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast"));
@@ -285,9 +270,8 @@ public class HazelcastClientWrapperImplTest {
}
}
- private static MapSettings createClusterSettings(String name, String localEndPoint) {
+ private static MapSettings createClusterSettings(String localEndPoint) {
return new MapSettings(new PropertyDefinitions())
- .setProperty(ProcessProperties.CLUSTER_NAME, name)
.setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, localEndPoint)
.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java
index d195bd01f02..5774dbce735 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java
@@ -29,14 +29,14 @@ import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import java.net.InetAddress;
-import static org.sonar.process.NetworkUtils.getHostName;
+import static org.sonar.process.NetworkUtils.getHostname;
import static org.sonar.process.cluster.ClusterObjectKeys.CLIENT_UUIDS;
public class HazelcastTestHelper {
- public static HazelcastInstance createHazelcastCluster(String clusterName, int port) {
+ public static HazelcastInstance createHazelcastCluster(int port) {
Config hzConfig = new Config();
- hzConfig.getGroupConfig().setName(clusterName);
+ hzConfig.getGroupConfig().setName("sonarqube");
// Configure the network instance
NetworkConfig netConfig = hzConfig.getNetworkConfig();
@@ -66,7 +66,7 @@ public class HazelcastTestHelper {
.setProperty("hazelcast.logging.type", "slf4j");
// Trying to resolve the hostname
- hzConfig.getMemberAttributeConfig().setStringAttribute("HOSTNAME", getHostName());
+ hzConfig.getMemberAttributeConfig().setStringAttribute("HOSTNAME", getHostname());
// We are not using the partition group of Hazelcast, so disabling it
hzConfig.getPartitionGroupConfig().setEnabled(false);
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
index 3578e586c65..2a775ea8298 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
@@ -60,7 +60,6 @@ import static org.sonar.process.ProcessProperties.PATH_TEMP;
public class ComputeEngineContainerImplTest {
private static final int CONTAINER_ITSELF = 1;
private static final int COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION = CONTAINER_ITSELF + 1;
- private static final String CLUSTER_NAME = "test";
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@@ -83,13 +82,12 @@ public class ComputeEngineContainerImplTest {
@Test
public void real_start_with_cluster() throws IOException {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
- HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(CLUSTER_NAME, port);
+ HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(port);
Properties properties = getProperties();
properties.setProperty(ProcessProperties.CLUSTER_NODE_TYPE, "application");
properties.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
properties.setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, String.format("%s:%d", hzInstance.getCluster().getLocalMember().getAddress().getHost(), port));
- properties.setProperty(ProcessProperties.CLUSTER_NAME, CLUSTER_NAME);
// required persisted properties
insertProperty(CoreProperties.SERVER_ID, "a_startup_id");