Skip to content

Commit 5eaafde

Browse files
neilstevensonsnicoll
authored andcommitted
Add support for detecting .yml Hazelcast config files
See gh-32142
1 parent cd61d69 commit 5eaafde

File tree

9 files changed

+81
-5
lines changed

9 files changed

+81
-5
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfigAvailableCondition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class HazelcastClientConfigAvailableCondition extends HazelcastConfigResourceCon
3939

4040
HazelcastClientConfigAvailableCondition() {
4141
super(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml",
42-
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml");
42+
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml",
43+
"file:./hazelcast-client.yml", "classpath:/hazelcast-client.yml");
4344
}
4445

4546
@Override

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ HazelcastInstance hazelcastInstance(HazelcastProperties properties, ResourceLoad
7272
private ClientConfig loadClientConfig(Resource configLocation) throws IOException {
7373
URL configUrl = configLocation.getURL();
7474
String configFileName = configUrl.getPath();
75-
if (configFileName.endsWith(".yaml")) {
75+
if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
7676
return new YamlClientConfigBuilder(configUrl).build();
7777
}
7878
return new XmlClientConfigBuilder(configUrl).build();

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private Config loadConfig(Resource configLocation) throws IOException {
8282

8383
private static Config loadConfig(URL configUrl) throws IOException {
8484
String configFileName = configUrl.getPath();
85-
if (configFileName.endsWith(".yaml")) {
85+
if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
8686
return new YamlConfigBuilder(configUrl).build();
8787
}
8888
return new XmlConfigBuilder(configUrl).build();
@@ -109,7 +109,7 @@ static class ConfigAvailableCondition extends HazelcastConfigResourceCondition {
109109

110110
ConfigAvailableCondition() {
111111
super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast.xml", "classpath:/hazelcast.xml", "file:./hazelcast.yaml",
112-
"classpath:/hazelcast.yaml");
112+
"classpath:/hazelcast.yaml", "file:./hazelcast.yml", "classpath:/hazelcast.yml");
113113
}
114114

115115
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ void systemPropertyWithYaml() {
8181
.run(assertSpecificHazelcastClient("explicit-yaml"));
8282
}
8383

84+
@Test
85+
void systemPropertyWithYml() {
86+
this.contextRunner
87+
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
88+
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.yml")
89+
.run(assertSpecificHazelcastClient("explicit-yml"));
90+
}
91+
8492
@Test
8593
void explicitConfigFileWithXml() {
8694
this.contextRunner.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
@@ -95,6 +103,14 @@ void explicitConfigFileWithYaml() {
95103
.run(assertSpecificHazelcastClient("explicit-yaml"));
96104
}
97105

106+
@Test
107+
void explicitConfigFileWithYml() {
108+
this.contextRunner
109+
.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
110+
+ "hazelcast/hazelcast-client-specific.yml")
111+
.run(assertSpecificHazelcastClient("explicit-yml"));
112+
}
113+
98114
@Test
99115
void explicitConfigUrlWithXml() {
100116
this.contextRunner
@@ -111,6 +127,14 @@ void explicitConfigUrlWithYaml() {
111127
.run(assertSpecificHazelcastClient("explicit-yaml"));
112128
}
113129

130+
@Test
131+
void explicitConfigUrlWithYml() {
132+
this.contextRunner
133+
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
134+
+ "boot/autoconfigure/hazelcast/hazelcast-client-specific.yml")
135+
.run(assertSpecificHazelcastClient("explicit-yml"));
136+
}
137+
114138
@Test
115139
void unknownConfigFile() {
116140
this.contextRunner.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ void systemPropertyWithYaml() {
7979
});
8080
}
8181

82+
@Test
83+
void systemPropertyWithYml() {
84+
this.contextRunner
85+
.withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY
86+
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml")
87+
.run((context) -> {
88+
Config config = context.getBean(HazelcastInstance.class).getConfig();
89+
assertThat(config.getMapConfigs().keySet()).containsOnly("foobar");
90+
});
91+
}
92+
8293
@Test
8394
void explicitConfigFileWithXml() {
8495
this.contextRunner
@@ -97,6 +108,15 @@ void explicitConfigFileWithYaml() {
97108
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"));
98109
}
99110

111+
@Test
112+
void explicitConfigFileWithYml() {
113+
this.contextRunner
114+
.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
115+
+ "hazelcast-specific.yml")
116+
.run(assertSpecificHazelcastServer(
117+
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml"));
118+
}
119+
100120
@Test
101121
void explicitConfigUrlWithXml() {
102122
this.contextRunner
@@ -115,6 +135,15 @@ void explicitConfigUrlWithYaml() {
115135
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"));
116136
}
117137

138+
@Test
139+
void explicitConfigUrlWithYml() {
140+
this.contextRunner
141+
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
142+
+ "boot/autoconfigure/hazelcast/hazelcast-specific.yml")
143+
.run(assertSpecificHazelcastServer(
144+
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml"));
145+
}
146+
118147
private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastServer(String location) {
119148
return (context) -> {
120149
Config config = context.getBean(HazelcastInstance.class).getConfig();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class HazelcastAutoConfigurationTests {
4545
void defaultConfigFile() {
4646
// no hazelcast-client.xml and hazelcast.xml is present in root classpath
4747
// this also asserts that XML has priority over YAML
48-
// as both hazelcast.yaml and hazelcast.xml in test classpath.
48+
// as both hazelcast.yaml, hazelcast.yml and hazelcast.xml in test classpath.
4949
this.contextRunner.run((context) -> {
5050
Config config = context.getBean(HazelcastInstance.class).getConfig();
5151
assertThat(config.getConfigurationUrl()).isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
hazelcast:
2+
network:
3+
join:
4+
auto-detection:
5+
enabled: false
6+
multicast:
7+
enabled: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hazelcast-client:
2+
client-labels:
3+
- explicit-yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
hazelcast:
2+
network:
3+
join:
4+
auto-detection:
5+
enabled: false
6+
multicast:
7+
enabled: false
8+
9+
map:
10+
foobar:
11+
time-to-live-seconds: 3600
12+
max-idle-seconds: 600

0 commit comments

Comments
 (0)