From 7028ef099b722ce889b90ce497b61e673129e69f Mon Sep 17 00:00:00 2001 From: costin Date: Fri, 27 Aug 2010 18:22:26 +0300 Subject: [PATCH] + add partitioned region namespace tests SGF-10 SGF-13 --- .../data/gemfire/SimplePartitionResolver.java | 39 +++++++++ .../PartitionedRegionNamespaceTest.java | 87 +++++++++++++++++++ .../data/gemfire/config/partitioned-ns.xml | 34 ++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java create mode 100644 src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java create mode 100644 src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml diff --git a/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java b/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java new file mode 100644 index 00000000..740dc209 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java @@ -0,0 +1,39 @@ +/* + * Copyright 2010 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 java.io.Serializable; + +import com.gemstone.gemfire.cache.EntryOperation; +import com.gemstone.gemfire.cache.PartitionResolver; + +/** + * @author Costin Leau + */ +public class SimplePartitionResolver implements PartitionResolver { + + public String getName() { + return getClass().getName(); + } + + public Serializable getRoutingObject(EntryOperation opDetails) { + return getName(); + } + + public void close() { + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java new file mode 100644 index 00000000..f4d904f7 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2010 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.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +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.RegionFactoryBean; +import org.springframework.data.gemfire.SimplePartitionResolver; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.test.context.ContextConfiguration; +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; + +/** + * @author Costin Leau + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("partitioned-ns.xml") +public class PartitionedRegionNamespaceTest { + + @Autowired + private ApplicationContext context; + + @Test + public void testBasicReplica() throws Exception { + assertTrue(context.containsBean("simple")); + } + + @Test + public void testPartitionOptions() throws Exception { + assertTrue(context.containsBean("options")); + RegionFactoryBean fb = context.getBean("&options", RegionFactoryBean.class); + assertEquals(DataPolicy.PARTITION, TestUtils.readField("dataPolicy", fb)); + assertEquals(null, TestUtils.readField("scope", fb)); + + RegionAttributes attrs = TestUtils.readField("attributes", fb); + PartitionAttributes pAttr = attrs.getPartitionAttributes(); + + assertEquals(1, pAttr.getRedundantCopies()); + assertEquals(4, pAttr.getTotalNumBuckets()); + assertSame(SimplePartitionResolver.class, pAttr.getPartitionResolver().getClass()); + } + + @Test + public void testComplexPartition() throws Exception { + assertTrue(context.containsBean("complex")); + RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); + CacheListener[] listeners = TestUtils.readField("cacheListeners", fb); + assertFalse(ObjectUtils.isEmpty(listeners)); + assertEquals(2, listeners.length); + assertSame(listeners[0], context.getBean("c-listener")); + + assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", fb)); + assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); + + RegionAttributes attrs = TestUtils.readField("attributes", fb); + PartitionAttributes pAttr = attrs.getPartitionAttributes(); + + assertEquals(20, pAttr.getLocalMaxMemory()); + } +} \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml new file mode 100644 index 00000000..47f042b8 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file