diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast3HazelcastHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast4HazelcastHealthIndicatorTests.java similarity index 92% rename from spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast3HazelcastHealthIndicatorTests.java rename to spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast4HazelcastHealthIndicatorTests.java index 7fb13886ee5..8ad3aa1da23 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast3HazelcastHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast4HazelcastHealthIndicatorTests.java @@ -40,18 +40,18 @@ import static org.mockito.Mockito.mock; * @author Stephane Nicoll */ @ClassPathExclusions("hazelcast*.jar") -@ClassPathOverrides("com.hazelcast:hazelcast:3.12.12") -class Hazelcast3HazelcastHealthIndicatorTests { +@ClassPathOverrides("com.hazelcast:hazelcast:4.2.5") +class Hazelcast4HazelcastHealthIndicatorTests { @Test void hazelcastUp() { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)) - .withPropertyValues("spring.hazelcast.config=hazelcast-3.xml").run((context) -> { + .withPropertyValues("spring.hazelcast.config=hazelcast-4.xml").run((context) -> { HazelcastInstance hazelcast = context.getBean(HazelcastInstance.class); Health health = new HazelcastHealthIndicator(hazelcast).health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", - "actuator-hazelcast-3"); + "actuator-hazelcast-4"); assertThat(health.getDetails().get("uuid")).asString().isNotEmpty(); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml b/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml similarity index 77% rename from spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml rename to spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml index 1d6e65e8892..50017168737 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml +++ b/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml @@ -1,12 +1,12 @@ - actuator-hazelcast-3 + http://www.hazelcast.com/schema/config/hazelcast-config-4.2.xsd"> + actuator-hazelcast-4 - + diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast4AutoConfigurationTests.java similarity index 65% rename from spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java rename to spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast4AutoConfigurationTests.java index c89b9bf6386..e1b15687c2a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast4AutoConfigurationTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.hazelcast; import com.hazelcast.client.impl.clientside.HazelcastClientProxy; import com.hazelcast.config.Config; +import com.hazelcast.config.JoinConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.spring.context.SpringManagedContext; @@ -30,42 +31,43 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; import org.springframework.boot.testsupport.classpath.ClassPathOverrides; -import org.springframework.core.io.ClassPathResource; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link HazelcastAutoConfiguration} with Hazelcast 3. + * Tests for {@link HazelcastAutoConfiguration} with Hazelcast 4. * * @author Stephane Nicoll */ @ClassPathExclusions("hazelcast*.jar") -@ClassPathOverrides({ "com.hazelcast:hazelcast:3.12.12", "com.hazelcast:hazelcast-client:3.12.12", - "com.hazelcast:hazelcast-spring:3.12.12" }) -class Hazelcast3AutoConfigurationTests { +@ClassPathOverrides({ "com.hazelcast:hazelcast:4.2.5", "com.hazelcast:hazelcast-spring:4.2.5" }) +class Hazelcast4AutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)); @Test - void defaultConfigFile() { - // no hazelcast-client.xml and hazelcast.xml is present in root classpath - // this also asserts that XML has priority over YAML - // as both hazelcast.yaml and hazelcast.xml in test classpath. - this.contextRunner.run((context) -> { - Config config = context.getBean(HazelcastInstance.class).getConfig(); - assertThat(config.getConfigurationUrl()).isEqualTo(new ClassPathResource("hazelcast.xml").getURL()); - }); + void serverConfig() { + this.contextRunner.withPropertyValues( + "spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml") + .run((context) -> { + Config config = context.getBean(HazelcastInstance.class).getConfig(); + assertThat(config.getInstanceName()).isEqualTo("explicit-server"); + }); } @Test void explicitConfigFileWithXml() { - HazelcastInstance hazelcastServer = Hazelcast.newHazelcastInstance(); + Config config = new Config(); + JoinConfig join = config.getNetworkConfig().getJoin(); + join.getAutoDetectionConfig().setEnabled(false); + join.getMulticastConfig().setEnabled(false); + HazelcastInstance hazelcastServer = Hazelcast.newHazelcastInstance(config); try { this.contextRunner - .withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/" - + "hazelcast/hazelcast-client-specific.xml") - .run(assertSpecificHazelcastClient("explicit-xml")); + .withPropertyValues("spring.hazelcast.config=" + + "org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-client.xml") + .run(assertSpecificHazelcastClient("explicit-client")); } finally { hazelcastServer.shutdown(); @@ -74,10 +76,12 @@ class Hazelcast3AutoConfigurationTests { @Test void autoConfiguredConfigUsesSpringManagedContext() { - this.contextRunner.run((context) -> { - Config config = context.getBean(HazelcastInstance.class).getConfig(); - assertThat(config.getManagedContext()).isInstanceOf(SpringManagedContext.class); - }); + this.contextRunner.withPropertyValues( + "spring.hazelcast.config=" + "org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml") + .run((context) -> { + Config config = context.getBean(HazelcastInstance.class).getConfig(); + assertThat(config.getManagedContext()).isInstanceOf(SpringManagedContext.class); + }); } private ContextConsumer assertSpecificHazelcastClient(String label) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast3Tests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast4Tests.java similarity index 82% rename from spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast3Tests.java rename to spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast4Tests.java index 07e27f6088d..eb1261f1399 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast3Tests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast4Tests.java @@ -29,24 +29,25 @@ import org.springframework.session.FlushMode; import org.springframework.session.SaveMode; import org.springframework.session.data.mongo.MongoIndexedSessionRepository; import org.springframework.session.data.redis.RedisIndexedSessionRepository; -import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; +import org.springframework.session.hazelcast.Hazelcast4IndexedSessionRepository; import org.springframework.session.jdbc.JdbcIndexedSessionRepository; import static org.assertj.core.api.Assertions.assertThat; /** - * Hazelcast 3 specific tests for {@link SessionAutoConfiguration}. + * Hazelcast 4 specific tests for {@link SessionAutoConfiguration}. * * @author Vedran Pavic + * @author Stephane Nicoll */ @ClassPathExclusions("hazelcast*.jar") -@ClassPathOverrides("com.hazelcast:hazelcast:3.12.12") -class SessionAutoConfigurationHazelcast3Tests extends AbstractSessionAutoConfigurationTests { +@ClassPathOverrides("com.hazelcast:hazelcast:4.2.5") +class SessionAutoConfigurationHazelcast4Tests extends AbstractSessionAutoConfigurationTests { private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class, SessionAutoConfiguration.class)) .withPropertyValues( - "spring.hazelcast.config=org/springframework/boot/autoconfigure/session/hazelcast-3.xml"); + "spring.hazelcast.config=org/springframework/boot/autoconfigure/session/hazelcast-4.xml"); @Test void defaultConfig() { @@ -62,7 +63,7 @@ class SessionAutoConfigurationHazelcast3Tests extends AbstractSessionAutoConfigu } private void validateDefaultConfig(AssertableWebApplicationContext context) { - validateSessionRepository(context, HazelcastIndexedSessionRepository.class); + validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class); } @Test @@ -70,15 +71,15 @@ class SessionAutoConfigurationHazelcast3Tests extends AbstractSessionAutoConfigu this.contextRunner .withPropertyValues("spring.session.store-type=hazelcast", "spring.session.hazelcast.map-name=foo:bar:biz") - .run((context) -> validateSessionRepository(context, HazelcastIndexedSessionRepository.class)); + .run((context) -> validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class)); } @Test void customFlushMode() { this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast", "spring.session.hazelcast.flush-mode=immediate").run((context) -> { - HazelcastIndexedSessionRepository repository = validateSessionRepository(context, - HazelcastIndexedSessionRepository.class); + Hazelcast4IndexedSessionRepository repository = validateSessionRepository(context, + Hazelcast4IndexedSessionRepository.class); assertThat(repository).hasFieldOrPropertyWithValue("flushMode", FlushMode.IMMEDIATE); }); } @@ -87,8 +88,8 @@ class SessionAutoConfigurationHazelcast3Tests extends AbstractSessionAutoConfigu void customSaveMode() { this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast", "spring.session.hazelcast.save-mode=on-get-attribute").run((context) -> { - HazelcastIndexedSessionRepository repository = validateSessionRepository(context, - HazelcastIndexedSessionRepository.class); + Hazelcast4IndexedSessionRepository repository = validateSessionRepository(context, + Hazelcast4IndexedSessionRepository.class); assertThat(repository).hasFieldOrPropertyWithValue("saveMode", SaveMode.ON_GET_ATTRIBUTE); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-client.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-client.xml new file mode 100644 index 00000000000..b409bb547ea --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-client.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml new file mode 100644 index 00000000000..360fc1b50f7 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml @@ -0,0 +1,12 @@ + + explicit-server + + + + + + + + diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-3.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-4.xml similarity index 85% rename from spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-3.xml rename to spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-4.xml index f8af5591502..34898c7e840 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-3.xml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-4.xml @@ -1,4 +1,4 @@ - @@ -11,7 +11,7 @@ - +