Refactored and fixed failing test cases after the integration of SGF-207, SGF-254, SGF-307, SGF-310, SGF-311 and SGF-312.

(cherry picked from commit b251a9071a)

Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
John Blum
2014-09-03 17:04:33 -07:00
parent e396925776
commit d682be8885
5 changed files with 67 additions and 47 deletions

View File

@@ -17,8 +17,9 @@
package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -42,6 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
import com.gemstone.gemfire.cache.EvictionAction;
@@ -58,10 +60,11 @@ import com.gemstone.gemfire.cache.util.ObjectSizer;
/**
* @author Costin Leau
* @author David Turanski
* @author John Blum
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="diskstore-ns.xml",
initializers=GemfireTestApplicationContextInitializer.class)
@ContextConfiguration(locations="diskstore-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
@SuppressWarnings({"rawtypes", "unused"})
public class DiskStoreAndEvictionRegionParsingTest {
@Autowired
@@ -117,24 +120,33 @@ public class DiskStoreAndEvictionRegionParsingTest {
}
@SuppressWarnings("rawtypes")
@Test
public void testReplicaDataOptions() throws Exception {
public void testReplicatedDataRegionAttributes() throws Exception {
assertTrue(context.containsBean("replicated-data"));
RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class);
assertTrue(fb instanceof ReplicatedRegionFactoryBean);
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
@SuppressWarnings("unused")
Region region = context.getBean("replicated-data", Region.class);
// eviction tests
RegionAttributes attrs = TestUtils.readField("attributes", fb);
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction());
assertEquals(EvictionAlgorithm.LRU_ENTRY, evicAttr.getAlgorithm());
assertEquals(50, evicAttr.getMaximum());
assertNull(evicAttr.getObjectSizer());
RegionFactoryBean replicatedDataRegionFactoryBean = context.getBean("&replicated-data", RegionFactoryBean.class);
assertTrue(replicatedDataRegionFactoryBean instanceof ReplicatedRegionFactoryBean);
assertEquals(DataPolicy.REPLICATE, replicatedDataRegionFactoryBean.getDataPolicy());
assertFalse(replicatedDataRegionFactoryBean.getDataPolicy().withPersistence());
assertEquals("diskStore1", TestUtils.readField("diskStoreName", replicatedDataRegionFactoryBean));
assertNull(TestUtils.readField("scope", replicatedDataRegionFactoryBean));
Region replicatedDataRegion = context.getBean("replicated-data", Region.class);
RegionAttributes replicatedDataRegionAttributes = TestUtils.readField("attributes", replicatedDataRegionFactoryBean);
assertNotNull(replicatedDataRegionAttributes);
assertEquals(Scope.DISTRIBUTED_NO_ACK, replicatedDataRegionAttributes.getScope());
EvictionAttributes replicatedDataEvictionAttributes = replicatedDataRegionAttributes.getEvictionAttributes();
assertNotNull(replicatedDataEvictionAttributes);
assertEquals(EvictionAction.OVERFLOW_TO_DISK, replicatedDataEvictionAttributes.getAction());
assertEquals(EvictionAlgorithm.LRU_ENTRY, replicatedDataEvictionAttributes.getAlgorithm());
assertEquals(50, replicatedDataEvictionAttributes.getMaximum());
assertNull(replicatedDataEvictionAttributes.getObjectSizer());
}
@SuppressWarnings("rawtypes")
@Test
public void testPartitionDataOptions() throws Exception {
assertTrue(context.containsBean("partition-data"));
@@ -153,7 +165,6 @@ public class DiskStoreAndEvictionRegionParsingTest {
assertEquals(SimpleObjectSizer.class, sizer.getClass());
}
@SuppressWarnings("rawtypes")
@Test
public void testEntryTtl() throws Exception {
assertTrue(context.containsBean("replicated-data"));
@@ -177,8 +188,6 @@ public class DiskStoreAndEvictionRegionParsingTest {
assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction());
}
@SuppressWarnings("rawtypes")
@Test
public void testCustomExpiry() throws Exception {
assertTrue(context.containsBean("replicated-data-custom-expiry"));
@@ -212,4 +221,4 @@ public class DiskStoreAndEvictionRegionParsingTest {
}
}
}

View File

@@ -18,6 +18,8 @@ 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.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -43,10 +45,11 @@ import com.gemstone.gemfire.cache.Scope;
/**
* @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
@@ -55,10 +58,18 @@ public class ReplicatedRegionNamespaceTest {
@Test
public void testBasicReplica() 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));
assertNull(TestUtils.readField("scope", simpleRegionFactoryBean));
RegionAttributes simpleRegionAttributes = TestUtils.readField("attributes", simpleRegionFactoryBean);
assertNotNull(simpleRegionAttributes);
assertFalse(simpleRegionAttributes.getConcurrencyChecksEnabled());
assertEquals(Scope.DISTRIBUTED_NO_ACK, simpleRegionAttributes.getScope());
}
@Test
@@ -74,8 +85,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 +99,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 +122,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");

View File

@@ -48,13 +48,12 @@ import com.gemstone.gemfire.cache.Region;
*/
@ContextConfiguration(locations = "subregion-ns.xml", initializers = GemfireTestApplicationContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
@SuppressWarnings("deprecation")
@SuppressWarnings({ "deprecation", "rawtypes" })
public class SubRegionNamespaceTest {
@Autowired
private ApplicationContext context;
@SuppressWarnings("rawtypes")
@Test
public void testNestedRegionsCreated() {
Cache cache = context.getBean(Cache.class);
@@ -64,7 +63,6 @@ public class SubRegionNamespaceTest {
assertNotNull(cache.getRegion("/parent/child/grandchild"));
}
@SuppressWarnings("rawtypes")
@Test
public void testNestedReplicatedRegions() {
Region parent = context.getBean("parent", Region.class);
@@ -72,15 +70,17 @@ public class SubRegionNamespaceTest {
Region grandchild = context.getBean("/parent/child/grandchild", Region.class);
assertNotNull(child);
assertEquals("child", child.getName());
assertEquals("/parent/child", child.getFullPath());
assertSame(child, parent.getSubregion("child"));
assertNotNull(grandchild);
assertEquals("grandchild", grandchild.getName());
assertEquals("/parent/child/grandchild", grandchild.getFullPath());
assertSame(grandchild, child.getSubregion("grandchild"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@SuppressWarnings("unchecked")
public void testMixedNestedRegions() {
Region parent = context.getBean("replicatedParent", Region.class);
Region child = context.getBean("/replicatedParent/replicatedChild", Region.class);
@@ -94,7 +94,6 @@ public class SubRegionNamespaceTest {
assertSame(grandchild, child.getSubregion("partitionedGrandchild"));
}
@SuppressWarnings("rawtypes")
@Test
public void testNestedRegionsWithSiblings() {
Region parent = context.getBean("parentWithSiblings", Region.class);
@@ -108,8 +107,8 @@ public class SubRegionNamespaceTest {
assertEquals("/parentWithSiblings/child1/grandChild11", grandchild1.getFullPath());
}
@SuppressWarnings({ "rawtypes", "unused" })
@Test
@SuppressWarnings("unused" )
public void testComplexNestedRegions() throws Exception {
Region parent = context.getBean("complexNested", Region.class);
Region child1 = context.getBean("/complexNested/child1", Region.class);

View File

@@ -110,6 +110,7 @@ public class MockRegionFactory<K,V> {
Region subRegion = mockRegion(subRegionName);
cache.allRegions().put(subRegionName, subRegion);
cache.allRegions().put(name, subRegion);
return subRegion;
}
@@ -468,7 +469,7 @@ public class MockRegionFactory<K,V> {
public Region answer(InvocationOnMock invocation) throws Throwable {
Region parent = (Region) invocation.getMock();
String parentRegionName = parent.getName();
String parentRegionName = parent.getFullPath();
String subRegionName = (String) invocation.getArguments()[0];
String subRegionPath = (parentRegionName.startsWith("/") ? parentRegionName+"/"+subRegionName
: "/"+parentRegionName+"/"+subRegionName);

View File

@@ -1,19 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" default-lazy-init="true">
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
" default-lazy-init="true">
<gfe:cache />
<gfe:replicated-region id="simple" close="false" concurrency-checks-enabled="false" />
<gfe:replicated-region id="pub" name="publisher"/>
<gfe:replicated-region id="pub" name="publisher" scope="DISTRIBUTED_ACK"/>
<gfe:replicated-region id="complex" close="true" destroy="false">
<gfe:cache-listener>
<ref bean="c-listener"/>
@@ -45,4 +44,5 @@
<bean id="c-writer" class="org.springframework.data.gemfire.SimpleCacheWriter"/>
<gfe:lookup-region id="lookup" name="existing"/>
</beans>
</beans>