Refactored region factories

This commit is contained in:
David Turanski
2012-07-04 10:37:44 -04:00
parent e9d1173b05
commit 8e6e43b96e
20 changed files with 226 additions and 126 deletions

View File

@@ -27,52 +27,54 @@ import com.gemstone.gemfire.cache.Region;
/**
*
* @author David Turanski
*
*
*/
public class SubRegionTest extends RecreatingContextTest {
@Override
protected String location() {
return "org/springframework/data/gemfire/basic-subregion.xml";
return "org/springframework/data/gemfire/basic-subregion.xml";
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@Test
public void testBasic() throws Exception {
CacheFactoryBean cfb = new CacheFactoryBean();
cfb.setUseBeanFactoryLocator(false);
cfb.afterPropertiesSet();
GemFireCache cache = cfb.getObject();
RegionFactoryBean rfb = new RegionFactoryBean();
RegionFactoryBean rfb = new ReplicatedRegionFactoryBean();
rfb.setCache(cache);
rfb.setName("parent");
rfb.afterPropertiesSet();
Region parent = rfb.getObject();
SubRegionFactoryBean srfb = new SubRegionFactoryBean();
srfb.setParent(parent);
srfb.setName("/parent/child");
srfb.setRegionName("child");
srfb.afterPropertiesSet();
Region child = srfb.getObject();
assertNotNull(parent.getSubregion("child"));
assertSame(child,parent.getSubregion("child"));
assertSame(child, parent.getSubregion("child"));
cache.close();
}
@SuppressWarnings("rawtypes")
@Test
@Test
public void testContext() throws Exception {
Region parent = ctx.getBean("parent", Region.class);
Region child = ctx.getBean("/parent/child", Region.class);
assertNotNull(parent.getSubregion("child"));
assertSame(child,parent.getSubregion("child"));
assertEquals("/parent/child",child.getFullPath());
assertSame(child, parent.getSubregion("child"));
assertEquals("/parent/child", child.getFullPath());
}
@SuppressWarnings("rawtypes")
@Test
@Test
public void testChildOnly() throws Exception {
Region child = ctx.getBean("/parent/child", Region.class);
assertEquals("/parent/child",child.getFullPath());
assertEquals("/parent/child", child.getFullPath());
}
}

View File

@@ -29,14 +29,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
import org.springframework.data.gemfire.SimpleObjectSizer;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
import com.gemstone.gemfire.cache.EvictionAction;
@@ -98,7 +99,7 @@ public class DiskStoreAndEvictionRegionParsingTest {
public void testReplicaDataOptions() throws Exception {
assertTrue(context.containsBean("replicated-data"));
RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class);
assertEquals(DataPolicy.REPLICATE, TestUtils.readField("dataPolicy", fb));
assertTrue(fb instanceof ReplicatedRegionFactoryBean);
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
Region region = context.getBean("replicated-data", Region.class);
// eviction tests
@@ -114,8 +115,10 @@ public class DiskStoreAndEvictionRegionParsingTest {
public void testPartitionDataOptions() throws Exception {
assertTrue(context.containsBean("partition-data"));
RegionFactoryBean fb = context.getBean("&partition-data", RegionFactoryBean.class);
assertEquals(DataPolicy.PERSISTENT_PARTITION, TestUtils.readField("dataPolicy", fb));
assertTrue(fb instanceof PartitionedRegionFactoryBean);
assertTrue((Boolean) TestUtils.readField("persistent", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
assertEquals(EvictionAction.LOCAL_DESTROY, evicAttr.getAction());
assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm());

View File

@@ -25,6 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.SimplePartitionResolver;
import org.springframework.data.gemfire.TestUtils;
@@ -33,7 +34,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.RegionAttributes;
@@ -56,7 +56,7 @@ public class PartitionedRegionNamespaceTest {
public void testPartitionOptions() throws Exception {
assertTrue(context.containsBean("options"));
RegionFactoryBean fb = context.getBean("&options", RegionFactoryBean.class);
assertEquals(DataPolicy.PARTITION, TestUtils.readField("dataPolicy", fb));
assertTrue(fb instanceof PartitionedRegionFactoryBean);
assertEquals(null, TestUtils.readField("scope", fb));
assertEquals("redundant", TestUtils.readField("name", fb));

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.RegionLookupFactoryBean;
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -34,7 +35,6 @@ import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
@@ -58,7 +58,7 @@ public class ReplicatedRegionNamespaceTest {
public void testPublishingReplica() throws Exception {
assertTrue(context.containsBean("pub"));
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
assertEquals(DataPolicy.REPLICATE, TestUtils.readField("dataPolicy", fb));
assertTrue(fb instanceof ReplicatedRegionFactoryBean);
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
assertEquals("publisher", TestUtils.readField("name", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);