mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Migrate Hazelcast 3 sanity tests to Hazelcast 4
Closes gh-31881
This commit is contained in:
parent
bfc703a40d
commit
9cb614c626
@ -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();
|
||||
});
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
<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-3.12.xsd">
|
||||
<instance-name>actuator-hazelcast-3</instance-name>
|
||||
http://www.hazelcast.com/schema/config/hazelcast-config-4.2.xsd">
|
||||
<instance-name>actuator-hazelcast-4</instance-name>
|
||||
<map name="defaultCache"/>
|
||||
<network>
|
||||
<join>
|
||||
<tcp-ip enabled="false"/>
|
||||
<auto-detection enabled="false"/>
|
||||
<multicast enabled="false"/>
|
||||
</join>
|
||||
</network>
|
@ -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<AssertableApplicationContext> assertSpecificHazelcastClient(String label) {
|
@ -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);
|
||||
});
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?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-4.2.xsd">
|
||||
<client-labels>
|
||||
<label>explicit-client</label>
|
||||
</client-labels>
|
||||
|
||||
</hazelcast-client>
|
@ -0,0 +1,12 @@
|
||||
<hazelcast
|
||||
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.2.xsd"
|
||||
xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<instance-name>explicit-server</instance-name>
|
||||
<map name="defaultCache" />
|
||||
<network>
|
||||
<join>
|
||||
<auto-detection enabled="false"/>
|
||||
<multicast enabled="false" />
|
||||
</join>
|
||||
</network>
|
||||
</hazelcast>
|
@ -1,4 +1,4 @@
|
||||
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.2.xsd"
|
||||
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.2.xsd"
|
||||
xmlns="http://www.hazelcast.com/schema/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
<network>
|
||||
<join>
|
||||
<tcp-ip enabled="false"/>
|
||||
<auto-detection enabled="false"/>
|
||||
<multicast enabled="false"/>
|
||||
</join>
|
||||
</network>
|
Loading…
Reference in New Issue
Block a user