From 6d40df291f1c81c4bcefe0c48156405f89a2ac81 Mon Sep 17 00:00:00 2001 From: David Turanski Date: Thu, 18 Aug 2011 13:08:21 -0400 Subject: [PATCH] INT-2062 - Fixed GemfireMessageGroupStoreTest (changed Set to List to avoid equals() collisions affecting size()) --- spring-integration-gemfire/.gitignore | 1 + .../store/KeyValueMessageGroupStore.java | 1 - .../GemfireMessageGroupStoreTest-context.xml | 0 .../GemfireMessageGroupStoreTest.java | 67 ++++++++++--------- ...ireMessageGroupStoreTestConfiguration.java | 50 +++++++------- 5 files changed, 63 insertions(+), 56 deletions(-) create mode 100644 spring-integration-gemfire/.gitignore rename spring-integration-gemfire/src/test/{resources => java}/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest-context.xml (100%) diff --git a/spring-integration-gemfire/.gitignore b/spring-integration-gemfire/.gitignore new file mode 100644 index 0000000000..2e2298678e --- /dev/null +++ b/spring-integration-gemfire/.gitignore @@ -0,0 +1 @@ +*.cfg \ No newline at end of file diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/KeyValueMessageGroupStore.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/KeyValueMessageGroupStore.java index d8228b805f..2fd6ce34ce 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/KeyValueMessageGroupStore.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/KeyValueMessageGroupStore.java @@ -24,7 +24,6 @@ import org.springframework.util.Assert; import java.util.HashSet; import java.util.Iterator; import java.util.Map; -import java.util.concurrent.ConcurrentMap; /** * Provides an implementation of {@link org.springframework.integration.store.MessageGroupStore} that delegates to a backend Gemfire instance. diff --git a/spring-integration-gemfire/src/test/resources/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest-context.xml b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest-context.xml similarity index 100% rename from spring-integration-gemfire/src/test/resources/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest-context.xml rename to spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest-context.xml diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest.java index 5d436c7400..5a4c782e5e 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTest.java @@ -1,5 +1,10 @@ package org.springframework.integration.gemfire.store.messagegroupstore; +import static org.junit.Assert.assertEquals; + +import java.util.Collection; +import java.util.List; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -8,50 +13,48 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import java.util.Collection; -import java.util.List; -import java.util.Set; - /** - * Tests the Gemfire {@link org.springframework.integration.store.MessageGroupStore} implementation, - * {@link org.springframework.integration.gemfire.store.GemfireMessageGroupStore}. + * Tests the Gemfire + * {@link org.springframework.integration.store.MessageGroupStore} + * implementation, + * {@link org.springframework.integration.gemfire.store.GemfireMessageGroupStore} + * . *

- * It tests the {@link org.springframework.integration.store.MessageGroupStore} by sending 10 batches of letters (all of the same width), - * and then counting on the other end that indeed all 10 batches arrived and that all letters expected are there. - * * - * + * It tests the {@link org.springframework.integration.store.MessageGroupStore} + * by sending 10 batches of letters (all of the same width), and then counting + * on the other end that indeed all 10 batches arrived and that all letters + * expected are there. * + * * @author Josh Long */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {GemfireMessageGroupStoreTestConfiguration.class}) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = { GemfireMessageGroupStoreTestConfiguration.class }) public class GemfireMessageGroupStoreTest { - @Autowired private GemfireMessageGroupStoreTestConfiguration.FakeMessageConsumer consumer; + @Autowired + private GemfireMessageGroupStoreTestConfiguration.FakeMessageConsumer consumer; + @Autowired + private GemfireMessageGroupStoreTestConfiguration.FakeMessageProducer producer; private List letters = GemfireMessageGroupStoreTestConfiguration.LIST_OF_STRINGS; + private int maxSize = 10; - private long totalTimeSleeping = 10 * 1000; // give it 10s to send the messages @Test - public void testGemfireMessageGroupStore() throws Throwable { - long counter = 0; - int delay = 1000; - Set> batches = consumer.getBatches(); - - while (batches.size() < maxSize && counter < totalTimeSleeping) { - counter += delay; - Thread.sleep(delay); - } - - Assert.assertTrue(batches.size() == maxSize); - for (Collection collection : batches) { - Assert.assertTrue(letters.size() == collection.size()); - for (String c : this.letters) { - Assert.assertTrue(collection.contains(c)); + public void testGemfireMessageGroupStore() throws Exception { + producer.afterPropertiesSet(); + producer.start(); + List> batches = consumer.getBatches(); + assertEquals(maxSize, batches.size()); + for (Collection collection : batches) { + Assert.assertTrue(letters.size() == collection.size()); + for (String c : this.letters) { + Assert.assertTrue(collection.contains(c)); + } + for (Object o : collection) { + Assert.assertTrue(o instanceof String); + } } - for (Object o : collection) { - Assert.assertTrue(o instanceof String); - } - } + producer.stop(); } } \ No newline at end of file diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTestConfiguration.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTestConfiguration.java index 26ad2879f8..8c24291782 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTestConfiguration.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageGroupStoreTestConfiguration.java @@ -16,8 +16,11 @@ package org.springframework.integration.gemfire.store.messagegroupstore; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; @@ -43,12 +46,14 @@ import org.springframework.integration.gemfire.store.KeyValueMessageGroupStore; import org.springframework.integration.support.MessageBuilder; import org.springframework.util.Assert; -import java.util.*; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; /** - * Our aggregator needs a {@link org.springframework.integration.gemfire.store.KeyValueMessageGroupStore}. - * This handles configuration of the ancillary objects. - * + * Our aggregator needs a + * {@link org.springframework.integration.gemfire.store.KeyValueMessageGroupStore} + * . This handles configuration of the ancillary objects. + * * @author Josh Long * @since 2.1 */ @@ -70,7 +75,6 @@ public class GemfireMessageGroupStoreTestConfiguration { return cacheFactoryBean.getObject(); } - @Bean public Region messageGroupRegion() throws Throwable { RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); @@ -98,7 +102,6 @@ public class GemfireMessageGroupStoreTestConfiguration { return regionFactoryBean.getObject(); } - @Bean(name = "messageGroupStoreActivator") public FakeMessageConsumer serviceActivator() { return new FakeMessageConsumer(); @@ -126,9 +129,9 @@ public class GemfireMessageGroupStoreTestConfiguration { static public class FakeMessageConsumer { - private Set> batches = new HashSet>(); + private List> batches = new ArrayList>(); - public Set> getBatches() { + public List> getBatches() { return this.batches; } @@ -136,6 +139,7 @@ public class GemfireMessageGroupStoreTestConfiguration { public void activateAsMessagesArriveInBatches(Message> msg) throws Throwable { Collection payloads = msg.getPayload(); batches.add(payloads); + if (log.isDebugEnabled()) { log.debug(payloads); } @@ -146,17 +150,20 @@ public class GemfireMessageGroupStoreTestConfiguration { static public class FakeMessageProducer implements InitializingBean, SmartLifecycle { public boolean isAutoStartup() { - return true; + return false; } public void stop(Runnable callback) { + stop(); + callback.run(); } public int getPhase() { return 0; } - @Autowired @Qualifier("i") + @Autowired + @Qualifier("i") private MessageChannel messageChannel; private MessagingTemplate messagingTemplate = new MessagingTemplate(); @@ -172,35 +179,32 @@ public class GemfireMessageGroupStoreTestConfiguration { int ctr = 0; int size = lines.size(); for (String l : lines) { - Message msg = MessageBuilder.withPayload(l) - .setCorrelationId(this.correlationHeader) - .setHeader(this.correlationHeader, correlationValue) - .setSequenceNumber(++ctr) - .setSequenceSize(size) - .build(); + Message msg = MessageBuilder.withPayload(l).setCorrelationId(this.correlationHeader) + .setHeader(this.correlationHeader, correlationValue).setSequenceNumber(++ctr) + .setSequenceSize(size).build(); this.messagingTemplate.send(msg); } } - public void afterPropertiesSet() throws Exception { this.messagingTemplate.setDefaultChannel(this.messageChannel); } - public void start() { + running = true; for (int i = 0; i < 10; i++) { try { - running = true; sendManyMessages(i, LIST_OF_STRINGS); - running = false; - } catch (Throwable throwable) { + } + catch (Throwable throwable) { throw new RuntimeException(throwable); } } + } public void stop() { + running = false; } public boolean isRunning() {