General test code cleanup and optimizations along with other code refactoring.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -22,7 +22,9 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
*/
|
||||
public class GemfireTestApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
<gfe:eviction type="HEAP_PERCENTAGE" action="OVERFLOW_TO_DISK"/>
|
||||
</gfe:partitioned-region>
|
||||
|
||||
<gfe:replicated-region id="Five">
|
||||
<gfe:eviction threshold="85" type="MEMORY_SIZE" action="OVERFLOW_TO_DISK"/>
|
||||
</gfe:replicated-region>
|
||||
|
||||
<gfe:partitioned-region id="Six">
|
||||
<gfe:eviction type="MEMORY_SIZE"/>
|
||||
<gfe:partitioned-region id="Five">
|
||||
<gfe:eviction threshold="85" type="MEMORY_SIZE" action="LOCAL_DESTROY"/>
|
||||
</gfe:partitioned-region>
|
||||
|
||||
<gfe:replicated-region id="Six">
|
||||
<gfe:eviction type="MEMORY_SIZE"/>
|
||||
</gfe:replicated-region>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -11,10 +11,8 @@
|
||||
|
||||
<util:properties id="peerCacheConfigurationSettings">
|
||||
<prop key="name">springGemFireLookupSubRegionTest</prop>
|
||||
<prop key="locators">localhost[11235]</prop>
|
||||
<prop key="log-level">config</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="start-locator">localhost[11235]</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache cache-xml-location="/subregion-cache.xml" properties-ref="peerCacheConfigurationSettings"/>
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
|
||||
<util:properties id="peerCacheConfigurationSettings">
|
||||
<prop key="name">cacheInitializationTest</prop>
|
||||
<prop key="locators">localhost[11235]</prop>
|
||||
<prop key="log-level">config</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="start-locator">localhost[11235]</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache properties-ref="peerCacheConfigurationSettings"/>
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
|
||||
<util:properties id="peerCacheConfigurationSettings">
|
||||
<prop key="name">repositoryQueriesTest</prop>
|
||||
<prop key="locators">localhost[11235]</prop>
|
||||
<prop key="log-level">config</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="start-locator">localhost[11235]</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache/>
|
||||
|
||||
Reference in New Issue
Block a user