From 4009acf025b3a6926c6eeedd38618d2fd67210cc Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 9 Sep 2020 17:48:49 +0200 Subject: [PATCH] Add support for Hazelcast This commit upgrades to Hazelcast 4.0.3, yet keeping compatibility with Hazelcast 3.x. Closes gh-20856 Closes gh-23475 --- ...utorAutoConfigurationIntegrationTests.java | 2 +- .../src/test/resources/hazelcast.xml | 2 +- .../hazelcast/HazelcastHealthIndicator.java | 7 +- ...elcast3HazelcastHealthIndicatorTests.java} | 10 +- ...azelcastCacheMeterBinderProviderTests.java | 4 +- .../{hazelcast-4.xml => hazelcast-3.xml} | 4 +- .../src/test/resources/hazelcast.xml | 8 +- .../spring-boot-autoconfigure/build.gradle | 1 - ...zelcastClientConfigAvailableCondition.java | 79 +++++++++++++++ .../HazelcastClientConfiguration.java | 17 +--- .../HazelcastConfigResourceCondition.java | 6 +- .../cache/CacheAutoConfigurationTests.java | 16 ++-- .../Hazelcast3AutoConfigurationTests.java | 83 ++++++++++++++++ ...stClientConfigAvailableConditionTests.java | 72 ++++++++++++++ ...ssionAutoConfigurationHazelcast3Tests.java | 96 +++++++++++++++++++ ...essionAutoConfigurationHazelcastTests.java | 16 ++-- ...sionAutoConfigurationIntegrationTests.java | 2 +- .../src/test/resources/hazelcast.xml | 2 +- .../hazelcast/hazelcast-client-instance.xml | 2 +- .../hazelcast/hazelcast-client-specific.xml | 2 +- .../hazelcast/hazelcast-specific.xml | 2 +- .../autoconfigure/session/hazelcast-3.xml | 19 ++++ .../spring-boot-dependencies/build.gradle | 3 +- .../docs/asciidoc/spring-boot-features.adoc | 20 ++-- .../build.gradle | 6 +- .../java/smoketest/hazelcast3}/Country.java | 2 +- .../hazelcast3}/CountryRepository.java | 2 +- .../SampleHazelcast3Application.java} | 6 +- .../src/main/resources/application.properties | 0 .../src/main/resources/hazelcast.xml | 2 +- .../SampleHazelcast4ApplicationTests.java | 2 +- .../src/main/resources/hazelcast.xml | 2 +- 32 files changed, 418 insertions(+), 79 deletions(-) rename spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/{Hazelcast4HazelcastHealthIndicatorTests.java => Hazelcast3HazelcastHealthIndicatorTests.java} (90%) rename spring-boot-project/spring-boot-actuator/src/test/resources/{hazelcast-4.xml => hazelcast-3.xml} (85%) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableCondition.java create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableConditionTests.java create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast3Tests.java create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-3.xml rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4 => spring-boot-smoke-test-hazelcast3}/build.gradle (83%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4 => spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3}/Country.java (97%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4 => spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3}/CountryRepository.java (97%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/SampleHazelcast4Application.java => spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/SampleHazelcast3Application.java} (91%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4 => spring-boot-smoke-test-hazelcast3}/src/main/resources/application.properties (100%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4 => spring-boot-smoke-test-hazelcast3}/src/main/resources/hazelcast.xml (97%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-hazelcast4/src/test/java/smoketest/hazelcast4 => spring-boot-smoke-test-hazelcast3/src/test/java/smoketest/hazelcast3}/SampleHazelcast4ApplicationTests.java (98%) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/hazelcast/HazelcastHealthContributorAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/hazelcast/HazelcastHealthContributorAutoConfigurationIntegrationTests.java index 0d6b540181..51b6f0128b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/hazelcast/HazelcastHealthContributorAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/hazelcast/HazelcastHealthContributorAutoConfigurationIntegrationTests.java @@ -48,7 +48,7 @@ class HazelcastHealthContributorAutoConfigurationIntegrationTests { Health health = context.getBean(HazelcastHealthIndicator.class).health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", hazelcast.getName()) - .containsEntry("uuid", hazelcast.getLocalEndpoint().getUuid()); + .containsEntry("uuid", hazelcast.getLocalEndpoint().getUuid().toString()); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/hazelcast.xml b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/hazelcast.xml index 1a61470e60..cfb3b2e15b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/hazelcast.xml +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/resources/hazelcast.xml @@ -1,5 +1,5 @@ diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicator.java index b421ee4e7a..33abb53377 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicator.java @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.hazelcast; import java.lang.reflect.Method; -import java.util.UUID; import com.hazelcast.core.HazelcastInstance; @@ -54,14 +53,14 @@ public class HazelcastHealthIndicator extends AbstractHealthIndicator { private String extractUuid() { try { - return this.hazelcast.getLocalEndpoint().getUuid(); + return this.hazelcast.getLocalEndpoint().getUuid().toString(); } catch (NoSuchMethodError ex) { - // Hazelcast 4 + // Hazelcast 3 Method endpointAccessor = ReflectionUtils.findMethod(HazelcastInstance.class, "getLocalEndpoint"); Object endpoint = ReflectionUtils.invokeMethod(endpointAccessor, this.hazelcast); Method uuidAccessor = ReflectionUtils.findMethod(endpoint.getClass(), "getUuid"); - return ((UUID) ReflectionUtils.invokeMethod(uuidAccessor, endpoint)).toString(); + return (String) ReflectionUtils.invokeMethod(uuidAccessor, endpoint); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast4HazelcastHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast3HazelcastHealthIndicatorTests.java similarity index 90% rename from spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast4HazelcastHealthIndicatorTests.java rename to spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast3HazelcastHealthIndicatorTests.java index f6d3076c0f..5312e65f1d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast4HazelcastHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/Hazelcast3HazelcastHealthIndicatorTests.java @@ -35,24 +35,24 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; /** - * Tests for {@link HazelcastHealthIndicator} with Hazelcast 4. + * Tests for {@link HazelcastHealthIndicator} with Hazelcast 3. * * @author Dmytro Nosan * @author Stephane Nicoll */ @ClassPathExclusions("hazelcast*.jar") -@ClassPathOverrides("com.hazelcast:hazelcast:4.0") -class Hazelcast4HazelcastHealthIndicatorTests { +@ClassPathOverrides("com.hazelcast:hazelcast:3.12.8") +class Hazelcast3HazelcastHealthIndicatorTests { @Test void hazelcastUp() throws IOException { - HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast-4.xml")) + HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast-3.xml")) .getHazelcastInstance(); try { Health health = new HazelcastHealthIndicator(hazelcast).health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", - "actuator-hazelcast-4"); + "actuator-hazelcast-3"); assertThat(health.getDetails().get("uuid")).asString().isNotEmpty(); } finally { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProviderTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProviderTests.java index 6bd2b383cf..08b9a08f59 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProviderTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.boot.actuate.metrics.cache; import java.util.Collections; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import com.hazelcast.spring.cache.HazelcastCache; import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics; diff --git a/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml b/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml similarity index 85% rename from spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml rename to spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml index 40ed902d1b..1d6e65e889 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml +++ b/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml @@ -1,8 +1,8 @@ - actuator-hazelcast-4 + http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd"> + actuator-hazelcast-3 diff --git a/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast.xml b/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast.xml index 3e528bf80e..56298f8e79 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast.xml +++ b/spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast.xml @@ -1,7 +1,7 @@ - + actuator-hazelcast diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index 8dc8e1da75..e54a918749 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -21,7 +21,6 @@ dependencies { optional("com.fasterxml.jackson.module:jackson-module-parameter-names") optional("com.google.code.gson:gson") optional("com.hazelcast:hazelcast") - optional("com.hazelcast:hazelcast-client") optional("com.hazelcast:hazelcast-spring") optional("com.h2database:h2") optional("com.nimbusds:oauth2-oidc-sdk") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableCondition.java new file mode 100644 index 0000000000..9fa54d72c6 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableCondition.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.hazelcast; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import com.hazelcast.client.config.ClientConfigRecognizer; +import com.hazelcast.config.ConfigStream; + +import org.springframework.boot.autoconfigure.condition.ConditionMessage.Builder; +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.io.Resource; +import org.springframework.core.type.AnnotatedTypeMetadata; + +/** + * {@link HazelcastConfigResourceCondition} that checks if the + * {@code spring.hazelcast.config} configuration key is defined. + */ +class HazelcastClientConfigAvailableCondition extends HazelcastConfigResourceCondition { + + HazelcastClientConfigAvailableCondition() { + super(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml", + "classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml"); + } + + @Override + public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { + if (context.getEnvironment().containsProperty(HAZELCAST_CONFIG_PROPERTY)) { + ConditionOutcome configValidationOutcome = Hazelcast4ClientValidation.clientConfigOutcome(context, + HAZELCAST_CONFIG_PROPERTY, startConditionMessage()); + return (configValidationOutcome != null) ? configValidationOutcome : ConditionOutcome + .match(startConditionMessage().foundExactly("property " + HAZELCAST_CONFIG_PROPERTY)); + } + return getResourceOutcome(context, metadata); + } + + static class Hazelcast4ClientValidation { + + static ConditionOutcome clientConfigOutcome(ConditionContext context, String propertyName, Builder builder) { + String resourcePath = context.getEnvironment().getProperty(propertyName); + Resource resource = context.getResourceLoader().getResource(resourcePath); + if (!resource.exists()) { + return ConditionOutcome.noMatch(builder.because("Hazelcast configuration does not exist")); + } + try (InputStream in = resource.getInputStream()) { + boolean clientConfig = new ClientConfigRecognizer().isRecognized(new ConfigStream(in)); + return new ConditionOutcome(clientConfig, existingConfigurationOutcome(resource, clientConfig)); + } + catch (Throwable ex) { // Hazelcast 4 specific API + return null; + } + } + + private static String existingConfigurationOutcome(Resource resource, boolean client) throws IOException { + URL location = resource.getURL(); + return client ? "Hazelcast client configuration detected at '" + location + "'" + : "Hazelcast server configuration detected at '" + location + "'"; + } + + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfiguration.java index d3ed1a3df4..2e02677636 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ class HazelcastClientConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnMissingBean(ClientConfig.class) - @Conditional(ConfigAvailableCondition.class) + @Conditional(HazelcastClientConfigAvailableCondition.class) static class HazelcastClientConfigFileConfiguration { @Bean @@ -70,17 +70,4 @@ class HazelcastClientConfiguration { } - /** - * {@link HazelcastConfigResourceCondition} that checks if the - * {@code spring.hazelcast.config} configuration key is defined. - */ - static class ConfigAvailableCondition extends HazelcastConfigResourceCondition { - - ConfigAvailableCondition() { - super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml", "classpath:/hazelcast-client.xml", - "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml"); - } - - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java index f49a89d7c0..359810d591 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,10 +35,12 @@ import org.springframework.util.Assert; */ public abstract class HazelcastConfigResourceCondition extends ResourceCondition { + protected static final String HAZELCAST_CONFIG_PROPERTY = "spring.hazelcast.config"; + private final String configSystemProperty; protected HazelcastConfigResourceCondition(String configSystemProperty, String... resourceLocations) { - super("Hazelcast", "spring.hazelcast.config", resourceLocations); + super("Hazelcast", HAZELCAST_CONFIG_PROPERTY, resourceLocations); Assert.notNull(configSystemProperty, "ConfigSystemProperty must not be null"); this.configSystemProperty = configSystemProperty; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 482093f79a..1550285c86 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -28,7 +28,7 @@ import javax.cache.expiry.Duration; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.CaffeineSpec; -import com.hazelcast.cache.HazelcastCachingProvider; +import com.hazelcast.cache.impl.HazelcastServerCachingProvider; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.spring.cache.HazelcastCacheManager; @@ -481,7 +481,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { @Test void hazelcastAsJCacheWithCaches() { - String cachingProviderFqn = HazelcastCachingProvider.class.getName(); + String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); try { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) .withPropertyValues("spring.cache.type=jcache", @@ -500,7 +500,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { @Test void hazelcastAsJCacheWithConfig() { - String cachingProviderFqn = HazelcastCachingProvider.class.getName(); + String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); try { String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"; this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) @@ -521,7 +521,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { @Test void hazelcastAsJCacheWithExistingHazelcastInstance() { - String cachingProviderFqn = HazelcastCachingProvider.class.getName(); + String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); this.contextRunner.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)) .withUserConfiguration(DefaultCacheConfiguration.class) .withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn) @@ -605,19 +605,19 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { @Test void jCacheCacheWithCachesAndCustomizer() { - String cachingProviderClassName = HazelcastCachingProvider.class.getName(); + String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); try { this.contextRunner.withUserConfiguration(JCacheWithCustomizerConfiguration.class) .withPropertyValues("spring.cache.type=jcache", - "spring.cache.jcache.provider=" + cachingProviderClassName, - "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar") + "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=foo", + "spring.cache.cacheNames[1]=bar") .run((context) -> // see customizer assertThat(getCacheManager(context, JCacheCacheManager.class).getCacheNames()).containsOnly("foo", "custom1")); } finally { - Caching.getCachingProvider(cachingProviderClassName).close(); + Caching.getCachingProvider(cachingProviderFqn).close(); } } 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/Hazelcast3AutoConfigurationTests.java new file mode 100644 index 0000000000..1478cb35c7 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java @@ -0,0 +1,83 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.hazelcast; + +import com.hazelcast.client.impl.clientside.HazelcastClientProxy; +import com.hazelcast.config.Config; +import com.hazelcast.core.Hazelcast; +import com.hazelcast.core.HazelcastInstance; +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; +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. + * + * @author Stephane Nicoll + */ +@ClassPathExclusions("hazelcast*.jar") +@ClassPathOverrides({ "com.hazelcast:hazelcast:3.12.8", "com.hazelcast:hazelcast-client:3.12.8" }) +class Hazelcast3AutoConfigurationTests { + + 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()); + }); + } + + @Test + void explicitConfigFileWithXml() { + HazelcastInstance hazelcastServer = Hazelcast.newHazelcastInstance(); + try { + this.contextRunner + .withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/" + + "hazelcast/hazelcast-client-specific.xml") + .run(assertSpecificHazelcastClient("explicit-xml")); + } + finally { + hazelcastServer.shutdown(); + } + } + + private ContextConsumer assertSpecificHazelcastClient(String label) { + return (context) -> assertThat(context).getBean(HazelcastInstance.class).isInstanceOf(HazelcastInstance.class) + .has(labelEqualTo(label)); + } + + private static Condition labelEqualTo(String label) { + return new Condition<>((o) -> ((HazelcastClientProxy) o).getClientConfig().getLabels().stream() + .anyMatch((e) -> e.equals(label)), "Label equals to " + label); + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableConditionTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableConditionTests.java new file mode 100644 index 0000000000..f26e71ffb8 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableConditionTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.hazelcast; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.env.Environment; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.type.AnnotatedTypeMetadata; +import org.springframework.mock.env.MockEnvironment; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +/** + * Tests for {@link HazelcastClientConfigAvailableCondition}. + * + * @author Stephane Nicoll + */ +class HazelcastClientConfigAvailableConditionTests { + + private final HazelcastClientConfigAvailableCondition condition = new HazelcastClientConfigAvailableCondition(); + + @Test + void explicitConfigurationWithClientConfigMatches() { + ConditionOutcome outcome = getMatchOutcome(new MockEnvironment().withProperty("spring.hazelcast.config", + "classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml")); + assertThat(outcome.isMatch()).isTrue(); + assertThat(outcome.getMessage()).contains("Hazelcast client configuration detected"); + } + + @Test + void explicitConfigurationWithServerConfigDoesNotMatch() { + ConditionOutcome outcome = getMatchOutcome(new MockEnvironment().withProperty("spring.hazelcast.config", + "classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml")); + assertThat(outcome.isMatch()).isFalse(); + assertThat(outcome.getMessage()).contains("Hazelcast server configuration detected"); + } + + @Test + void explicitConfigurationWithMissingConfigDoesNotMatch() { + ConditionOutcome outcome = getMatchOutcome(new MockEnvironment().withProperty("spring.hazelcast.config", + "classpath:org/springframework/boot/autoconfigure/hazelcast/test-config-does-not-exist.xml")); + assertThat(outcome.isMatch()).isFalse(); + assertThat(outcome.getMessage()).contains("Hazelcast configuration does not exist"); + } + + private ConditionOutcome getMatchOutcome(Environment environment) { + ConditionContext conditionContext = mock(ConditionContext.class); + given(conditionContext.getEnvironment()).willReturn(environment); + given(conditionContext.getResourceLoader()).willReturn(new DefaultResourceLoader()); + return this.condition.getMatchOutcome(conditionContext, mock(AnnotatedTypeMetadata.class)); + } + +} 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/SessionAutoConfigurationHazelcast3Tests.java new file mode 100644 index 0000000000..0e9e1f1ae4 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcast3Tests.java @@ -0,0 +1,96 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.session; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration; +import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.ClassPathOverrides; +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.jdbc.JdbcIndexedSessionRepository; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Hazelcast 3 specific tests for {@link SessionAutoConfiguration}. + * + * @author Vedran Pavic + */ +@ClassPathExclusions("hazelcast*.jar") +@ClassPathOverrides("com.hazelcast:hazelcast:3.12.8") +class SessionAutoConfigurationHazelcast3Tests 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"); + + @Test + void defaultConfig() { + this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast").run(this::validateDefaultConfig); + } + + @Test + void defaultConfigWithUniqueStoreImplementation() { + this.contextRunner + .withClassLoader(new FilteredClassLoader(JdbcIndexedSessionRepository.class, + RedisIndexedSessionRepository.class, MongoIndexedSessionRepository.class)) + .run(this::validateDefaultConfig); + } + + private void validateDefaultConfig(AssertableWebApplicationContext context) { + validateSessionRepository(context, HazelcastIndexedSessionRepository.class); + } + + @Test + void customMapName() { + this.contextRunner + .withPropertyValues("spring.session.store-type=hazelcast", + "spring.session.hazelcast.map-name=foo:bar:biz") + .run((context) -> validateSessionRepository(context, HazelcastIndexedSessionRepository.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); + assertThat(repository).hasFieldOrPropertyWithValue("flushMode", FlushMode.IMMEDIATE); + }); + } + + @Test + 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); + assertThat(repository).hasFieldOrPropertyWithValue("saveMode", SaveMode.ON_GET_ATTRIBUTE); + }); + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java index 83bae517f4..da92f174cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java @@ -17,7 +17,7 @@ package org.springframework.boot.autoconfigure.session; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -30,7 +30,7 @@ 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; @@ -64,7 +64,7 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur } private void validateDefaultConfig(AssertableWebApplicationContext context) { - validateSessionRepository(context, HazelcastIndexedSessionRepository.class); + validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class); HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class); verify(hazelcastInstance, times(1)).getMap("spring:session:sessions"); } @@ -73,7 +73,7 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur void customMapName() { this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast", "spring.session.hazelcast.map-name=foo:bar:biz").run((context) -> { - validateSessionRepository(context, HazelcastIndexedSessionRepository.class); + validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class); HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class); verify(hazelcastInstance, times(1)).getMap("foo:bar:biz"); }); @@ -83,8 +83,8 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur 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); }); } @@ -93,8 +93,8 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur 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/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationIntegrationTests.java index d4d1287b86..686fc91019 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationIntegrationTests.java @@ -17,7 +17,7 @@ package org.springframework.boot.autoconfigure.session; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml index 3c415fa4db..4e6920f317 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml @@ -1,5 +1,5 @@ default-instance diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml index 0dbc09b64f..84e3970a93 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-4.0.xsd"> spring-boot diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml index bf69f0902f..202e9bcebb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-4.0.xsd"> diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml index 078fbdca6a..f5788c2e50 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml @@ -1,4 +1,4 @@ - 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-3.xml new file mode 100644 index 0000000000..f8af559150 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/session/hazelcast-3.xml @@ -0,0 +1,19 @@ + + + + + + 3600 + 600 + + + + + + + + + + diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 8ea1e0e766..9f3199b26e 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -379,11 +379,10 @@ bom { ] } } - library("Hazelcast", "3.12.9") { + library("Hazelcast", "4.0.3") { group("com.hazelcast") { modules = [ "hazelcast", - "hazelcast-client", "hazelcast-spring" ] } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 0458f88dce..fa248d61d2 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -6207,6 +6207,18 @@ The {spring-boot-module-code}/jta/atomikos/AtomikosXAConnectionFactoryWrapper.ja == Hazelcast If https://hazelcast.com/[Hazelcast] is on the classpath and a suitable configuration is found, Spring Boot auto-configures a `HazelcastInstance` that you can inject in your application. +Spring Boot first attempts to create a client by checking the following configuration options: + +* The presence of a `com.hazelcast.client.config.ClientConfig` bean. +* A configuration file defined by the configprop:spring.hazelcast.config[] property. +* The presence of the `hazelcast.client.config` system property. +* A `hazelcast-client.xml` in the working directory or at the root of the classpath. +* A `hazelcast-client.yaml` in the working directory or at the root of the classpath. + +NOTE: Spring Boot supports both Hazelcast 4 and Hazelcast 3. +If you downgrade to Hazelcast 3, `hazelcast-client` should be added to the classpath to configure a client. + +If a client can't be created, Spring Boot attempts to configure an embedded server. If you define a `com.hazelcast.config.Config` bean, Spring Boot uses that. If your configuration defines an instance name, Spring Boot tries to locate an existing instance rather than creating a new one. @@ -6221,14 +6233,6 @@ Otherwise, Spring Boot tries to find the Hazelcast configuration from the defaul We also check if the `hazelcast.config` system property is set. See the https://docs.hazelcast.org/docs/latest/manual/html-single/[Hazelcast documentation] for more details. -If `hazelcast-client` is present on the classpath, Spring Boot first attempts to create a client by checking the following configuration options: - -* The presence of a `com.hazelcast.client.config.ClientConfig` bean. -* A configuration file defined by the configprop:spring.hazelcast.config[] property. -* The presence of the `hazelcast.client.config` system property. -* A `hazelcast-client.xml` in the working directory or at the root of the classpath. -* A `hazelcast-client.yaml` in the working directory or at the root of the classpath. - NOTE: Spring Boot also has <>. If caching is enabled, the `HazelcastInstance` is automatically wrapped in a `CacheManager` implementation. diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle similarity index 83% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/build.gradle rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle index 54d13f0e6b..c64d5334d1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/build.gradle @@ -3,12 +3,12 @@ plugins { id "org.springframework.boot.conventions" } -description = "Spring Boot Hazelcast 4 smoke test" +description = "Spring Boot Hazelcast 3 smoke test" configurations.all { resolutionStrategy { - force "com.hazelcast:hazelcast:4.0.1" - force "com.hazelcast:hazelcast-spring:4.0.1" + force "com.hazelcast:hazelcast:3.12.8" + force "com.hazelcast:hazelcast-spring:3.12.8" } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/Country.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/Country.java similarity index 97% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/Country.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/Country.java index 4a7d74dceb..8e638a8fcb 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/Country.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/Country.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package smoketest.hazelcast4; +package smoketest.hazelcast3; import java.io.Serializable; diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/CountryRepository.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/CountryRepository.java similarity index 97% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/CountryRepository.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/CountryRepository.java index 971bd1010e..7febaaa49b 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/CountryRepository.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/CountryRepository.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package smoketest.hazelcast4; +package smoketest.hazelcast3; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/SampleHazelcast4Application.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/SampleHazelcast3Application.java similarity index 91% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/SampleHazelcast4Application.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/SampleHazelcast3Application.java index fc9055d592..5fbac81b38 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/java/smoketest/hazelcast4/SampleHazelcast4Application.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/java/smoketest/hazelcast3/SampleHazelcast3Application.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package smoketest.hazelcast4; +package smoketest.hazelcast3; import com.hazelcast.spring.cache.HazelcastCacheManager; @@ -27,10 +27,10 @@ import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableCaching -public class SampleHazelcast4Application { +public class SampleHazelcast3Application { public static void main(String[] args) { - SpringApplication.run(SampleHazelcast4Application.class, args); + SpringApplication.run(SampleHazelcast3Application.class, args); } @Bean diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/resources/application.properties similarity index 100% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/resources/application.properties rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/resources/application.properties diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/resources/hazelcast.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/resources/hazelcast.xml similarity index 97% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/resources/hazelcast.xml rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/resources/hazelcast.xml index 1dd42796db..4fbcdb0b59 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/main/resources/hazelcast.xml +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/main/resources/hazelcast.xml @@ -1,7 +1,7 @@ + http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd"> 600 diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/test/java/smoketest/hazelcast4/SampleHazelcast4ApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/test/java/smoketest/hazelcast3/SampleHazelcast4ApplicationTests.java similarity index 98% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/test/java/smoketest/hazelcast4/SampleHazelcast4ApplicationTests.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/test/java/smoketest/hazelcast3/SampleHazelcast4ApplicationTests.java index 5a63b767eb..5512077212 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast4/src/test/java/smoketest/hazelcast4/SampleHazelcast4ApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hazelcast3/src/test/java/smoketest/hazelcast3/SampleHazelcast4ApplicationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package smoketest.hazelcast4; +package smoketest.hazelcast3; import com.hazelcast.spring.cache.HazelcastCacheManager; import org.junit.jupiter.api.Test; diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml index f15c77b46f..9a988bf978 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml @@ -1,4 +1,4 @@ -