Polish "Add service connection support for Hazelcast"
See gh-42416
This commit is contained in:
@@ -66,7 +66,9 @@ class HazelcastDockerComposeConnectionDetailsFactory
|
||||
@Override
|
||||
public ClientConfig getClientConfig() {
|
||||
ClientConfig config = new ClientConfig();
|
||||
this.environment.getClusterName().ifPresent(config::setClusterName);
|
||||
if (this.environment.getClusterName() != null) {
|
||||
config.setClusterName(this.environment.getClusterName());
|
||||
}
|
||||
config.getNetworkConfig().addAddress(this.host + ":" + this.port);
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.docker.compose.service.connection.hazelcast;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Hazelcast environment details.
|
||||
@@ -32,8 +31,8 @@ class HazelcastEnvironment {
|
||||
this.clusterName = env.get("HZ_CLUSTERNAME");
|
||||
}
|
||||
|
||||
Optional<String> getClusterName() {
|
||||
return Optional.ofNullable(this.clusterName);
|
||||
String getClusterName() {
|
||||
return this.clusterName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ class HazelcastEnvironmentTests {
|
||||
@Test
|
||||
void getClusterNameWhenHasNoHzClusterNameSet() {
|
||||
HazelcastEnvironment environment = new HazelcastEnvironment(Collections.emptyMap());
|
||||
assertThat(environment.getClusterName()).isEmpty();
|
||||
assertThat(environment.getClusterName()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClusterNameWhenHzClusterNameSet() {
|
||||
HazelcastEnvironment environment = new HazelcastEnvironment(Map.of("HZ_CLUSTERNAME", "spring-boot"));
|
||||
assertThat(environment.getClusterName()).isNotEmpty().hasValue("spring-boot");
|
||||
assertThat(environment.getClusterName()).isEqualTo("spring-boot");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user