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.
This commit is contained in:
Gary Russell
2015-06-15 12:57:07 -04:00
committed by Artem Bilan
parent 8782d097cf
commit f32fd1967b
5 changed files with 58 additions and 39 deletions

View File

@@ -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<Object, Object> messageRegionFactoryBean = new RegionFactoryBean<Object, Object>();
RegionFactoryBean<Object, Object> messageRegionFactoryBean = new RegionFactoryBean<Object, Object>() {};
messageRegionFactoryBean.setBeanName(MESSAGE_STORE_REGION_NAME);
messageRegionFactoryBean.setAttributes(attributesFactoryBean.getObject());
messageRegionFactoryBean.setCache(cache);

View File

@@ -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<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() {};
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<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() {};
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<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() {};
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<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() {};
regionFactoryBean.setName("test.receiveOldValuePayloadForDestroyEvent");
regionFactoryBean.setCache(cache);
this.setRegionAttributes(regionFactoryBean);

View File

@@ -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<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() {};
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<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>() {};
regionFactoryBean.setName("test.expressionsWriteToCache");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();

View File

@@ -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<Object, Object> 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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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

View File

@@ -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<Object, Object> 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<Object, Object> region = new RegionFactoryBean<Object, Object>();
RegionFactoryBean<Object, Object> region = new RegionFactoryBean<Object, Object>() {};
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<String>("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");
}
}