DATAGEODE-271 - Cannot enable the BeanFactoryLocator for a ClientCache instance using SDG property.
This commit is contained in:
@@ -351,6 +351,7 @@ public abstract class AbstractCacheConfiguration extends AbstractAnnotationConfi
|
||||
gemfireCache.setProperties(gemfireProperties());
|
||||
gemfireCache.setTransactionListeners(getTransactionListeners());
|
||||
gemfireCache.setTransactionWriter(getTransactionWriter());
|
||||
gemfireCache.setUseBeanFactoryLocator(useBeanFactoryLocator());
|
||||
|
||||
return gemfireCache;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -21,6 +20,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
|
||||
|
||||
/**
|
||||
@@ -33,6 +33,9 @@ import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
* @see org.springframework.context.annotation.Configuration
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer
|
||||
* @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator
|
||||
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
|
||||
* @since 2.0.0
|
||||
@@ -42,19 +45,19 @@ import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
|
||||
public class BeanFactoryLocatorConfiguration {
|
||||
|
||||
/**
|
||||
* Declares and registers a Spring {@link BeanPostProcessor} and post processes a Spring Data GemFire/Geode
|
||||
* {@link CacheFactoryBean} by setting the {@literal useBeanFactoryLocator} property to {@literal true}.
|
||||
* Declares and registers a Spring {@link BeanPostProcessor} bean to post process a Spring Data Geode
|
||||
* {@link CacheFactoryBean} or {@link ClientCacheFactoryBean} by setting the {@literal useBeanFactoryLocator}
|
||||
* property to {@literal true}.
|
||||
*
|
||||
* @return a Spring {@link BeanPostProcessor} used to post process the SDG {@link CacheFactoryBean}.
|
||||
* @return a Spring {@link BeanPostProcessor} used to post process an SDG {@link CacheFactoryBean}.
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor
|
||||
*/
|
||||
@Bean
|
||||
public BeanPostProcessor cacheFactoryBeanPostProcessor() {
|
||||
public BeanPostProcessor useBeanFactoryLocatorBeanPostProcessor() {
|
||||
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
if (bean instanceof CacheFactoryBean) {
|
||||
@@ -65,4 +68,30 @@ public class BeanFactoryLocatorConfiguration {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares and registers a {@link ClientCacheConfigurer} bean to configure a {@link ClientCacheFactoryBean}
|
||||
* by setting the {@literal useBeanFactoryLocator} property to {@literal true}.
|
||||
*
|
||||
* @return a {@link ClientCacheConfigurer} used to configure and set the SDG {@link ClientCacheFactoryBean}'s
|
||||
* {@literal useBeanFactoryLocator} property to {@literal true}.
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer
|
||||
*/
|
||||
@Bean
|
||||
public ClientCacheConfigurer useBeanFactoryLocatorClientCacheConfigurer() {
|
||||
return (beanName, bean) -> bean.setUseBeanFactoryLocator(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares and registers a {@link PeerCacheConfigurer} bean to configure a {@link CacheFactoryBean}
|
||||
* by setting the {@literal useBeanFactoryLocator} property to {@literal true}.
|
||||
*
|
||||
* @return a {@link PeerCacheConfigurer} used to configure and set the SDG {@link CacheFactoryBean}'s
|
||||
* {@literal useBeanFactoryLocator} property to {@literal true}.
|
||||
* @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
|
||||
*/
|
||||
@Bean
|
||||
public PeerCacheConfigurer useBeanFactoryLocatorPeerCacheConfigurer() {
|
||||
return (beanName, bean) -> bean.setUseBeanFactoryLocator(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
|
||||
@@ -90,7 +90,6 @@ public class PeerCacheConfiguration extends AbstractCacheConfiguration {
|
||||
gemfireCache.setMessageSyncInterval(messageSyncInterval());
|
||||
gemfireCache.setPeerCacheConfigurers(resolvePeerCacheConfigurers());
|
||||
gemfireCache.setSearchTimeout(searchTimeout());
|
||||
gemfireCache.setUseBeanFactoryLocator(useBeanFactoryLocator());
|
||||
gemfireCache.setUseClusterConfiguration(useClusterConfiguration());
|
||||
|
||||
return gemfireCache;
|
||||
|
||||
@@ -105,7 +105,6 @@ public class CacheServerFactoryBean extends AbstractFactoryBeanSupport<CacheServ
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSet() throws IOException {
|
||||
|
||||
applyCacheServerConfigurers();
|
||||
|
||||
@@ -13,20 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientCache;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
@@ -35,7 +34,7 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link AbstractCacheConfiguration}.
|
||||
* Integration Tests for {@link AbstractCacheConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -75,8 +74,8 @@ public class AbstractCacheConfigurationIntegrationTests {
|
||||
propertySources.addFirst(testPropertySource);
|
||||
});
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.refresh();
|
||||
|
||||
return applicationContext;
|
||||
@@ -130,11 +129,10 @@ public class AbstractCacheConfigurationIntegrationTests {
|
||||
|
||||
@ClientCacheApplication
|
||||
@EnableGemFireMockObjects
|
||||
static class TestClientCacheConfiguration {
|
||||
}
|
||||
static class TestClientCacheConfiguration { }
|
||||
|
||||
@PeerCacheApplication(name = "TestPeerCacheApp")
|
||||
@EnableGemFireMockObjects
|
||||
static class TestPeerCacheConfiguration {
|
||||
}
|
||||
@PeerCacheApplication(name = "TestPeerCacheApp")
|
||||
static class TestPeerCacheConfiguration { }
|
||||
|
||||
}
|
||||
|
||||
@@ -14,12 +14,18 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration.DEFAULT_MCAST_PORT;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -27,16 +33,26 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.apache.geode.cache.TransactionListener;
|
||||
import org.apache.geode.cache.TransactionWriter;
|
||||
import org.apache.geode.cache.util.GatewayConflictResolver;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractCacheConfiguration}.
|
||||
* Unit Tests for {@link AbstractCacheConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.Spy
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@@ -65,4 +81,58 @@ public class AbstractCacheConfigurationUnitTests {
|
||||
assertThat(gemfireProperties.getProperty("locators")).isEqualTo("skullbox[11235]");
|
||||
assertThat(gemfireProperties.getProperty("start-locator")).isEqualTo("boombox[12480]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheFactoryBeanConfigurationIsCorrect() {
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = mock(CacheFactoryBean.class);
|
||||
|
||||
ClassLoader testBeanClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class);
|
||||
|
||||
List<CacheFactoryBean.JndiDataSource> jndiDataSources = Collections.emptyList();
|
||||
List<TransactionListener> transactionListeners = Collections.singletonList(mock(TransactionListener.class));
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
Resource mockResource = mock(Resource.class);
|
||||
|
||||
TransactionWriter mockTransactionWriter = mock(TransactionWriter.class);
|
||||
|
||||
doReturn(gemfireProperties).when(this.cacheConfiguration).gemfireProperties();
|
||||
|
||||
this.cacheConfiguration.setBeanClassLoader(testBeanClassLoader);
|
||||
this.cacheConfiguration.setBeanFactory(mockBeanFactory);
|
||||
this.cacheConfiguration.setCacheXml(mockResource);
|
||||
this.cacheConfiguration.setClose(false);
|
||||
this.cacheConfiguration.setCopyOnRead(true);
|
||||
this.cacheConfiguration.setCriticalHeapPercentage(0.90f);
|
||||
this.cacheConfiguration.setCriticalOffHeapPercentage(0.85f);
|
||||
this.cacheConfiguration.setEvictionHeapPercentage(0.75f);
|
||||
this.cacheConfiguration.setEvictionOffHeapPercentage(0.55f);
|
||||
this.cacheConfiguration.setGatewayConflictResolver(mockGatewayConflictResolver);
|
||||
this.cacheConfiguration.setJndiDataSources(jndiDataSources);
|
||||
this.cacheConfiguration.setTransactionListeners(transactionListeners);
|
||||
this.cacheConfiguration.setTransactionWriter(mockTransactionWriter);
|
||||
this.cacheConfiguration.setUseBeanFactoryLocator(true);
|
||||
|
||||
assertThat(this.cacheConfiguration.configureCacheFactoryBean(cacheFactoryBean)).isEqualTo(cacheFactoryBean);
|
||||
|
||||
verify(cacheFactoryBean, times(1)).setBeanClassLoader(eq(testBeanClassLoader));
|
||||
verify(cacheFactoryBean, times(1)).setBeanFactory(eq(mockBeanFactory));
|
||||
verify(cacheFactoryBean, times(1)).setClose(eq(false));
|
||||
verify(cacheFactoryBean, times(1)).setCopyOnRead(eq(true));
|
||||
verify(cacheFactoryBean, times(1)).setCriticalHeapPercentage(eq(0.90f));
|
||||
verify(cacheFactoryBean, times(1)).setCriticalOffHeapPercentage(eq(0.85f));
|
||||
verify(cacheFactoryBean, times(1)).setEvictionHeapPercentage(eq(0.75f));
|
||||
verify(cacheFactoryBean, times(1)).setEvictionOffHeapPercentage(eq(0.55f));
|
||||
verify(cacheFactoryBean, times(1)).setGatewayConflictResolver(eq(mockGatewayConflictResolver));
|
||||
verify(cacheFactoryBean, times(1)).setJndiDataSources(eq(jndiDataSources));
|
||||
verify(cacheFactoryBean, times(1)).setTransactionListeners(eq(transactionListeners));
|
||||
verify(cacheFactoryBean, times(1)).setTransactionWriter(eq(mockTransactionWriter));
|
||||
verify(cacheFactoryBean, times(1)).setUseBeanFactoryLocator(eq(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -22,15 +21,15 @@ import static org.mockito.Mockito.mock;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.client.ClientCache;
|
||||
import org.apache.geode.cache.client.Pool;
|
||||
import org.apache.geode.cache.client.PoolFactory;
|
||||
import org.apache.geode.cache.control.ResourceManager;
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -41,11 +40,13 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ClientCacheApplication}.
|
||||
* Integration Tests for {@link ClientCacheApplication}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.apache.geode.cache.client.Pool
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
@@ -103,6 +104,12 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue();
|
||||
|
||||
ClientCacheFactoryBean testClientCacheFactoryBean =
|
||||
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(testClientCacheFactoryBean).isNotNull();
|
||||
assertThat(testClientCacheFactoryBean.isUseBeanFactoryLocator()).isFalse();
|
||||
|
||||
ClientCache testClientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
|
||||
|
||||
assertThat(testClientCache).isNotNull();
|
||||
@@ -153,6 +160,7 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
public void dynamicClientCacheConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
.withProperty("spring.data.gemfire.use-bean-factory-locator", true)
|
||||
.withProperty("spring.data.gemfire.cache.copy-on-read", true)
|
||||
.withProperty("spring.data.gemfire.cache.critical-heap-percentage", 90.0f)
|
||||
.withProperty("spring.data.gemfire.cache.eviction-heap-percentage", 75.0f)
|
||||
@@ -191,19 +199,24 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue();
|
||||
|
||||
PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(clientCacheFactoryBean).isNotNull();
|
||||
|
||||
ClientCache clientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
|
||||
|
||||
assertThat(clientCache).isNotNull();
|
||||
|
||||
PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
|
||||
assertThat(mockPdxSerializer).isNotNull();
|
||||
assertThat(clientCacheFactoryBean).isNotNull();
|
||||
assertThat(clientCacheFactoryBean.getDurableClientId()).isEqualTo("123");
|
||||
assertThat(clientCacheFactoryBean.getDurableClientTimeout()).isEqualTo(600);
|
||||
assertThat(clientCacheFactoryBean.getUseClusterConfiguration()).isFalse();
|
||||
assertThat(clientCacheFactoryBean.isKeepAlive()).isTrue();
|
||||
assertThat(clientCacheFactoryBean.isReadyForEvents()).isTrue();
|
||||
assertThat(clientCacheFactoryBean.isUseBeanFactoryLocator()).isTrue();
|
||||
assertThat(clientCache).isNotNull();
|
||||
assertThat(clientCache.getCopyOnRead()).isTrue();
|
||||
assertThat(clientCache.getDistributedSystem()).isNotNull();
|
||||
@@ -249,7 +262,7 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(75.0f);
|
||||
}
|
||||
|
||||
// TODO add more tests!
|
||||
// TODO add more tests
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@ClientCacheApplication(name = "TestClientCache", copyOnRead = true,
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -26,15 +25,17 @@ import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
|
||||
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects;
|
||||
|
||||
/**
|
||||
* Integration test for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}.
|
||||
* Integration Tests for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator
|
||||
* @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects
|
||||
@@ -46,19 +47,27 @@ public class EnableBeanFactoryLocatorConfigurationIntegrationTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
Optional.ofNullable(this.applicationContext).
|
||||
ifPresent(ConfigurableApplicationContext::close);
|
||||
|
||||
GemfireBeanFactoryLocator.clear();
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
|
||||
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(annotatedClasses);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireBeanFactoryLocatorIsDisabled() {
|
||||
private <T extends CacheFactoryBean> void testGemFireCacheBeanFactoryLocator(Class<?> configuration,
|
||||
Class<T> cacheFactoryBeanType, boolean beanFactoryLocatorEnabled) {
|
||||
|
||||
this.applicationContext = newApplicationContext(TestBeanFactoryLocatorDisabledConfiguration.class);
|
||||
this.applicationContext = newApplicationContext(configuration);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -66,31 +75,50 @@ public class EnableBeanFactoryLocatorConfigurationIntegrationTests {
|
||||
CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.isUseBeanFactoryLocator()).isFalse();
|
||||
assertThat(gemfireCache).isInstanceOf(cacheFactoryBeanType);
|
||||
assertThat(gemfireCache.isUseBeanFactoryLocator()).isEqualTo(beanFactoryLocatorEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireBeanFactoryLocatorIsEnabled() {
|
||||
|
||||
this.applicationContext = newApplicationContext(TestBeanFactoryLocatorEnabledConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
|
||||
CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.isUseBeanFactoryLocator()).isTrue();
|
||||
public void gemfireClientCacheBeanFactoryLocatorIsDisabled() {
|
||||
testGemFireCacheBeanFactoryLocator(TestClientCacheBeanFactoryLocatorDisabledConfiguration.class,
|
||||
CacheFactoryBean.class, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfireClientCacheBeanFactoryLocatorIsEnabled() {
|
||||
testGemFireCacheBeanFactoryLocator(TestClientCacheBeanFactoryLocatorEnabledConfiguration.class,
|
||||
CacheFactoryBean.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfirePeerCacheBeanFactoryLocatorIsDisabled() {
|
||||
testGemFireCacheBeanFactoryLocator(TestPeerCacheBeanFactoryLocatorDisabledConfiguration.class,
|
||||
CacheFactoryBean.class, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gemfirePeerCacheBeanFactoryLocatorIsEnabled() {
|
||||
testGemFireCacheBeanFactoryLocator(TestPeerCacheBeanFactoryLocatorEnabledConfiguration.class,
|
||||
CacheFactoryBean.class, true);
|
||||
}
|
||||
|
||||
@ClientCacheApplication
|
||||
@EnableGemFireMockObjects
|
||||
static class TestClientCacheBeanFactoryLocatorDisabledConfiguration { }
|
||||
|
||||
@ClientCacheApplication
|
||||
@EnableBeanFactoryLocator
|
||||
@EnableGemFireMockObjects
|
||||
static class TestClientCacheBeanFactoryLocatorEnabledConfiguration { }
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@PeerCacheApplication
|
||||
static class TestBeanFactoryLocatorDisabledConfiguration {
|
||||
}
|
||||
static class TestPeerCacheBeanFactoryLocatorDisabledConfiguration { }
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@EnableBeanFactoryLocator
|
||||
@PeerCacheApplication
|
||||
static class TestBeanFactoryLocatorEnabledConfiguration {
|
||||
}
|
||||
static class TestPeerCacheBeanFactoryLocatorEnabledConfiguration { }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
|
||||
/**
|
||||
* Unit Tests for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator
|
||||
* @since 2.2.1
|
||||
*/
|
||||
public class EnableBeanFactoryLocatorConfigurationUnitTests {
|
||||
|
||||
private BeanFactoryLocatorConfiguration configuration = new BeanFactoryLocatorConfiguration();
|
||||
|
||||
private void testUseBeanFactoryLocatorBeanPostProcessorProcessesBean(Object cacheBean) {
|
||||
|
||||
BeanPostProcessor beanPostProcessor = this.configuration.useBeanFactoryLocatorBeanPostProcessor();
|
||||
|
||||
assertThat(beanPostProcessor).isNotNull();
|
||||
assertThat(beanPostProcessor.postProcessBeforeInitialization(cacheBean, "TestCache"))
|
||||
.isEqualTo(cacheBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useBeanFactoryLocatorBeanPostProcessorProcessesCacheFactoryBean() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isFalse();
|
||||
|
||||
testUseBeanFactoryLocatorBeanPostProcessorProcessesBean(cacheFactoryBean);
|
||||
|
||||
assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useBeanFactoryLocatorBeanPostProcessorProcessesClientCacheFactoryBean() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.isUseBeanFactoryLocator()).isFalse();
|
||||
|
||||
testUseBeanFactoryLocatorBeanPostProcessorProcessesBean(clientCacheFactoryBean);
|
||||
|
||||
assertThat(clientCacheFactoryBean.isUseBeanFactoryLocator()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useBeanFactoryLocatorClientCacheConfigurerIsCorrect() throws Exception {
|
||||
|
||||
ClientCacheFactoryBean factoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(factoryBean.isUseBeanFactoryLocator()).isFalse();
|
||||
|
||||
factoryBean.setClientCacheConfigurers(this.configuration.useBeanFactoryLocatorClientCacheConfigurer());
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(factoryBean.isUseBeanFactoryLocator()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useBeanFactoryLocatorPeerCacheConfigurerIsCorrect() throws Exception {
|
||||
|
||||
CacheFactoryBean factoryBean = new CacheFactoryBean();
|
||||
|
||||
assertThat(factoryBean.isUseBeanFactoryLocator()).isFalse();
|
||||
|
||||
factoryBean.setPeerCacheConfigurers(this.configuration.useBeanFactoryLocatorPeerCacheConfigurer());
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(factoryBean.isUseBeanFactoryLocator()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,13 @@ import static org.mockito.Mockito.mock;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.control.ResourceManager;
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -38,14 +38,16 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link PeerCacheApplication}.
|
||||
* Integration Tests for {@link PeerCacheApplication}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication
|
||||
* @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.mock.env.MockPropertySource
|
||||
@@ -58,9 +60,7 @@ public class PeerCachePropertiesIntegrationTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
Optional.ofNullable(this.applicationContext)
|
||||
.ifPresent(ConfigurableApplicationContext::close);
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
@@ -175,7 +175,7 @@ public class PeerCachePropertiesIntegrationTests {
|
||||
assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(80.0f);
|
||||
}
|
||||
|
||||
//TODO add more tests
|
||||
// TODO add more tests
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@EnablePdx(ignoreUnreadFields = true, readSerialized = true, serializerBeanName = "mockPdxSerializer")
|
||||
|
||||
Reference in New Issue
Block a user