Skip to content

Commit 9cb614c

Browse files
committed
Migrate Hazelcast 3 sanity tests to Hazelcast 4
Closes gh-31881
1 parent bfc703a commit 9cb614c

File tree

7 files changed

+67
-41
lines changed

7 files changed

+67
-41
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@
4040
* @author Stephane Nicoll
4141
*/
4242
@ClassPathExclusions("hazelcast*.jar")
43-
@ClassPathOverrides("com.hazelcast:hazelcast:3.12.12")
44-
class Hazelcast3HazelcastHealthIndicatorTests {
43+
@ClassPathOverrides("com.hazelcast:hazelcast:4.2.5")
44+
class Hazelcast4HazelcastHealthIndicatorTests {
4545

4646
@Test
4747
void hazelcastUp() {
4848
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class))
49-
.withPropertyValues("spring.hazelcast.config=hazelcast-3.xml").run((context) -> {
49+
.withPropertyValues("spring.hazelcast.config=hazelcast-4.xml").run((context) -> {
5050
HazelcastInstance hazelcast = context.getBean(HazelcastInstance.class);
5151
Health health = new HazelcastHealthIndicator(hazelcast).health();
5252
assertThat(health.getStatus()).isEqualTo(Status.UP);
5353
assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name",
54-
"actuator-hazelcast-3");
54+
"actuator-hazelcast-4");
5555
assertThat(health.getDetails().get("uuid")).asString().isNotEmpty();
5656
});
5757
}

spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-3.xml renamed to spring-boot-project/spring-boot-actuator/src/test/resources/hazelcast-4.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://www.hazelcast.com/schema/config
4-
http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd">
5-
<instance-name>actuator-hazelcast-3</instance-name>
4+
http://www.hazelcast.com/schema/config/hazelcast-config-4.2.xsd">
5+
<instance-name>actuator-hazelcast-4</instance-name>
66
<map name="defaultCache"/>
77
<network>
88
<join>
9-
<tcp-ip enabled="false"/>
9+
<auto-detection enabled="false"/>
1010
<multicast enabled="false"/>
1111
</join>
1212
</network>
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.hazelcast.client.impl.clientside.HazelcastClientProxy;
2020
import com.hazelcast.config.Config;
21+
import com.hazelcast.config.JoinConfig;
2122
import com.hazelcast.core.Hazelcast;
2223
import com.hazelcast.core.HazelcastInstance;
2324
import com.hazelcast.spring.context.SpringManagedContext;
@@ -30,42 +31,43 @@
3031
import org.springframework.boot.test.context.runner.ContextConsumer;
3132
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
3233
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
33-
import org.springframework.core.io.ClassPathResource;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
3636

3737
/**
38-
* Tests for {@link HazelcastAutoConfiguration} with Hazelcast 3.
38+
* Tests for {@link HazelcastAutoConfiguration} with Hazelcast 4.
3939
*
4040
* @author Stephane Nicoll
4141
*/
4242
@ClassPathExclusions("hazelcast*.jar")
43-
@ClassPathOverrides({ "com.hazelcast:hazelcast:3.12.12", "com.hazelcast:hazelcast-client:3.12.12",
44-
"com.hazelcast:hazelcast-spring:3.12.12" })
45-
class Hazelcast3AutoConfigurationTests {
43+
@ClassPathOverrides({ "com.hazelcast:hazelcast:4.2.5", "com.hazelcast:hazelcast-spring:4.2.5" })
44+
class Hazelcast4AutoConfigurationTests {
4645

4746
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
4847
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
4948

5049
@Test
51-
void defaultConfigFile() {
52-
// no hazelcast-client.xml and hazelcast.xml is present in root classpath
53-
// this also asserts that XML has priority over YAML
54-
// as both hazelcast.yaml and hazelcast.xml in test classpath.
55-
this.contextRunner.run((context) -> {
56-
Config config = context.getBean(HazelcastInstance.class).getConfig();
57-
assertThat(config.getConfigurationUrl()).isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
58-
});
50+
void serverConfig() {
51+
this.contextRunner.withPropertyValues(
52+
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml")
53+
.run((context) -> {
54+
Config config = context.getBean(HazelcastInstance.class).getConfig();
55+
assertThat(config.getInstanceName()).isEqualTo("explicit-server");
56+
});
5957
}
6058

6159
@Test
6260
void explicitConfigFileWithXml() {
63-
HazelcastInstance hazelcastServer = Hazelcast.newHazelcastInstance();
61+
Config config = new Config();
62+
JoinConfig join = config.getNetworkConfig().getJoin();
63+
join.getAutoDetectionConfig().setEnabled(false);
64+
join.getMulticastConfig().setEnabled(false);
65+
HazelcastInstance hazelcastServer = Hazelcast.newHazelcastInstance(config);
6466
try {
6567
this.contextRunner
66-
.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
67-
+ "hazelcast/hazelcast-client-specific.xml")
68-
.run(assertSpecificHazelcastClient("explicit-xml"));
68+
.withPropertyValues("spring.hazelcast.config="
69+
+ "org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-client.xml")
70+
.run(assertSpecificHazelcastClient("explicit-client"));
6971
}
7072
finally {
7173
hazelcastServer.shutdown();
@@ -74,10 +76,12 @@ void explicitConfigFileWithXml() {
7476

7577
@Test
7678
void autoConfiguredConfigUsesSpringManagedContext() {
77-
this.contextRunner.run((context) -> {
78-
Config config = context.getBean(HazelcastInstance.class).getConfig();
79-
assertThat(config.getManagedContext()).isInstanceOf(SpringManagedContext.class);
80-
});
79+
this.contextRunner.withPropertyValues(
80+
"spring.hazelcast.config=" + "org/springframework/boot/autoconfigure/hazelcast/hazelcast-4-server.xml")
81+
.run((context) -> {
82+
Config config = context.getBean(HazelcastInstance.class).getConfig();
83+
assertThat(config.getManagedContext()).isInstanceOf(SpringManagedContext.class);
84+
});
8185
}
8286

8387
private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastClient(String label) {
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,25 @@
2929
import org.springframework.session.SaveMode;
3030
import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
3131
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
32-
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
32+
import org.springframework.session.hazelcast.Hazelcast4IndexedSessionRepository;
3333
import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
3636

3737
/**
38-
* Hazelcast 3 specific tests for {@link SessionAutoConfiguration}.
38+
* Hazelcast 4 specific tests for {@link SessionAutoConfiguration}.
3939
*
4040
* @author Vedran Pavic
41+
* @author Stephane Nicoll
4142
*/
4243
@ClassPathExclusions("hazelcast*.jar")
43-
@ClassPathOverrides("com.hazelcast:hazelcast:3.12.12")
44-
class SessionAutoConfigurationHazelcast3Tests extends AbstractSessionAutoConfigurationTests {
44+
@ClassPathOverrides("com.hazelcast:hazelcast:4.2.5")
45+
class SessionAutoConfigurationHazelcast4Tests extends AbstractSessionAutoConfigurationTests {
4546

4647
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
4748
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class, SessionAutoConfiguration.class))
4849
.withPropertyValues(
49-
"spring.hazelcast.config=org/springframework/boot/autoconfigure/session/hazelcast-3.xml");
50+
"spring.hazelcast.config=org/springframework/boot/autoconfigure/session/hazelcast-4.xml");
5051

5152
@Test
5253
void defaultConfig() {
@@ -62,23 +63,23 @@ void defaultConfigWithUniqueStoreImplementation() {
6263
}
6364

6465
private void validateDefaultConfig(AssertableWebApplicationContext context) {
65-
validateSessionRepository(context, HazelcastIndexedSessionRepository.class);
66+
validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class);
6667
}
6768

6869
@Test
6970
void customMapName() {
7071
this.contextRunner
7172
.withPropertyValues("spring.session.store-type=hazelcast",
7273
"spring.session.hazelcast.map-name=foo:bar:biz")
73-
.run((context) -> validateSessionRepository(context, HazelcastIndexedSessionRepository.class));
74+
.run((context) -> validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class));
7475
}
7576

7677
@Test
7778
void customFlushMode() {
7879
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast",
7980
"spring.session.hazelcast.flush-mode=immediate").run((context) -> {
80-
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
81-
HazelcastIndexedSessionRepository.class);
81+
Hazelcast4IndexedSessionRepository repository = validateSessionRepository(context,
82+
Hazelcast4IndexedSessionRepository.class);
8283
assertThat(repository).hasFieldOrPropertyWithValue("flushMode", FlushMode.IMMEDIATE);
8384
});
8485
}
@@ -87,8 +88,8 @@ void customFlushMode() {
8788
void customSaveMode() {
8889
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast",
8990
"spring.session.hazelcast.save-mode=on-get-attribute").run((context) -> {
90-
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
91-
HazelcastIndexedSessionRepository.class);
91+
Hazelcast4IndexedSessionRepository repository = validateSessionRepository(context,
92+
Hazelcast4IndexedSessionRepository.class);
9293
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", SaveMode.ON_GET_ATTRIBUTE);
9394
});
9495
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-4.2.xsd">
5+
<client-labels>
6+
<label>explicit-client</label>
7+
</client-labels>
8+
9+
</hazelcast-client>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<hazelcast
2+
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.2.xsd"
3+
xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<instance-name>explicit-server</instance-name>
5+
<map name="defaultCache" />
6+
<network>
7+
<join>
8+
<auto-detection enabled="false"/>
9+
<multicast enabled="false" />
10+
</join>
11+
</network>
12+
</hazelcast>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.2.xsd"
1+
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-4.2.xsd"
22
xmlns="http://www.hazelcast.com/schema/config"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
44

@@ -11,7 +11,7 @@
1111

1212
<network>
1313
<join>
14-
<tcp-ip enabled="false"/>
14+
<auto-detection enabled="false"/>
1515
<multicast enabled="false"/>
1616
</join>
1717
</network>

0 commit comments

Comments
 (0)