SGF-338 - Both <gfe:custom-entry-ttl> and <gfe:custom-entry-tti> SDG XML namespace elements allow for more than one 'CustomExpiry' bean to be set in the Region Expiration Attributes although GemFire only allows one!
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* The InvalidRegionExpirationAttributesNamespaceTest class is a test suite of test cases testing the proper syntax
|
||||
* of declaring "custom" expiration attributes on a Region.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.support.GenericXmlApplicationContext
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class InvalidRegionExpirationAttributesNamespaceTest {
|
||||
|
||||
protected String contextConfigLocation() {
|
||||
return getClass().getName().replaceAll("\\.", "/").concat("-context.xml");
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext createApplicationContext() {
|
||||
return new GenericXmlApplicationContext();
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext configureContext(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor());
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext initializeApplicationContext(ConfigurableApplicationContext applicationContext) {
|
||||
assertTrue(applicationContext instanceof GenericXmlApplicationContext);
|
||||
((GenericXmlApplicationContext) applicationContext).load(contextConfigLocation());
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.refresh();
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test(expected = XmlBeanDefinitionStoreException.class)
|
||||
public void testInvalidXmlSyntax() {
|
||||
try {
|
||||
initializeApplicationContext(configureContext(createApplicationContext()));
|
||||
}
|
||||
catch (XmlBeanDefinitionStoreException expected) {
|
||||
assertTrue(expected.getCause() instanceof SAXParseException);
|
||||
assertTrue(expected.getMessage().contains("Invalid content was found starting with element 'bean'"));
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,15 +34,20 @@ import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.internal.cache.lru.LRUCapacityController;
|
||||
|
||||
/**
|
||||
* The RegionEvictionAttributesNamespaceTest class is a test suite of test cases testing the use of Eviction settings
|
||||
* (EvictionAttributes) in the SDG XML namespace.
|
||||
* The RegionEvictionAttributesNamespaceTest class is a test suite of test cases testing the use of
|
||||
* Eviction configuration settings (EvictionAttributes) in the SDG XML namespace.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.3.4
|
||||
*/
|
||||
@ContextConfiguration(locations = "regions-with-eviction-attributes-ns.xml",
|
||||
initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class RegionEvictionAttributesNamespaceTest {
|
||||
|
||||
@Resource(name = "One")
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.gemstone.gemfire.cache.CustomExpiry;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAttributes;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* The RegionExpirationAttributesNamespaceTest class is a test suite of test cases testing the configuration of
|
||||
* ExpirationAttribute settings on Region Entries.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @see com.gemstone.gemfire.cache.RegionAttributes
|
||||
* @see com.gemstone.gemfire.cache.EvictionAttributes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class RegionExpirationAttributesNamespaceTest {
|
||||
|
||||
@Resource(name = "ReplicateExample")
|
||||
private Region<?, ?> replicateExample;
|
||||
|
||||
@Resource(name = "PreloadedExample")
|
||||
private Region<?, ?> preloadedExample;
|
||||
|
||||
@Resource(name = "PartitionExample")
|
||||
private Region<?, ?> partitionExample;
|
||||
|
||||
@Resource(name = "LocalExample")
|
||||
private Region<?, ?> localExample;
|
||||
|
||||
protected void assertRegionMetaData(final Region<?, ?> region, final String regionName, final DataPolicy dataPolicy) {
|
||||
assertRegionMetaData(region, regionName, Region.SEPARATOR + regionName, dataPolicy);
|
||||
}
|
||||
|
||||
protected void assertRegionMetaData(final Region<?, ?> region, final String regionName, final String regionFullPath,
|
||||
final DataPolicy dataPolicy) {
|
||||
assertNotNull(String.format("The '%1$s' Region was not properly configured and initialized!", regionName), region);
|
||||
assertEquals(regionName, region.getName());
|
||||
assertEquals(regionFullPath, region.getFullPath());
|
||||
assertNotNull(region.getAttributes());
|
||||
assertEquals(dataPolicy, region.getAttributes().getDataPolicy());
|
||||
}
|
||||
|
||||
protected void assertNoExpiration(final ExpirationAttributes expirationAttributes) {
|
||||
if (expirationAttributes != null) {
|
||||
//assertEquals(ExpirationAction.INVALIDATE, expirationAttributes.getAction());
|
||||
assertEquals(0, expirationAttributes.getTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertExpirationAttributes(final ExpirationAttributes expirationAttributes,
|
||||
final int timeout, final ExpirationAction action) {
|
||||
assertNotNull(expirationAttributes);
|
||||
assertEquals(timeout, expirationAttributes.getTimeout());
|
||||
assertEquals(action, expirationAttributes.getAction());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void assertCustomExpiry(final CustomExpiry<?, ?> customExpiry, final String name,
|
||||
final int timeout, final ExpirationAction action) {
|
||||
assertNotNull(customExpiry);
|
||||
assertEquals(name, customExpiry.toString());
|
||||
assertExpirationAttributes(customExpiry.getExpiry(mock(Region.Entry.class)), timeout, action);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplicateExampleExpirationAttributes() {
|
||||
assertRegionMetaData(replicateExample, "ReplicateExample", DataPolicy.REPLICATE);
|
||||
assertExpirationAttributes(replicateExample.getAttributes().getEntryTimeToLive(),
|
||||
600, ExpirationAction.DESTROY);
|
||||
assertExpirationAttributes(replicateExample.getAttributes().getEntryIdleTimeout(),
|
||||
300, ExpirationAction.INVALIDATE);
|
||||
assertNull(replicateExample.getAttributes().getCustomEntryTimeToLive());
|
||||
assertNull(replicateExample.getAttributes().getCustomEntryIdleTimeout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreloadedExampleExpirationAttributes() {
|
||||
assertRegionMetaData(preloadedExample, "PreloadedExample", DataPolicy.PRELOADED);
|
||||
assertExpirationAttributes(preloadedExample.getAttributes().getEntryTimeToLive(),
|
||||
120, ExpirationAction.LOCAL_DESTROY);
|
||||
assertNoExpiration(preloadedExample.getAttributes().getEntryIdleTimeout());
|
||||
assertNull(preloadedExample.getAttributes().getCustomEntryTimeToLive());
|
||||
assertNull(preloadedExample.getAttributes().getCustomEntryIdleTimeout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartitionExampleExpirationAttributes() {
|
||||
assertRegionMetaData(partitionExample, "PartitionExample", DataPolicy.PARTITION);
|
||||
assertExpirationAttributes(partitionExample.getAttributes().getEntryTimeToLive(),
|
||||
300, ExpirationAction.DESTROY);
|
||||
assertNoExpiration(partitionExample.getAttributes().getEntryIdleTimeout());
|
||||
assertNull(partitionExample.getAttributes().getCustomEntryTimeToLive());
|
||||
assertCustomExpiry(partitionExample.getAttributes().getCustomEntryIdleTimeout(), "PartitionCustomExpiry",
|
||||
120, ExpirationAction.INVALIDATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalExampleExpirationAttributes() {
|
||||
assertRegionMetaData(localExample, "LocalExample", DataPolicy.NORMAL);
|
||||
assertNoExpiration(localExample.getAttributes().getEntryTimeToLive());
|
||||
assertNoExpiration(localExample.getAttributes().getEntryIdleTimeout());
|
||||
assertCustomExpiry(localExample.getAttributes().getCustomEntryTimeToLive(), "LocalTtlCustomExpiry",
|
||||
180, ExpirationAction.LOCAL_DESTROY);
|
||||
assertCustomExpiry(localExample.getAttributes().getCustomEntryIdleTimeout(), "LocalTtiCustomExpiry",
|
||||
60, ExpirationAction.LOCAL_INVALIDATE);
|
||||
}
|
||||
|
||||
public static class TestCustomExpiry<K, V> implements CustomExpiry<K, V> {
|
||||
|
||||
private ExpirationAction action;
|
||||
|
||||
private Integer timeout;
|
||||
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public ExpirationAttributes getExpiry(final Region.Entry<K, V> kvEntry) {
|
||||
Assert.state(timeout != null, "The expiration 'timeout' must be specified!");
|
||||
Assert.state(action != null, "The expiration 'action' must be specified!");
|
||||
return new ExpirationAttributes(timeout, action);
|
||||
}
|
||||
|
||||
public void setAction(final ExpirationAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setTimeout(final Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user