Additional code refactoring and cleanup to the strongly-typed, Region Namespace tests.
This commit is contained in:
@@ -19,6 +19,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.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -30,6 +31,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.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
@@ -45,12 +47,12 @@ import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.EvictionAlgorithm;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.LoaderHelper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -60,6 +62,8 @@ import com.gemstone.gemfire.compression.Compressor;
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.ClientRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="client-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@@ -81,67 +85,111 @@ public class ClientRegionNamespaceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicClient() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNames() throws Exception {
|
||||
assertTrue(context.containsBean("SimpleRegion"));
|
||||
assertTrue(context.containsBean("publisher"));
|
||||
assertTrue(context.containsBean("Publisher"));
|
||||
assertTrue(context.containsBean("ComplexRegion"));
|
||||
assertTrue(context.containsBean("PersistentRegion"));
|
||||
assertTrue(context.containsBean("OverflowRegion"));
|
||||
assertTrue(context.containsBean("Compressed"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testPublishingClient() throws Exception {
|
||||
public void testSimpleClientRegion() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
|
||||
Region<?, ?> simple = context.getBean("simple", Region.class);
|
||||
|
||||
assertNotNull("The 'SimpleRegion' Client Region was not properly configured and initialized!", simple);
|
||||
assertEquals("SimpleRegion", simple.getName());
|
||||
assertEquals(Region.SEPARATOR + "SimpleRegion", simple.getFullPath());
|
||||
assertNotNull(simple.getAttributes());
|
||||
assertEquals(DataPolicy.NORMAL, simple.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testPublishingClientRegion() throws Exception {
|
||||
assertTrue(context.containsBean("empty"));
|
||||
ClientRegionFactoryBean fb = context.getBean("&empty", ClientRegionFactoryBean.class);
|
||||
assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", fb));
|
||||
|
||||
ClientRegionFactoryBean emptyClientRegionFactoryBean = context.getBean("&empty", ClientRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(emptyClientRegionFactoryBean);
|
||||
assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", emptyClientRegionFactoryBean));
|
||||
assertEquals("empty", TestUtils.readField("beanName", emptyClientRegionFactoryBean));
|
||||
assertEquals("Publisher", TestUtils.readField("name", emptyClientRegionFactoryBean));
|
||||
assertEquals("gemfire-pool", TestUtils.readField("poolName", emptyClientRegionFactoryBean));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testComplexClient() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexClientRegion() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
ClientRegionFactoryBean fb = context.getBean("&complex", ClientRegionFactoryBean.class);
|
||||
CacheListener[] listeners = TestUtils.readField("cacheListeners", fb);
|
||||
assertFalse(ObjectUtils.isEmpty(listeners));
|
||||
assertEquals(2, listeners.length);
|
||||
assertSame(listeners[0], context.getBean("c-listener"));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
assertEquals(500, attrs.getEntryTimeToLive().getTimeout());
|
||||
assertEquals(0.5f,attrs.getLoadFactor(),0.001);
|
||||
assertEquals(5, attrs.getEvictionAttributes().getMaximum());
|
||||
|
||||
ClientRegionFactoryBean complexClientRegionFactoryBean = context.getBean("&complex", ClientRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(complexClientRegionFactoryBean);
|
||||
|
||||
CacheListener[] cacheListeners = TestUtils.readField("cacheListeners", complexClientRegionFactoryBean);
|
||||
|
||||
assertFalse(ObjectUtils.isEmpty(cacheListeners));
|
||||
assertEquals(2, cacheListeners.length);
|
||||
assertSame(cacheListeners[0], context.getBean("c-listener"));
|
||||
assertTrue(cacheListeners[1] instanceof SimpleCacheListener);
|
||||
assertNotSame(cacheListeners[0], cacheListeners[1]);
|
||||
|
||||
RegionAttributes complexRegionAttributes = TestUtils.readField("attributes", complexClientRegionFactoryBean);
|
||||
|
||||
assertNotNull(complexRegionAttributes);
|
||||
assertEquals(0.5f, complexRegionAttributes.getLoadFactor(), 0.001);
|
||||
assertEquals(ExpirationAction.INVALIDATE, complexRegionAttributes.getEntryTimeToLive().getAction());
|
||||
assertEquals(500, complexRegionAttributes.getEntryTimeToLive().getTimeout());
|
||||
assertEquals(5, complexRegionAttributes.getEvictionAttributes().getMaximum());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public void testPersistent() throws Exception {
|
||||
public void testPersistentClientRegion() throws Exception {
|
||||
assertTrue(context.containsBean("persistent"));
|
||||
Region region = context.getBean("persistent", Region.class);
|
||||
RegionAttributes attrs = region.getAttributes();
|
||||
assertEquals("diskStore", attrs.getDiskStoreName());
|
||||
assertEquals(10, attrs.getDiskDirSizes()[0]);
|
||||
|
||||
Region persistent = context.getBean("persistent", Region.class);
|
||||
|
||||
assertNotNull("The 'PersistentRegion' Region was not properly configured and initialized!", persistent);
|
||||
assertEquals("PersistentRegion", persistent.getName());
|
||||
assertEquals(Region.SEPARATOR + "PersistentRegion", persistent.getFullPath());
|
||||
|
||||
RegionAttributes persistentRegionAttributes = persistent.getAttributes();
|
||||
|
||||
assertEquals(DataPolicy.PERSISTENT_REPLICATE, persistentRegionAttributes.getDataPolicy());
|
||||
assertEquals("diskStore", persistentRegionAttributes.getDiskStoreName());
|
||||
assertEquals(10, persistentRegionAttributes.getDiskDirSizes()[0]);
|
||||
assertEquals("gemfire-pool", persistentRegionAttributes.getPoolName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testOverflowToDisk() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testOverflowClientRegion() throws Exception {
|
||||
assertTrue(context.containsBean("overflow"));
|
||||
ClientRegionFactoryBean fb = context.getBean("&overflow", ClientRegionFactoryBean.class);
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction());
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm());
|
||||
// for some reason GemFire resets this to 56 on my machine (not sure
|
||||
// why)
|
||||
// assertEquals(10, evicAttr.getMaximum());
|
||||
ObjectSizer sizer = evicAttr.getObjectSizer();
|
||||
assertEquals(SimpleObjectSizer.class, sizer.getClass());
|
||||
|
||||
ClientRegionFactoryBean overflowClientRegionFactoryBean = context.getBean("&overflow", ClientRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(overflowClientRegionFactoryBean);
|
||||
assertEquals("diskStore", TestUtils.readField("diskStoreName", overflowClientRegionFactoryBean));
|
||||
assertEquals("gemfire-pool", TestUtils.readField("poolName", overflowClientRegionFactoryBean));
|
||||
|
||||
RegionAttributes overflowRegionAttributes = TestUtils.readField("attributes", overflowClientRegionFactoryBean);
|
||||
|
||||
assertNotNull(overflowRegionAttributes);
|
||||
assertEquals(DataPolicy.NORMAL, overflowRegionAttributes.getDataPolicy());
|
||||
|
||||
EvictionAttributes overflowEvictionAttributes = overflowRegionAttributes.getEvictionAttributes();
|
||||
|
||||
assertNotNull(overflowEvictionAttributes);
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, overflowEvictionAttributes.getAction());
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, overflowEvictionAttributes.getAlgorithm());
|
||||
assertEquals(10, overflowEvictionAttributes.getMaximum());
|
||||
assertTrue(overflowEvictionAttributes.getObjectSizer() instanceof SimpleObjectSizer);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,6 +199,7 @@ public class ClientRegionNamespaceTest {
|
||||
ClientRegionFactoryBean factory = context.getBean("&loadWithWrite", ClientRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(factory);
|
||||
assertEquals("LoadedFullOfWrites", TestUtils.readField("name", factory));
|
||||
assertEquals(ClientRegionShortcut.LOCAL, TestUtils.readField("shortcut", factory));
|
||||
assertTrue(TestUtils.readField("cacheLoader", factory) instanceof TestCacheLoader);
|
||||
assertTrue(TestUtils.readField("cacheWriter", factory) instanceof TestCacheWriter);
|
||||
@@ -158,19 +207,19 @@ public class ClientRegionNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testCompressedReplicateRegion() {
|
||||
assertTrue(context.containsBean("compressed"));
|
||||
assertTrue(context.containsBean("Compressed"));
|
||||
|
||||
Region<?, ?> compressed = context.getBean("compressed", Region.class);
|
||||
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("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);
|
||||
ObjectUtils.nullSafeClassName(compressed.getAttributes().getCompressor())),
|
||||
compressed.getAttributes().getCompressor() instanceof TestCompressor);
|
||||
assertEquals("STD", compressed.getAttributes().getCompressor().toString());
|
||||
}
|
||||
|
||||
@@ -213,4 +262,5 @@ public class ClientRegionNamespaceTest {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,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.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -28,6 +29,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.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -49,6 +51,8 @@ import com.gemstone.gemfire.compression.Compressor;
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.LocalRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.LocalRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="local-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@@ -59,48 +63,77 @@ public class LocalRegionNamespaceTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicLocal() throws Exception {
|
||||
public void testSimpleLocalRegion() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
|
||||
Region<?, ?> simple = context.getBean("simple", Region.class);
|
||||
|
||||
assertNotNull("The 'simple' Region was not properly configured or initialized!", simple);
|
||||
assertEquals("simple", simple.getName());
|
||||
assertEquals(Region.SEPARATOR + "simple", simple.getFullPath());
|
||||
assertNotNull(simple.getAttributes());
|
||||
assertEquals(DataPolicy.NORMAL, simple.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public void testPublishingLocal() throws Exception {
|
||||
public void testPublisherLocalRegion() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
|
||||
assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
|
||||
assertEquals("publisher", TestUtils.readField("name", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
assertFalse(attrs.getPublisher());
|
||||
|
||||
RegionFactoryBean publisherRegionFactoryBean = context.getBean("&pub", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(publisherRegionFactoryBean);
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", publisherRegionFactoryBean));
|
||||
assertEquals("publisher", TestUtils.readField("name", publisherRegionFactoryBean));
|
||||
assertEquals(Scope.LOCAL, TestUtils.readField("scope", publisherRegionFactoryBean));
|
||||
|
||||
RegionAttributes publisherRegionAttributes = TestUtils.readField("attributes", publisherRegionFactoryBean);
|
||||
|
||||
assertNotNull(publisherRegionAttributes);
|
||||
assertFalse(publisherRegionAttributes.getPublisher());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexLocal() 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));
|
||||
RegionFactoryBean complexRegionFactoryBean = context.getBean("&complex", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(complexRegionFactoryBean);
|
||||
|
||||
CacheListener[] cacheListeners = TestUtils.readField("cacheListeners", complexRegionFactoryBean);
|
||||
|
||||
assertFalse(ObjectUtils.isEmpty(cacheListeners));
|
||||
assertEquals(2, cacheListeners.length);
|
||||
assertSame(context.getBean("c-listener"), cacheListeners[0]);
|
||||
assertTrue(cacheListeners[1] instanceof SimpleCacheListener);
|
||||
assertNotSame(cacheListeners[0], cacheListeners[1]);
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testLocalWithAttributes() throws Exception {
|
||||
assertTrue(context.containsBean("local-with-attributes"));
|
||||
|
||||
Region region = context.getBean("local-with-attributes", Region.class);
|
||||
RegionAttributes attrs = region.getAttributes();
|
||||
assertEquals(10, attrs.getInitialCapacity());
|
||||
assertEquals(true, attrs.getIgnoreJTA());
|
||||
assertEquals(false, attrs.getIndexMaintenanceSynchronous());
|
||||
assertEquals(String.class, attrs.getKeyConstraint());
|
||||
assertEquals(String.class, attrs.getValueConstraint());
|
||||
assertEquals(true, attrs.isDiskSynchronous());
|
||||
|
||||
assertNotNull("The 'local-with-attributes' Region was not properly configured and initialized!", region);
|
||||
assertEquals("local-with-attributes", region.getName());
|
||||
assertEquals(Region.SEPARATOR + "local-with-attributes", region.getFullPath());
|
||||
|
||||
RegionAttributes localRegionAttributes = region.getAttributes();
|
||||
|
||||
assertEquals(DataPolicy.PRELOADED, localRegionAttributes.getDataPolicy());
|
||||
assertTrue(localRegionAttributes.isDiskSynchronous());
|
||||
assertTrue(localRegionAttributes.getIgnoreJTA());
|
||||
assertFalse(localRegionAttributes.getIndexMaintenanceSynchronous());
|
||||
assertEquals(10, localRegionAttributes.getInitialCapacity());
|
||||
assertEquals(String.class, localRegionAttributes.getKeyConstraint());
|
||||
assertEquals("0.9", String.valueOf(localRegionAttributes.getLoadFactor()));
|
||||
assertEquals(String.class, localRegionAttributes.getValueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,30 +141,39 @@ public class LocalRegionNamespaceTest {
|
||||
public void testRegionLookup() throws Exception {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
Region existing = cache.createRegionFactory().create("existing");
|
||||
|
||||
|
||||
assertTrue(context.containsBean("lookup"));
|
||||
RegionLookupFactoryBean lfb = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
assertEquals("existing", TestUtils.readField("name", lfb));
|
||||
assertEquals(existing, context.getBean("lookup"));
|
||||
|
||||
RegionLookupFactoryBean localRegionFactoryBean = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
|
||||
assertEquals("existing", TestUtils.readField("name", localRegionFactoryBean));
|
||||
assertSame(existing, context.getBean("lookup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testLocalPersistent() {
|
||||
Region region = context.getBean("persistent", Region.class);
|
||||
RegionAttributes attrs = region.getAttributes();
|
||||
assertTrue(attrs.getDataPolicy().withPersistence());
|
||||
Region persistentLocalRegion = context.getBean("persistent", Region.class);
|
||||
|
||||
assertNotNull("The 'persistent' Local Region was not properly configured and initialized!", persistentLocalRegion);
|
||||
assertEquals("persistent", persistentLocalRegion.getName());
|
||||
assertEquals(Region.SEPARATOR + "persistent", persistentLocalRegion.getFullPath());
|
||||
|
||||
RegionAttributes persistentRegionAttributes = persistentLocalRegion.getAttributes();
|
||||
|
||||
assertNotNull(persistentRegionAttributes);
|
||||
assertTrue(persistentRegionAttributes.getDataPolicy().withPersistence());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompressedLocalRegion() {
|
||||
assertTrue(context.containsBean("compressed"));
|
||||
assertTrue(context.containsBean("Compressed"));
|
||||
|
||||
Region<?, ?> compressed = context.getBean("compressed", Region.class);
|
||||
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("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());
|
||||
|
||||
@@ -56,6 +56,8 @@ import com.gemstone.gemfire.compression.Compressor;
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.PartitionedRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "partitioned-ns.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
|
||||
@@ -19,6 +19,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.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -29,6 +30,7 @@ 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.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -50,6 +52,8 @@ import com.gemstone.gemfire.compression.Compressor;
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.ReplicatedRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="replicated-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@@ -60,62 +64,84 @@ public class ReplicatedRegionNamespaceTest {
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testBasicReplica() throws Exception {
|
||||
public void testSimpleReplicateRegion() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
RegionFactoryBean fb = context.getBean("&simple", RegionFactoryBean.class);
|
||||
assertEquals(false, TestUtils.readField("close", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
assertFalse(attrs.getConcurrencyChecksEnabled());
|
||||
|
||||
RegionFactoryBean simpleRegionFactoryBean = context.getBean("&simple", RegionFactoryBean.class);
|
||||
|
||||
assertEquals("simple", TestUtils.readField("beanName", simpleRegionFactoryBean));
|
||||
assertEquals(false, TestUtils.readField("close", simpleRegionFactoryBean));
|
||||
|
||||
RegionAttributes simpleRegionAttributes = TestUtils.readField("attributes", simpleRegionFactoryBean);
|
||||
|
||||
assertNotNull(simpleRegionAttributes);
|
||||
assertFalse(simpleRegionAttributes.getConcurrencyChecksEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public void testPublishingReplica() throws Exception {
|
||||
public void testPublishReplicateRegion() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertTrue(fb instanceof ReplicatedRegionFactoryBean);
|
||||
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
|
||||
assertEquals("publisher", TestUtils.readField("name", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
assertFalse(attrs.getPublisher());
|
||||
assertTrue(attrs.getConcurrencyChecksEnabled());
|
||||
|
||||
RegionFactoryBean publisherRegionFactoryBean = context.getBean("&pub", RegionFactoryBean.class);
|
||||
|
||||
assertTrue(publisherRegionFactoryBean instanceof ReplicatedRegionFactoryBean);
|
||||
assertEquals("publisher", TestUtils.readField("name", publisherRegionFactoryBean));
|
||||
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", publisherRegionFactoryBean));
|
||||
|
||||
RegionAttributes publisherRegionAttributes = TestUtils.readField("attributes", publisherRegionFactoryBean);
|
||||
|
||||
assertTrue(publisherRegionAttributes.getConcurrencyChecksEnabled());
|
||||
assertFalse(publisherRegionAttributes.getPublisher());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexReplica() throws Exception {
|
||||
public void testComplexReplicateRegion() 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));
|
||||
RegionFactoryBean complexRegionFactoryBean = context.getBean("&complex", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(complexRegionFactoryBean);
|
||||
assertEquals("complex", TestUtils.readField("beanName", complexRegionFactoryBean));
|
||||
|
||||
CacheListener[] cacheListeners = TestUtils.readField("cacheListeners", complexRegionFactoryBean);
|
||||
|
||||
assertFalse(ObjectUtils.isEmpty(cacheListeners));
|
||||
assertEquals(2, cacheListeners.length);
|
||||
assertSame(context.getBean("c-listener"), cacheListeners[0]);
|
||||
assertTrue(cacheListeners[1] instanceof SimpleCacheListener);
|
||||
assertNotSame(cacheListeners[0], cacheListeners[1]);
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testReplicaWithAttributes() throws Exception {
|
||||
public void testReplicatedRegionWithAttributes() throws Exception {
|
||||
assertTrue(context.containsBean("replicated-with-attributes"));
|
||||
|
||||
Region region = context.getBean("replicated-with-attributes", Region.class);
|
||||
RegionAttributes attrs = region.getAttributes();
|
||||
|
||||
assertEquals(10, attrs.getInitialCapacity());
|
||||
assertEquals(true, attrs.getIgnoreJTA());
|
||||
assertEquals(false, attrs.getIndexMaintenanceSynchronous());
|
||||
assertEquals(String.class, attrs.getKeyConstraint());
|
||||
assertEquals(String.class, attrs.getValueConstraint());
|
||||
assertEquals(true, attrs.isDiskSynchronous());
|
||||
assertEquals(Scope.GLOBAL, attrs.getScope());
|
||||
//assertEquals(true, attrs.isLockGrantor());
|
||||
assertEquals(true, attrs.getEnableAsyncConflation());
|
||||
assertEquals(true, attrs.getEnableSubscriptionConflation());
|
||||
assertEquals(0.50, attrs.getLoadFactor(), 0.001);
|
||||
assertEquals(false, attrs.getCloningEnabled());
|
||||
assertEquals(10, attrs.getConcurrencyLevel());
|
||||
assertEquals(true, attrs.getMulticastEnabled());
|
||||
|
||||
assertNotNull("The 'replicated-with-attributes' Region was not properly configured and initialized!", region);
|
||||
|
||||
RegionAttributes regionAttributes = region.getAttributes();
|
||||
|
||||
assertNotNull(regionAttributes);
|
||||
assertFalse(regionAttributes.getCloningEnabled());
|
||||
assertEquals(10, regionAttributes.getConcurrencyLevel());
|
||||
assertTrue(regionAttributes.isDiskSynchronous());
|
||||
assertTrue(regionAttributes.getEnableAsyncConflation());
|
||||
assertTrue(regionAttributes.getEnableSubscriptionConflation());
|
||||
assertTrue(regionAttributes.getIgnoreJTA());
|
||||
assertEquals(10, regionAttributes.getInitialCapacity());
|
||||
assertFalse(regionAttributes.getIndexMaintenanceSynchronous());
|
||||
assertEquals(String.class, regionAttributes.getKeyConstraint());
|
||||
assertEquals(0.50, regionAttributes.getLoadFactor(), 0.001);
|
||||
assertTrue(regionAttributes.isLockGrantor());
|
||||
assertTrue(regionAttributes.getMulticastEnabled());
|
||||
assertEquals(Scope.GLOBAL, regionAttributes.getScope());
|
||||
assertEquals(String.class, regionAttributes.getValueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,28 +149,31 @@ public class ReplicatedRegionNamespaceTest {
|
||||
public void testRegionLookup() throws Exception {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
Region existing = cache.createRegionFactory().create("existing");
|
||||
|
||||
assertTrue(context.containsBean("lookup"));
|
||||
RegionLookupFactoryBean lfb = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
assertEquals("existing", TestUtils.readField("name", lfb));
|
||||
assertEquals(existing, context.getBean("lookup"));
|
||||
|
||||
RegionLookupFactoryBean regionLookupFactoryBean = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
|
||||
assertNotNull(regionLookupFactoryBean);
|
||||
assertEquals("existing", TestUtils.readField("name", regionLookupFactoryBean));
|
||||
assertSame(existing, context.getBean("lookup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompressedReplicateRegion() {
|
||||
assertTrue(context.containsBean("compressed"));
|
||||
assertTrue(context.containsBean("Compressed"));
|
||||
|
||||
Region<?, ?> compressed = context.getBean("compressed", Region.class);
|
||||
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("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;
|
||||
|
||||
Reference in New Issue
Block a user