Completes JIRA ticket SGF-204 changing the default behavior of peer and client Region types to not perform a lookup first of an existing Region of the same name/path if the Region was created and configured using native cache.xml in GemFire in addition Spring config.

This commit is contained in:
John Blum
2014-03-11 21:19:10 -07:00
parent d2d54bf40c
commit c5a33d6fef
27 changed files with 812 additions and 83 deletions

View File

@@ -41,7 +41,6 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
@SuppressWarnings("rawtypes")
private RegionFactoryBeanConfig defaultConfig() {
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "default") {
@Override
public void verify() {
Region region = regionFactoryBean.getRegion();
@@ -53,13 +52,11 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
// TODO Auto-generated method stub
}
};
}
@SuppressWarnings("rawtypes")
private RegionFactoryBeanConfig persistent() {
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "persistent") {
@Override
public void verify() {
Region region = regionFactoryBean.getRegion();
@@ -76,7 +73,6 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
@SuppressWarnings("rawtypes")
private RegionFactoryBeanConfig invalidPersistence() {
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "invalid-persistence") {
@Override
public void configureRegionFactoryBean() {
regionFactoryBean.setDataPolicy("persistent_replicate");

View File

@@ -0,0 +1,269 @@
/*
* Copyright 2010-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.gemfire.fork.SpringCacheServerProcess;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionExistsException;
import com.gemstone.gemfire.cache.Scope;
/**
* The RegionLookupIntegrationTests class is a test suite of test cases testing the lookup functionality for various
* peer Region types.
* <p/>
* @author John Blum
* @see org.junit.Test
* @see org.springframework.context.ConfigurableApplicationContext
* @see org.springframework.data.gemfire.fork.SpringCacheServerProcess
* @see com.gemstone.gemfire.cache.Region
* @since 1.4.0
* @link https://jira.spring.io/browse/SGF-204
*/
public class RegionLookupIntegrationTests {
@BeforeClass
public static void preTestSuiteSetup() {
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() + " "
+ "/org/springframework/data/gemfire/RegionLookupIntegrationTests-server-context.xml");
}
protected void assertNoRegionLookup(final String configLocation) {
ConfigurableApplicationContext applicationContext = null;
try {
applicationContext = createApplicationContext(configLocation);
fail("Spring ApplicationContext should have thrown a BeanCreationException caused by a RegionExistsException!");
}
catch (BeanCreationException expected) {
//expected.printStackTrace(System.err);
assertTrue(expected.getMessage(), expected.getCause() instanceof RegionExistsException);
throw (RegionExistsException) expected.getCause();
}
finally {
closeApplicationContext(applicationContext);
}
}
protected void closeApplicationContext(final ConfigurableApplicationContext applicationContext) {
if (applicationContext != null) {
applicationContext.close();
}
}
protected ConfigurableApplicationContext createApplicationContext(final String configLocation) {
return new ClassPathXmlApplicationContext(configLocation);
}
@Test
public void testAllowRegionBeanDefinitionOverrides() {
ConfigurableApplicationContext applicationContext = null;
try {
applicationContext = createApplicationContext(
"/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml");
assertNotNull(applicationContext);
assertTrue(applicationContext.containsBean("regionOne"));
Region appDataRegion = applicationContext.getBean("regionOne", Region.class);
assertNotNull(appDataRegion);
assertEquals("AppDataRegion", appDataRegion.getName());
assertEquals("/AppDataRegion", appDataRegion.getFullPath());
assertNotNull(appDataRegion.getAttributes());
assertEquals(DataPolicy.PERSISTENT_REPLICATE, appDataRegion.getAttributes().getDataPolicy());
assertFalse(appDataRegion.getAttributes().getMulticastEnabled());
assertEquals(Scope.DISTRIBUTED_ACK, appDataRegion.getAttributes().getScope());
assertEquals(101, appDataRegion.getAttributes().getInitialCapacity());
assertEquals(new Float(0.85f), new Float(appDataRegion.getAttributes().getLoadFactor()));
assertTrue(appDataRegion.getAttributes().getCloningEnabled());
assertTrue(appDataRegion.getAttributes().getConcurrencyChecksEnabled());
assertEquals(Integer.class, appDataRegion.getAttributes().getKeyConstraint());
assertEquals(String.class, appDataRegion.getAttributes().getValueConstraint());
}
finally {
closeApplicationContext(applicationContext);
}
}
@Test(expected = RegionExistsException.class)
public void testNoDuplicateRegionDefinitions() {
assertNoRegionLookup("/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml");
}
@Test(expected = RegionExistsException.class)
public void testNoClientRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noClientRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
public void testNoClientSubRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
public void testNoLocalRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noLocalRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
public void testNoPartitionRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
public void testNoReplicateRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml");
}
@Test(expected = RegionExistsException.class)
public void testNoSubRegionLookups() {
assertNoRegionLookup("/org/springframework/data/gemfire/noSubRegionLookupTest.xml");
}
@Test
public void testEnableRegionLookups() {
ConfigurableApplicationContext applicationContext = null;
try {
applicationContext = createApplicationContext("/org/springframework/data/gemfire/enableRegionLookupsTest.xml");
assertNotNull(applicationContext);
assertTrue(applicationContext.containsBean("NativeLocalRegion"));
assertTrue(applicationContext.containsBean("NativePartitionRegion"));
assertTrue(applicationContext.containsBean("NativeReplicateRegion"));
assertTrue(applicationContext.containsBean("NativeParentRegion"));
assertTrue(applicationContext.containsBean("/NativeParentRegion/NativeChildRegion"));
assertTrue(applicationContext.containsBean("SpringReplicateRegion"));
Region nativeLocalRegion = applicationContext.getBean("NativeLocalRegion", Region.class);
assertNotNull(nativeLocalRegion);
assertEquals("NativeLocalRegion", nativeLocalRegion.getName());
assertEquals("/NativeLocalRegion", nativeLocalRegion.getFullPath());
assertNotNull(nativeLocalRegion.getAttributes());
assertEquals(DataPolicy.NORMAL, nativeLocalRegion.getAttributes().getDataPolicy());
assertFalse(nativeLocalRegion.getAttributes().getCloningEnabled());
assertFalse(nativeLocalRegion.getAttributes().getConcurrencyChecksEnabled());
assertEquals(80, nativeLocalRegion.getAttributes().getConcurrencyLevel());
assertEquals(101, nativeLocalRegion.getAttributes().getInitialCapacity());
assertEquals(Integer.class, nativeLocalRegion.getAttributes().getKeyConstraint());
assertEquals(new Float(0.95f), new Float(nativeLocalRegion.getAttributes().getLoadFactor()));
assertEquals(String.class, nativeLocalRegion.getAttributes().getValueConstraint());
Region nativePartitionRegion = applicationContext.getBean("NativePartitionRegion", Region.class);
assertNotNull(nativePartitionRegion);
assertEquals("NativePartitionRegion", nativePartitionRegion.getName());
assertEquals("/NativePartitionRegion", nativePartitionRegion.getFullPath());
assertNotNull(nativePartitionRegion.getAttributes());
assertEquals(DataPolicy.PERSISTENT_PARTITION, nativePartitionRegion.getAttributes().getDataPolicy());
assertTrue(nativePartitionRegion.getAttributes().getCloningEnabled());
assertTrue(nativePartitionRegion.getAttributes().getConcurrencyChecksEnabled());
assertEquals(40, nativePartitionRegion.getAttributes().getConcurrencyLevel());
assertEquals(51, nativePartitionRegion.getAttributes().getInitialCapacity());
assertEquals(Integer.class, nativePartitionRegion.getAttributes().getKeyConstraint());
assertEquals(new Float(0.85f), new Float(nativePartitionRegion.getAttributes().getLoadFactor()));
assertFalse(nativePartitionRegion.getAttributes().getMulticastEnabled());
assertEquals(String.class, nativePartitionRegion.getAttributes().getValueConstraint());
Region nativeReplicateRegion = applicationContext.getBean("NativeReplicateRegion", Region.class);
assertNotNull(nativeReplicateRegion);
assertEquals("NativeReplicateRegion", nativeReplicateRegion.getName());
assertEquals("/NativeReplicateRegion", nativeReplicateRegion.getFullPath());
assertNotNull(nativeReplicateRegion.getAttributes());
assertEquals(DataPolicy.PERSISTENT_REPLICATE, nativeReplicateRegion.getAttributes().getDataPolicy());
assertFalse(nativeReplicateRegion.getAttributes().getCloningEnabled());
assertTrue(nativeReplicateRegion.getAttributes().getConcurrencyChecksEnabled());
assertEquals(23, nativeReplicateRegion.getAttributes().getInitialCapacity());
assertEquals(new Float(0.75f), new Float(nativeReplicateRegion.getAttributes().getLoadFactor()));
assertEquals(Integer.class, nativeReplicateRegion.getAttributes().getKeyConstraint());
assertFalse(nativeReplicateRegion.getAttributes().getMulticastEnabled());
assertEquals(Scope.DISTRIBUTED_NO_ACK, nativeReplicateRegion.getAttributes().getScope());
assertEquals(String.class, nativeReplicateRegion.getAttributes().getValueConstraint());
Region nativeChildRegion = applicationContext.getBean("/NativeParentRegion/NativeChildRegion", Region.class);
assertNotNull(nativeChildRegion);
assertEquals("NativeChildRegion", nativeChildRegion.getName());
assertEquals("/NativeParentRegion/NativeChildRegion", nativeChildRegion.getFullPath());
assertNotNull(nativeChildRegion.getAttributes());
assertEquals(DataPolicy.REPLICATE, nativeChildRegion.getAttributes().getDataPolicy());
Region springReplicateRegion = applicationContext.getBean("SpringReplicateRegion", Region.class);
assertNotNull(springReplicateRegion);
assertEquals("SpringReplicateRegion", springReplicateRegion.getName());
assertEquals("/SpringReplicateRegion", springReplicateRegion.getFullPath());
assertNotNull(springReplicateRegion.getAttributes());
assertEquals(DataPolicy.REPLICATE, springReplicateRegion.getAttributes().getDataPolicy());
}
finally {
closeApplicationContext(applicationContext);
}
}
@Test
public void testEnableClientRegionLookups() {
ConfigurableApplicationContext applicationContext = null;
try {
applicationContext = createApplicationContext("/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml");
assertNotNull(applicationContext);
assertTrue(applicationContext.containsBean("NativeClientRegion"));
assertTrue(applicationContext.containsBean("NativeClientParentRegion"));
assertTrue(applicationContext.containsBean("/NativeClientParentRegion/NativeClientChildRegion"));
Region nativeClientRegion = applicationContext.getBean("NativeClientRegion", Region.class);
assertNotNull(nativeClientRegion);
assertEquals("NativeClientRegion", nativeClientRegion.getName());
assertEquals("/NativeClientRegion", nativeClientRegion.getFullPath());
assertNotNull(nativeClientRegion.getAttributes());
assertFalse(nativeClientRegion.getAttributes().getCloningEnabled());
assertEquals(DataPolicy.EMPTY, nativeClientRegion.getAttributes().getDataPolicy());
Region nativeClientChildRegion = applicationContext.getBean("/NativeClientParentRegion/NativeClientChildRegion",
Region.class);
assertNotNull(nativeClientChildRegion);
assertEquals("NativeClientChildRegion", nativeClientChildRegion.getName());
assertEquals("/NativeClientParentRegion/NativeClientChildRegion", nativeClientChildRegion.getFullPath());
assertNotNull(nativeClientChildRegion.getAttributes());
assertEquals(DataPolicy.EMPTY, nativeClientChildRegion.getAttributes().getDataPolicy());
}
finally {
closeApplicationContext(applicationContext);
}
}
}

View File

@@ -21,13 +21,13 @@ import static org.junit.Assert.assertSame;
import org.junit.Test;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
/**
*
* @author David Turanski
*
* @author John Blum
*/
public class SubRegionTest extends RecreatingContextTest {
@Override
@@ -44,25 +44,41 @@ public class SubRegionTest extends RecreatingContextTest {
@SuppressWarnings({ "rawtypes", "unchecked" })
private void testBasic() throws Exception {
CacheFactoryBean cfb = new CacheFactoryBean();
cfb.setBeanName("gemfireCache");
cfb.setUseBeanFactoryLocator(false);
GemFireCache cache = cfb.getObject();
RegionFactoryBean rfb = new ReplicatedRegionFactoryBean();
rfb.setCache(cache);
rfb.setName("parent");
rfb.afterPropertiesSet();
Region parent = rfb.getObject();
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
SubRegionFactoryBean srfb = new SubRegionFactoryBean();
srfb.setParent(parent);
srfb.setName("/parent/child");
srfb.setRegionName("child");
srfb.afterPropertiesSet();
Region child = srfb.getObject();
cacheFactoryBean.setBeanName("gemfireCache");
cacheFactoryBean.setUseBeanFactoryLocator(false);
assertNotNull(parent.getSubregion("child"));
assertSame(child, parent.getSubregion("child"));
Cache cache = cacheFactoryBean.getObject();
assertNotNull(cache);
RegionFactoryBean regionFactory = new ReplicatedRegionFactoryBean();
regionFactory.setCache(cache);
regionFactory.setName("Outer");
regionFactory.afterPropertiesSet();
Region outer = regionFactory.getObject();
assertNotNull(outer);
assertEquals("Outer", outer.getName());
assertEquals("/Outer", outer.getFullPath());
assertSame(outer, cache.getRegion("/Outer"));
RegionFactoryBean subRegionFactory = new RegionFactoryBean();
subRegionFactory.setCache(cache);
subRegionFactory.setParent(outer);
subRegionFactory.setName("/Outer/Inner");
subRegionFactory.setRegionName("Inner");
subRegionFactory.afterPropertiesSet();
Region inner = subRegionFactory.getObject();
assertNotNull(inner);
assertSame(inner, outer.getSubregion("Inner"));
assertSame(inner, cache.getRegion("/Outer/Inner"));
}
@SuppressWarnings("rawtypes")

View File

@@ -81,12 +81,14 @@ public class ClientRegionFactoryBeanTest {
}
@Test
@SuppressWarnings("deprecation")
public void testSetDataPolicyName() throws Exception {
factoryBean.setDataPolicyName("NORMAL");
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", factoryBean));
}
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings("deprecation")
public void testSetDataPolicyNameWithInvalidName() throws Exception {
try {
factoryBean.setDataPolicyName("INVALID");
@@ -100,6 +102,17 @@ public class ClientRegionFactoryBeanTest {
}
}
@Test
public void testIsPersistentUnspecified() {
assertTrue(factoryBean.isPersistentUnspecified());
factoryBean.setPersistent(true);
assertTrue(factoryBean.isPersistent());
assertFalse(factoryBean.isPersistentUnspecified());
factoryBean.setPersistent(false);
assertTrue(factoryBean.isNotPersistent());
assertFalse(factoryBean.isPersistentUnspecified());
}
@Test
public void testIsPersistent() {
assertFalse(factoryBean.isPersistent());

View File

@@ -13,9 +13,9 @@
package org.springframework.data.gemfire.client;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
@@ -28,30 +28,33 @@ import com.gemstone.gemfire.cache.Region;
/**
* @author David Turanski
* @author John Blum
*/
public class MultipleClientCacheTest {
@BeforeClass
public static void startUp() throws Exception {
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() + " "
+ "/org/springframework/data/gemfire/client/datasource-server.xml");
ForkUtil.startCacheServer(String.format("%1$s %2$s", SpringCacheServerProcess.class.getName(),
"/org/springframework/data/gemfire/client/datasource-server.xml"));
}
@Test
public void testMultipleCaches() {
String resourcePath = "/org/springframework/data/gemfire/client/client-cache-no-close.xml";
String configLocation = "/org/springframework/data/gemfire/client/client-cache-no-close.xml";
ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(resourcePath);
ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(resourcePath);
ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(configLocation);
ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(configLocation);
Cache cache1 = context1.getBean(Cache.class);
Cache cache2 = context2.getBean(Cache.class);
assertNotNull(cache1);
assertSame(cache1, cache2);
Region region1 = context1.getBean(Region.class);
Region region2 = context2.getBean(Region.class);
assertNotNull(region1);
assertSame(region1, region2);
assertFalse(cache1.isClosed());
assertFalse(region1.isDestroyed());
@@ -62,10 +65,4 @@ public class MultipleClientCacheTest {
assertFalse("region was destroyed", region1.isDestroyed());
}
@AfterClass
public static void cleanUp() throws InterruptedException {
Thread.sleep(3000);
ForkUtil.sendSignal();
}
}

View File

@@ -12,8 +12,8 @@
*/
package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import org.junit.Test;
@@ -25,24 +25,35 @@ import com.gemstone.gemfire.cache.Region;
/**
* @author David Turanski
*
* @author John Blum
*/
public class MultipleCacheTest {
@Test
public void testMultipleCaches() {
String resourcePath = "/org/springframework/data/gemfire/config/MultipleCacheTest-context.xml";
ConfigurableApplicationContext ctx1 = new ClassPathXmlApplicationContext(resourcePath);
ConfigurableApplicationContext ctx2 = new ClassPathXmlApplicationContext(resourcePath);
Region region1 = ctx1.getBean(Region.class);
Cache cache1 = ctx1.getBean(Cache.class);
Region region2 = ctx2.getBean(Region.class);
Cache cache2 = ctx2.getBean(Cache.class);
assertSame(region1,region2);
assertSame(cache1,cache2);
ctx1.close();
String configLocation = "/org/springframework/data/gemfire/config/MultipleCacheTest-context.xml";
ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(configLocation);
ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(configLocation);
Cache cache1 = context1.getBean(Cache.class);
Cache cache2 = context2.getBean(Cache.class);
assertNotNull(cache1);
assertSame(cache1, cache2);
Region region1 = context1.getBean(Region.class);
Region region2 = context2.getBean(Region.class);
assertNotNull(region1);
assertSame(region1, region2);
assertFalse(cache1.isClosed());
assertFalse("region was destroyed" ,region1.isDestroyed());
assertFalse(region1.isDestroyed());
context1.close();
assertFalse(cache1.isClosed());
assertFalse("region was destroyed", region1.isDestroyed());
}
}