From a64a89e3577e49eb735baaa97ec6396e46b79b1e Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 3 Mar 2014 13:06:33 -0800 Subject: [PATCH] General test code cleanup and optimizations along with other code refactoring. --- .../RegionEvictionAttributesNamespaceTest.java | 8 ++++---- ...mfireTestApplicationContextInitializer.java | 9 +++++++-- .../test/GemfireTestBeanPostProcessor.java | 18 ++++++++++-------- .../test/StubAsyncEventQueueFactory.java | 4 +++- ...cEventQueueWithListenerIntegrationTest.java | 4 +++- .../regions-with-eviction-attributes-ns.xml | 12 ++++++------ .../data/gemfire/lookupSubRegion.xml | 2 -- .../repository/sample/subregionRepository.xml | 2 -- .../userRepositoryQueriesIntegrationTest.xml | 2 -- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java index cc65ab53..11842fae 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java @@ -117,17 +117,17 @@ public class RegionEvictionAttributesNamespaceTest { public void testMemorySizeRegionEvictionAttributes() { assertNotNull(five); assertNotNull(five.getAttributes()); - assertEquals(DataPolicy.REPLICATE, five.getAttributes().getDataPolicy()); + assertEquals(DataPolicy.PARTITION, five.getAttributes().getDataPolicy()); assertNotNull(five.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAction.OVERFLOW_TO_DISK, five.getAttributes().getEvictionAttributes().getAction()); + assertEquals(EvictionAction.LOCAL_DESTROY, five.getAttributes().getEvictionAttributes().getAction()); assertEquals(EvictionAlgorithm.LRU_MEMORY, five.getAttributes().getEvictionAttributes().getAlgorithm()); assertEquals(85, five.getAttributes().getEvictionAttributes().getMaximum()); assertNotNull(six); assertNotNull(six.getAttributes()); - assertEquals(DataPolicy.PARTITION, six.getAttributes().getDataPolicy()); + assertEquals(DataPolicy.REPLICATE, six.getAttributes().getDataPolicy()); assertNotNull(six.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAction.LOCAL_DESTROY, six.getAttributes().getEvictionAttributes().getAction()); + assertEquals(EvictionAction.OVERFLOW_TO_DISK, six.getAttributes().getEvictionAttributes().getAction()); assertEquals(EvictionAlgorithm.LRU_MEMORY, six.getAttributes().getEvictionAttributes().getAlgorithm()); if (six.getAttributes().getEvictionAttributes() instanceof EvictionAttributesImpl) { diff --git a/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java b/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java index 29f4e067..e6606181 100644 --- a/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java +++ b/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java @@ -22,7 +22,9 @@ import org.springframework.util.StringUtils; * */ public class GemfireTestApplicationContextInitializer implements ApplicationContextInitializer { + private static Log logger = LogFactory.getLog(GemfireTestApplicationContextInitializer.class); + public static final String GEMFIRE_TEST_RUNNER_DISABLED = "org.springframework.data.gemfire.test.GemfireTestRunner.nomock"; /* (non-Javadoc) @@ -32,11 +34,14 @@ public class GemfireTestApplicationContextInitializer implements ApplicationCont public void initialize(ConfigurableApplicationContext applicationContext) { if (StringUtils.hasText(System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED))) { String value = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED); - if (!(value.equalsIgnoreCase("NO") || value.equalsIgnoreCase("FALSE"))) { - logger.warn("Mocks disabled. Using real GemFire components:" + GEMFIRE_TEST_RUNNER_DISABLED + " = " + value); + + if (!("NO".equalsIgnoreCase(value) || "FALSE".equalsIgnoreCase(value))) { + logger.warn(String.format("Mocks disabled. Using real GemFire components: %1$s = %2$s", + GEMFIRE_TEST_RUNNER_DISABLED, value)); return; } } + applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor()); } diff --git a/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java b/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java index 5f8e2948..50222e06 100644 --- a/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java +++ b/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java @@ -22,26 +22,28 @@ import org.springframework.data.gemfire.server.CacheServerFactoryBean; /** * @author David Turanski - * */ public class GemfireTestBeanPostProcessor implements BeanPostProcessor { + private static Log logger = LogFactory.getLog(GemfireTestBeanPostProcessor.class); + /* (non-Javadoc) * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) */ @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof CacheFactoryBean) { - - bean = (bean instanceof ClientCacheFactoryBean)? - new MockClientCacheFactoryBean((ClientCacheFactoryBean)bean): - new MockCacheFactoryBean((CacheFactoryBean)bean); - logger.info(String.format("replacing '%s' definition with type %s", - beanName, bean.getClass().getName())); + bean = (bean instanceof ClientCacheFactoryBean + ? new MockClientCacheFactoryBean((ClientCacheFactoryBean) bean) + : new MockCacheFactoryBean((CacheFactoryBean) bean)); + + logger.info(String.format("Replacing the '%1$s' bean definition having type '%2$s' with mock...", + beanName, bean.getClass().getName())); } else if (bean instanceof CacheServerFactoryBean) { - ((CacheServerFactoryBean)bean).setCache(new StubCache()); + ((CacheServerFactoryBean) bean).setCache(new StubCache()); } + return bean; } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java index caf84acf..f982d387 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java @@ -19,6 +19,7 @@ import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener; import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueueFactory; import com.gemstone.gemfire.cache.util.Gateway.OrderPolicy; +import com.gemstone.gemfire.cache.wan.GatewaySender; /** * @author David Turanski @@ -43,7 +44,7 @@ public class StubAsyncEventQueueFactory implements AsyncEventQueueFactory { private boolean batchConflationEnabled; - private int dispatcherThreads; + private int dispatcherThreads = GatewaySender.DEFAULT_DISPATCHER_THREADS; private OrderPolicy orderPolicy; @@ -66,6 +67,7 @@ public class StubAsyncEventQueueFactory implements AsyncEventQueueFactory { when(asyncEventQueue.getBatchTimeInterval()).thenReturn(this.batchTimeInterval); when(asyncEventQueue.getOrderPolicy()).thenReturn(this.orderPolicy); when(asyncEventQueue.getDispatcherThreads()).thenReturn(this.dispatcherThreads); + return this.asyncEventQueue; } diff --git a/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java index 05bd7528..bb207f71 100644 --- a/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java @@ -27,6 +27,7 @@ import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; @@ -49,7 +50,8 @@ import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; * @see com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue * @since 1.0.0 */ -@ContextConfiguration("asyncEventQueueWithListener.xml") +@ContextConfiguration(value = "asyncEventQueueWithListener.xml", + initializers = GemfireTestApplicationContextInitializer.class) @RunWith(SpringJUnit4ClassRunner.class) @SuppressWarnings("unused") public class AsyncEventQueueWithListenerIntegrationTest { diff --git a/src/test/resources/org/springframework/data/gemfire/config/regions-with-eviction-attributes-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/regions-with-eviction-attributes-ns.xml index 51420b42..8e117f96 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/regions-with-eviction-attributes-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/regions-with-eviction-attributes-ns.xml @@ -25,12 +25,12 @@ - - - - - - + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/lookupSubRegion.xml b/src/test/resources/org/springframework/data/gemfire/lookupSubRegion.xml index 2ed2e4cf..51fb4f06 100644 --- a/src/test/resources/org/springframework/data/gemfire/lookupSubRegion.xml +++ b/src/test/resources/org/springframework/data/gemfire/lookupSubRegion.xml @@ -11,10 +11,8 @@ springGemFireLookupSubRegionTest - localhost[11235] config 0 - localhost[11235] diff --git a/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml b/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml index 9b4a03d3..613d4fce 100644 --- a/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml +++ b/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml @@ -13,10 +13,8 @@ cacheInitializationTest - localhost[11235] config 0 - localhost[11235] diff --git a/src/test/resources/org/springframework/data/gemfire/repository/sample/userRepositoryQueriesIntegrationTest.xml b/src/test/resources/org/springframework/data/gemfire/repository/sample/userRepositoryQueriesIntegrationTest.xml index 332a09ea..9afaac4f 100644 --- a/src/test/resources/org/springframework/data/gemfire/repository/sample/userRepositoryQueriesIntegrationTest.xml +++ b/src/test/resources/org/springframework/data/gemfire/repository/sample/userRepositoryQueriesIntegrationTest.xml @@ -13,10 +13,8 @@ repositoryQueriesTest - localhost[11235] config 0 - localhost[11235]