Skip to content

Commit

Permalink
Merge pull request #32184 from ldziedziul
Browse files Browse the repository at this point in the history
* pr/32184:
  Polish "Make sure Hazelcast shutdown logs are available"
  Make sure Hazelcast shutdown logs are available

Closes gh-32184
  • Loading branch information
snicoll committed Sep 7, 2022
2 parents 9ef067d + 960b034 commit 74a88cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Expand Up @@ -52,6 +52,8 @@ class HazelcastServerConfiguration {

static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.config";

static final String HAZELCAST_LOGGING_TYPE = "hazelcast.logging.type";

private static HazelcastInstance getHazelcastInstance(Config config) {
if (StringUtils.hasText(config.getInstanceName())) {
return Hazelcast.getOrCreateHazelcastInstance(config);
Expand Down Expand Up @@ -123,6 +125,22 @@ HazelcastConfigCustomizer springManagedContextHazelcastConfigCustomizer(Applicat

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(org.slf4j.Logger.class)
static class HazelcastLoggingConfigCustomizerConfiguration {

@Bean
@Order(0)
HazelcastConfigCustomizer loggingHazelcastConfigCustomizer() {
return (config) -> {
if (!config.getProperties().containsKey(HAZELCAST_LOGGING_TYPE)) {
config.setProperty(HAZELCAST_LOGGING_TYPE, "slf4j");
}
};
}

}

/**
* {@link HazelcastConfigResourceCondition} that checks if the
* {@code spring.hazelcast.config} configuration key is defined.
Expand Down
Expand Up @@ -206,6 +206,22 @@ void autoConfiguredContextCanOverrideManagementContextUsingCustomizer() {
});
}

@Test
void autoConfiguredConfigSetsHazelcastLoggingToSlf4j() {
this.contextRunner.run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE)).isEqualTo("slf4j");
});
}

@Test
void autoConfiguredConfigCanOverrideHazelcastLogging() {
this.contextRunner.withUserConfiguration(HazelcastConfigWithJDKLogging.class).run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE)).isEqualTo("jdk");
});
}

private static Config createTestConfig(String instanceName) {
Config config = new Config(instanceName);
JoinConfig join = config.getNetworkConfig().getJoin();
Expand Down Expand Up @@ -236,6 +252,18 @@ Config anotherHazelcastConfig() {

}

@Configuration(proxyBeanMethods = false)
static class HazelcastConfigWithJDKLogging {

@Bean
Config anotherHazelcastConfig() {
Config config = new Config();
config.setProperty(HazelcastServerConfiguration.HAZELCAST_LOGGING_TYPE, "jdk");
return config;
}

}

@SpringAware
static class SpringAwareEntryProcessor<V> implements EntryProcessor<String, V, String> {

Expand Down

0 comments on commit 74a88cd

Please sign in to comment.