Associate application classloader to auto-configured Hazelcast instance

Closes gh-24836
This commit is contained in:
Stephane Nicoll
2021-02-11 15:13:10 +01:00
parent 5576f26115
commit 0bc03c7141
8 changed files with 124 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -135,6 +135,18 @@ class HazelcastAutoConfigurationClientTests {
.extracting(HazelcastInstance::getName).isEqualTo("spring-boot"));
}
@Test
void autoConfiguredClientConfigUsesApplicationClassLoader() {
this.contextRunner.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast/hazelcast-client-specific.xml").run((context) -> {
HazelcastInstance hazelcast = context.getBean(HazelcastInstance.class);
assertThat(hazelcast).isInstanceOf(HazelcastClientProxy.class);
ClientConfig clientConfig = ((HazelcastClientProxy) hazelcast).getClientConfig();
assertThat(clientConfig.getClassLoader())
.isSameAs(context.getSourceApplicationContext().getClassLoader());
});
}
private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastClient(String label) {
return (context) -> assertThat(context).getBean(HazelcastInstance.class).isInstanceOf(HazelcastInstance.class)
.has(labelEqualTo(label));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -156,6 +156,14 @@ class HazelcastAutoConfigurationServerTests {
});
}
@Test
void autoConfiguredConfigUsesApplicationClassLoader() {
this.contextRunner.run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getClassLoader()).isSameAs(context.getSourceApplicationContext().getClassLoader());
});
}
@Configuration(proxyBeanMethods = false)
static class HazelcastConfigWithName {