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
pull/23502/head
Stephane Nicoll 4 years ago
parent 7b183ef99d
commit 4009acf025

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

@ -1,5 +1,5 @@
<hazelcast
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.12.xsd"
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.0.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<map name="defaultCache" />

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

@ -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 {

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

@ -1,8 +1,8 @@
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config
http://www.hazelcast.com/schema/config/hazelcast-config-4.0.xsd">
<instance-name>actuator-hazelcast-4</instance-name>
http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd">
<instance-name>actuator-hazelcast-3</instance-name>
<map name="defaultCache"/>
<network>
<join>

@ -1,7 +1,7 @@
<hazelcast
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.12.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config
http://www.hazelcast.com/schema/config/hazelcast-config-4.0.xsd">
<instance-name>actuator-hazelcast</instance-name>
<map name="defaultCache" />
<network>

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

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

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

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

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

@ -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<AssertableApplicationContext> assertSpecificHazelcastClient(String label) {
return (context) -> assertThat(context).getBean(HazelcastInstance.class).isInstanceOf(HazelcastInstance.class)
.has(labelEqualTo(label));
}
private static Condition<HazelcastInstance> labelEqualTo(String label) {
return new Condition<>((o) -> ((HazelcastClientProxy) o).getClientConfig().getLabels().stream()
.anyMatch((e) -> e.equals(label)), "Label equals to " + label);
}
}

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

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

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

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

@ -1,5 +1,5 @@
<hazelcast
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.12.xsd"
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.0.xsd"
xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<instance-name>default-instance</instance-name>
<map name="defaultCache" />

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.12.xsd">
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-4.0.xsd">
<instance-name>spring-boot</instance-name>

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.12.xsd">
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-4.0.xsd">
<client-labels>
<label>explicit-xml</label>
</client-labels>

@ -1,4 +1,4 @@
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.12.xsd"
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.0.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

@ -0,0 +1,19 @@
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.2.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<queue name="foobar"/>
<map name="foobar">
<time-to-live-seconds>3600</time-to-live-seconds>
<max-idle-seconds>600</max-idle-seconds>
</map>
<network>
<join>
<tcp-ip enabled="false"/>
<multicast enabled="false"/>
</join>
</network>
</hazelcast>

@ -379,11 +379,10 @@ bom {
]
}
}
library("Hazelcast", "3.12.9") {
library("Hazelcast", "4.0.3") {
group("com.hazelcast") {
modules = [
"hazelcast",
"hazelcast-client",
"hazelcast-spring"
]
}

@ -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 <<boot-features-caching-provider-hazelcast,explicit caching support for Hazelcast>>.
If caching is enabled, the `HazelcastInstance` is automatically wrapped in a `CacheManager` implementation.

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

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

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

@ -1,7 +1,7 @@
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config
http://www.hazelcast.com/schema/config/hazelcast-config-4.0.xsd">
http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd">
<map name="countries">
<time-to-live-seconds>600</time-to-live-seconds>
</map>

@ -1,4 +1,4 @@
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.12.xsd"
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.0.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Loading…
Cancel
Save