INT-4176: Fix Gemfire tests

JIRA: https://jira.spring.io/browse/INT-4176

The `DelayerHandlerRescheduleIntegrationTests` doesn't close `context` in the end of test.
That causes clashes for `beanFactoryResolver` in other tests.
When those tests are fail, we come into condition when new processes can't be started/stopped because of effect of non-stopped context

* Fix all the `DelayerHandlerRescheduleIntegrationTests` to stop `context` in the end of test
* Remove unused files in the `gemfire/store` test package
* Add current date value to the `CacheServerProcess` name to avoid clashes with other ran on the same host
* Add NPE check for `region` in the `GemfireMetadataStoreTests`
* Extract `@BeforeClass/@AfterClass` for the `CacheWritingMessageHandlerTests` to start only one Gemfire cache per class

**Cherry-pick to 4.3.x & 4.2.x**
This commit is contained in:
Artem Bilan
2016-11-30 14:03:09 -05:00
committed by Gary Russell
parent 85730bfe60
commit 9078a74a19
10 changed files with 64 additions and 92 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.gemfire.fork;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Properties;
import org.apache.commons.logging.Log;
@@ -51,7 +52,7 @@ public class CacheServerProcess {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty("name", "CacheServer");
props.setProperty("name", "CacheServer at " + new Date());
props.setProperty("log-level", "info");
logger.info("Connecting to the distributed system and creating the cache.");
@@ -75,6 +76,6 @@ public class CacheServerProcess {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine();
}
}

View File

@@ -41,19 +41,24 @@ import com.gemstone.gemfire.cache.Region;
*/
public class GemfireMetadataStoreTests {
public static Cache cache;
private static Cache cache;
public static ConcurrentMetadataStore metadataStore;
private static ConcurrentMetadataStore metadataStore;
private static Region<Object, Object> region;
@BeforeClass
public static void startUp() throws Exception {
cache = new CacheFactory().create();
metadataStore = new GemfireMetadataStore(cache);
region = cache.getRegion(GemfireMetadataStore.KEY);
}
@AfterClass
public static void cleanUp() {
getRegion().close();
if (region != null) {
region.close();
}
if (cache != null) {
cache.close();
Assert.isTrue(cache.isClosed(), "Cache did not close after close() call");
@@ -63,7 +68,9 @@ public class GemfireMetadataStoreTests {
@Before
@After
public void setup() {
getRegion().clear();
if (region != null) {
region.clear();
}
}
@Test
@@ -76,7 +83,7 @@ public class GemfireMetadataStoreTests {
public void testPersistKeyValue() {
metadataStore.put("GemfireMetadataStoreTests-Spring", "Integration");
GemfireTemplate gemfireTemplate = new GemfireTemplate(getRegion());
GemfireTemplate gemfireTemplate = new GemfireTemplate(region);
assertEquals("Integration", gemfireTemplate.get("GemfireMetadataStoreTests-Spring"));
}
@@ -156,13 +163,9 @@ public class GemfireMetadataStoreTests {
public void testPersistKeyValueIfAbsent() {
metadataStore.putIfAbsent("GemfireMetadataStoreTests-Spring", "Integration");
GemfireTemplate gemfireTemplate = new GemfireTemplate(getRegion());
GemfireTemplate gemfireTemplate = new GemfireTemplate(region);
assertEquals("Integration", gemfireTemplate.get("GemfireMetadataStoreTests-Spring"));
}
private static Region<Object, Object> getRegion() {
return cache.getRegion(GemfireMetadataStore.KEY);
}
}

View File

@@ -23,11 +23,12 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.expression.ValueExpression;
@@ -37,6 +38,7 @@ import org.springframework.messaging.support.GenericMessage;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Scope;
/**
* @author Mark Fisher
@@ -48,17 +50,38 @@ import com.gemstone.gemfire.cache.Region;
*/
public class CacheWritingMessageHandlerTests {
private static CacheFactoryBean cacheFactoryBean;
private static Region<Object, Object> region;
@BeforeClass
public static void startUp() throws Exception {
cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
region = cache.createRegionFactory().setScope(Scope.LOCAL).create("sig-tests");
}
@AfterClass
public static void cleanUp() throws Exception {
if (region != null) {
region.close();
}
if (cacheFactoryBean != null) {
cacheFactoryBean.destroy();
}
}
@Before
public void prepare() {
if (region != null) {
region.clear();
}
}
@Test
public void mapPayloadWritesToCache() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() { };
regionFactoryBean.setName("test.mapPayloadWritesToCache");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, String> region = regionFactoryBean.getObject();
assertEquals(0, region.size());
CacheWritingMessageHandler handler = new CacheWritingMessageHandler(region);
@@ -71,23 +94,10 @@ public class CacheWritingMessageHandlerTests {
handler.handleMessage(message);
assertEquals(1, region.size());
assertEquals("bar", region.get("foo"));
regionFactoryBean.destroy();
cacheFactoryBean.destroy();
}
@Test
@SuppressWarnings("unchecked")
public void ExpressionsWriteToCache() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, Object> regionFactoryBean = new RegionFactoryBean<String, Object>() { };
regionFactoryBean.setName("test.expressionsWriteToCache");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, Object> region = regionFactoryBean.getObject();
assertEquals(0, region.size());
CacheWritingMessageHandler handler = new CacheWritingMessageHandler(region);
@@ -113,9 +123,6 @@ public class CacheWritingMessageHandlerTests {
handler.handleMessage(new GenericMessage<String>("test"));
assertEquals(3, region.size());
assertEquals(10L, region.get("baz"));
regionFactoryBean.destroy();
cacheFactoryBean.destroy();
}
}

View File

@@ -97,7 +97,8 @@ public class DelayerHandlerRescheduleIntegrationTests {
// Emulate restart and check Cache state before next start
// Interrupt taskScheduler as quickly as possible
ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
ThreadPoolTaskScheduler taskScheduler =
(ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
taskScheduler.shutdown();
taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS);
context.destroy();
@@ -144,6 +145,7 @@ public class DelayerHandlerRescheduleIntegrationTests {
}
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
context.destroy();
}
}

View File

@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="org/springframework/integration/gemfire/inbound/cq/common.properties"/>
<context:component-scan base-package="org.springframework.integration.gemfire.store"/>
<int:channel id="i"/>
<int:aggregator release-strategy="releaseStrategy" correlation-strategy="correlationStrategy" message-store="gemfireMessageGroupStore" input-channel="i" output-channel="o" />
<int:channel id="o"/>
<int:service-activator input-channel="o" ref="messageGroupStoreActivator" />
<util:properties id="props" location="org/springframework/integration/gemfire/inbound/cq/gfe-cache.properties"/>
<gfe:cache properties-ref="props" id="c"/>
<gfe:transaction-manager cache-ref="c"/>
<gfe:replicated-region id="unmarkedRegion" cache-ref="c"/>
<gfe:replicated-region id="markedRegion" cache-ref="c"/>
<gfe:replicated-region id="messageGroupRegion" cache-ref="c"/>
</beans>

View File

@@ -1,5 +0,0 @@
host=127.0.0.1
port=55221
region-name=people
region-query=select * from /people
correlation-header=time

View File

@@ -1,3 +0,0 @@
log-level=warning
name=Spring Integration GemFire World
bind-address=127.0.0.1

View File

@@ -142,7 +142,7 @@ public class DelayerHandlerRescheduleIntegrationTests {
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
context.destroy();
}
@Test //INT-2649

View File

@@ -59,13 +59,13 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe
@Test
@MongoDbAvailable
public void testWithMongoDbMessageStore() throws Exception {
this.testDelayerHandlerRescheduleWithMongoDbMessageStore("DelayerHandlerRescheduleIntegrationTests-context.xml");
testDelayerHandlerRescheduleWithMongoDbMessageStore("DelayerHandlerRescheduleIntegrationTests-context.xml");
}
@Test
@MongoDbAvailable
public void testWithConfigurableMongoDbMessageStore() throws Exception {
this.testDelayerHandlerRescheduleWithMongoDbMessageStore("DelayerHandlerRescheduleIntegrationConfigurableTests-context.xml");
testDelayerHandlerRescheduleWithMongoDbMessageStore("DelayerHandlerRescheduleIntegrationConfigurableTests-context.xml");
}
@SuppressWarnings("unchecked")
@@ -84,7 +84,8 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe
// Emulate restart and check DB state before next start
// Interrupt taskScheduler as quickly as possible
ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
ThreadPoolTaskScheduler taskScheduler =
(ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
taskScheduler.shutdown();
taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS);
context.destroy();
@@ -110,7 +111,8 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe
Message<String> original1 = (Message<String>) ((DelayHandler.DelayedMessageWrapper) payload).getOriginal();
messageInStore = iterator.next();
Message<String> original2 = (Message<String>) ((DelayHandler.DelayedMessageWrapper) messageInStore.getPayload()).getOriginal();
Message<String> original2 = (Message<String>) ((DelayHandler.DelayedMessageWrapper) messageInStore.getPayload())
.getOriginal();
assertThat(message1, Matchers.anyOf(Matchers.is(original1), Matchers.is(original2)));
context.refresh();
@@ -128,7 +130,7 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe
assertNotSame(payload1, payload2);
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
context.destroy();
}
}

View File

@@ -73,7 +73,8 @@ public class DelayerHandlerRescheduleIntegrationTests extends RedisAvailableTest
// Emulate restart and check DB state before next start
// Interrupt taskScheduler as quickly as possible
ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
ThreadPoolTaskScheduler taskScheduler =
(ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
taskScheduler.shutdown();
taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS);
context.destroy();
@@ -121,7 +122,7 @@ public class DelayerHandlerRescheduleIntegrationTests extends RedisAvailableTest
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
messageStore.removeMessageGroup(delayerMessageGroupId);
context.destroy();
}
}