Implements JIRA feature request SGF-309 adding support for compression of GemFire Cache Region data using the new Compressor attribute and property in the RegionAttributes API.

This commit is contained in:
John Blum
2014-08-28 15:32:11 -07:00
parent b9a966e11a
commit 84be164f60
14 changed files with 308 additions and 81 deletions

View File

@@ -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<Object, Object> {
@Override
@@ -168,4 +189,28 @@ public class ClientRegionNamespaceTest {
public static final class TestCacheWriter extends CacheWriterAdapter<Object, Object> {
}
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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;

View File

@@ -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;
}
}
}