From 72593f9ee9eca9e4836bd47f5bc19e1b5d045b02 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Sun, 6 Nov 2011 03:46:15 -0500 Subject: [PATCH] INT-2220 polished Gemfire tests --- .../gemfire/store/GemfireGroupStoreTests.java | 11 ++++++++-- .../store/GemfireMessageStoreTests.java | 22 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java index 52aa45d341..ddb0b8c53f 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java @@ -37,6 +37,7 @@ import org.springframework.integration.message.GenericMessage; import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.SimpleMessageGroup; import org.springframework.integration.support.MessageBuilder; +import org.springframework.util.Assert; import com.gemstone.gemfire.cache.Cache; @@ -90,10 +91,15 @@ public class GemfireGroupStoreTests { messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage("1")); messageGroup = store.getMessageGroup(1); - + assertEquals(1, messageGroup.size()); + Thread.sleep(1); //since it adds to a local region some times CREATED_DATE ends up to be the same + // Unrealistic in a real scenario + messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message); messageGroup = store.getMessageGroup(1); - + assertEquals(2, messageGroup.size()); + Thread.sleep(1); + messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage("3")); messageGroup = store.getMessageGroup(1); assertEquals(3, messageGroup.size()); @@ -323,6 +329,7 @@ public class GemfireGroupStoreTests { @After public void cleanup(){ this.cache.close(); + Assert.isTrue(this.cache.isClosed(), "Cache did not close after close() call"); } } diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireMessageStoreTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireMessageStoreTests.java index 2245c8f2af..b9e0c08683 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireMessageStoreTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireMessageStoreTests.java @@ -16,10 +16,13 @@ package org.springframework.integration.gemfire.store; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.integration.Message; import org.springframework.integration.support.MessageBuilder; +import org.springframework.util.Assert; import com.gemstone.gemfire.cache.Cache; @@ -31,12 +34,11 @@ import static org.junit.Assert.assertEquals; */ public class GemfireMessageStoreTests { + private Cache cache; + @Test public void addAndGetMessage() throws Exception { - CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); - cacheFactoryBean.afterPropertiesSet(); - Cache cache = (Cache)cacheFactoryBean.getObject(); - GemfireMessageStore store = new GemfireMessageStore(cache); + GemfireMessageStore store = new GemfireMessageStore(this.cache); store.afterPropertiesSet(); Message message = MessageBuilder.withPayload("test").build(); @@ -45,4 +47,16 @@ public class GemfireMessageStoreTests { assertEquals(message, retrieved); } + @Before + public void init() throws Exception{ + CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); + cacheFactoryBean.afterPropertiesSet(); + this.cache = (Cache)cacheFactoryBean.getObject(); + } + + @After + public void cleanup(){ + this.cache.close(); + Assert.isTrue(this.cache.isClosed(), "Cache did not close after close() call"); + } }