SGF-383 - Refactor and make RegionFactoryBean and RegionLookupFactoryBean abstract.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* The LookupRegionFactoryBean class is a concrete implementation of RegionLookupFactoryBean for handling &
|
||||
* gt;gfe:lookup-region/< SDG XML namespace (XSD) elements.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.RegionLookupFactoryBean
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class LookupRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> {
|
||||
|
||||
}
|
||||
@@ -63,7 +63,7 @@ import com.gemstone.gemfire.internal.cache.UserSpecifiedRegionAttributes;
|
||||
* @author John Blum
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> implements DisposableBean, SmartLifecycle {
|
||||
public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> implements DisposableBean, SmartLifecycle {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.gemstone.gemfire.cache.Region;
|
||||
* @author John Blum
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class RegionLookupFactoryBean<K, V> implements FactoryBean<Region<K, V>>, InitializingBean, BeanNameAware {
|
||||
public abstract class RegionLookupFactoryBean<K, V> implements FactoryBean<Region<K, V>>, InitializingBean, BeanNameAware {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.gemfire.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.RegionLookupFactoryBean;
|
||||
import org.springframework.data.gemfire.LookupRegionFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ class LookupRegionParser extends AbstractRegionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return RegionLookupFactoryBean.class;
|
||||
return LookupRegionFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,7 +72,7 @@ import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
private final RegionFactoryBean factoryBean = new RegionFactoryBean();
|
||||
private final RegionFactoryBean factoryBean = new TestRegionFactoryBean();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@@ -82,7 +82,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig defaultConfig() {
|
||||
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "default") {
|
||||
return new RegionFactoryBeanConfig(new TestRegionFactoryBean(), "default") {
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig persistentConfig() {
|
||||
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "persistent") {
|
||||
return new RegionFactoryBeanConfig(new TestRegionFactoryBean(), "persistent") {
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setPersistent(true);
|
||||
@@ -113,7 +113,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
private RegionFactoryBeanConfig invalidPersistentConfig() {
|
||||
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "invalid-persistence") {
|
||||
return new RegionFactoryBeanConfig(new TestRegionFactoryBean(), "invalid-persistence") {
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setDataPolicy("persistent_replicate");
|
||||
@@ -169,7 +169,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
}
|
||||
@Test
|
||||
public void testAssertDataPolicyAndPersistentAttributesAreCompatible() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new RegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
|
||||
factoryBean.setPersistent(null);
|
||||
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.PARTITION);
|
||||
@@ -187,7 +187,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAssertNonPersistentDataPolicyWithPersistentAttribute() {
|
||||
try {
|
||||
RegionFactoryBean<?, ?> factoryBean = new RegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
factoryBean.setPersistent(true);
|
||||
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.REPLICATE);
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAssertPersistentDataPolicyWithNonPersistentAttribute() {
|
||||
try {
|
||||
RegionFactoryBean<?, ?> factoryBean = new RegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
factoryBean.setPersistent(false);
|
||||
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.PERSISTENT_PARTITION);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void testIsPersistent() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new RegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
|
||||
@@ -228,7 +228,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void testIsPersistentUnspecified() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new RegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
|
||||
assertTrue(factoryBean.isPersistentUnspecified());
|
||||
|
||||
@@ -247,7 +247,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void testIsNotPersistent() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new RegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
|
||||
assertFalse(factoryBean.isNotPersistent());
|
||||
|
||||
@@ -306,12 +306,11 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
final RegionFactory mockRegionFactory = createMockRegionFactory();
|
||||
RegionFactory mockRegionFactory = createMockRegionFactory();
|
||||
|
||||
when(mockCache.createRegionFactory(eq(mockRegionAttributes))).thenReturn(mockRegionFactory);
|
||||
|
||||
RegionFactoryBean factoryBean = new RegionFactoryBean();
|
||||
RegionFactoryBean factoryBean = new TestRegionFactoryBean();
|
||||
|
||||
factoryBean.setAttributes(mockRegionAttributes);
|
||||
factoryBean.setShortcut(null);
|
||||
@@ -324,12 +323,11 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
@Test
|
||||
public void testCreateRegionFactory() {
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
final RegionFactory mockRegionFactory = createMockRegionFactory();
|
||||
RegionFactory mockRegionFactory = createMockRegionFactory();
|
||||
|
||||
when(mockCache.createRegionFactory()).thenReturn(mockRegionFactory);
|
||||
|
||||
RegionFactoryBean factoryBean = new RegionFactoryBean();
|
||||
RegionFactoryBean factoryBean = new TestRegionFactoryBean();
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setShortcut(null);
|
||||
@@ -1054,4 +1052,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class TestRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SubRegionTest extends RecreatingContextTest {
|
||||
assertEquals("/Outer", outer.getFullPath());
|
||||
assertSame(outer, cache.getRegion("/Outer"));
|
||||
|
||||
RegionFactoryBean subRegionFactory = new RegionFactoryBean();
|
||||
RegionFactoryBean subRegionFactory = new RegionFactoryBean() { };
|
||||
|
||||
subRegionFactory.setCache(cache);
|
||||
subRegionFactory.setParent(outer);
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
|
||||
/**
|
||||
* The InvalidRegionDefinitionUsingBeansNamespaceTest class is a test suite of test cases testing the definition of
|
||||
@@ -48,4 +49,8 @@ public class InvalidRegionDefinitionUsingBeansNamespaceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static final class TestRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,4 +113,7 @@ public class RegionDefinitionUsingBeansNamespaceTest {
|
||||
assertEquals(2, anotherExample.getAttributes().getPartitionAttributes().getRedundantCopies());
|
||||
}
|
||||
|
||||
public static final class TestRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<bean id="replicate-persistent-region" class="org.springframework.data.gemfire.RegionFactoryBean">
|
||||
<bean id="replicate-persistent-region" class="org.springframework.data.gemfire.RegionFactoryBeanTest$TestRegionFactoryBean">
|
||||
<property name="cache" ref="gemfireCache"/>
|
||||
<property name="dataPolicy" value="REPLICATE_PERSISTENT"/>
|
||||
</bean>
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
<bean class="org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor"/>
|
||||
|
||||
<bean id="Example" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="gemfireCache"
|
||||
p:persistent="true">
|
||||
<bean id="Example" class="org.springframework.data.gemfire.config.InvalidRegionDefinitionUsingBeansNamespaceTest$TestRegionFactoryBean"
|
||||
p:cache-ref="gemfireCache" p:persistent="true">
|
||||
<property name="attributes">
|
||||
<bean class="org.springframework.data.gemfire.RegionAttributesFactoryBean" p:dataPolicy="REPLICATE"/>
|
||||
</property>
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<bean id="Example" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="gemfireCache">
|
||||
<bean id="Example" class="org.springframework.data.gemfire.config.RegionDefinitionUsingBeansNamespaceTest$TestRegionFactoryBean"
|
||||
p:cache-ref="gemfireCache">
|
||||
<property name="attributes">
|
||||
<bean class="org.springframework.data.gemfire.RegionAttributesFactoryBean"
|
||||
p:dataPolicy="PERSISTENT_PARTITION"
|
||||
@@ -31,8 +32,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="AnotherExample" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="gemfireCache"
|
||||
p:dataPolicy="PERSISTENT_PARTITION" p:persistent="true">
|
||||
<bean id="AnotherExample" class="org.springframework.data.gemfire.config.RegionDefinitionUsingBeansNamespaceTest$TestRegionFactoryBean"
|
||||
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">
|
||||
|
||||
Reference in New Issue
Block a user