diff --git a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java index 849b67de..76621135 100644 --- a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java @@ -345,6 +345,7 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple validateRegionAttributes(regionAttributes); regionFactory.setCloningEnabled(regionAttributes.getCloningEnabled()); + regionFactory.setCompressor(regionAttributes.getCompressor()); regionFactory.setConcurrencyChecksEnabled(regionAttributes.getConcurrencyChecksEnabled()); regionFactory.setConcurrencyLevel(regionAttributes.getConcurrencyLevel()); regionFactory.setCustomEntryIdleTimeout(regionAttributes.getCustomEntryIdleTimeout()); diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java index f1676455..feb9d66c 100644 --- a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java @@ -105,6 +105,7 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean // map region attributes onto the client region factory if (attributes != null) { factory.setCloningEnabled(attributes.getCloningEnabled()); + factory.setCompressor(attributes.getCompressor()); factory.setConcurrencyLevel(attributes.getConcurrencyLevel()); factory.setCustomEntryIdleTimeout(attributes.getCustomEntryIdleTimeout()); factory.setCustomEntryTimeToLive(attributes.getCustomEntryTimeToLive()); diff --git a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java index 79cdf298..a6f621b1 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java @@ -91,9 +91,10 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { ParsingUtils.parseOptionalRegionAttributes(parserContext, element, regionAttributesBuilder); ParsingUtils.parseSubscription(parserContext, element, regionAttributesBuilder); ParsingUtils.parseStatistics(element, regionAttributesBuilder); + ParsingUtils.parseMembershipAttributes(parserContext, element, regionAttributesBuilder); ParsingUtils.parseExpiration(parserContext, element, regionAttributesBuilder); ParsingUtils.parseEviction(parserContext, element, regionAttributesBuilder); - ParsingUtils.parseMembershipAttributes(parserContext, element, regionAttributesBuilder); + ParsingUtils.parseCompressor(parserContext, element, regionAttributesBuilder); String enableGateway = element.getAttribute("enable-gateway"); String hubId = element.getAttribute("hub-id"); @@ -133,11 +134,11 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { } else if (subElement.getLocalName().equals("cache-loader")) { builder.addPropertyValue("cacheLoader", - ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder)); + ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, subElement, builder)); } else if (subElement.getLocalName().equals("cache-writer")) { builder.addPropertyValue("cacheWriter", - ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder)); + ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, subElement, builder)); } } diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java index 198b24db..7ad934c4 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java @@ -76,6 +76,7 @@ class ClientRegionParser extends AbstractRegionParser { ParsingUtils.parseStatistics(element, regionAttributesBuilder); ParsingUtils.parseExpiration(parserContext, element, regionAttributesBuilder); ParsingUtils.parseEviction(parserContext, element, regionAttributesBuilder); + ParsingUtils.parseCompressor(parserContext, element, regionAttributesBuilder); builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition()); diff --git a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java index bd360db6..19a42bb3 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java @@ -432,6 +432,17 @@ abstract class ParsingUtils { return false; } + public static void parseCompressor(ParserContext parserContext, Element element, + BeanDefinitionBuilder regionAttributesBuilder) { + + Element compressorElement = DomUtils.getChildElementByTagName(element, "compressor"); + + if (compressorElement != null) { + regionAttributesBuilder.addPropertyValue("compressor", parseRefOrSingleNestedBeanDeclaration( + parserContext, compressorElement, regionAttributesBuilder)); + } + } + static String resolveCacheReference(final String cacheRef) { return (StringUtils.hasText(cacheRef) ? cacheRef : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); } diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.5.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.5.xsd index c1f72fca..620dfcb2 100644 --- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.5.xsd +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.5.xsd @@ -522,6 +522,19 @@ use inner bean declarations. + + + + + + + + + + diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java index cd72f4aa..193989d3 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -51,15 +51,19 @@ import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.client.ClientRegionShortcut; import com.gemstone.gemfire.cache.util.CacheWriterAdapter; import com.gemstone.gemfire.cache.util.ObjectSizer; +import com.gemstone.gemfire.compression.Compressor; /** + * The ClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality + * of GemFire Client Region namespace support in SDG. + * * @author Costin Leau * @author David Turanski * @author John Blum */ -@ContextConfiguration(locations="/org/springframework/data/gemfire/config/client-ns.xml", - initializers=GemfireTestApplicationContextInitializer.class) @RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="client-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) +@SuppressWarnings("unused") public class ClientRegionNamespaceTest { @Autowired @@ -152,7 +156,24 @@ public class ClientRegionNamespaceTest { assertTrue(TestUtils.readField("cacheWriter", factory) instanceof TestCacheWriter); } - @SuppressWarnings("unused") + @Test + public void testCompressedReplicateRegion() { + assertTrue(context.containsBean("compressed")); + + Region compressed = context.getBean("compressed", Region.class); + + assertNotNull("The 'compressed' Client Region was not properly configured and initialized!", compressed); + assertEquals("compressed", compressed.getName()); + assertEquals(Region.SEPARATOR + "compressed", compressed.getFullPath()); + assertNotNull(compressed.getAttributes()); + assertEquals(DataPolicy.EMPTY, compressed.getAttributes().getDataPolicy()); + assertEquals("gemfire-pool", compressed.getAttributes().getPoolName()); + assertTrue(String.format("Expected 'TestCompressor'; but was '%1$s'!", + ObjectUtils.nullSafeClassName(compressed.getAttributes().getCompressor())), + compressed.getAttributes().getCompressor() instanceof TestCompressor); + assertEquals("STD", compressed.getAttributes().getCompressor().toString()); + } + public static final class TestCacheLoader implements CacheLoader { @Override @@ -168,4 +189,28 @@ public class ClientRegionNamespaceTest { public static final class TestCacheWriter extends CacheWriterAdapter { } + public static class TestCompressor implements Compressor { + + private String name; + + public void setName(final String name) { + this.name = name; + } + + @Override + public byte[] compress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public byte[] decompress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public String toString() { + return this.name; + } + + } } diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java index f0f8ff1f..c369995f 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java @@ -18,7 +18,7 @@ package org.springframework.data.gemfire.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -40,14 +40,18 @@ import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.compression.Compressor; /** + * The LocalRegionNamespaceTest class is a test suite of test cases testing the contract and functionality + * of GemFire's Local Region support in SDG. + * * @author Costin Leau * @author David Turanski + * @author John Blum */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="local-ns.xml", - initializers=GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations="local-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) public class LocalRegionNamespaceTest { @Autowired @@ -71,8 +75,8 @@ public class LocalRegionNamespaceTest { assertFalse(attrs.getPublisher()); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testComplexLocal() throws Exception { assertTrue(context.containsBean("complex")); RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); @@ -85,8 +89,8 @@ public class LocalRegionNamespaceTest { assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testLocalWithAttributes() throws Exception { assertTrue(context.containsBean("local-with-attributes")); Region region = context.getBean("local-with-attributes", Region.class); @@ -99,8 +103,8 @@ public class LocalRegionNamespaceTest { assertEquals(true, attrs.isDiskSynchronous()); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testRegionLookup() throws Exception { Cache cache = context.getBean(Cache.class); Region existing = cache.createRegionFactory().create("existing"); @@ -111,11 +115,52 @@ public class LocalRegionNamespaceTest { assertEquals(existing, context.getBean("lookup")); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testLocalPersistent() { Region region = context.getBean("persistent", Region.class); RegionAttributes attrs = region.getAttributes(); assertTrue(attrs.getDataPolicy().withPersistence()); } + + @Test + public void testCompressedLocalRegion() { + assertTrue(context.containsBean("compressed")); + + Region compressed = context.getBean("compressed", Region.class); + + assertNotNull("The 'compressed' Local Region was not properly configured and initialized!", compressed); + assertEquals("compressed", compressed.getName()); + assertEquals(Region.SEPARATOR + "compressed", compressed.getFullPath()); + assertNotNull(compressed.getAttributes()); + assertEquals(DataPolicy.NORMAL, compressed.getAttributes().getDataPolicy()); + assertEquals(Scope.LOCAL, compressed.getAttributes().getScope()); + assertTrue(compressed.getAttributes().getCompressor() instanceof TestCompressor); + assertEquals("ABC", compressed.getAttributes().getCompressor().toString()); + } + + public static class TestCompressor implements Compressor { + + private String name; + + public void setName(final String name) { + this.name = name; + } + + @Override + public byte[] compress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public byte[] decompress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public String toString() { + return this.name; + } + } + } diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java index bf70017b..ec2a9002 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -47,6 +47,7 @@ import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.partition.PartitionListener; import com.gemstone.gemfire.cache.partition.PartitionListenerAdapter; +import com.gemstone.gemfire.compression.Compressor; /** * The PartitionRegionNamespaceTest class is a test suite of test cases testing the contract and functionality @@ -131,9 +132,24 @@ public class PartitionedRegionNamespaceTest { assertTrue(complexRegionPartitionAttributes.getPartitionListeners()[0] instanceof TestPartitionListener); } + @Test + public void testCompressedPartitionRegion() { + assertTrue(context.containsBean("compressed")); + + Region compressed = context.getBean("compressed", Region.class); + + assertNotNull("The 'compressed' PARTITION Region was not properly configured and initialized!", compressed); + assertEquals("compressed", compressed.getName()); + assertEquals(Region.SEPARATOR + "compressed", compressed.getFullPath()); + assertNotNull(compressed.getAttributes()); + assertEquals(DataPolicy.PARTITION, compressed.getAttributes().getDataPolicy()); + assertTrue(compressed.getAttributes().getCompressor() instanceof TestCompressor); + assertEquals("testCompressor", compressed.getAttributes().getCompressor().toString()); + } + @Test @SuppressWarnings("rawtypes") - public void testFixedPartition() throws Exception { + public void testFixedPartitionRegion() throws Exception { RegionFactoryBean fixedRegionFactoryBean = context.getBean("&fixed", RegionFactoryBean.class); assertNotNull(fixedRegionFactoryBean); @@ -203,6 +219,30 @@ public class PartitionedRegionNamespaceTest { assertEquals("ABC", listenersPartitionAttributes.getPartitionListeners()[0].toString()); } + public static class TestCompressor implements Compressor { + + private String name; + + public void setName(final String name) { + this.name = name; + } + + @Override + public byte[] compress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public byte[] decompress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public String toString() { + return this.name; + } + } + public static class TestPartitionListener extends PartitionListenerAdapter { private String name; diff --git a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java index 0469c1cc..94df8f96 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java @@ -18,6 +18,7 @@ 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 static org.junit.Assert.assertTrue; @@ -36,17 +37,23 @@ 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; +import com.gemstone.gemfire.compression.Compressor; /** + * The ReplicatedRegionNamespaceTest class is a test suite of test cases testing the contract and functionality + * of GemFire Replicated Region support in SDG. + * * @author Costin Leau * @author David Turanski + * @author John Blum */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="replicated-ns.xml", - initializers=GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations="replicated-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) +@SuppressWarnings("unused") public class ReplicatedRegionNamespaceTest { @Autowired @@ -74,8 +81,8 @@ public class ReplicatedRegionNamespaceTest { assertTrue(attrs.getConcurrencyChecksEnabled()); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testComplexReplica() throws Exception { assertTrue(context.containsBean("complex")); RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); @@ -88,8 +95,8 @@ public class ReplicatedRegionNamespaceTest { assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testReplicaWithAttributes() throws Exception { assertTrue(context.containsBean("replicated-with-attributes")); Region region = context.getBean("replicated-with-attributes", Region.class); @@ -111,8 +118,8 @@ public class ReplicatedRegionNamespaceTest { assertEquals(true, attrs.getMulticastEnabled()); } - @SuppressWarnings("rawtypes") @Test + @SuppressWarnings("rawtypes") public void testRegionLookup() throws Exception { Cache cache = context.getBean(Cache.class); Region existing = cache.createRegionFactory().create("existing"); @@ -121,5 +128,45 @@ public class ReplicatedRegionNamespaceTest { assertEquals("existing", TestUtils.readField("name", lfb)); assertEquals(existing, context.getBean("lookup")); } - + + @Test + public void testCompressedReplicateRegion() { + assertTrue(context.containsBean("compressed")); + + Region compressed = context.getBean("compressed", Region.class); + + assertNotNull("The 'compressed' REPLICATE Region was not properly configured and initialized!", compressed); + assertEquals("compressed", compressed.getName()); + assertEquals(Region.SEPARATOR + "compressed", compressed.getFullPath()); + assertNotNull(compressed.getAttributes()); + assertEquals(DataPolicy.REPLICATE, compressed.getAttributes().getDataPolicy()); + assertTrue(compressed.getAttributes().getCompressor() instanceof TestCompressor); + assertEquals("XYZ", compressed.getAttributes().getCompressor().toString()); + } + + + public static class TestCompressor implements Compressor { + + private String name; + + public void setName(final String name) { + this.name = name; + } + + @Override + public byte[] compress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public byte[] decompress(final byte[] input) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public String toString() { + return this.name; + } + } + } diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml index 5ba6b6ef..2f1eeb42 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml @@ -1,15 +1,14 @@ + http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd +" default-lazy-init="true"> - + @@ -53,4 +52,10 @@ + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml index 5139565b..a122bf49 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml @@ -1,21 +1,21 @@ + http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd +" default-lazy-init="true"> - + - + - + - + @@ -24,20 +24,26 @@ - - - + + + + + + + + + - \ 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 index 5b12344b..60fb0f55 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml @@ -42,6 +42,12 @@ + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml index f7600b52..937852f5 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml @@ -1,19 +1,19 @@ + http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd +" default-lazy-init="true"> + + + + - - - - - + @@ -22,27 +22,32 @@ - - - + + + + + + + - + + - \ No newline at end of file + +