From f32fd1967b1d8aa9a4da25563e709c122c15e32c Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 15 Jun 2015 12:57:07 -0400 Subject: [PATCH] INT-3742: spring-data-gemfire 1.7 Compatibility JIRA: https://jira.spring.io/browse/INT-3742 Deprecate the message store ctor that takes a `Cache` argument. --- .../gemfire/store/GemfireMessageStore.java | 5 +- .../CacheListeningMessageProducerTests.java | 13 ++--- .../CacheWritingMessageHandlerTests.java | 9 ++-- .../gemfire/store/GemfireGroupStoreTests.java | 50 +++++++++++-------- .../store/GemfireMessageStoreTests.java | 20 +++++--- 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java index ffd7ff0023..6627c2b9be 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/store/GemfireMessageStore.java @@ -67,7 +67,10 @@ public class GemfireMessageStore extends AbstractKeyValueMessageStore implements * 'messageStoreRegion' * * @param cache The cache. + * + * @deprecated - use the other constructor and provide a region directly. */ + @Deprecated public GemfireMessageStore(Cache cache) { Assert.notNull(cache, "'cache' must not be null"); this.cache = cache; @@ -92,7 +95,7 @@ public class GemfireMessageStore extends AbstractKeyValueMessageStore implements RegionAttributesFactoryBean attributesFactoryBean = new RegionAttributesFactoryBean(); attributesFactoryBean.setIgnoreJTA(this.ignoreJta); attributesFactoryBean.afterPropertiesSet(); - RegionFactoryBean messageRegionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean messageRegionFactoryBean = new RegionFactoryBean() {}; messageRegionFactoryBean.setBeanName(MESSAGE_STORE_REGION_NAME); messageRegionFactoryBean.setAttributes(attributesFactoryBean.getObject()); messageRegionFactoryBean.setCache(cache); diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/CacheListeningMessageProducerTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/CacheListeningMessageProducerTests.java index 4be1614911..9693561811 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/CacheListeningMessageProducerTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/CacheListeningMessageProducerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,14 +27,15 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.RegionAttributesFactoryBean; import org.springframework.data.gemfire.RegionFactoryBean; -import org.springframework.messaging.Message; import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.Region; /** * @author Mark Fisher + * @author Gary Russell * @since 2.1 */ public class CacheListeningMessageProducerTests { @@ -45,7 +46,7 @@ public class CacheListeningMessageProducerTests { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); Cache cache = cacheFactoryBean.getObject(); - RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean regionFactoryBean = new RegionFactoryBean() {}; regionFactoryBean.setName("test.receiveNewValuePayloadForCreateEvent"); regionFactoryBean.setCache(cache); this.setRegionAttributes(regionFactoryBean); @@ -72,7 +73,7 @@ public class CacheListeningMessageProducerTests { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); Cache cache = cacheFactoryBean.getObject(); - RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean regionFactoryBean = new RegionFactoryBean() {}; regionFactoryBean.setName("test.receiveNewValuePayloadForUpdateEvent"); regionFactoryBean.setCache(cache); this.setRegionAttributes(regionFactoryBean); @@ -103,7 +104,7 @@ public class CacheListeningMessageProducerTests { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); Cache cache = cacheFactoryBean.getObject(); - RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean regionFactoryBean = new RegionFactoryBean() {}; regionFactoryBean.setName("test.receiveOldValuePayloadForDestroyEvent"); regionFactoryBean.setCache(cache); this.setRegionAttributes(regionFactoryBean); @@ -133,7 +134,7 @@ public class CacheListeningMessageProducerTests { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); Cache cache = cacheFactoryBean.getObject(); - RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean regionFactoryBean = new RegionFactoryBean() {}; regionFactoryBean.setName("test.receiveOldValuePayloadForDestroyEvent"); regionFactoryBean.setCache(cache); this.setRegionAttributes(regionFactoryBean); diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandlerTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandlerTests.java index 235542930b..8251a50cf9 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandlerTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,8 @@ import org.junit.Test; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.RegionFactoryBean; -import org.springframework.messaging.Message; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.Region; @@ -36,6 +36,7 @@ import com.gemstone.gemfire.cache.Region; * @author Mark Fisher * @author David Turanski * @author Gunnar Hillert + * @author Gary Russell * @since 2.1 */ public class CacheWritingMessageHandlerTests { @@ -44,7 +45,7 @@ public class CacheWritingMessageHandlerTests { public void mapPayloadWritesToCache() throws Exception { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); Cache cache = cacheFactoryBean.getObject(); - RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean regionFactoryBean = new RegionFactoryBean() {}; regionFactoryBean.setName("test.mapPayloadWritesToCache"); regionFactoryBean.setCache(cache); regionFactoryBean.afterPropertiesSet(); @@ -63,7 +64,7 @@ public class CacheWritingMessageHandlerTests { public void ExpressionsWriteToCache() throws Exception { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); Cache cache = cacheFactoryBean.getObject(); - RegionFactoryBean regionFactoryBean = new RegionFactoryBean(); + RegionFactoryBean regionFactoryBean = new RegionFactoryBean() {}; regionFactoryBean.setName("test.expressionsWriteToCache"); regionFactoryBean.setCache(cache); regionFactoryBean.afterPropertiesSet(); 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 83d17b6e09..54001ef40b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2007-2013 the original author or authors + * Copyright 2007-2015 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import junit.framework.AssertionFailedError; - import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -52,22 +50,29 @@ import org.springframework.messaging.support.GenericMessage; import org.springframework.util.Assert; import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Scope; + +import junit.framework.AssertionFailedError; /** * @author Oleg Zhurakousky * @author David Turanski + * @author Gary Russell * */ public class GemfireGroupStoreTests { private Cache cache; + private Region region; + @Rule public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); @Test public void testNonExistingEmptyMessageGroup() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); assertNotNull(messageGroup); @@ -77,7 +82,7 @@ public class GemfireGroupStoreTests { @Test public void testMessageGroupWithAddedMessage() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); Message message = new GenericMessage("Hello"); @@ -85,7 +90,7 @@ public class GemfireGroupStoreTests { assertEquals(1, messageGroup.size()); // make sure the store is properly rebuild from Gemfire - store = new GemfireMessageStore(this.cache); + store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); messageGroup = store.getMessageGroup(1); @@ -94,7 +99,7 @@ public class GemfireGroupStoreTests { @Test public void testRemoveMessageFromTheGroup() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); Message message = new GenericMessage("2"); @@ -119,7 +124,7 @@ public class GemfireGroupStoreTests { assertEquals(2, messageGroup.size()); // make sure the store is properly rebuild from Gemfire - store = new GemfireMessageStore(this.cache); + store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); messageGroup = store.getMessageGroup(1); @@ -129,7 +134,7 @@ public class GemfireGroupStoreTests { @Test public void testRemoveMessageGroup() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); Message message = new GenericMessage("Hello"); @@ -143,7 +148,7 @@ public class GemfireGroupStoreTests { assertEquals(0, messageGroupA.size()); // make sure the store is properly rebuild from Gemfire - store = new GemfireMessageStore(this.cache); + store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); messageGroup = store.getMessageGroup(1); @@ -154,7 +159,7 @@ public class GemfireGroupStoreTests { @Test public void testRemoveNonExistingMessageFromTheGroup() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage("1")); @@ -163,14 +168,14 @@ public class GemfireGroupStoreTests { @Test public void testRemoveNonExistingMessageFromNonExistingTheGroup() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); store.removeMessageFromGroup(1, new GenericMessage("2")); } @Test public void testCompleteMessageGroup() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); Message messageToMark = new GenericMessage("1"); @@ -182,7 +187,7 @@ public class GemfireGroupStoreTests { @Test public void testLastReleasedSequenceNumber() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); MessageGroup messageGroup = store.getMessageGroup(1); Message messageToMark = new GenericMessage("1"); @@ -194,10 +199,10 @@ public class GemfireGroupStoreTests { @Test public void testMultipleInstancesOfGroupStore() throws Exception { - GemfireMessageStore store1 = new GemfireMessageStore(this.cache); + GemfireMessageStore store1 = new GemfireMessageStore(this.region); store1.afterPropertiesSet(); - GemfireMessageStore store2 = new GemfireMessageStore(this.cache); + GemfireMessageStore store2 = new GemfireMessageStore(this.region); store2.afterPropertiesSet(); Message message = new GenericMessage("1"); @@ -206,7 +211,7 @@ public class GemfireGroupStoreTests { assertEquals(2, messageGroup.getMessages().size()); - GemfireMessageStore store3 = new GemfireMessageStore(this.cache); + GemfireMessageStore store3 = new GemfireMessageStore(this.region); store3.afterPropertiesSet(); messageGroup = store3.removeMessageFromGroup(1, message); @@ -216,7 +221,7 @@ public class GemfireGroupStoreTests { @Test public void testWithMessageHistory() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); store.getMessageGroup(1); @@ -243,9 +248,9 @@ public class GemfireGroupStoreTests { @Test public void testIteratorOfMessageGroups() throws Exception { - GemfireMessageStore store1 = new GemfireMessageStore(this.cache); + GemfireMessageStore store1 = new GemfireMessageStore(this.region); store1.afterPropertiesSet(); - GemfireMessageStore store2 = new GemfireMessageStore(this.cache); + GemfireMessageStore store2 = new GemfireMessageStore(this.region); store2.afterPropertiesSet(); store1.addMessageToGroup(1, new GenericMessage("1")); @@ -276,9 +281,9 @@ public class GemfireGroupStoreTests { @Ignore public void testConcurrentModifications() throws Exception { - final GemfireMessageStore store1 = new GemfireMessageStore(this.cache); + final GemfireMessageStore store1 = new GemfireMessageStore(this.region); store1.afterPropertiesSet(); - final GemfireMessageStore store2 = new GemfireMessageStore(this.cache); + final GemfireMessageStore store2 = new GemfireMessageStore(this.region); store2.afterPropertiesSet(); final Message message = new GenericMessage("1"); @@ -371,6 +376,7 @@ public class GemfireGroupStoreTests { public void init() throws Exception { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); this.cache = cacheFactoryBean.getObject(); + this.region = cache.createRegionFactory().setScope(Scope.LOCAL).create("sig-tests"); } @After 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 de9b18aec9..670dc20efc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,30 +25,36 @@ import java.util.Properties; import org.junit.After; import org.junit.Before; import org.junit.Test; + import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.RegionFactoryBean; -import org.springframework.messaging.Message; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.history.MessageHistory; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.GenericMessage; import org.springframework.util.Assert; import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Scope; /** * @author Mark Fisher * @author David Turanski + * @author Gary Russell * @since 2.1 */ public class GemfireMessageStoreTests { private Cache cache; + private Region region; + @Test public void addAndGetMessage() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); Message message = MessageBuilder.withPayload("test").build(); @@ -59,7 +65,7 @@ public class GemfireMessageStoreTests { @Test public void testRegionConstructor() throws Exception { - RegionFactoryBean region = new RegionFactoryBean(); + RegionFactoryBean region = new RegionFactoryBean() {}; region.setName("someRegion"); region.setCache(this.cache); region.afterPropertiesSet(); @@ -71,7 +77,7 @@ public class GemfireMessageStoreTests { @Test public void testWithMessageHistory() throws Exception { - GemfireMessageStore store = new GemfireMessageStore(this.cache); + GemfireMessageStore store = new GemfireMessageStore(this.region); store.afterPropertiesSet(); Message message = new GenericMessage("Hello"); @@ -96,6 +102,7 @@ public class GemfireMessageStoreTests { public void init() throws Exception { CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); this.cache = cacheFactoryBean.getObject(); + this.region = cache.createRegionFactory().setScope(Scope.LOCAL).create("sig-tests"); } @After @@ -103,4 +110,5 @@ public class GemfireMessageStoreTests { this.cache.close(); Assert.isTrue(this.cache.isClosed(), "Cache did not close after close() call"); } + }