Skip to content

Commit

Permalink
Adds auto-configuration for Apache Geode & Pivotal GemFire logging.
Browse files Browse the repository at this point in the history
Resolves gh-40.
  • Loading branch information
jxblum committed Jun 24, 2019
1 parent d86c4be commit 611d5fa
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
@@ -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 {

}
Expand Up @@ -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,\
Expand Down
@@ -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 { }

}

0 comments on commit 611d5fa

Please sign in to comment.