Add support for detecting .yml Hazelcast config files
See gh-32142
This commit is contained in:
parent
cd61d69a2f
commit
5eaafdee9a
|
@ -39,7 +39,8 @@ class HazelcastClientConfigAvailableCondition extends HazelcastConfigResourceCon
|
|||
|
||||
HazelcastClientConfigAvailableCondition() {
|
||||
super(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml",
|
||||
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml");
|
||||
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml",
|
||||
"file:./hazelcast-client.yml", "classpath:/hazelcast-client.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,7 +72,7 @@ class HazelcastClientConfiguration {
|
|||
private ClientConfig loadClientConfig(Resource configLocation) throws IOException {
|
||||
URL configUrl = configLocation.getURL();
|
||||
String configFileName = configUrl.getPath();
|
||||
if (configFileName.endsWith(".yaml")) {
|
||||
if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
|
||||
return new YamlClientConfigBuilder(configUrl).build();
|
||||
}
|
||||
return new XmlClientConfigBuilder(configUrl).build();
|
||||
|
|
|
@ -82,7 +82,7 @@ class HazelcastServerConfiguration {
|
|||
|
||||
private static Config loadConfig(URL configUrl) throws IOException {
|
||||
String configFileName = configUrl.getPath();
|
||||
if (configFileName.endsWith(".yaml")) {
|
||||
if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
|
||||
return new YamlConfigBuilder(configUrl).build();
|
||||
}
|
||||
return new XmlConfigBuilder(configUrl).build();
|
||||
|
@ -109,7 +109,7 @@ class HazelcastServerConfiguration {
|
|||
|
||||
ConfigAvailableCondition() {
|
||||
super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast.xml", "classpath:/hazelcast.xml", "file:./hazelcast.yaml",
|
||||
"classpath:/hazelcast.yaml");
|
||||
"classpath:/hazelcast.yaml", "file:./hazelcast.yml", "classpath:/hazelcast.yml");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,6 +81,14 @@ class HazelcastAutoConfigurationClientTests {
|
|||
.run(assertSpecificHazelcastClient("explicit-yaml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void systemPropertyWithYml() {
|
||||
this.contextRunner
|
||||
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
|
||||
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.yml")
|
||||
.run(assertSpecificHazelcastClient("explicit-yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigFileWithXml() {
|
||||
this.contextRunner.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
|
||||
|
@ -95,6 +103,14 @@ class HazelcastAutoConfigurationClientTests {
|
|||
.run(assertSpecificHazelcastClient("explicit-yaml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigFileWithYml() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
|
||||
+ "hazelcast/hazelcast-client-specific.yml")
|
||||
.run(assertSpecificHazelcastClient("explicit-yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigUrlWithXml() {
|
||||
this.contextRunner
|
||||
|
@ -111,6 +127,14 @@ class HazelcastAutoConfigurationClientTests {
|
|||
.run(assertSpecificHazelcastClient("explicit-yaml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigUrlWithYml() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
|
||||
+ "boot/autoconfigure/hazelcast/hazelcast-client-specific.yml")
|
||||
.run(assertSpecificHazelcastClient("explicit-yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownConfigFile() {
|
||||
this.contextRunner.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
|
||||
|
|
|
@ -79,6 +79,17 @@ class HazelcastAutoConfigurationServerTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void systemPropertyWithYml() {
|
||||
this.contextRunner
|
||||
.withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY
|
||||
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml")
|
||||
.run((context) -> {
|
||||
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||
assertThat(config.getMapConfigs().keySet()).containsOnly("foobar");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigFileWithXml() {
|
||||
this.contextRunner
|
||||
|
@ -97,6 +108,15 @@ class HazelcastAutoConfigurationServerTests {
|
|||
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigFileWithYml() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
|
||||
+ "hazelcast-specific.yml")
|
||||
.run(assertSpecificHazelcastServer(
|
||||
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigUrlWithXml() {
|
||||
this.contextRunner
|
||||
|
@ -115,6 +135,15 @@ class HazelcastAutoConfigurationServerTests {
|
|||
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitConfigUrlWithYml() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
|
||||
+ "boot/autoconfigure/hazelcast/hazelcast-specific.yml")
|
||||
.run(assertSpecificHazelcastServer(
|
||||
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml"));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastServer(String location) {
|
||||
return (context) -> {
|
||||
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||
|
|
|
@ -45,7 +45,7 @@ class HazelcastAutoConfigurationTests {
|
|||
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.
|
||||
// as both hazelcast.yaml, hazelcast.yml 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());
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
hazelcast:
|
||||
network:
|
||||
join:
|
||||
auto-detection:
|
||||
enabled: false
|
||||
multicast:
|
||||
enabled: false
|
|
@ -0,0 +1,3 @@
|
|||
hazelcast-client:
|
||||
client-labels:
|
||||
- explicit-yml
|
|
@ -0,0 +1,12 @@
|
|||
hazelcast:
|
||||
network:
|
||||
join:
|
||||
auto-detection:
|
||||
enabled: false
|
||||
multicast:
|
||||
enabled: false
|
||||
|
||||
map:
|
||||
foobar:
|
||||
time-to-live-seconds: 3600
|
||||
max-idle-seconds: 600
|
Loading…
Reference in New Issue