SGF-381 - Enable RegionFactoryBean to respect the Data Policy specified on a nested or referenced RegionAttributes bean definition.

Added additional test cases to test and cover different combinations of data-policy and persistent attribute settings with explicit RegionFactoryBean and nested RegionAttributesFatoryBean 'bean' definitions in Spring XML configuration meta-data.
This commit is contained in:
John Blum
2015-03-12 17:25:42 -07:00
parent ac8ff3750c
commit e514b004d8
4 changed files with 139 additions and 2 deletions

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2010-2013 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.assertTrue;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* The InvalidRegionDefinitionUsingBeansNamespaceTest class is a test suite of test cases testing the definition of
* invalid Region beans in a Spring context. Specifically, this test class tests the specification of the Region's
* DataPolicy on a nested RegionAttributesFactoryBean conflicting with the 'persistent' attribute configuration
* on the containing RegionFactoryBean definition.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.RegionFactoryBean
* @since 1.6.0
*/
public class InvalidRegionDefinitionUsingBeansNamespaceTest {
@Test(expected = IllegalArgumentException.class)
public void testInvalidDataPolicyPersistentAttributeSettings() {
try {
new ClassPathXmlApplicationContext("org/springframework/data/gemfire/config/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml");
}
catch (BeanCreationException expected) {
assertTrue(expected.getCause() instanceof IllegalArgumentException);
assertEquals("Data Policy 'REPLICATE' is invalid when persistent is true.", expected.getCause().getMessage());
throw (IllegalArgumentException) expected.getCause();
}
}
}

View File

@@ -24,12 +24,18 @@ import javax.annotation.Resource;
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.TestUtils;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
/**
* The RawRegionBeanDefinitionTest class is a test suite of test cases testing the contract and functionality
@@ -37,6 +43,7 @@ import com.gemstone.gemfire.cache.Region;
* when used as raw bean definition in Spring XML configuration meta-data.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.PartitionAttributesFactoryBean
* @see org.springframework.data.gemfire.RegionAttributesFactoryBean
* @see org.springframework.data.gemfire.RegionFactoryBean
@@ -52,12 +59,18 @@ import com.gemstone.gemfire.cache.Region;
@SuppressWarnings("unused")
public class RegionDefinitionUsingBeansNamespaceTest {
@Autowired
private ApplicationContext context;
@Resource(name = "Example")
private Region<?, ?> example;
@Resource(name = "AnotherExample")
private Region<?, ?> anotherExample;
@Test
public void testExampleRegionBeanDefinitionConfiguration() {
assertNotNull("The 'Example' Region was not properly configured and initialized!", example);
assertNotNull("The '/Example' Region was not properly configured and initialized!", example);
assertEquals("Example", example.getName());
assertEquals("/Example", example.getFullPath());
assertNotNull(example.getAttributes());
@@ -68,4 +81,36 @@ public class RegionDefinitionUsingBeansNamespaceTest {
assertEquals(0, example.getAttributes().getPartitionAttributes().getRecoveryDelay());
}
@Test
public void testAnotherExampleRegionFactoryBeanConfiguration() throws Exception {
RegionFactoryBean<?, ?> anotherExampleRegionFactoryBean = context.getBean("&AnotherExample",
RegionFactoryBean.class);
assertNotNull(anotherExampleRegionFactoryBean);
assertEquals(DataPolicy.PERSISTENT_PARTITION, anotherExampleRegionFactoryBean.getDataPolicy());
assertTrue(Boolean.TRUE.equals(TestUtils.readField("persistent", anotherExampleRegionFactoryBean)));
RegionAttributes<?, ?> anotherExampleRegionAttributes = TestUtils.readField("attributes",
anotherExampleRegionFactoryBean);
assertNotNull(anotherExampleRegionAttributes);
assertEquals(DataPolicy.PARTITION, anotherExampleRegionAttributes.getDataPolicy());
PartitionAttributes<?, ?> anotherExamplePartitionAttributes = anotherExampleRegionAttributes.getPartitionAttributes();
assertNotNull(anotherExamplePartitionAttributes);
assertEquals(2, anotherExamplePartitionAttributes.getRedundantCopies());
}
@Test
public void testAnotherExampleRegionDefinitionConfiguration() {
assertNotNull("The '/AnotherExample' Region was not properly configured and initialized!", anotherExample);
assertEquals("AnotherExample", anotherExample.getName());
assertEquals("/AnotherExample", anotherExample.getFullPath());
assertNotNull(anotherExample.getAttributes());
assertEquals(DataPolicy.PERSISTENT_PARTITION, anotherExample.getAttributes().getDataPolicy());
assertNotNull(anotherExample.getAttributes().getPartitionAttributes());
assertEquals(2, anotherExample.getAttributes().getPartitionAttributes().getRedundantCopies());
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
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/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<util:properties id="gemfireProperties">
<prop key="name">InvalidDataPolicyPersistentAttributeSettingsTest</prop>
<prop key="mcast-port">0</prop>
<prop key="log-level">warning</prop>
</util:properties>
<gfe:cache properties-ref="gemfireProperties"/>
<bean class="org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor"/>
<bean id="Example" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="gemfireCache"
p:persistent="true">
<property name="attributes">
<bean class="org.springframework.data.gemfire.RegionAttributesFactoryBean" p:dataPolicy="REPLICATE"/>
</property>
</bean>
</beans>

View File

@@ -11,7 +11,7 @@
">
<util:properties id="gemfireProperties">
<prop key="name">RawRegionBeanDefinitionTest</prop>
<prop key="name">RegionDefinitionUsingBeansNamespaceTest</prop>
<prop key="mcast-port">0</prop>
<prop key="log-level">warning</prop>
</util:properties>
@@ -31,4 +31,15 @@
</property>
</bean>
<bean id="AnotherExample" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="gemfireCache"
p:dataPolicy="PERSISTENT_PARTITION" p:persistent="true">
<property name="attributes">
<bean class="org.springframework.data.gemfire.RegionAttributesFactoryBean" p:dataPolicy="PARTITION">
<property name="partitionAttributes">
<bean class="org.springframework.data.gemfire.PartitionAttributesFactoryBean" p:redundantCopies="2"/>
</property>
</bean>
</property>
</bean>
</beans>