SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.
Removed the XSD enumeration restriction on the 'result-policy' attribute of the 'interestType' SDG XSD complex-type definition in order to allow users to specify an Interest Policy using concrete values or properly placeholders when registering client Region Interests.
This commit is contained in:
@@ -37,6 +37,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -51,6 +52,7 @@ import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.TransactionListener;
|
||||
import com.gemstone.gemfire.cache.TransactionWriter;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
|
||||
@@ -82,6 +84,7 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
* @see org.springframework.beans.factory.DisposableBean
|
||||
* @see org.springframework.dao.support.PersistenceExceptionTranslator
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, FactoryBean<Cache>,
|
||||
InitializingBean, DisposableBean, PersistenceExceptionTranslator {
|
||||
|
||||
@@ -923,6 +926,7 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
|
||||
beanFactory.registerCustomEditor(IndexMaintenancePolicyType.class, IndexMaintenancePolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @author John Blum
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -23,20 +23,26 @@ import org.springframework.util.Assert;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* Basic holder class for registering an interest. Useful for configuring Gemfire caches through XML
|
||||
* and or JavaBeans means.
|
||||
* The Interest class holds details for registering a client interest.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Interest<K> implements InitializingBean {
|
||||
|
||||
private static final Constants constants = new Constants(InterestResultPolicy.class);
|
||||
|
||||
private K key;
|
||||
private InterestResultPolicy policy = InterestResultPolicy.DEFAULT;
|
||||
private boolean durable = false;
|
||||
private boolean receiveValues = true;
|
||||
|
||||
private InterestResultPolicy policy = InterestResultPolicy.DEFAULT;
|
||||
|
||||
private K key;
|
||||
|
||||
public Interest() {
|
||||
}
|
||||
|
||||
@@ -44,10 +50,6 @@ public class Interest<K> implements InitializingBean {
|
||||
this(key, InterestResultPolicy.DEFAULT, false);
|
||||
}
|
||||
|
||||
public Interest(K key, InterestResultPolicy policy) {
|
||||
this(key, policy, false);
|
||||
}
|
||||
|
||||
public Interest(K key, String policy) {
|
||||
this(key, policy, false);
|
||||
}
|
||||
@@ -60,6 +62,10 @@ public class Interest<K> implements InitializingBean {
|
||||
this(key, (InterestResultPolicy) constants.asObject(policy), durable, receiveValues);
|
||||
}
|
||||
|
||||
public Interest(K key, InterestResultPolicy policy) {
|
||||
this(key, policy, false);
|
||||
}
|
||||
|
||||
public Interest(K key, InterestResultPolicy policy, boolean durable) {
|
||||
this(key, policy, durable, true);
|
||||
}
|
||||
@@ -69,6 +75,7 @@ public class Interest<K> implements InitializingBean {
|
||||
this.policy = policy;
|
||||
this.durable = durable;
|
||||
this.receiveValues = receiveValues;
|
||||
|
||||
afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -81,7 +88,7 @@ public class Interest<K> implements InitializingBean {
|
||||
*
|
||||
* @return the key
|
||||
*/
|
||||
protected K getKey() {
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -99,7 +106,7 @@ public class Interest<K> implements InitializingBean {
|
||||
*
|
||||
* @return the policy
|
||||
*/
|
||||
protected InterestResultPolicy getPolicy() {
|
||||
public InterestResultPolicy getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
@@ -114,13 +121,12 @@ public class Interest<K> implements InitializingBean {
|
||||
if (policy instanceof InterestResultPolicy) {
|
||||
this.policy = (InterestResultPolicy) policy;
|
||||
}
|
||||
else if (policy instanceof String) {
|
||||
this.policy = (InterestResultPolicy) constants.asObject(String.valueOf(policy));
|
||||
}
|
||||
else {
|
||||
if (policy instanceof String) {
|
||||
this.policy = (InterestResultPolicy) constants.asObject((String) policy);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unknown argument type for property 'policy'" + policy);
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("Unknown argument type (%1$s) for property 'policy'!",
|
||||
policy));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +135,7 @@ public class Interest<K> implements InitializingBean {
|
||||
*
|
||||
* @return the durable
|
||||
*/
|
||||
protected boolean isDurable() {
|
||||
public boolean isDurable() {
|
||||
return durable;
|
||||
}
|
||||
|
||||
@@ -147,7 +153,7 @@ public class Interest<K> implements InitializingBean {
|
||||
*
|
||||
* @return the receiveValues
|
||||
*/
|
||||
protected boolean isReceiveValues() {
|
||||
public boolean isReceiveValues() {
|
||||
return receiveValues;
|
||||
}
|
||||
|
||||
@@ -159,4 +165,5 @@ public class Interest<K> implements InitializingBean {
|
||||
public void setReceiveValues(boolean receiveValues) {
|
||||
this.receiveValues = receiveValues;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.client;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyConverter class is a Spring Converter and JavaBeans PropertyEditor capable of converting
|
||||
* a String into a GemFire InterestResultPolicyConverter.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyConverter extends AbstractPropertyEditorConverterSupport<InterestResultPolicy> {
|
||||
|
||||
/**
|
||||
* Converts the given String into an instance of GemFire InterestResultPolicy.
|
||||
*
|
||||
* @param source the String to convert into an InterestResultPolicy value.
|
||||
* @return a GemFire InterestResultPolicy value for the given String.
|
||||
* @throws java.lang.IllegalArgumentException if the String is not a valid GemFire InterestResultPolicy.
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyType#getInterestResultPolicy(InterestResultPolicyType)
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyType#valueOfIgnoreCase(String)
|
||||
* @see #assertConverted(String, Object, Class)
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
*/
|
||||
@Override
|
||||
public InterestResultPolicy convert(final String source) {
|
||||
return assertConverted(source, InterestResultPolicyType.getInterestResultPolicy(
|
||||
InterestResultPolicyType.valueOfIgnoreCase(source)), InterestResultPolicy.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyType enum is an enumeration of all client Register Interests (result) policy values.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public enum InterestResultPolicyType {
|
||||
KEYS(InterestResultPolicy.KEYS),
|
||||
KEYS_VALUES(InterestResultPolicy.KEYS_VALUES),
|
||||
NONE(InterestResultPolicy.NONE);
|
||||
|
||||
public static final InterestResultPolicyType DEFAULT = InterestResultPolicyType.valueOf(
|
||||
InterestResultPolicy.DEFAULT);
|
||||
|
||||
private final InterestResultPolicy interestResultPolicy;
|
||||
|
||||
InterestResultPolicyType(final InterestResultPolicy interestResultPolicy) {
|
||||
this.interestResultPolicy = interestResultPolicy;
|
||||
}
|
||||
|
||||
public static InterestResultPolicy getInterestResultPolicy(final InterestResultPolicyType interestResultPolicyType) {
|
||||
return (interestResultPolicyType != null ? interestResultPolicyType.getInterestResultPolicy() : null);
|
||||
}
|
||||
|
||||
public static InterestResultPolicyType valueOf(final InterestResultPolicy interestResultPolicy) {
|
||||
for (InterestResultPolicyType interestResultPolicyType : values()) {
|
||||
if (interestResultPolicyType.getInterestResultPolicy().equals(interestResultPolicy)) {
|
||||
return interestResultPolicyType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static InterestResultPolicyType valueOfIgnoreCase(final String name) {
|
||||
for (InterestResultPolicyType interestResultPolicyType : values()) {
|
||||
if (interestResultPolicyType.name().equalsIgnoreCase(name)) {
|
||||
return interestResultPolicyType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public InterestResultPolicy getInterestResultPolicy() {
|
||||
return interestResultPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1106,10 +1106,10 @@ The RegionShortcut for this region. Allows easy initialization of the region bas
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="REPLICATE"/>
|
||||
<xsd:enumeration value="REPLICATE_PERSISTENT"/>
|
||||
<xsd:enumeration value="REPLICATE_OVERFLOW"/>
|
||||
<xsd:enumeration value="REPLICATE_PERSISTENT_OVERFLOW"/>
|
||||
<xsd:enumeration value="REPLICATE_HEAP_LRU"/>
|
||||
<xsd:enumeration value="REPLICATE_OVERFLOW"/>
|
||||
<xsd:enumeration value="REPLICATE_PERSISTENT"/>
|
||||
<xsd:enumeration value="REPLICATE_PERSISTENT_OVERFLOW"/>
|
||||
<xsd:enumeration value="REPLICATE_PROXY"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
@@ -1373,17 +1373,17 @@ The RegionShortcut for this region. Allows easy initialization of the region bas
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="PARTITION"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT"/>
|
||||
<xsd:enumeration value="PARTITION_PERSISTENT"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_PERSISTENT"/>
|
||||
<xsd:enumeration value="PARTITION_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_PERSISTENT_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_PERSISTENT_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_HEAP_LRU"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_HEAP_LRU"/>
|
||||
<xsd:enumeration value="PARTITION_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_PERSISTENT"/>
|
||||
<xsd:enumeration value="PARTITION_PERSISTENT_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_PROXY"/>
|
||||
<xsd:enumeration value="PARTITION_PROXY_REDUNDANT"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_HEAP_LRU"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_OVERFLOW"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_PERSISTENT"/>
|
||||
<xsd:enumeration value="PARTITION_REDUNDANT_PERSISTENT_OVERFLOW"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
@@ -1514,9 +1514,9 @@ The RegionShortcut for this region. Allows easy initialization of the region bas
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="LOCAL"/>
|
||||
<xsd:enumeration value="LOCAL_PERSISTENT"/>
|
||||
<xsd:enumeration value="LOCAL_HEAP_LRU"/>
|
||||
<xsd:enumeration value="LOCAL_OVERFLOW"/>
|
||||
<xsd:enumeration value="LOCAL_PERSISTENT"/>
|
||||
<xsd:enumeration value="LOCAL_PERSISTENT_OVERFLOW"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
@@ -1822,8 +1822,7 @@ to any key in this region in the CacheServer to be pushed to the client.
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="interestType">
|
||||
<xsd:sequence minOccurs="0" maxOccurs="1">
|
||||
<xsd:any namespace="##other" processContents="skip"
|
||||
minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Inner bean definition of the client key interest.
|
||||
@@ -1831,8 +1830,7 @@ Inner bean definition of the client key interest.
|
||||
</xsd:annotation>
|
||||
</xsd:any>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="key-ref" type="xsd:string"
|
||||
use="optional">
|
||||
<xsd:attribute name="key-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the client key interest bean referred by this declaration. Used as a convenience method. If no reference exists,
|
||||
@@ -2006,35 +2004,14 @@ The port number of the connection (between 1 and 65535 inclusive).
|
||||
</xsd:complexType>
|
||||
<!-- -->
|
||||
<xsd:complexType name="interestType" abstract="true">
|
||||
<xsd:attribute name="durable" type="xsd:string" use="optional"
|
||||
default="false">
|
||||
<xsd:attribute name="durable" type="xsd:string" use="optional" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether or not the registered interest is durable or not. Default is false.
|
||||
Indicates whether the Registered Interest is durable or not. Default is false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="result-policy" use="optional"
|
||||
default="KEYS_VALUES">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The result policy for this interest. Can be one of 'KEYS' or 'KEYS_VALUES' (the default) or 'NONE'.
|
||||
|
||||
KEYS - Initializes the local cache with the keys satisfying the request.
|
||||
KEYS-VALUES - initializes the local cache with the keys and current values satisfying the request.
|
||||
NONE - Does not initialize the local cache.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="KEYS" />
|
||||
<xsd:enumeration value="KEYS_VALUES" />
|
||||
<xsd:enumeration value="NONE" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="receive-values" type="xsd:string"
|
||||
use="optional" default="true">
|
||||
<xsd:attribute name="receive-values" type="xsd:string" use="optional" default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether values are received with create and update events on keys of interest (true)
|
||||
@@ -2043,6 +2020,17 @@ Default is true.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="result-policy" type="xsd:string" use="optional" default="KEYS_VALUES">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The result policy for this interest. Can be one of 'KEYS', 'KEYS_VALUES' (the default) or 'NONE'.
|
||||
|
||||
KEYS - Initializes the local Cache with the keys satisfying the request.
|
||||
KEYS_VALUES - Initializes the local Cache with the keys and current values satisfying the request.
|
||||
NONE - Does not initialize the local Cache.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
<!-- -->
|
||||
<xsd:element name="pool">
|
||||
@@ -2134,8 +2122,7 @@ The client subscription configuration that is used to control a clients use of s
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="eviction-type" use="optional"
|
||||
default="NONE">
|
||||
<xsd:attribute name="eviction-type" use="optional" default="NONE">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="NONE" />
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -56,6 +57,12 @@ public class EvictionActionTypeTest {
|
||||
assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, EvictionActionType.DEFAULT.getEvictionAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, EvictionActionType.DEFAULT.getEvictionAction());
|
||||
assertSame(EvictionActionType.LOCAL_DESTROY, EvictionActionType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOf() {
|
||||
assertEquals(EvictionActionType.LOCAL_DESTROY, EvictionActionType.valueOf(EvictionAction.LOCAL_DESTROY));
|
||||
|
||||
@@ -37,10 +37,10 @@ public class EvictionPolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testStaticGetEvictionAlgorithm() {
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, EvictionPolicyType
|
||||
.getEvictionAlgorithm(EvictionPolicyType.HEAP_PERCENTAGE));
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, EvictionPolicyType
|
||||
.getEvictionAlgorithm(EvictionPolicyType.MEMORY_SIZE));
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, EvictionPolicyType.getEvictionAlgorithm(
|
||||
EvictionPolicyType.HEAP_PERCENTAGE));
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, EvictionPolicyType.getEvictionAlgorithm(
|
||||
EvictionPolicyType.MEMORY_SIZE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +57,7 @@ public class EvictionPolicyTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfEvictionAlgorithms() {
|
||||
public void testValueOf() {
|
||||
assertEquals(EvictionPolicyType.ENTRY_COUNT, EvictionPolicyType.valueOf(EvictionAlgorithm.LRU_ENTRY));
|
||||
assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, EvictionPolicyType.valueOf(EvictionAlgorithm.LRU_HEAP));
|
||||
assertEquals(EvictionPolicyType.MEMORY_SIZE, EvictionPolicyType.valueOf(EvictionAlgorithm.LRU_MEMORY));
|
||||
@@ -69,6 +69,10 @@ public class EvictionPolicyTypeTest {
|
||||
public void testValueOfInvalidEvictionAlgorithms() {
|
||||
assertNull(EvictionPolicyType.valueOf(EvictionAlgorithm.LIFO_ENTRY));
|
||||
assertNull(EvictionPolicyType.valueOf(EvictionAlgorithm.LIFO_MEMORY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(EvictionPolicyType.valueOf((EvictionAlgorithm) null));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ public class ExpirationActionConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid_value");
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid_value) is not a valid ExpirationAction!", expected.getMessage());
|
||||
assertEquals("(illegal_value) is not a valid ExpirationAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class ExpirationActionConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextThrowsIllegalArgumentException() {
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("destruction");
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -58,7 +60,7 @@ public class ExpirationActionTypeTest {
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(ExpirationAction.INVALIDATE, ExpirationActionType.DEFAULT.getExpirationAction());
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
|
||||
assertSame(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +69,6 @@ public class ExpirationActionTypeTest {
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.valueOf(ExpirationAction.INVALIDATE));
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, ExpirationActionType.valueOf(ExpirationAction.LOCAL_DESTROY));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, ExpirationActionType.valueOf(ExpirationAction.LOCAL_INVALIDATE));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +76,10 @@ public class ExpirationActionTypeTest {
|
||||
try {
|
||||
for (int ordinal = 0; ordinal < Integer.MAX_VALUE; ordinal++) {
|
||||
ExpirationAction expirationAction = ExpirationAction.fromOrdinal(ordinal);
|
||||
assertEquals(expirationAction, ExpirationActionType.valueOf(expirationAction).getExpirationAction());
|
||||
ExpirationActionType expirationActionType = ExpirationActionType.valueOf(expirationAction);
|
||||
|
||||
assertNotNull(expirationActionType);
|
||||
assertEquals(expirationAction, expirationActionType.getExpirationAction());
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException ignore) {
|
||||
@@ -92,7 +96,7 @@ public class ExpirationActionTypeTest {
|
||||
assertEquals(ExpirationActionType.DESTROY, ExpirationActionType.valueOfIgnoreCase("destroy"));
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.valueOfIgnoreCase("Invalidate"));
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, ExpirationActionType.valueOfIgnoreCase("LOCAL_DESTROY"));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, ExpirationActionType.valueOfIgnoreCase("Local_Invalidate"));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, ExpirationActionType.valueOfIgnoreCase("LocaL_InValidAte"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -67,7 +67,7 @@ public class IndexMaintenancePolicyConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextThrowsIllegalArgumentException() {
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("async");
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -41,7 +42,7 @@ public class IndexMaintenancePolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, IndexMaintenancePolicyType.DEFAULT);
|
||||
assertSame(IndexMaintenancePolicyType.SYNCHRONOUS, IndexMaintenancePolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -50,7 +50,7 @@ public class IndexTypeConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertWithInvalidValue() {
|
||||
public void testConvertWithIllegalValue() {
|
||||
try {
|
||||
converter.convert("function");
|
||||
}
|
||||
@@ -72,12 +72,16 @@ public class IndexTypeConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("invalid");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Failed to convert String (invalid) into an IndexType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.junit.Test;
|
||||
public class IndexTypeTest {
|
||||
|
||||
@Test
|
||||
public void testGetGemFireIndexType() {
|
||||
public void testGetGemfireIndexType() {
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, IndexType.FUNCTIONAL.getGemfireIndexType());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, IndexType.HASH.getGemfireIndexType());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY, IndexType.KEY.getGemfireIndexType());
|
||||
@@ -44,13 +44,17 @@ public class IndexTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfGemFireIndexType() {
|
||||
assertNull(IndexType.valueOf((com.gemstone.gemfire.cache.query.IndexType) null));
|
||||
public void testValueOf() {
|
||||
assertEquals(IndexType.FUNCTIONAL, IndexType.valueOf(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL));
|
||||
assertEquals(IndexType.HASH, IndexType.valueOf(com.gemstone.gemfire.cache.query.IndexType.HASH));
|
||||
assertEquals(IndexType.PRIMARY_KEY, IndexType.valueOf(com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(IndexType.valueOf((com.gemstone.gemfire.cache.query.IndexType) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCase() {
|
||||
assertEquals(IndexType.FUNCTIONAL, IndexType.valueOfIgnoreCase("functional"));
|
||||
@@ -61,12 +65,12 @@ public class IndexTypeTest {
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidValues() {
|
||||
assertNull(IndexType.valueOfIgnoreCase(null));
|
||||
assertNull(IndexType.valueOfIgnoreCase(""));
|
||||
assertNull(IndexType.valueOfIgnoreCase(" "));
|
||||
assertNull(IndexType.valueOfIgnoreCase("Prime_Index"));
|
||||
assertNull(IndexType.valueOfIgnoreCase("SECONDARY_INDEX"));
|
||||
assertNull(IndexType.valueOfIgnoreCase("unique_index"));
|
||||
assertNull(IndexType.valueOfIgnoreCase(null));
|
||||
assertNull(IndexType.valueOfIgnoreCase(" "));
|
||||
assertNull(IndexType.valueOfIgnoreCase(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -52,12 +52,12 @@ public class InterestPolicyConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValueValue() {
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid");
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid) is not a valid InterestPolicy!", expected.getMessage());
|
||||
assertEquals("(invalid_value) is not a valid InterestPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.gemfire;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -55,16 +56,17 @@ public class InterestPolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(InterestPolicy.DEFAULT, InterestPolicyType.valueOf(InterestPolicy.DEFAULT).getInterestPolicy());
|
||||
assertEquals(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.DEFAULT);
|
||||
assertEquals(InterestPolicy.DEFAULT, InterestPolicyType.DEFAULT.getInterestPolicy());
|
||||
assertSame(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfInterestPolicies() {
|
||||
public void testValueOf() {
|
||||
try {
|
||||
for (byte ordinal = 0; ordinal < Byte.MAX_VALUE; ordinal++) {
|
||||
InterestPolicy interestPolicy = InterestPolicy.fromOrdinal(ordinal);
|
||||
InterestPolicyType interestPolicyType = InterestPolicyType.valueOf(interestPolicy);
|
||||
|
||||
assertNotNull(interestPolicyType);
|
||||
assertEquals(interestPolicy, interestPolicyType.getInterestPolicy());
|
||||
}
|
||||
@@ -74,7 +76,7 @@ public class InterestPolicyTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfInterestPolicyWithNull() {
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(InterestPolicyType.valueOf((InterestPolicy) null));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the InterestResultPolicyConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyConverter
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyType
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyConverterTest {
|
||||
|
||||
private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(InterestResultPolicy.NONE, converter.convert("NONE"));
|
||||
assertEquals(InterestResultPolicy.KEYS, converter.convert("Keys"));
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, converter.convert("kEyS_ValUes"));
|
||||
assertEquals(InterestResultPolicy.NONE, converter.convert("nONe"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("NOne");
|
||||
assertEquals(InterestResultPolicy.NONE, converter.getValue());
|
||||
converter.setAsText("KeYs");
|
||||
assertEquals(InterestResultPolicy.KEYS, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyTypeTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the InterestResultPolicyType enum.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyTypeTest
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testStaticGetInterestResultPolicy() {
|
||||
assertEquals(InterestResultPolicy.KEYS, InterestResultPolicyType.getInterestResultPolicy(
|
||||
InterestResultPolicyType.KEYS));
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, InterestResultPolicyType.getInterestResultPolicy(
|
||||
InterestResultPolicyType.KEYS_VALUES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticGetInterestResultPolicyWithNull() {
|
||||
assertNull(InterestResultPolicyType.getInterestResultPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(InterestResultPolicyType.DEFAULT, InterestResultPolicyType.valueOf(InterestResultPolicy.DEFAULT));
|
||||
assertEquals(InterestResultPolicy.DEFAULT, InterestResultPolicyType.DEFAULT.getInterestResultPolicy());
|
||||
assertSame(InterestResultPolicyType.KEYS_VALUES, InterestResultPolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOf() {
|
||||
try {
|
||||
for (byte ordinal = 0; ordinal < Byte.MAX_VALUE; ordinal++) {
|
||||
InterestResultPolicy interestResultPolicy = InterestResultPolicy.fromOrdinal(ordinal);
|
||||
InterestResultPolicyType interestResultPolicyType = InterestResultPolicyType.valueOf(
|
||||
interestResultPolicy);
|
||||
|
||||
assertNotNull(interestResultPolicyType);
|
||||
assertEquals(interestResultPolicy, interestResultPolicyType.getInterestResultPolicy());
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(InterestResultPolicyType.valueOf((InterestResultPolicy) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCase() {
|
||||
assertEquals(InterestResultPolicyType.KEYS, InterestResultPolicyType.valueOfIgnoreCase("KEYS"));
|
||||
assertEquals(InterestResultPolicyType.KEYS_VALUES, InterestResultPolicyType.valueOfIgnoreCase("Keys_Values"));
|
||||
assertEquals(InterestResultPolicyType.NONE, InterestResultPolicyType.valueOfIgnoreCase("none"));
|
||||
assertEquals(InterestResultPolicyType.NONE, InterestResultPolicyType.valueOfIgnoreCase("nONE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidValues() {
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase("keyz"));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase("KEY_VALUE"));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase("all"));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase(" "));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase(""));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase(null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.ConstantException;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestTest class is a test suite of test cases testing the contract and functionality of the Interest class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.Interest
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestTest {
|
||||
|
||||
@Test
|
||||
public void testConstruct() {
|
||||
Interest<String> interest = new Interest<String>("aKey", "keys", true, false);
|
||||
|
||||
assertEquals("aKey", interest.getKey());
|
||||
assertEquals(InterestResultPolicy.KEYS, interest.getPolicy());
|
||||
assertTrue(interest.isDurable());
|
||||
assertFalse(interest.isReceiveValues());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConstructWithNullKey() {
|
||||
try {
|
||||
new Interest<Object>(null);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("a non-null key is required", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ConstantException.class)
|
||||
public void testConstructWithInvalidPolicy() {
|
||||
new Interest<String>("aKey", "INVALID");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetState() {
|
||||
Interest<String> interest = new Interest();
|
||||
|
||||
assertNull(interest.getKey());
|
||||
assertEquals(InterestResultPolicy.DEFAULT, interest.getPolicy());
|
||||
assertFalse(interest.isDurable());
|
||||
assertTrue(interest.isReceiveValues());
|
||||
|
||||
interest.setDurable(true);
|
||||
interest.setKey("testKey");
|
||||
interest.setPolicy(InterestResultPolicy.KEYS_VALUES);
|
||||
interest.setReceiveValues(false);
|
||||
|
||||
assertEquals("testKey", interest.getKey());
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, interest.getPolicy());
|
||||
assertTrue(interest.isDurable());
|
||||
assertFalse(interest.isReceiveValues());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetPolicy() {
|
||||
Interest<Object> interest = new Interest<Object>();
|
||||
|
||||
assertEquals(InterestResultPolicy.DEFAULT, interest.getPolicy());
|
||||
|
||||
interest.setPolicy(InterestResultPolicy.NONE);
|
||||
|
||||
assertEquals(InterestResultPolicy.NONE, interest.getPolicy());
|
||||
|
||||
interest.setPolicy("keys");
|
||||
|
||||
assertEquals(InterestResultPolicy.KEYS, interest.getPolicy());
|
||||
}
|
||||
|
||||
@Test(expected = ConstantException.class)
|
||||
public void testSetPolicyWithIllegalValue() {
|
||||
new Interest<Object>().setPolicy("ILLEGAL");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,19 +22,29 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
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;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -48,9 +58,11 @@ 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.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.LoaderHelper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
|
||||
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
|
||||
import com.gemstone.gemfire.compression.Compressor;
|
||||
@@ -245,6 +257,85 @@ public class ClientRegionNamespaceTest {
|
||||
assertEquals(String.class, clientRegion.getAttributes().getValueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testClientRegionWithRegisteredInterests() throws Exception {
|
||||
assertTrue(context.containsBean("client-with-interests"));
|
||||
|
||||
ClientRegionFactoryBean factory = context.getBean("&client-with-interests", ClientRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(factory);
|
||||
|
||||
Interest<?>[] interests = TestUtils.readField("interests", factory);
|
||||
|
||||
assertNotNull(interests);
|
||||
assertEquals(2, interests.length);
|
||||
|
||||
assertInterest(true, false, InterestResultPolicy.KEYS, getInterestWithKey(".*", interests));
|
||||
assertInterest(true, false, InterestResultPolicy.KEYS_VALUES, getInterestWithKey("keyPrefix.*", interests));
|
||||
|
||||
Region mockClientRegion = MockCacheFactoryBean.MOCK_REGION_REF.get();
|
||||
|
||||
assertNotNull(mockClientRegion);
|
||||
|
||||
verify(mockClientRegion, times(1)).registerInterest(eq(".*"), eq(InterestResultPolicy.KEYS),
|
||||
eq(true), eq(false));
|
||||
verify(mockClientRegion, times(1)).registerInterestRegex(eq("keyPrefix.*"), eq(InterestResultPolicy.KEYS_VALUES),
|
||||
eq(true), eq(false));
|
||||
}
|
||||
|
||||
protected void assertInterest(final boolean expectedDurable, final boolean expectedReceiveValues,
|
||||
final InterestResultPolicy expectedPolicy, final Interest actualInterest) {
|
||||
assertNotNull(actualInterest);
|
||||
assertEquals(expectedDurable, actualInterest.isDurable());
|
||||
assertEquals(expectedReceiveValues, actualInterest.isReceiveValues());
|
||||
assertEquals(expectedPolicy, actualInterest.getPolicy());
|
||||
}
|
||||
|
||||
protected Interest getInterestWithKey(final String key, final Interest... interests) {
|
||||
for (Interest interest : interests) {
|
||||
if (interest.getKey().equals(key)) {
|
||||
return interest;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class MockCacheFactoryBean implements FactoryBean<ClientCache>, InitializingBean {
|
||||
|
||||
protected static final AtomicReference<Region> MOCK_REGION_REF = new AtomicReference<Region>(null);
|
||||
|
||||
private ClientCache mockClientCache;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
mockClientCache = mock(ClientCache.class, ClientRegionNamespaceTest.class.getSimpleName()
|
||||
.concat(".MockClientCache"));
|
||||
|
||||
MOCK_REGION_REF.compareAndSet(null, mock(Region.class, ClientRegionNamespaceTest.class.getSimpleName()
|
||||
.concat(".MockClientRegion")));
|
||||
|
||||
when(mockClientCache.getRegion(anyString())).thenReturn(MOCK_REGION_REF.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientCache getObject() throws Exception {
|
||||
return mockClientCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return ClientCache.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TestCacheLoader implements CacheLoader<Object, Object> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,9 +30,6 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
this.useBeanFactoryLocator = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bean
|
||||
*/
|
||||
public MockCacheFactoryBean(CacheFactoryBean cacheFactoryBean) {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
@@ -70,8 +67,9 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
return new CacheFactory(gemfireProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GemFireCache fetchCache() {
|
||||
((StubCache) cache).setProperties(this.properties);
|
||||
((StubCache) cache).setProperties(getProperties());
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
this.factoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = cacheFactoryBean.getBeanFactory();
|
||||
this.beanName = cacheFactoryBean.getBeanName();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.cacheXml = cacheFactoryBean.getCacheXml();
|
||||
this.copyOnRead = cacheFactoryBean.getCopyOnRead();
|
||||
this.criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
@@ -54,16 +54,17 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
this.pdxPersistent = cacheFactoryBean.getPdxPersistent();
|
||||
this.pdxSerializer = cacheFactoryBean.getPdxSerializer();
|
||||
this.properties = cacheFactoryBean.getProperties();
|
||||
this.readyForEvents = cacheFactoryBean.getReadyForEvents();
|
||||
this.searchTimeout = cacheFactoryBean.getSearchTimeout();
|
||||
this.transactionListeners = cacheFactoryBean.getTransactionListeners();
|
||||
this.transactionWriter = cacheFactoryBean.getTransactionWriter();
|
||||
this.readyForEvents = cacheFactoryBean.getReadyForEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties gemfireProperties) {
|
||||
((StubCache)cache).setProperties(gemfireProperties);
|
||||
setProperties(gemfireProperties);
|
||||
return new ClientCacheFactory(gemfireProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
<?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:context="http://www.springframework.org/schema/context"
|
||||
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/context http://www.springframework.org/schema/context/spring-context.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
|
||||
" default-lazy-init="true">
|
||||
|
||||
<util:properties id="placeholderProperties">
|
||||
<prop key="client.interests.durable">true</prop>
|
||||
<prop key="client.interests.receive-values">false</prop>
|
||||
<prop key="client.key.interests.result-policy">keys</prop>
|
||||
<prop key="client.regex.interests.result-policy">Keys_VALUes</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="placeholderProperties"/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">ClientRegionNamespaceTest</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:pool id="gemfire-pool" subscription-enabled="false">
|
||||
<gfe:locator host="localhost" port="40403"/>
|
||||
</gfe:pool>
|
||||
|
||||
<gfe:client-cache/>
|
||||
<gfe:client-cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<gfe:client-region id="simple" name="SimpleRegion"/>
|
||||
|
||||
@@ -66,6 +85,20 @@
|
||||
shortcut="CACHING_PROXY"
|
||||
value-constraint="java.lang.String"/>
|
||||
|
||||
<bean id="mockCache" class="org.springframework.data.gemfire.config.ClientRegionNamespaceTest$MockCacheFactoryBean"/>
|
||||
|
||||
<gfe:client-region id="client-with-interests" ignore-if-exists="true" shortcut="PROXY" cache-ref="mockCache">
|
||||
<gfe:key-interest durable="${client.interests.durable}" receive-values="${client.interests.receive-values}"
|
||||
result-policy="${client.key.interests.result-policy}">
|
||||
<bean class="java.lang.String">
|
||||
<constructor-arg value=".*"/>
|
||||
</bean>
|
||||
</gfe:key-interest>
|
||||
<gfe:regex-interest pattern="keyPrefix.*" durable="${client.interests.durable}"
|
||||
receive-values="${client.interests.receive-values}"
|
||||
result-policy="${client.regex.interests.result-policy}"/>
|
||||
</gfe:client-region>
|
||||
|
||||
<bean id="c-listener" class="org.springframework.data.gemfire.SimpleCacheListener"/>
|
||||
<bean id="testCompressor" class="org.springframework.data.gemfire.config.ClientRegionNamespaceTest$TestCompressor" p:name="STD"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user