Add auto-configuration support for creating Templates per Cache Region.
Resolves gh-31.
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.internal.concurrent.ConcurrentHashSet;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.SingletonBeanRegistry;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Spring Boot {@link EnableAutoConfiguration auto-configuration} class used to configure a {@link GemfireTemplate}
|
||||
* for each Apache Geode / Pivotal GemFire {@link Region} declared/defined in
|
||||
* the Spring {@link ConfigurableApplicationContext} in order to perform {@link Region} data access operations.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor
|
||||
* @see org.springframework.beans.factory.config.SingletonBeanRegistry
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.data.gemfire.GemfireTemplate
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureAfter(ClientCacheAutoConfiguration.class)
|
||||
@ConditionalOnBean(GemFireCache.class)
|
||||
@ConditionalOnClass(GemfireTemplate.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class RegionTemplateAutoConfiguration {
|
||||
|
||||
private static final Set<String> regionTemplateNames = new ConcurrentHashSet<>();
|
||||
|
||||
private String toRegionTemplateName(String regionName) {
|
||||
return StringUtils.uncapitalize(regionName) + "Template";
|
||||
}
|
||||
|
||||
@Bean
|
||||
BeanPostProcessor regionTemplateBeanPostProcessor(ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
if (bean instanceof Region) {
|
||||
|
||||
String regionTemplateName = toRegionTemplateName(beanName);
|
||||
|
||||
registerRegionTemplateBean(regionTemplateName, bean);
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private void registerRegionTemplateBean(String regionTemplateName, Object bean) {
|
||||
|
||||
Optional.ofNullable(applicationContext)
|
||||
.filter(it -> bean instanceof Region)
|
||||
.map(ConfigurableApplicationContext::getBeanFactory)
|
||||
.filter(SingletonBeanRegistry.class::isInstance)
|
||||
.map(SingletonBeanRegistry.class::cast)
|
||||
.ifPresent(beanFactory -> {
|
||||
beanFactory.registerSingleton(regionTemplateName, new GemfireTemplate((Region) bean));
|
||||
regionTemplateNames.add(regionTemplateName);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@EventListener({ ContextRefreshedEvent.class })
|
||||
public void registerRemainingRegionTemplatesOnContextRefresh(ContextRefreshedEvent event) {
|
||||
|
||||
ApplicationContext applicationContext = event.getApplicationContext();
|
||||
|
||||
if (applicationContext instanceof ConfigurableApplicationContext) {
|
||||
|
||||
ConfigurableListableBeanFactory beanFactory =
|
||||
((ConfigurableApplicationContext) applicationContext).getBeanFactory();
|
||||
|
||||
Optional.ofNullable(applicationContext.getBean(GemFireCache.class))
|
||||
.map(GemFireCache::rootRegions)
|
||||
.ifPresent(rootRegions -> rootRegions.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(region -> !regionTemplateNames.contains(toRegionTemplateName(region.getName())))
|
||||
.forEach(region -> beanFactory.registerSingleton(toRegionTemplateName(region.getName()),
|
||||
new GemfireTemplate(region))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ org.springframework.geode.boot.autoconfigure.FunctionExecutionAutoConfiguration,
|
||||
org.springframework.geode.boot.autoconfigure.GemFirePropertiesAutoConfiguration,\
|
||||
org.springframework.geode.boot.autoconfigure.PdxSerializationAutoConfiguration,\
|
||||
org.springframework.geode.boot.autoconfigure.PeerSecurityAutoConfiguration,\
|
||||
org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration,\
|
||||
org.springframework.geode.boot.autoconfigure.RepositoriesAutoConfiguration,\
|
||||
org.springframework.geode.boot.autoconfigure.SpringSessionAutoConfiguration,\
|
||||
org.springframework.geode.boot.autoconfigure.SpringSessionPropertiesAutoConfiguration,\
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 example.library.service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import example.app.model.Author;
|
||||
import example.app.model.Book;
|
||||
|
||||
/**
|
||||
* The LibraryService class...
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Service
|
||||
@SuppressWarnings("unused")
|
||||
public class LibraryService {
|
||||
|
||||
@Cacheable("BooksByAuthor")
|
||||
public List<Book> findBooksByAuthor(Author author) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Cacheable("BooksByYear")
|
||||
public List<Book> findBooksByYear(int year) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.template;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions;
|
||||
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import example.app.NonBeanType;
|
||||
import example.app.model.Author;
|
||||
import example.app.model.Book;
|
||||
import example.library.service.LibraryService;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RegionTemplateAutoConfiguration} using SDG's {@link EnableCachingDefinedRegions}
|
||||
* annotation to define {@link Region Regions} and associated Templates.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.data.gemfire.GemfireTemplate
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SuppressWarnings("unused")
|
||||
public class CachingDefinedRegionTemplateAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private GemFireCache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("booksByAuthorTemplate")
|
||||
private GemfireTemplate booksByAuthorTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("cachedBooksTemplate")
|
||||
private GemfireTemplate booksByTitleTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("booksByYearTemplate")
|
||||
private GemfireTemplate booksByYearTemplate;
|
||||
|
||||
@Resource(name = "BooksByAuthor")
|
||||
private Region<Author, List<Book>> booksByAuthor;
|
||||
|
||||
@Resource(name = "CachedBooks")
|
||||
private Region<String, Book> booksByTitle;
|
||||
|
||||
@Resource(name = "BooksByYear")
|
||||
private Region<Integer, List<Book>> booksByYear;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
assertThat(this.gemfireCache).isNotNull();
|
||||
|
||||
assertThat(this.gemfireCache.rootRegions().stream()
|
||||
.map(Region::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList())).containsExactly("BooksByAuthor", "BooksByYear", "CachedBooks");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authorsBooksRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.booksByAuthorTemplate).isNotNull();
|
||||
assertThat(this.booksByAuthorTemplate.getRegion()).isEqualTo(this.booksByAuthor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booksByTitleRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.booksByTitleTemplate).isNotNull();
|
||||
assertThat(this.booksByTitleTemplate.getRegion()).isEqualTo(this.booksByTitle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booksByYearRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.booksByYearTemplate).isNotNull();
|
||||
assertThat(this.booksByYearTemplate.getRegion()).isEqualTo(this.booksByYear);
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL)
|
||||
@SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class,
|
||||
scanBasePackageClasses = { NonBeanType.class, LibraryService.class })
|
||||
static class TestApplicationConfiguration {
|
||||
|
||||
@Bean
|
||||
LibraryService libraryService() {
|
||||
return new LibraryService();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.template;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RegionTemplateAutoConfiguration} using explicitly declared {@link Region}
|
||||
* bean definitions in a Spring {@link ApplicationContext}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.data.gemfire.GemfireTemplate
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SuppressWarnings("unused")
|
||||
public class DeclaredRegionTemplateAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("exampleTemplate")
|
||||
private GemfireTemplate exampleTemplate;
|
||||
|
||||
@Resource(name = "Example")
|
||||
private Region<Long, String> exampleRegion;
|
||||
|
||||
@Test
|
||||
public void exampleRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.exampleTemplate).isNotNull();
|
||||
assertThat(this.exampleTemplate.getRegion()).isEqualTo(this.exampleRegion);
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class)
|
||||
static class TestGemFireConfiguration {
|
||||
|
||||
@Bean("Example")
|
||||
ClientRegionFactoryBean<Long, String> exampleRegion(GemFireCache gemfireCache) {
|
||||
|
||||
ClientRegionFactoryBean<Long, String> exampleRegion = new ClientRegionFactoryBean<>();
|
||||
|
||||
exampleRegion.setCache(gemfireCache);
|
||||
exampleRegion.setShortcut(ClientRegionShortcut.LOCAL);
|
||||
|
||||
return exampleRegion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.template;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions;
|
||||
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import example.app.model.Author;
|
||||
import example.app.model.Book;
|
||||
import example.app.model.ISBN;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RegionTemplateAutoConfiguration} using SDG's {@link EnableEntityDefinedRegions}
|
||||
* annotation to define {@link Region Regions} and associated Templates.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.data.gemfire.GemfireTemplate
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SuppressWarnings("unused")
|
||||
public class EntityDefinedRegionTemplateAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("authorsTemplate")
|
||||
private GemfireTemplate authorsTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("booksTemplate")
|
||||
private GemfireTemplate booksTemplate;
|
||||
|
||||
@Resource(name = "Authors")
|
||||
private Region<Long, Author> authors;
|
||||
|
||||
@Resource(name = "Books")
|
||||
private Region<ISBN, Book> books;
|
||||
|
||||
@Test
|
||||
public void authorsRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.authorsTemplate).isNotNull();
|
||||
assertThat(this.authorsTemplate.getRegion()).isEqualTo(this.authors);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booksRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.booksTemplate).isNotNull();
|
||||
assertThat(this.booksTemplate.getRegion()).isEqualTo(this.books);
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class)
|
||||
@EnableEntityDefinedRegions(basePackageClasses = Book.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
|
||||
static class TestApplicationConfiguration { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.template;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableGemFireProperties;
|
||||
import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RegionTemplateAutoConfiguration} using natively declared {@link Region}
|
||||
* definitions in GemFire/Geode {@literal cache.xml}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableGemFireProperties
|
||||
* @see org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SuppressWarnings("unused")
|
||||
public class NativeDefinedRegionTemplateAutoConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private GemfireTemplate exampleTemplate;
|
||||
|
||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||
public void exampleRegionBeanIsNotPresent() {
|
||||
this.applicationContext.getBean("Example", Region.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleRegionTemplateIsPresent() {
|
||||
|
||||
assertThat(this.exampleTemplate).isNotNull();
|
||||
assertThat(this.exampleTemplate.getRegion()).isNotNull();
|
||||
assertThat(this.exampleTemplate.getRegion().getName()).isEqualTo("Example");
|
||||
}
|
||||
|
||||
@EnableGemFireProperties(cacheXmlFile = "template-cache.xml")
|
||||
@SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class)
|
||||
static class TestConfiguration { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.template;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.LocalRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RegionTemplateAutoConfiguration} using SDG's {@link EnableServerDefinedRegions}
|
||||
* annotation to define {@link Region Regions} and associated Templates.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.data.gemfire.GemfireTemplate
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableServerDefinedRegions
|
||||
* @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport
|
||||
* @see org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Ignore
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
|
||||
classes = ServerDefinedRegionTemplateAutoConfigurationIntegrationTests.GemFireClientConfiguration.class)
|
||||
// TODO enable and complete test class when SBDG is rebased on SD Lovelace
|
||||
public class ServerDefinedRegionTemplateAutoConfigurationIntegrationTests
|
||||
extends ForkingClientServerIntegrationTestsSupport {
|
||||
|
||||
@BeforeClass
|
||||
public static void startGemFireServer() throws IOException {
|
||||
startGemFireServer(GemFireServerConfiguration.class);
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
//@EnableServerDefinedRegions
|
||||
static class GemFireClientConfiguration { }
|
||||
|
||||
@CacheServerApplication
|
||||
static class GemFireServerConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(GemFireServerConfiguration.class);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
}
|
||||
|
||||
@Bean("ExampleServerRegion")
|
||||
LocalRegionFactoryBean<Object, Object> exampleServerRegion(GemFireCache gemfireCache) {
|
||||
|
||||
LocalRegionFactoryBean<Object, Object> exampleServerRegion = new LocalRegionFactoryBean<>();
|
||||
|
||||
exampleServerRegion.setCache(gemfireCache);
|
||||
exampleServerRegion.setClose(false);
|
||||
exampleServerRegion.setPersistent(false);
|
||||
|
||||
return exampleServerRegion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<client-cache xmlns="http://geode.apache.org/schema/cache"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
|
||||
version="1.0">
|
||||
|
||||
<region name="Example" refid="LOCAL"/>
|
||||
|
||||
</client-cache>
|
||||
Reference in New Issue
Block a user