private static HazelcastMember createHzMember(Props props) {
HazelcastMemberBuilder builder = new HazelcastMemberBuilder()
- .setClusterName("sonarqube")
.setNetworkInterface(props.nonNullValue(ProcessProperties.CLUSTER_NODE_HOST))
.setMembers(asList(props.nonNullValue(ProcessProperties.CLUSTER_HOSTS).split(",")))
.setNodeType(NodeType.parse(props.nonNullValue(ProcessProperties.CLUSTER_NODE_TYPE)))
return new HazelcastMemberBuilder()
.setNodeType(NodeType.APPLICATION)
.setProcessId(ProcessId.COMPUTE_ENGINE)
- .setClusterName("foo")
.setNodeName("bar")
.setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
.setNetworkInterface(loopback.getHostAddress())
public class HazelcastMemberBuilder {
- private String clusterName;
private String nodeName;
private int port;
private NodeType nodeType;
private String networkInterface;
private List<String> members = new ArrayList<>();
- public HazelcastMemberBuilder setClusterName(String s) {
- this.clusterName = s;
- return this;
- }
-
public HazelcastMemberBuilder setNodeName(String s) {
this.nodeName = s;
return this;
public HazelcastMember build() {
Config config = new Config();
- config.getGroupConfig().setName(requireNonNull(clusterName, "Cluster name is missing"));
+ // do not use the value defined by property sonar.cluster.name.
+ // Hazelcast does not fail when joining a cluster with different name.
+ // Apparently this behavior exists since Hazelcast 3.8.2 (see note
+ // at http://docs.hazelcast.org/docs/3.8.6/manual/html-single/index.html#creating-cluster-groups)
+ config.getGroupConfig().setName("SonarQube");
// Configure network
NetworkConfig netConfig = config.getNetworkConfig();
HazelcastMember member = underTest
.setNodeType(NodeType.APPLICATION)
.setProcessId(ProcessId.COMPUTE_ENGINE)
- .setClusterName("foo")
.setNodeName("bar")
.setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
.setNetworkInterface(loopback.getHostAddress())
return new HazelcastMemberBuilder()
.setNodeType(NodeType.APPLICATION)
.setProcessId(ProcessId.COMPUTE_ENGINE)
- .setClusterName("foo")
.setNodeName("name" + port)
.setPort(port)
.setNetworkInterface(loopback.getHostAddress())
throw new IllegalStateException(format("Can not resolve address %s", networkAddress), e);
}
this.member = new HazelcastMemberBuilder()
- .setClusterName(config.get(ProcessProperties.CLUSTER_NAME).orElseThrow(() -> new IllegalStateException("Missing cluster name")))
.setNodeName(config.get(ProcessProperties.CLUSTER_NODE_NAME).orElseThrow(() -> new IllegalStateException("Missing node name")))
.setNodeType(NodeType.parse(config.get(CLUSTER_NODE_TYPE).orElseThrow(() -> new IllegalStateException("Missing node type"))))
.setPort(freePort)
}
}
+ @Test
+ public void cluster_name_can_be_overridden() throws Exception {
+ try (Cluster cluster = new Cluster("foo")) {
+ NodeConfig searchConfig1 = newSearchConfig("Search 1");
+ NodeConfig searchConfig2 = newSearchConfig("Search 2");
+ NodeConfig appConfig = newApplicationConfig("App 1");
+ NodeConfig.interconnectBus(searchConfig1, searchConfig2, appConfig);
+ NodeConfig.interconnectSearch(searchConfig1, searchConfig2, appConfig);
+
+ cluster.startNode(searchConfig1, nothing());
+ cluster.startNode(searchConfig2, nothing());
+ cluster.startNode(appConfig, nothing());
+
+ Node appNode = cluster.getAppNode(0);
+ appNode.waitForStatusUp();
+ }
+ }
+
@Test
public void node_fails_to_join_cluster_if_different_cluster_name() throws Exception {
try (Cluster cluster = new Cluster("foo")) {