From 611d5fa5d799e650884c98eb07e98b1afbcea5ee Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 24 Jun 2019 13:39:29 -0700 Subject: [PATCH] Adds auto-configuration for Apache Geode & Pivotal GemFire logging. Resolves gh-40. --- .../LoggingAutoConfiguration.java | 46 ++++++++++++ .../main/resources/META-INF/spring.factories | 1 + ...gingAutoConfigurationIntegrationTests.java | 75 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/LoggingAutoConfiguration.java create mode 100644 spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/logging/LoggingAutoConfigurationIntegrationTests.java diff --git a/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/LoggingAutoConfiguration.java b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/LoggingAutoConfiguration.java new file mode 100644 index 00000000..9474a281 --- /dev/null +++ b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/LoggingAutoConfiguration.java @@ -0,0 +1,46 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.springframework.geode.boot.autoconfigure; + +import org.apache.geode.cache.GemFireCache; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.config.annotation.EnableLogging; + +/** + * Spring Boot {@link EnableAutoConfiguration Auto-Configuration} for Apache Geode and Pivotal GemFire logging. + * + * @author John Blum + * @see org.springframework.boot.autoconfigure.EnableAutoConfiguration + * @see org.springframework.boot.autoconfigure.condition.ConditionalOnBean + * @see org.springframework.boot.autoconfigure.condition.ConditionalOnClass + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.data.gemfire.CacheFactoryBean + * @see org.springframework.data.gemfire.config.annotation.EnableLogging + * @since 1.1.0 + */ +@Configuration +@ConditionalOnBean(GemFireCache.class) +@ConditionalOnClass(CacheFactoryBean.class) +@EnableLogging +@SuppressWarnings("unused") +public class LoggingAutoConfiguration { + +} diff --git a/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories index ebfc8f1b..385af067 100644 --- a/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories @@ -7,6 +7,7 @@ org.springframework.geode.boot.autoconfigure.ClientSecurityAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.FunctionExecutionAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.GemFirePropertiesAutoConfiguration,\ +org.springframework.geode.boot.autoconfigure.LoggingAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.PdxSerializationAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.PeerSecurityAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration,\ diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/logging/LoggingAutoConfigurationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/logging/LoggingAutoConfigurationIntegrationTests.java new file mode 100644 index 00000000..91896e5f --- /dev/null +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/logging/LoggingAutoConfigurationIntegrationTests.java @@ -0,0 +1,75 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.springframework.geode.boot.autoconfigure.logging; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.distributed.internal.DistributionConfig; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * The LoggingAutoConfigurationIntegrationTests class... + * + * @author John Blum + * @since 1.0.0 + */ +@RunWith(SpringRunner.class) +@SpringBootTest( + properties = { + "spring.data.gemfire.logging.level=fine", + "spring.data.gemfire.logging.log-disk-space-limit=4096", + "spring.data.gemfire.logging.log-file=/path/to/gemfire.log", + "spring.data.gemfire.logging.log-file-size-limit=512" + }, + webEnvironment = SpringBootTest.WebEnvironment.NONE +) +@SuppressWarnings("unused") +public class LoggingAutoConfigurationIntegrationTests { + + @Autowired + private GemFireCache gemfireCache; + + @Test + public void loggingConfigurationWasApplied() { + + assertThat(this.gemfireCache).isNotNull(); + assertThat(this.gemfireCache.getDistributedSystem()).isNotNull(); + + Properties distributedSystemProperties = this.gemfireCache.getDistributedSystem().getProperties(); + + assertThat(distributedSystemProperties.getProperty(DistributionConfig.LOG_DISK_SPACE_LIMIT_NAME)).isEqualTo("4096"); + assertThat(distributedSystemProperties.getProperty(DistributionConfig.LOG_FILE_NAME)).isEqualTo("/path/to/gemfire.log"); + assertThat(distributedSystemProperties.getProperty(DistributionConfig.LOG_FILE_SIZE_LIMIT_NAME)).isEqualTo("512"); + assertThat(distributedSystemProperties.getProperty(DistributionConfig.LOG_LEVEL_NAME)).isEqualTo("fine"); + } + + @EnableGemFireMockObjects + @SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class) + static class TestConfiguration { } + +}