From 9cb614c626857ffcbfb6da3be1ff9c376e8ffb1a Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 27 Jul 2022 09:09:03 +0200 Subject: [PATCH] Migrate Hazelcast 3 sanity tests to Hazelcast 4 Closes gh-31881 --- ...elcast4HazelcastHealthIndicatorTests.java} | 8 ++-- .../{hazelcast-3.xml => hazelcast-4.xml} | 6 +-- ... => Hazelcast4AutoConfigurationTests.java} | 46 ++++++++++--------- ...sionAutoConfigurationHazelcast4Tests.java} | 23 +++++----- .../hazelcast/hazelcast-4-client.xml | 9 ++++ .../hazelcast/hazelcast-4-server.xml | 12 +++++ .../{hazelcast-3.xml => hazelcast-4.xml} | 4 +- 7 files changed, 67 insertions(+), 41 deletions(-) rename spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/{Hazelcast3HazelcastHealthIndicatorTests.java => Hazelcast4HazelcastHealthIndicatorTests.java} (92%) rename spring-boot-project/spring-boot-actuator/src/test/resources/{hazelcast-3.xml => hazelcast-4.xml} (77%) rename spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/{Hazelcast3AutoConfigurationTests.java => Hazelcast4AutoConfigurationTests.java} (65%) rename spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/{SessionAutoConfigurationHazelcast3Tests.java => SessionAutoConfigurationHazelcast4Tests.java} (82%) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-client.xml create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/{hazelcast-3.xml => hazelcast-4.xml} (85%) 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 7fb13886ee..8ad3aa1da2 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 1d6e65e889..5001716873 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 c89b9bf638..e1b15687c2 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 07e27f6088..eb1261f139 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 0000000000..b409bb547e --- /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 0000000000..360fc1b50f --- /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 f8af559150..34898c7e84 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 @@ - +