refactored Cachefactory bean to work with Gemfire 6 and some enhancements to region data policy validation
This commit is contained in:
@@ -134,7 +134,7 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
}
|
||||
|
||||
if (gatewayConflictResolver != null) {
|
||||
cacheImpl.setGatewayConflictResolver(gatewayConflictResolver);
|
||||
cacheImpl.setGatewayConflictResolver((GatewayConflictResolver) gatewayConflictResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,7 +267,8 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
|
||||
protected List<Function> functions;
|
||||
|
||||
protected GatewayConflictResolver gatewayConflictResolver;
|
||||
// Defined this way for backward compatibility
|
||||
protected Object gatewayConflictResolver;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@@ -632,7 +633,12 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
this.functions = functions;
|
||||
}
|
||||
|
||||
public void setGatewayConflictResolver(GatewayConflictResolver gatewayConflictResolver) {
|
||||
/**
|
||||
*
|
||||
* @param gatewayConflictResolver defined as Object for backward
|
||||
* compatibility with Gemfire 6 compatibility
|
||||
*/
|
||||
public void setGatewayConflictResolver(Object gatewayConflictResolver) {
|
||||
this.gatewayConflictResolver = gatewayConflictResolver;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class DataPolicyConverter implements Converter<String, DataPolicy> {
|
||||
private static enum Policy {
|
||||
EMPTY, DEFAULT, NORMAL, PERSISTENT_PARTITION, PERSISTENT_REPLICATE, PRELOADED, REPLICATE;
|
||||
public DataPolicy toDataPolicy() {
|
||||
DataPolicy dataPolicy = null;
|
||||
switch (this) {
|
||||
case EMPTY:
|
||||
dataPolicy = DataPolicy.EMPTY;
|
||||
break;
|
||||
case DEFAULT:
|
||||
dataPolicy = DataPolicy.DEFAULT;
|
||||
break;
|
||||
case NORMAL:
|
||||
dataPolicy = DataPolicy.NORMAL;
|
||||
break;
|
||||
case PERSISTENT_PARTITION:
|
||||
dataPolicy = DataPolicy.PERSISTENT_PARTITION;
|
||||
break;
|
||||
case PERSISTENT_REPLICATE:
|
||||
dataPolicy = DataPolicy.PERSISTENT_REPLICATE;
|
||||
break;
|
||||
case PRELOADED:
|
||||
dataPolicy = DataPolicy.PRELOADED;
|
||||
break;
|
||||
case REPLICATE:
|
||||
dataPolicy = DataPolicy.REPLICATE;
|
||||
break;
|
||||
}
|
||||
return dataPolicy;
|
||||
}
|
||||
|
||||
public static Policy getValue(String value) {
|
||||
Policy policy = null;
|
||||
try {
|
||||
policy = valueOf(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public DataPolicy convert(String source) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
source = source.toUpperCase();
|
||||
return Policy.getValue(source) == null ? null : Policy.getValue(source).toDataPolicy();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,27 +17,44 @@ package org.springframework.data.gemfire;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.RegionFactory;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class LocalRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
|
||||
@Override
|
||||
public void setScope(Scope scope) {
|
||||
throw new UnsupportedOperationException("setScope() is not allowed for Local Regions");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, boolean persistent, String dataPolicyName) {
|
||||
if (dataPolicyName != null) {
|
||||
if ("NORMAL".equals(dataPolicyName) || dataPolicyName == null) {
|
||||
public void setPersistent(boolean persistent) {
|
||||
throw new UnsupportedOperationException("setPersistent() is not allowed for Local Regions");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.setScope(Scope.LOCAL);
|
||||
super.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) {
|
||||
if (dataPolicy != null) {
|
||||
dataPolicy = dataPolicy.toUpperCase();
|
||||
if ("NORMAL".equals(dataPolicy) || dataPolicy == null) {
|
||||
regionFactory.setDataPolicy(DataPolicy.NORMAL);
|
||||
}
|
||||
else if ("PRELOADED".equals(dataPolicyName)) {
|
||||
else if ("PRELOADED".equals(dataPolicy)) {
|
||||
regionFactory.setDataPolicy(DataPolicy.PRELOADED);
|
||||
}
|
||||
else if ("EMPTY".equals(dataPolicyName)) {
|
||||
else if ("EMPTY".equals(dataPolicy)) {
|
||||
regionFactory.setDataPolicy(DataPolicy.EMPTY);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Data policy '" + dataPolicyName
|
||||
throw new IllegalArgumentException("Data policy '" + dataPolicy
|
||||
+ "' is unsupported or invalid for local regions.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.gemfire;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
@@ -29,8 +31,23 @@ import com.gemstone.gemfire.cache.RegionFactory;
|
||||
public class PartitionedRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
|
||||
|
||||
@Override
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, boolean persistent, String dataPolicyName) {
|
||||
if (persistent) {
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) {
|
||||
if (dataPolicy != null) {
|
||||
DataPolicy dp = new DataPolicyConverter().convert(dataPolicy);
|
||||
Assert.notNull(dp, "Data policy " + dataPolicy + " is invalid");
|
||||
Assert.isTrue(dp.withPartitioning(), "Data Policy " + dp.toString()
|
||||
+ " is not supported in partitioned regions");
|
||||
if (!isPersistent()) {
|
||||
regionFactory.setDataPolicy(dp);
|
||||
}
|
||||
else {
|
||||
Assert.isTrue(dp.withPersistence(), "Data Policy " + dp.toString()
|
||||
+ "is invalid when persistent is false");
|
||||
regionFactory.setDataPolicy(dp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isPersistent()) {
|
||||
// check first for GemFire 6.5
|
||||
if (ConcurrentMap.class.isAssignableFrom(Region.class)) {
|
||||
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
import com.gemstone.gemfire.cache.CacheWriter;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
@@ -54,7 +55,7 @@ import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
*/
|
||||
public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> implements DisposableBean {
|
||||
public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> implements DisposableBean {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -70,15 +71,15 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
|
||||
private CacheWriter<K, V> cacheWriter;
|
||||
|
||||
private GatewaySender gatewaySenders[];
|
||||
private Object gatewaySenders[];
|
||||
|
||||
private AsyncEventQueue asyncEventQueues[];
|
||||
private Object asyncEventQueues[];
|
||||
|
||||
private RegionAttributes<K, V> attributes;
|
||||
|
||||
private Scope scope;
|
||||
|
||||
private boolean persistent;
|
||||
private Boolean persistent;
|
||||
|
||||
private Boolean enableGateway;
|
||||
|
||||
@@ -86,7 +87,7 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
|
||||
private String diskStoreName;
|
||||
|
||||
private String dataPolicyName;
|
||||
private String dataPolicy;
|
||||
|
||||
private Region<K, V> region;
|
||||
|
||||
@@ -131,14 +132,14 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
Assert.isTrue(
|
||||
hubId == null,
|
||||
"It is invalid to configure a region with both a hubId and gatewaySenders. Note that the enableGateway and hubId properties are deprecated since Gemfire 7.0");
|
||||
for (GatewaySender gatewaySender : gatewaySenders) {
|
||||
regionFactory.addGatewaySender(gatewaySender);
|
||||
for (Object gatewaySender : gatewaySenders) {
|
||||
regionFactory.addGatewaySender((GatewaySender) gatewaySender);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(asyncEventQueues)) {
|
||||
for (AsyncEventQueue asyncEventQueue : asyncEventQueues) {
|
||||
regionFactory.addAsyncEventQueue(asyncEventQueue);
|
||||
for (Object asyncEventQueue : asyncEventQueues) {
|
||||
regionFactory.addAsyncEventQueue((AsyncEventQueue) asyncEventQueue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +151,7 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
regionFactory.setCacheWriter(cacheWriter);
|
||||
}
|
||||
|
||||
resolveDataPolicy(regionFactory, persistent, dataPolicyName);
|
||||
resolveDataPolicy(regionFactory, persistent, dataPolicy);
|
||||
|
||||
if (scope != null) {
|
||||
regionFactory.setScope(scope);
|
||||
@@ -180,8 +181,31 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
return reg;
|
||||
}
|
||||
|
||||
protected abstract void resolveDataPolicy(RegionFactory<K, V> regionFactory, boolean persistent,
|
||||
String dataPolicyName);
|
||||
/**
|
||||
* This validates the configured data policy and may override it, taking
|
||||
* into account the persistent attribute and constraints for the region type
|
||||
* @param regionFactory
|
||||
* @param persistent
|
||||
* @param dataPolicy requested data policy
|
||||
*/
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) {
|
||||
if (dataPolicy == null) {
|
||||
if (isPersistent()) {
|
||||
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
|
||||
}
|
||||
else {
|
||||
regionFactory.setDataPolicy(DataPolicy.DEFAULT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
DataPolicy dp = new DataPolicyConverter().convert(dataPolicy);
|
||||
Assert.notNull(dp, "Data policy " + dataPolicy + " is invalid");
|
||||
if (dp.withPersistence()) {
|
||||
Assert.isTrue(!isNotPersistent(), "Data policy " + dataPolicy + " is invalid when persistent is false");
|
||||
}
|
||||
regionFactory.setDataPolicy(dp);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private AttributesFactory<K, V> findAttrFactory(RegionFactory<K, V> regionFactory) {
|
||||
@@ -330,10 +354,10 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
/**
|
||||
* Sets the dataPolicy as a String. Required to support property
|
||||
* placeholders
|
||||
* @param dataPolicyName the dataPolicy name (NORMAL, PRELOADED, etc)
|
||||
* @param dataPolicy the dataPolicy name (NORMAL, PRELOADED, etc)
|
||||
*/
|
||||
public void setDataPolicyName(String dataPolicyName) {
|
||||
this.dataPolicyName = dataPolicyName;
|
||||
public void setDataPolicy(String dataPolicyName) {
|
||||
this.dataPolicy = dataPolicyName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,11 +368,21 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
this.diskStoreName = diskStoreName;
|
||||
}
|
||||
|
||||
public void setGatewaySenders(GatewaySender[] gatewaySenders) {
|
||||
/**
|
||||
*
|
||||
* @param gatewaySenders defined as Object for backward compatibility with
|
||||
* Gemfire 6
|
||||
*/
|
||||
public void setGatewaySenders(Object[] gatewaySenders) {
|
||||
this.gatewaySenders = gatewaySenders;
|
||||
}
|
||||
|
||||
public void setAsyncEventQueues(AsyncEventQueue[] asyncEventQueues) {
|
||||
/**
|
||||
*
|
||||
* @param asyncEventQueues defined as Object for backward compatibility with
|
||||
* Gemfire 6
|
||||
*/
|
||||
public void setAsyncEventQueues(Object[] asyncEventQueues) {
|
||||
this.asyncEventQueues = asyncEventQueues;
|
||||
}
|
||||
|
||||
@@ -370,4 +404,12 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
public void setAttributes(RegionAttributes<K, V> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
protected boolean isPersistent() {
|
||||
return persistent != null && persistent;
|
||||
}
|
||||
|
||||
protected boolean isNotPersistent() {
|
||||
return persistent != null && !persistent;
|
||||
}
|
||||
}
|
||||
@@ -26,22 +26,28 @@ import com.gemstone.gemfire.cache.RegionFactory;
|
||||
*/
|
||||
public class ReplicatedRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
|
||||
@Override
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, boolean persistent, String dataPolicyName) {
|
||||
|
||||
DataPolicy dataPolicy = null;
|
||||
if (dataPolicyName != null) {
|
||||
if ("EMPTY".equals(dataPolicyName)) {
|
||||
Assert.isTrue(!persistent, "Cannot have persistence on an empty region");
|
||||
dataPolicy = DataPolicy.EMPTY;
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) {
|
||||
DataPolicy dp = null;
|
||||
if (dataPolicy != null) {
|
||||
dataPolicy = dataPolicy.toUpperCase();
|
||||
if ("EMPTY".equals(dataPolicy)) {
|
||||
Assert.isTrue(persistent == null || !persistent, "Cannot have persistence on an empty region");
|
||||
dp = DataPolicy.EMPTY;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Data policy '" + dataPolicyName
|
||||
+ "' is unsupported or invalid for replicated regions.");
|
||||
dp = new DataPolicyConverter().convert(dataPolicy);
|
||||
Assert.notNull(dp, "Data policy " + dataPolicy + " is invalid");
|
||||
Assert.isTrue(dp.withReplication(), "Data policy " + dataPolicy
|
||||
+ " is invalid or unsupported in replicated regions");
|
||||
if (isPersistent()) {
|
||||
Assert.isTrue(dp.withPersistence(), "Data policy " + dataPolicy
|
||||
+ " is invalid when persistent is false");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
dataPolicy = persistent ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE;
|
||||
dp = (isPersistent()) ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE;
|
||||
}
|
||||
regionFactory.setDataPolicy(dataPolicy);
|
||||
regionFactory.setDataPolicy(dp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser {
|
||||
ParsingUtils.setPropertyValue(element, builder, "persistent");
|
||||
}
|
||||
// set the data policy
|
||||
ParsingUtils.setPropertyValue(element, builder, "data-policy", "dataPolicyName");
|
||||
ParsingUtils.setPropertyValue(element, builder, "data-policy");
|
||||
|
||||
if (StringUtils.hasText(element.getAttribute("disk-store-ref"))) {
|
||||
ParsingUtils.setPropertyValue(element, builder, "disk-store-ref", "diskStoreName");
|
||||
|
||||
@@ -22,12 +22,9 @@ import org.springframework.data.gemfire.LocalRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
/**
|
||||
* Parser for <replicated-region;gt; definitions.
|
||||
* Parser for <local-region;gt; definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
*/
|
||||
class LocalRegionParser extends AbstractRegionParser {
|
||||
@@ -35,8 +32,6 @@ class LocalRegionParser extends AbstractRegionParser {
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion) {
|
||||
|
||||
builder.addPropertyValue("scope", Scope.LOCAL);
|
||||
|
||||
BeanDefinitionBuilder attrBuilder = subRegion ? builder : BeanDefinitionBuilder
|
||||
.genericBeanDefinition(RegionAttributesFactoryBean.class);
|
||||
|
||||
|
||||
@@ -541,11 +541,10 @@ use inner bean declarations.
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="persistent" type="xsd:string"
|
||||
default="false">
|
||||
<xsd:attribute name="persistent" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether the defined region is persistent or not. GemFire ensures that all the data you put into a region that
|
||||
Indicates whether the defined region is persistent. GemFire ensures that all the data you put into a region that
|
||||
is configured for persistence will be written to disk in a way that it can be recovered the next time you create the
|
||||
region. This allows data to be recovered after a machine or process failure or after an orderly shutdown and restart
|
||||
of GemFire.
|
||||
@@ -948,8 +947,20 @@ Provides an estimate of the maximum number of application threads that will conc
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="scope" type="scopeType" />
|
||||
<xsd:attribute name="data-policy" type="baseDataPolicyType" />
|
||||
<xsd:attribute name="scope" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies the scope for this region: distributed-ack,distributed-no-ack, global
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="data-policy" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies the data policy for this region
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="is-lock-grantor"
|
||||
type="xsd:string" use="optional" default="false">
|
||||
<xsd:annotation>
|
||||
@@ -990,7 +1001,7 @@ Provides an estimate of the maximum number of application threads that will conc
|
||||
<xsd:complexType name="baseLocalRegionType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation
|
||||
source="org.springframework.data.gemfire.RegionFactoryBean"><![CDATA[
|
||||
source="org.springframework.data.gemfire.ReplicatedRegionFactoryBean"><![CDATA[
|
||||
Defines a GemFire local region instance. Each local region is scoped only to the local JVM.
|
||||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
@@ -1600,7 +1611,7 @@ The action to take when performing eviction.
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="data-policy"
|
||||
type="baseDataPolicyType" use="optional"
|
||||
type="xsd:string" use="optional"
|
||||
default="NORMAL">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
@@ -2486,14 +2497,6 @@ The id of the cache - default is gemfire-cache
|
||||
|
||||
<xsd:element name="gateway-receiver" type="gatewayReceiverType" />
|
||||
<!-- -->
|
||||
<xsd:simpleType name="baseDataPolicyType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="NORMAL" />
|
||||
<xsd:enumeration value="EMPTY" />
|
||||
<xsd:enumeration value="PRELOADED" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:element name="function-service">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class DataPolicyConverterTest {
|
||||
DataPolicyConverter converter = new DataPolicyConverter();
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals(DataPolicy.EMPTY, converter.convert("empty"));
|
||||
assertNull(converter.convert("invalid"));
|
||||
assertNull(converter.convert(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractRegionFactoryBeanTest;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig defaultConfig() {
|
||||
return new RegionFactoryBeanConfig(new LocalRegionFactoryBean(), "default") {
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
Region region = regionFactoryBean.getRegion();
|
||||
assertEquals(DataPolicy.DEFAULT, region.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig emptyConfig() {
|
||||
return new RegionFactoryBeanConfig(new LocalRegionFactoryBean(), "empty") {
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
Region region = regionFactoryBean.getRegion();
|
||||
assertEquals(DataPolicy.EMPTY, region.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setDataPolicy("empty");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig invalidConfig() {
|
||||
return new RegionFactoryBeanConfig(new LocalRegionFactoryBean(), "local-replicate") {
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
assertNotNull(this.exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setDataPolicy("replicate");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createRegionFactoryBeanConfigs() {
|
||||
addRFBConfig(defaultConfig());
|
||||
addRFBConfig(emptyConfig());
|
||||
addRFBConfig(invalidConfig());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractRegionFactoryBeanTest;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig defaultConfig() {
|
||||
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "default") {
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
Region region = regionFactoryBean.getRegion();
|
||||
assertEquals(DataPolicy.DEFAULT, region.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig persistent() {
|
||||
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "persistent") {
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
Region region = regionFactoryBean.getRegion();
|
||||
assertEquals(DataPolicy.PERSISTENT_REPLICATE, region.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setPersistent(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig invalidPersistence() {
|
||||
return new RegionFactoryBeanConfig(new RegionFactoryBean(), "invalid-persistence") {
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setDataPolicy("persistent_replicate");
|
||||
regionFactoryBean.setPersistent(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
assertNotNull(this.exception);
|
||||
assertEquals("Data policy persistent_replicate is invalid when persistent is false",
|
||||
exception.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createRegionFactoryBeanConfigs() {
|
||||
addRFBConfig(defaultConfig());
|
||||
addRFBConfig(persistent());
|
||||
addRFBConfig(invalidPersistence());
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class LocalRegionNamespaceTest {
|
||||
private void testPublishingLocal() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertEquals("NORMAL", TestUtils.readField("dataPolicyName", fb));
|
||||
assertEquals("NORMAL", TestUtils.readField("dataPolicy", fb));
|
||||
assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
|
||||
assertEquals("publisher", TestUtils.readField("name", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractRegionFactoryBeanTest {
|
||||
protected GemFireCache cache;
|
||||
|
||||
Map<String, RegionFactoryBeanConfig> regionFactoryBeanConfigs = new HashMap<String, RegionFactoryBeanConfig>();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
CacheFactoryBean cfb = new CacheFactoryBean();
|
||||
cfb.setBeanName("gemfire-cache");
|
||||
cfb.setUseBeanFactoryLocator(false);
|
||||
cfb.afterPropertiesSet();
|
||||
cache = cfb.getObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
createRegionFactoryBeanConfigs();
|
||||
for (RegionFactoryBeanConfig rfbc : regionFactoryBeanConfigs.values()) {
|
||||
rfbc.test();
|
||||
}
|
||||
}
|
||||
|
||||
protected void addRFBConfig(RegionFactoryBeanConfig rfbc) {
|
||||
if (regionFactoryBeanConfigs.containsKey(rfbc.regionName)) {
|
||||
throw new RuntimeException("duplicate region name " + rfbc.regionName);
|
||||
}
|
||||
regionFactoryBeanConfigs.put(rfbc.regionName, rfbc);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
cache.close();
|
||||
}
|
||||
|
||||
public abstract class RegionFactoryBeanConfig {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public final RegionFactoryBean regionFactoryBean;
|
||||
|
||||
public final String regionName;
|
||||
|
||||
public Exception exception;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public RegionFactoryBeanConfig(RegionFactoryBean rfb, String regionName) {
|
||||
this.regionFactoryBean = rfb;
|
||||
this.regionName = regionName;
|
||||
rfb.setBeanName(regionName);
|
||||
rfb.setCache(cache);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
configureRegionFactoryBean();
|
||||
try {
|
||||
regionFactoryBean.afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.exception = e;
|
||||
}
|
||||
verify();
|
||||
}
|
||||
|
||||
public abstract void configureRegionFactoryBean();
|
||||
|
||||
public abstract void verify();
|
||||
}
|
||||
|
||||
protected abstract void createRegionFactoryBeanConfigs();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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:p="http://www.springframework.org/schema/p"
|
||||
default-lazy-init="true"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire-1.2.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<gfe:cache/>
|
||||
<bean id="replicate-persistent-region" class="org.springframework.data.gemfire.RegionFactoryBean">
|
||||
<property name="cache" ref="gemfire-cache"/>
|
||||
<property name="dataPolicy" value="REPLICATE_PERSISTENT"/>
|
||||
</bean>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user