Polish "Add service connection support for Hazelcast"

See gh-42416
This commit is contained in:
Moritz Halbritter
2024-09-26 14:30:42 +02:00
parent cee7439dbe
commit 33def6d6b4
9 changed files with 85 additions and 42 deletions

View File

@@ -19,7 +19,6 @@ dependencies {
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
dockerTestImplementation("org.testcontainers:testcontainers")
dockerTestRuntimeOnly("com.microsoft.sqlserver:mssql-jdbc")
dockerTestRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
dockerTestRuntimeOnly("io.r2dbc:r2dbc-mssql")
@@ -31,11 +30,11 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
optional(project(":spring-boot-project:spring-boot-actuator-autoconfigure"))
optional("com.hazelcast:hazelcast")
optional("io.r2dbc:r2dbc-spi")
optional("org.mongodb:mongodb-driver-core")
optional("org.neo4j.driver:neo4j-java-driver")
optional("org.springframework.data:spring-data-r2dbc")
optional("com.hazelcast:hazelcast")
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation(project(":spring-boot-project:spring-boot-test"))

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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");
}
}