From 426c1101870772de55603e1cc35ef4c0caa3f036 Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 28 Apr 2014 15:55:05 -0700 Subject: [PATCH] Implements JIRA improvement SGF-281 involving the addition of logic in SDG to avoid setting the Disk Store Name on the RegionAttributes used to a create a Region in the RegionFactoryBean when the Region is neither 'persistent' nor has an Eviction policy of Overflow To Disk. GemFire erroneously throws an IllegalStateException when the Region references a Disk Store but is not configured with persistence or overflow, which should not matter. Also fixed JIRA issues SGF-282 where the Eviction 'action' is ignored for PARTITION Regions when the 'threshold' is not set. --- .../data/gemfire/LocalRegionFactoryBean.java | 11 +- .../gemfire/PartitionedRegionFactoryBean.java | 1 + .../data/gemfire/RegionFactoryBean.java | 43 +- .../gemfire/ReplicatedRegionFactoryBean.java | 1 + .../config/EvictionAttributesFactoryBean.java | 19 +- .../EvictionAttributesFactoryBeanTest.java | 215 ++++-- .../config/LocalRegionNamespaceTest.java | 3 +- ...oreAndPersistenceEvictionSettingsTest.java | 113 +++ .../data/gemfire/test/MockRegionFactory.java | 685 ++++++++---------- .../data/gemfire/test/StubCache.java | 106 ++- ...ersistenceEvictionSettingsTest-context.xml | 31 + 11 files changed, 743 insertions(+), 485 deletions(-) create mode 100644 src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java create mode 100644 src/test/resources/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml diff --git a/src/main/java/org/springframework/data/gemfire/LocalRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/LocalRegionFactoryBean.java index 5675cac4..1bd9373a 100644 --- a/src/main/java/org/springframework/data/gemfire/LocalRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/LocalRegionFactoryBean.java @@ -44,16 +44,23 @@ public class LocalRegionFactoryBean extends RegionFactoryBean { if (dataPolicy == null || DataPolicy.NORMAL.equals(dataPolicy)) { // NOTE this is safe since a LOCAL Scoped NORMAL Region requiring persistence can be satisfied with // PERSISTENT_REPLICATE, per the RegionShortcut.LOCAL_PERSISTENT - regionFactory.setDataPolicy(isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.NORMAL); + DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.NORMAL); + + regionFactory.setDataPolicy(resolvedDataPolicy); + setDataPolicy(resolvedDataPolicy); } else if (DataPolicy.PRELOADED.equals(dataPolicy)) { // NOTE this is safe since a LOCAL Scoped PRELOADED Region requiring persistence can be satisfied with // PERSISTENT_REPLICATE, per the RegionShortcut.LOCAL_PERSISTENT - regionFactory.setDataPolicy(isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.PRELOADED); + DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.PRELOADED); + + regionFactory.setDataPolicy(resolvedDataPolicy); + setDataPolicy(resolvedDataPolicy); } else if (DataPolicy.PERSISTENT_REPLICATE.equals(dataPolicy) && RegionShortcutWrapper.valueOf(getShortcut()).isPersistent()) { regionFactory.setDataPolicy(dataPolicy); + setDataPolicy(dataPolicy); } else { throw new IllegalArgumentException(String.format("Data Policy '%1$s' is not supported for Local Regions.", diff --git a/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java index 4d3f98a9..270287ed 100644 --- a/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java @@ -48,6 +48,7 @@ public class PartitionedRegionFactoryBean extends RegionFactoryBean assertDataPolicyAndPersistentAttributesAreCompatible(dataPolicy); regionFactory.setDataPolicy(dataPolicy); + setDataPolicy(dataPolicy); } @Override diff --git a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java index a44650f0..ee47b90d 100644 --- a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java @@ -34,6 +34,7 @@ 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.EvictionAction; import com.gemstone.gemfire.cache.GemFireCache; import com.gemstone.gemfire.cache.PartitionAttributes; import com.gemstone.gemfire.cache.PartitionAttributesFactory; @@ -153,7 +154,7 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple resolveDataPolicy(regionFactory, persistent, dataPolicy); - if (diskStoreName != null) { + if (isDiskStoreConfigurationAllowed()) { regionFactory.setDiskStoreName(diskStoreName); } @@ -192,6 +193,16 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple return region; } + private boolean isDiskStoreConfigurationAllowed() { + boolean allow = (diskStoreName != null); + + allow &= (getDataPolicy().withPersistence() || (getAttributes() != null + && getAttributes().getEvictionAttributes() != null + && EvictionAction.OVERFLOW_TO_DISK.equals(attributes.getEvictionAttributes().getAction()))); + + return allow; + } + /** * Validates that the settings for Data Policy and the 'persistent' attribute in <gfe:*-region> elements * are compatible. @@ -453,6 +464,7 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple if (dataPolicy != null) { assertDataPolicyAndPersistentAttributesAreCompatible(dataPolicy); regionFactory.setDataPolicy(dataPolicy); + setDataPolicy(dataPolicy); } else { resolveDataPolicy(regionFactory, persistent, (String) null); @@ -477,9 +489,13 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple assertDataPolicyAndPersistentAttributesAreCompatible(resolvedDataPolicy); regionFactory.setDataPolicy(resolvedDataPolicy); + setDataPolicy(resolvedDataPolicy); } else { - regionFactory.setDataPolicy(isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.DEFAULT); + DataPolicy resolvedDataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.DEFAULT); + + regionFactory.setDataPolicy(resolvedDataPolicy); + setDataPolicy(resolvedDataPolicy); } } @@ -522,6 +538,17 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple this.attributes = attributes; } + /** + * Returns the attributes used to configure the Region created by this factory as set in the SDG XML namespace + * configuration meta-data, or as set with the setAttributes(:Attributes) method. + * + * @return the RegionAttributes used to configure the Region created by this factory. + * @see com.gemstone.gemfire.cache.RegionAttributes + */ + public RegionAttributes getAttributes() { + return (getRegion() != null ? getRegion().getAttributes() : attributes); + } + /** * Sets the cache listeners used for the region used by this factory. Used * only when a new region is created.Overrides the settings specified @@ -592,6 +619,18 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple this.dataPolicy = new DataPolicyConverter().convert(dataPolicyName); } + /** + * Gets the "resolved" Data Policy as determined by this RegionFactory when configuring the attributes + * of the Region to be created. + * + * @return the "resolved" Data Policy to be used to create the Region. + * @see com.gemstone.gemfire.cache.DataPolicy + */ + public DataPolicy getDataPolicy() { + Assert.state(dataPolicy != null, "The Data Policy has not been properly resolved yet!"); + return dataPolicy; + } + /** * Sets the name of Disk Store used for either overflow or persistence, or both. * diff --git a/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java index 2794678c..8efee65a 100644 --- a/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java @@ -45,6 +45,7 @@ public class ReplicatedRegionFactoryBean extends RegionFactoryBean { assertDataPolicyAndPersistentAttributesAreCompatible(dataPolicy); regionFactory.setDataPolicy(dataPolicy); + setDataPolicy(dataPolicy); } @Override diff --git a/src/main/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBean.java b/src/main/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBean.java index af13431a..54b02cad 100644 --- a/src/main/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBean.java @@ -22,6 +22,8 @@ import org.springframework.beans.factory.InitializingBean; import com.gemstone.gemfire.cache.EvictionAction; import com.gemstone.gemfire.cache.EvictionAttributes; import com.gemstone.gemfire.cache.util.ObjectSizer; +import com.gemstone.gemfire.internal.cache.lru.LRUCapacityController; +import com.gemstone.gemfire.internal.cache.lru.MemLRUCapacityController; /** * Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans. @@ -36,6 +38,11 @@ import com.gemstone.gemfire.cache.util.ObjectSizer; @SuppressWarnings("unused") class EvictionAttributesFactoryBean implements FactoryBean, InitializingBean { + // TODO remove this reference to the GemFire internal class when the Gem team fixes the EvictionAttributes bug!!! + protected static final int DEFAULT_LRU_MAXIMUM_ENTRIES = LRUCapacityController.DEFAULT_MAXIMUM_ENTRIES; + + protected static final int DEFAULT_MEMORY_MAXIMUM_SIZE = MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES; + private EvictionAction action = null; private EvictionAttributes evictionAttributes; @@ -60,16 +67,12 @@ class EvictionAttributesFactoryBean implements FactoryBean, } return EvictionAttributes.createLRUHeapAttributes(objectSizer, action); case MEMORY_SIZE: - if (threshold != null) { - return EvictionAttributes.createLRUMemoryAttributes(threshold, objectSizer, action); - } - return EvictionAttributes.createLRUMemoryAttributes(objectSizer, action); + return (threshold != null ? EvictionAttributes.createLRUMemoryAttributes(threshold, objectSizer, action) + : EvictionAttributes.createLRUMemoryAttributes(objectSizer, action)); case ENTRY_COUNT: default: - if (threshold != null) { - return EvictionAttributes.createLRUEntryAttributes(threshold, action); - } - return EvictionAttributes.createLRUEntryAttributes(); + return (threshold != null ? EvictionAttributes.createLRUEntryAttributes(threshold, action) + : EvictionAttributes.createLRUEntryAttributes(DEFAULT_LRU_MAXIMUM_ENTRIES, action)); } } diff --git a/src/test/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBeanTest.java index 8d02d393..6599a7e3 100644 --- a/src/test/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/EvictionAttributesFactoryBeanTest.java @@ -22,14 +22,14 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.gemstone.gemfire.cache.EvictionAction; import com.gemstone.gemfire.cache.EvictionAlgorithm; import com.gemstone.gemfire.cache.EvictionAttributes; import com.gemstone.gemfire.cache.util.ObjectSizer; -import com.gemstone.gemfire.internal.cache.lru.LRUCapacityController; -import com.gemstone.gemfire.internal.cache.lru.MemLRUCapacityController; /** * The EvictionAttributesFactoryBeanTest class is a test suite of test cases testing the contract and functionality @@ -43,13 +43,44 @@ import com.gemstone.gemfire.internal.cache.lru.MemLRUCapacityController; */ public class EvictionAttributesFactoryBeanTest { - @Test - public void testCreateEntryCountHeapAttributes() { - EvictionAttributesFactoryBean factoryBean = new EvictionAttributesFactoryBean(); + private EvictionAttributesFactoryBean factoryBean; + private ObjectSizer mockObjectSizer; + + @Before + public void setup() { + factoryBean = new EvictionAttributesFactoryBean(); + mockObjectSizer = mock(ObjectSizer.class, "MockObjectSizer"); + } + + @After + public void tearDown() { + factoryBean = null; + mockObjectSizer = null; + } + + @Test + public void testCreateEntryCountEvictionAttributesWithNullAction() { + factoryBean.setAction(null); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(1024); + factoryBean.setType(EvictionType.ENTRY_COUNT); + factoryBean.afterPropertiesSet(); + + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, evictionAttributes.getAction()); + assertNull(evictionAttributes.getObjectSizer()); + assertEquals(1024, evictionAttributes.getMaximum()); + assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateEntryCountEvictionAttributesWithNone() { factoryBean.setAction(EvictionAction.NONE); - factoryBean.setObjectSizer(null); - factoryBean.setThreshold(8192); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(null); factoryBean.setType(EvictionType.ENTRY_COUNT); factoryBean.afterPropertiesSet(); @@ -58,32 +89,80 @@ public class EvictionAttributesFactoryBeanTest { assertNotNull(evictionAttributes); assertEquals(EvictionAction.NONE, evictionAttributes.getAction()); assertNull(evictionAttributes.getObjectSizer()); - assertEquals(8192, evictionAttributes.getMaximum()); - assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm()); - - ObjectSizer mockObjectSizer = mock(ObjectSizer.class, "testCreateEntryCountHeapAttributes"); - - factoryBean.setAction(null); - factoryBean.setObjectSizer(mockObjectSizer); // ObjectSize is not used for ENTRY LRU! - factoryBean.setThreshold(null); - factoryBean.afterPropertiesSet(); - - evictionAttributes = factoryBean.getObject(); - - assertNotNull(evictionAttributes); - assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, evictionAttributes.getAction()); - assertNull(evictionAttributes.getObjectSizer()); - assertEquals(LRUCapacityController.DEFAULT_MAXIMUM_ENTRIES, evictionAttributes.getMaximum()); + assertEquals(EvictionAttributesFactoryBean.DEFAULT_LRU_MAXIMUM_ENTRIES, evictionAttributes.getMaximum()); assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm()); } @Test - public void testCreateHeapPercentageEvictionAttributes() { - EvictionAttributesFactoryBean factoryBean = new EvictionAttributesFactoryBean(); + public void testCreateEntryCountEvictionAttributesWithLocalDestroy() { + factoryBean.setAction(EvictionAction.LOCAL_DESTROY); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(128); + factoryBean.setType(EvictionType.ENTRY_COUNT); + factoryBean.afterPropertiesSet(); + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.LOCAL_DESTROY, evictionAttributes.getAction()); + assertNull(evictionAttributes.getObjectSizer()); + assertEquals(128, evictionAttributes.getMaximum()); + assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateEntryCountEvictionAttributesWithOverflowToDisk() { + factoryBean.setAction(EvictionAction.OVERFLOW_TO_DISK); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(null); + factoryBean.setType(EvictionType.ENTRY_COUNT); + factoryBean.afterPropertiesSet(); + + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.OVERFLOW_TO_DISK, evictionAttributes.getAction()); + assertNull(evictionAttributes.getObjectSizer()); + assertEquals(EvictionAttributesFactoryBean.DEFAULT_LRU_MAXIMUM_ENTRIES, evictionAttributes.getMaximum()); + assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateHeapPercentageEvictionAttributesWithNullAction() { + factoryBean.setAction(null); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setType(EvictionType.HEAP_PERCENTAGE); + factoryBean.afterPropertiesSet(); + + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, evictionAttributes.getAction()); + assertSame(mockObjectSizer, evictionAttributes.getObjectSizer()); + assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateHeapPercentageEvictionAttributesWithNone() { + factoryBean.setAction(EvictionAction.NONE); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(null); + factoryBean.setType(EvictionType.HEAP_PERCENTAGE); + factoryBean.afterPropertiesSet(); + + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.NONE, evictionAttributes.getAction()); + assertSame(mockObjectSizer, evictionAttributes.getObjectSizer()); + assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateHeapPercentageEvictionAttributesWithLocalDestroy() { factoryBean.setAction(EvictionAction.LOCAL_DESTROY); factoryBean.setObjectSizer(null); - //factoryBean.setThreshold(50); // Threshold is not used in HEAP LRU + factoryBean.setThreshold(null); factoryBean.setType(EvictionType.HEAP_PERCENTAGE); factoryBean.afterPropertiesSet(); @@ -93,18 +172,20 @@ public class EvictionAttributesFactoryBeanTest { assertEquals(EvictionAction.LOCAL_DESTROY, evictionAttributes.getAction()); assertNull(evictionAttributes.getObjectSizer()); assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm()); + } - ObjectSizer mockObjectSizer = mock(ObjectSizer.class, "testCreateHeapPercentageEvictionAttributes"); - - factoryBean.setAction(null); + @Test + public void testCreateHeapPercentageEvictionAttributesWithOverflowToDisk() { + factoryBean.setAction(EvictionAction.OVERFLOW_TO_DISK); factoryBean.setObjectSizer(mockObjectSizer); factoryBean.setThreshold(null); + factoryBean.setType(EvictionType.HEAP_PERCENTAGE); factoryBean.afterPropertiesSet(); - evictionAttributes = factoryBean.getObject(); + EvictionAttributes evictionAttributes = factoryBean.getObject(); assertNotNull(evictionAttributes); - assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, evictionAttributes.getAction()); + assertEquals(EvictionAction.OVERFLOW_TO_DISK, evictionAttributes.getAction()); assertSame(mockObjectSizer, evictionAttributes.getObjectSizer()); assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm()); } @@ -128,12 +209,61 @@ public class EvictionAttributesFactoryBeanTest { } @Test - public void testCreateMemorySizeEvictionAttributes() { - EvictionAttributesFactoryBean factoryBean = new EvictionAttributesFactoryBean(); + public void testCreateMemorySizeEvictionAttributesWithNullAction() { + factoryBean.setAction(null); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(null); + factoryBean.setType(EvictionType.MEMORY_SIZE); + factoryBean.afterPropertiesSet(); + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, evictionAttributes.getAction()); + assertSame(mockObjectSizer, evictionAttributes.getObjectSizer()); + assertEquals(EvictionAttributesFactoryBean.DEFAULT_MEMORY_MAXIMUM_SIZE, evictionAttributes.getMaximum()); + assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateMemorySizeEvictionAttributesWithNone() { + factoryBean.setAction(EvictionAction.NONE); + factoryBean.setObjectSizer(null); + factoryBean.setThreshold(256); + factoryBean.setType(EvictionType.MEMORY_SIZE); + factoryBean.afterPropertiesSet(); + + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.NONE, evictionAttributes.getAction()); + assertNull(evictionAttributes.getObjectSizer()); + assertEquals(256, evictionAttributes.getMaximum()); + assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateMemorySizeEvictionAttributesWithLocalDestroy() { + factoryBean.setAction(EvictionAction.LOCAL_DESTROY); + factoryBean.setObjectSizer(mockObjectSizer); + factoryBean.setThreshold(1024); + factoryBean.setType(EvictionType.MEMORY_SIZE); + factoryBean.afterPropertiesSet(); + + EvictionAttributes evictionAttributes = factoryBean.getObject(); + + assertNotNull(evictionAttributes); + assertEquals(EvictionAction.LOCAL_DESTROY, evictionAttributes.getAction()); + assertSame(mockObjectSizer, evictionAttributes.getObjectSizer()); + assertEquals(1024, evictionAttributes.getMaximum()); + assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm()); + } + + @Test + public void testCreateMemorySizeEvictionAttributesWithOverflowToDisk() { factoryBean.setAction(EvictionAction.OVERFLOW_TO_DISK); factoryBean.setObjectSizer(null); - factoryBean.setThreshold(512); + factoryBean.setThreshold(null); factoryBean.setType(EvictionType.MEMORY_SIZE); factoryBean.afterPropertiesSet(); @@ -142,22 +272,7 @@ public class EvictionAttributesFactoryBeanTest { assertNotNull(evictionAttributes); assertEquals(EvictionAction.OVERFLOW_TO_DISK, evictionAttributes.getAction()); assertNull(evictionAttributes.getObjectSizer()); - assertEquals(512, evictionAttributes.getMaximum()); - assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm()); - - ObjectSizer mockObjectSizer = mock(ObjectSizer.class, "testCreateMemorySizeEvictionAttributes"); - - factoryBean.setAction(null); - factoryBean.setObjectSizer(mockObjectSizer); - factoryBean.setThreshold(null); - factoryBean.afterPropertiesSet(); - - evictionAttributes = factoryBean.getObject(); - - assertNotNull(evictionAttributes); - assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, evictionAttributes.getAction()); - assertSame(mockObjectSizer, evictionAttributes.getObjectSizer()); - assertEquals(MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES, evictionAttributes.getMaximum()); + assertEquals(EvictionAttributesFactoryBean.DEFAULT_MEMORY_MAXIMUM_SIZE, evictionAttributes.getMaximum()); assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm()); } diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java index 3f3f2974..f0f8ff1f 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java @@ -36,6 +36,7 @@ import org.springframework.util.ObjectUtils; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.Scope; @@ -63,7 +64,7 @@ public class LocalRegionNamespaceTest { public void testPublishingLocal() throws Exception { assertTrue(context.containsBean("pub")); RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class); - assertNull(TestUtils.readField("dataPolicy", fb)); + assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb)); assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb)); assertEquals("publisher", TestUtils.readField("name", fb)); RegionAttributes attrs = TestUtils.readField("attributes", fb); diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java b/src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java new file mode 100644 index 00000000..74dc97fc --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java @@ -0,0 +1,113 @@ +/* + * 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 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 com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.Region; + +/** + * The RegionsWithDiskStoreAndPersistenceEvictionSettingsTest class is a test suite testing the functionality + * of GemFire Cache Regions when persistent/non-persistent with and without Eviction settings when specifying a + * Disk Store. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.test.context.ContextConfiguration + * @since 1.4.0.RC1 + */ +@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringJUnit4ClassRunner.class) +public class RegionsWithDiskStoreAndPersistenceEvictionSettingsTest { + + @Resource(name = "NotPersistentNoOverflowRegion") + private Region notPersistentNoOverflowRegion; + + @Resource(name = "NotPersistentOverflowRegion") + private Region notPersistentOverflowRegion; + + @Resource(name = "PersistentNoOverflowRegion") + private Region persistentNoOverflowRegion; + + @Resource(name = "PersistentOverflowRegion") + private Region persistentOverflowRegion; + + @Test + public void testNotPersistentNoOverflowRegion() { + assertNotNull("The Not Persistent, No Overflow Region was not properly configured and initialized!", + notPersistentNoOverflowRegion); + + assertNotNull(notPersistentNoOverflowRegion.getAttributes()); + assertEquals(DataPolicy.PARTITION, notPersistentNoOverflowRegion.getAttributes().getDataPolicy()); + assertNotNull(notPersistentNoOverflowRegion.getAttributes().getEvictionAttributes()); + assertEquals(EvictionAction.NONE, notPersistentNoOverflowRegion.getAttributes() + .getEvictionAttributes().getAction()); + assertNull(notPersistentNoOverflowRegion.getAttributes().getDiskStoreName()); + } + + @Test + public void testNotPersistentOverflowRegion() { + assertNotNull("The Not Persistent, Overflow Region was not properly configured and initialized!", + notPersistentOverflowRegion); + + assertNotNull(notPersistentOverflowRegion.getAttributes()); + assertEquals(DataPolicy.PARTITION, notPersistentOverflowRegion.getAttributes().getDataPolicy()); + assertNotNull(notPersistentOverflowRegion.getAttributes().getEvictionAttributes()); + assertEquals(EvictionAction.OVERFLOW_TO_DISK, notPersistentOverflowRegion.getAttributes() + .getEvictionAttributes().getAction()); + assertEquals("DiskStoreOne", notPersistentOverflowRegion.getAttributes().getDiskStoreName()); + } + + @Test + public void testPersistentNoOverflowRegion() { + assertNotNull("The Persistent, No Overflow Region was not properly configured and initialized!", + persistentNoOverflowRegion); + + assertNotNull(persistentNoOverflowRegion.getAttributes()); + assertEquals(DataPolicy.PERSISTENT_PARTITION, persistentNoOverflowRegion.getAttributes().getDataPolicy()); + assertNotNull(persistentNoOverflowRegion.getAttributes().getEvictionAttributes()); + assertEquals(EvictionAction.LOCAL_DESTROY, persistentNoOverflowRegion.getAttributes() + .getEvictionAttributes().getAction()); + assertEquals("DiskStoreOne", persistentNoOverflowRegion.getAttributes().getDiskStoreName()); + } + + @Test + public void testPersistentOverflowRegion() { + assertNotNull("The Persistent, Overflow Region was not properly configured and initialized!", + persistentOverflowRegion); + + assertNotNull(persistentOverflowRegion.getAttributes()); + assertEquals(DataPolicy.PERSISTENT_PARTITION, persistentOverflowRegion.getAttributes().getDataPolicy()); + assertNotNull(persistentOverflowRegion.getAttributes().getEvictionAttributes()); + assertEquals(EvictionAction.OVERFLOW_TO_DISK, persistentOverflowRegion.getAttributes() + .getEvictionAttributes().getAction()); + assertEquals("DiskStoreOne", persistentOverflowRegion.getAttributes().getDiskStoreName()); + } + +} diff --git a/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java b/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java index 8e14e12c..ef28b6c7 100644 --- a/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java +++ b/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java @@ -14,6 +14,7 @@ package org.springframework.data.gemfire.test; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyFloat; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -48,11 +49,13 @@ import com.gemstone.gemfire.cache.query.QueryService; @SuppressWarnings("deprecation") public class MockRegionFactory { - private static QueryService queryService = mock(QueryService.class); + private static QueryService queryService = mock(QueryService.class); private static RegionService regionService = mock(RegionService.class); private com.gemstone.gemfire.cache.AttributesFactory attributesFactory; + private RegionAttributes regionAttributes; + private final StubCache cache; public MockRegionFactory(StubCache cache) { @@ -68,7 +71,8 @@ public class MockRegionFactory { attributesFactory = (attributes != null ? new com.gemstone.gemfire.cache.AttributesFactory(attributes) : new com.gemstone.gemfire.cache.AttributesFactory()); - //Workaround for GemFire bug + // Workaround for GemFire bug + // TODO ?!?!?! if (attributes !=null) { attributesFactory.setLockGrantor(attributes.isLockGrantor()); } @@ -76,18 +80,18 @@ public class MockRegionFactory { final RegionFactory regionFactory = mock(RegionFactory.class); when(regionFactory.create(anyString())).thenAnswer(new Answer() { - @Override - public Region answer(InvocationOnMock invocation) throws Throwable { + @Override public Region answer(InvocationOnMock invocation) throws Throwable { String name = (String) invocation.getArguments()[0]; Region region = mockRegion(name); + cache.allRegions().put(name, region); + return region; } }); - when(regionFactory.createSubregion(any(Region.class),anyString())).thenAnswer(new Answer() { - @Override - public Region answer(InvocationOnMock invocation) throws Throwable { + when(regionFactory.createSubregion(any(Region.class), anyString())).thenAnswer(new Answer() { + @Override public Region answer(InvocationOnMock invocation) throws Throwable { Region parent = (Region) invocation.getArguments()[0]; String name = (String) invocation.getArguments()[1]; String parentRegionName = null; @@ -112,380 +116,327 @@ public class MockRegionFactory { }); when(regionFactory.setCacheLoader(any(CacheLoader.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheLoader val = (CacheLoader)invocation.getArguments()[0]; - attributesFactory.setCacheLoader(val); + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + CacheLoader cacheLoader = (CacheLoader) invocation.getArguments()[0]; + attributesFactory.setCacheLoader(cacheLoader); return regionFactory; } }); when(regionFactory.setCacheWriter(any(CacheWriter.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheWriter val = (CacheWriter)invocation.getArguments()[0]; - attributesFactory.setCacheWriter(val); - return regionFactory; - } - }); - - - when(regionFactory.addAsyncEventQueueId(anyString())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String val = (String)invocation.getArguments()[0]; - attributesFactory.addAsyncEventQueueId(val); - return regionFactory; - } - }); - - when(regionFactory.addCacheListener(any(CacheListener.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheListener val = (CacheListener)invocation.getArguments()[0]; - attributesFactory.addCacheListener(val); - return regionFactory; - } - }); - - when(regionFactory.setEvictionAttributes(any(EvictionAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - EvictionAttributes val = (EvictionAttributes)invocation.getArguments()[0]; - attributesFactory.setEvictionAttributes(val); - return regionFactory; - } - }); - - when(regionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes val = (ExpirationAttributes)invocation.getArguments()[0]; - attributesFactory.setEntryIdleTimeout(val); - return regionFactory; - } - }); - - when(regionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CustomExpiry val = (CustomExpiry)invocation.getArguments()[0]; - attributesFactory.setCustomEntryIdleTimeout(val); - return regionFactory; - } - }); - - when(regionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes val = (ExpirationAttributes)invocation.getArguments()[0]; - attributesFactory.setEntryTimeToLive(val); - return regionFactory; - } - }); - - when(regionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CustomExpiry val = (CustomExpiry)invocation.getArguments()[0]; - attributesFactory.setCustomEntryTimeToLive(val); - return regionFactory; - } - }); - - when(regionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes val = (ExpirationAttributes)invocation.getArguments()[0]; - attributesFactory.setRegionIdleTimeout(val); - return regionFactory; - } - }); - - when(regionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes val = (ExpirationAttributes)invocation.getArguments()[0]; - attributesFactory.setRegionTimeToLive(val); - return regionFactory; - } - }); - - when(regionFactory.setScope(any(Scope.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - Scope val = (Scope)invocation.getArguments()[0]; - attributesFactory.setScope(val); - return regionFactory; - } - }); - - when(regionFactory.setDataPolicy(any(DataPolicy.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - DataPolicy val = (DataPolicy)invocation.getArguments()[0]; - attributesFactory.setDataPolicy(val); - return regionFactory; - } - }); - - when(regionFactory.setEarlyAck(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setEarlyAck(val); - return regionFactory; - } - }); - - when(regionFactory.setMulticastEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setMulticastEnabled(val); - return regionFactory; - } - }); - - when(regionFactory.setPoolName(anyString())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String val = (String)invocation.getArguments()[0]; - attributesFactory.setPoolName(val); - return regionFactory; - } - }); - - when(regionFactory.setEnableGateway(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setEnableGateway(val); - return regionFactory; - } - }); - - when(regionFactory.setEnableAsyncConflation(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setEnableAsyncConflation(val); - return regionFactory; - } - }); - - when(regionFactory.setEnableSubscriptionConflation(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setEnableSubscriptionConflation(val); - return regionFactory; - } - }); - - when(regionFactory.setKeyConstraint(any(Class.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - Class val = (Class)invocation.getArguments()[0]; - attributesFactory.setKeyConstraint(val); - return regionFactory; - } - }); - - when(regionFactory.setValueConstraint(any(Class.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - Class val = (Class)invocation.getArguments()[0]; - attributesFactory.setValueConstraint(val); - return regionFactory; - } - }); - - when(regionFactory.setInitialCapacity(anyInt())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - int val = (Integer)invocation.getArguments()[0]; - System.out.println("setInitialCapacity " + val); - attributesFactory.setInitialCapacity(val); - return regionFactory; - } - }); - - when(regionFactory.setLoadFactor(anyInt())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - int val = (Integer)invocation.getArguments()[0]; - attributesFactory.setLoadFactor(val); - return regionFactory; - } - }); - - when(regionFactory.setConcurrencyLevel(anyInt())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - int val = (Integer)invocation.getArguments()[0]; - attributesFactory.setConcurrencyLevel(val); - return regionFactory; - } - }); - - when(regionFactory.setConcurrencyChecksEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setConcurrencyChecksEnabled(val); - return regionFactory; - } - }); - - when(regionFactory.setDiskWriteAttributes(any(com.gemstone.gemfire.cache.DiskWriteAttributes.class))) - .thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - com.gemstone.gemfire.cache.DiskWriteAttributes val = - (com.gemstone.gemfire.cache.DiskWriteAttributes) invocation.getArguments()[0]; - attributesFactory.setDiskWriteAttributes(val); - return regionFactory; - } - }); - - when(regionFactory.setDiskStoreName(anyString())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String val = (String)invocation.getArguments()[0]; - attributesFactory.setDiskStoreName(val); - return regionFactory; - } - }); - - when(regionFactory.setDiskSynchronous(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setDiskSynchronous(val); - return regionFactory; - } - }); - - when(regionFactory.setDiskDirs(any(File[].class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - File[] val = (File[])invocation.getArguments()[0]; - attributesFactory.setDiskDirs(val); - return regionFactory; - } - }); - - when(regionFactory.setDiskDirsAndSizes(any(File[].class),any(int[].class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - File[] val0 = (File[])invocation.getArguments()[0]; - int[] val1 = (int[])invocation.getArguments()[1]; - attributesFactory.setDiskDirsAndSizes(val0,val1); - return regionFactory; - } - }); - - when(regionFactory.setPartitionAttributes(any(PartitionAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - PartitionAttributes val = (PartitionAttributes)invocation.getArguments()[0]; - attributesFactory.setPartitionAttributes(val); - return regionFactory; - } - }); - - when(regionFactory.setMembershipAttributes(any(MembershipAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - MembershipAttributes val = (MembershipAttributes)invocation.getArguments()[0]; - attributesFactory.setMembershipAttributes(val); - return regionFactory; - } - }); - - when(regionFactory.setIndexMaintenanceSynchronous(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setIndexMaintenanceSynchronous(val); - return regionFactory; - } - }); - - when(regionFactory.setStatisticsEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setStatisticsEnabled(val); - return regionFactory; - } - }); - - when(regionFactory.setIgnoreJTA(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setIgnoreJTA(val); - return regionFactory; - } - }); - - when(regionFactory.setLockGrantor(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - System.out.println("setting lock grantor to " + val); - attributesFactory.setLockGrantor(val); - return regionFactory; - } - }); - - when(regionFactory.setSubscriptionAttributes(any(SubscriptionAttributes.class))).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - SubscriptionAttributes val = (SubscriptionAttributes)invocation.getArguments()[0]; - attributesFactory.setSubscriptionAttributes(val); - return regionFactory; - } - }); - - when(regionFactory.setGatewayHubId(anyString())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String val = (String)invocation.getArguments()[0]; - attributesFactory.setGatewayHubId(val); + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + CacheWriter cacheWriter = (CacheWriter) invocation.getArguments()[0]; + attributesFactory.setCacheWriter(cacheWriter); return regionFactory; } }); when(regionFactory.setCloningEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean val = (Boolean)invocation.getArguments()[0]; - attributesFactory.setCloningEnabled(val); + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean cloningEnabled = (Boolean) invocation.getArguments()[0]; + attributesFactory.setCloningEnabled(cloningEnabled); return regionFactory; } }); - when(regionFactory.addGatewaySenderId(anyString())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String val = (String)invocation.getArguments()[0]; - attributesFactory.addGatewaySenderId(val); + when(regionFactory.setConcurrencyChecksEnabled(anyBoolean())).thenAnswer(new Answer() { + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean concurrencyChecksEnabled = (Boolean) invocation.getArguments()[0]; + attributesFactory.setConcurrencyChecksEnabled(concurrencyChecksEnabled); + return regionFactory; + } + }); + + when(regionFactory.setConcurrencyLevel(anyInt())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + int concurrencyLevel = (Integer) invocation.getArguments()[0]; + attributesFactory.setConcurrencyLevel(concurrencyLevel); + return regionFactory; + } + }); + + when(regionFactory.setDataPolicy(any(DataPolicy.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + DataPolicy dataPolicy = (DataPolicy) invocation.getArguments()[0]; + attributesFactory.setDataPolicy(dataPolicy); + return regionFactory; + } + }); + + when(regionFactory.setDiskDirs(any(File[].class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + File[] diskDirectories = (File[]) invocation.getArguments()[0]; + attributesFactory.setDiskDirs(diskDirectories); + return regionFactory; + } + }); + + when(regionFactory.setDiskDirsAndSizes(any(File[].class), any(int[].class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + File[] diskDirectories = (File[]) invocation.getArguments()[0]; + int[] diskSizes = (int[]) invocation.getArguments()[1]; + attributesFactory.setDiskDirsAndSizes(diskDirectories, diskSizes); + return regionFactory; + } + }); + + when(regionFactory.setDiskStoreName(anyString())).thenAnswer(new Answer() { + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + String diskStoreName = (String) invocation.getArguments()[0]; + attributesFactory.setDiskStoreName(diskStoreName); + return regionFactory; + } + }); + + when(regionFactory.setDiskWriteAttributes(any(com.gemstone.gemfire.cache.DiskWriteAttributes.class))) + .thenAnswer(new Answer() { + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + com.gemstone.gemfire.cache.DiskWriteAttributes diskWriteAttributes = + (com.gemstone.gemfire.cache.DiskWriteAttributes) invocation.getArguments()[0]; + attributesFactory.setDiskWriteAttributes(diskWriteAttributes); + return regionFactory; + } + }); + + when(regionFactory.setDiskSynchronous(anyBoolean())).thenAnswer(new Answer() { + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean diskSynchronous = (Boolean) invocation.getArguments()[0]; + attributesFactory.setDiskSynchronous(diskSynchronous); + return regionFactory; + } + }); + + when(regionFactory.setEarlyAck(anyBoolean())).thenAnswer(new Answer() { + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean earlyAck = (Boolean) invocation.getArguments()[0]; + attributesFactory.setEarlyAck(earlyAck); + return regionFactory; + } + }); + + when(regionFactory.setEnableAsyncConflation(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean enableAsyncConflation = (Boolean) invocation.getArguments()[0]; + attributesFactory.setEnableAsyncConflation(enableAsyncConflation); + return regionFactory; + } + }); + + when(regionFactory.setEnableGateway(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean enableGateway = (Boolean) invocation.getArguments()[0]; + attributesFactory.setEnableGateway(enableGateway); + return regionFactory; + } + }); + + when(regionFactory.setEnableSubscriptionConflation(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean enableSubscriptionConflation = (Boolean) invocation.getArguments()[0]; + attributesFactory.setEnableSubscriptionConflation(enableSubscriptionConflation); + return regionFactory; + } + }); + + when(regionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + ExpirationAttributes entryIdleTimeout = (ExpirationAttributes) invocation.getArguments()[0]; + attributesFactory.setEntryIdleTimeout(entryIdleTimeout); + return regionFactory; + } + }); + + when(regionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + CustomExpiry customEntryIdleTimeout = (CustomExpiry) invocation.getArguments()[0]; + attributesFactory.setCustomEntryIdleTimeout(customEntryIdleTimeout); + return regionFactory; + } + }); + + when(regionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + ExpirationAttributes entryTimeToLive = (ExpirationAttributes) invocation.getArguments()[0]; + attributesFactory.setEntryTimeToLive(entryTimeToLive); + return regionFactory; + } + }); + + when(regionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + CustomExpiry customEntryTimeToLive = (CustomExpiry) invocation.getArguments()[0]; + attributesFactory.setCustomEntryTimeToLive(customEntryTimeToLive); + return regionFactory; + } + }); + + when(regionFactory.setEvictionAttributes(any(EvictionAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + EvictionAttributes evictionAttributes = (EvictionAttributes) invocation.getArguments()[0]; + attributesFactory.setEvictionAttributes(evictionAttributes); + return regionFactory; + } + }); + + when(regionFactory.setGatewayHubId(anyString())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + String gatewayHubId = (String) invocation.getArguments()[0]; + attributesFactory.setGatewayHubId(gatewayHubId); + return regionFactory; + } + }); + + when(regionFactory.setIgnoreJTA(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean ignoreJta = (Boolean) invocation.getArguments()[0]; + attributesFactory.setIgnoreJTA(ignoreJta); + return regionFactory; + } + }); + + when(regionFactory.setIndexMaintenanceSynchronous(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean indexMaintenanceSynchronous = (Boolean) invocation.getArguments()[0]; + attributesFactory.setIndexMaintenanceSynchronous(indexMaintenanceSynchronous); + return regionFactory; + } + }); + + when(regionFactory.setInitialCapacity(anyInt())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + int initialCapacity = (Integer) invocation.getArguments()[0]; + attributesFactory.setInitialCapacity(initialCapacity); + return regionFactory; + } + }); + + when(regionFactory.setKeyConstraint(any(Class.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + Class keyConstraint = (Class) invocation.getArguments()[0]; + attributesFactory.setKeyConstraint(keyConstraint); + return regionFactory; + } + }); + + when(regionFactory.setLoadFactor(anyFloat())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + float loadFactor = (Float) invocation.getArguments()[0]; + attributesFactory.setLoadFactor(loadFactor); + return regionFactory; + } + }); + + when(regionFactory.setLockGrantor(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean lockGrantor = (Boolean) invocation.getArguments()[0]; + attributesFactory.setLockGrantor(lockGrantor); + return regionFactory; + } + }); + + when(regionFactory.setMembershipAttributes(any(MembershipAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + MembershipAttributes membershipAttributes = (MembershipAttributes) invocation.getArguments()[0]; + attributesFactory.setMembershipAttributes(membershipAttributes); + return regionFactory; + } + }); + + when(regionFactory.setMulticastEnabled(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean multicastEnabled = (Boolean) invocation.getArguments()[0]; + attributesFactory.setMulticastEnabled(multicastEnabled); + return regionFactory; + } + }); + + when(regionFactory.setPartitionAttributes(any(PartitionAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + PartitionAttributes partitionAttributes = (PartitionAttributes) invocation.getArguments()[0]; + attributesFactory.setPartitionAttributes(partitionAttributes); + return regionFactory; + } + }); + + when(regionFactory.setPoolName(anyString())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + String poolName = (String) invocation.getArguments()[0]; + attributesFactory.setPoolName(poolName); + return regionFactory; + } + }); + + when(regionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + ExpirationAttributes regionIdleTimeout = (ExpirationAttributes) invocation.getArguments()[0]; + attributesFactory.setRegionIdleTimeout(regionIdleTimeout); + return regionFactory; + } + }); + + when(regionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + ExpirationAttributes regionTimeToLive = (ExpirationAttributes) invocation.getArguments()[0]; + attributesFactory.setRegionTimeToLive(regionTimeToLive); + return regionFactory; + } + }); + + when(regionFactory.setScope(any(Scope.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + Scope scope = (Scope) invocation.getArguments()[0]; + attributesFactory.setScope(scope); + return regionFactory; + } + }); + + when(regionFactory.setStatisticsEnabled(anyBoolean())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + boolean statisticsEnabled = (Boolean) invocation.getArguments()[0]; + attributesFactory.setStatisticsEnabled(statisticsEnabled); + return regionFactory; + } + }); + + when(regionFactory.setSubscriptionAttributes(any(SubscriptionAttributes.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + SubscriptionAttributes subscriptionAttributes = (SubscriptionAttributes) invocation.getArguments()[0]; + attributesFactory.setSubscriptionAttributes(subscriptionAttributes); + return regionFactory; + } + }); + + when(regionFactory.setValueConstraint(any(Class.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + Class valueConstraint = (Class) invocation.getArguments()[0]; + attributesFactory.setValueConstraint(valueConstraint); return regionFactory; } }); when(regionFactory.addAsyncEventQueueId(anyString())).thenAnswer(new Answer(){ - @Override - public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String val = (String)invocation.getArguments()[0]; - attributesFactory.addAsyncEventQueueId(val); + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + String asyncEventQueueId = (String) invocation.getArguments()[0]; + attributesFactory.addAsyncEventQueueId(asyncEventQueueId); return regionFactory; } }); + when(regionFactory.addCacheListener(any(CacheListener.class))).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + CacheListener cacheListener = (CacheListener) invocation.getArguments()[0]; + attributesFactory.addCacheListener(cacheListener); + return regionFactory; + } + }); + + when(regionFactory.addGatewaySenderId(anyString())).thenAnswer(new Answer(){ + @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { + String gatewaySenderId = (String) invocation.getArguments()[0]; + attributesFactory.addGatewaySenderId(gatewaySenderId); + return regionFactory; + } + }); return regionFactory; } @@ -495,24 +446,24 @@ public class MockRegionFactory { return createMockRegionFactory(); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) public Region mockRegion(String name) { - RegionService regionService = mockRegionService(); + regionAttributes = attributesFactory.create(); + + RegionService mockRegionService = mockRegionService(); Region region = mock(Region.class); - when(region.getRegionService()).thenReturn(regionService); - when(region.getAttributes()).thenAnswer(new Answer() { - @Override - public RegionAttributes answer(InvocationOnMock invocation) throws Throwable { - return attributesFactory.create(); + @Override public RegionAttributes answer(InvocationOnMock invocation) throws Throwable { + return regionAttributes; } }); when(region.getFullPath()).thenReturn(name); when(region.getName()).thenReturn(name); + when(region.getRegionService()).thenReturn(mockRegionService); - when(region.getSubregion(anyString())).thenAnswer(new Answer() { + when(region.getSubregion(anyString())).thenAnswer(new Answer() { @Override public Region answer(InvocationOnMock invocation) throws Throwable { Region parent = (Region) invocation.getMock(); @@ -549,7 +500,7 @@ public class MockRegionFactory { } public static RegionService mockRegionService() { - when(regionService.getQueryService()).thenReturn(queryService); + when(regionService.getQueryService()).thenReturn(mockQueryService()); return regionService; } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubCache.java b/src/test/java/org/springframework/data/gemfire/test/StubCache.java index a5570565..ca76a482 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubCache.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubCache.java @@ -63,6 +63,8 @@ import com.gemstone.gemfire.pdx.PdxSerializer; @SuppressWarnings("deprecation") public class StubCache implements Cache { + protected static final String NOT_IMPLEMENTED = "Not Implemented!"; + private Properties properties; private DistributedSystem distributedSystem; @@ -289,8 +291,7 @@ public class StubCache implements Cache { * @see com.gemstone.gemfire.cache.GemFireCache#loadCacheXml(java.io.InputStream) */ @Override - public void loadCacheXml(InputStream is) throws TimeoutException, CacheWriterException, GatewayException, - RegionExistsException { + public void loadCacheXml(InputStream is) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException { } /* (non-Javadoc) @@ -323,7 +324,7 @@ public class StubCache implements Cache { */ @Override public PdxInstance createPdxEnum(String arg0, String arg1, int arg2) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -331,7 +332,7 @@ public class StubCache implements Cache { */ @Override public PdxInstanceFactory createPdxInstanceFactory(String arg0) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -339,7 +340,7 @@ public class StubCache implements Cache { */ @Override public CancelCriterion getCancelCriterion() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -394,7 +395,7 @@ public class StubCache implements Cache { @Override @Deprecated public com.gemstone.gemfire.cache.util.BridgeServer addBridgeServer() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -453,39 +454,19 @@ public class StubCache implements Cache { */ @Override @Deprecated - public Region createRegion(String arg0, RegionAttributes arg1) throws RegionExistsException, - TimeoutException { - // TODO Auto-generated method stub - throw new UnsupportedOperationException(); + public Region createRegion(String arg0, RegionAttributes arg1) throws RegionExistsException, TimeoutException { + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) * @see com.gemstone.gemfire.cache.Cache#createRegionFactory() */ - @SuppressWarnings("unchecked") @Override + @SuppressWarnings("unchecked") public RegionFactory createRegionFactory() { return new MockRegionFactory(this).createRegionFactory(); } - /* (non-Javadoc) - * @see com.gemstone.gemfire.cache.Cache#createRegionFactory(com.gemstone.gemfire.cache.RegionShortcut) - */ - @SuppressWarnings("unchecked") - @Override - public RegionFactory createRegionFactory(RegionShortcut shortCut) { - return new MockRegionFactory(this).createRegionFactory(); - } - - /* (non-Javadoc) - * @see com.gemstone.gemfire.cache.Cache#createRegionFactory(java.lang.String) - */ - @SuppressWarnings("unchecked") - @Override - public RegionFactory createRegionFactory(String arg0) { - return new MockRegionFactory(this).createRegionFactory(); - } - /* (non-Javadoc) * @see com.gemstone.gemfire.cache.Cache#createRegionFactory(com.gemstone.gemfire.cache.RegionAttributes) */ @@ -494,15 +475,31 @@ public class StubCache implements Cache { return new MockRegionFactory(this).createMockRegionFactory(regionAttributes); } + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.Cache#createRegionFactory(com.gemstone.gemfire.cache.RegionShortcut) + */ + @Override + @SuppressWarnings("unchecked") + public RegionFactory createRegionFactory(RegionShortcut shortcut) { + return new MockRegionFactory(this).createRegionFactory(); + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.Cache#createRegionFactory(java.lang.String) + */ + @Override + @SuppressWarnings("unchecked") + public RegionFactory createRegionFactory(String regionAttributesId) { + return new MockRegionFactory(this).createRegionFactory(); + } + /* (non-Javadoc) * @see com.gemstone.gemfire.cache.Cache#createVMRegion(java.lang.String, com.gemstone.gemfire.cache.RegionAttributes) */ @Override @Deprecated - public Region createVMRegion(String arg0, RegionAttributes arg1) throws RegionExistsException, - TimeoutException { - // TODO Auto-generated method stub - throw new UnsupportedOperationException(); + public Region createVMRegion(String arg0, RegionAttributes arg1) throws RegionExistsException, TimeoutException { + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -510,7 +507,7 @@ public class StubCache implements Cache { */ @Override public Set getAdminMembers() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -518,7 +515,7 @@ public class StubCache implements Cache { */ @Override public AsyncEventQueue getAsyncEventQueue(String name) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -526,7 +523,7 @@ public class StubCache implements Cache { */ @Override public Set getAsyncEventQueues() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -535,7 +532,7 @@ public class StubCache implements Cache { @Override @Deprecated public List getBridgeServers() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -543,7 +540,7 @@ public class StubCache implements Cache { */ @Override public List getCacheServers() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -592,7 +589,7 @@ public class StubCache implements Cache { */ @Override public GatewaySender getGatewaySender(String name) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -625,7 +622,7 @@ public class StubCache implements Cache { @Override @Deprecated public LogWriterI18n getLoggerI18n() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -633,7 +630,7 @@ public class StubCache implements Cache { */ @Override public Set getMembers() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -642,7 +639,7 @@ public class StubCache implements Cache { @SuppressWarnings({"rawtypes"}) @Override public Set getMembers(Region arg0) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -667,7 +664,7 @@ public class StubCache implements Cache { @Override @Deprecated public LogWriterI18n getSecurityLoggerI18n() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -675,7 +672,7 @@ public class StubCache implements Cache { */ @Override public CacheSnapshotService getSnapshotService() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -692,7 +689,6 @@ public class StubCache implements Cache { @Override @Deprecated public void readyForEvents() { - // TODO Auto-generated method stub } /* (non-Javadoc) @@ -709,7 +705,7 @@ public class StubCache implements Cache { @Override @Deprecated public GatewayHub setGatewayHub(String arg0, int arg1) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(NOT_IMPLEMENTED); } /* (non-Javadoc) @@ -752,7 +748,7 @@ public class StubCache implements Cache { public void setSearchTimeout(int arg0) { this.searchTimeout = arg0; } - + DistributedSystem mockDistributedSystem() { DistributedSystem ds = mock(DistributedSystem.class); DistributedMember dm = mockDistributedMember(); @@ -765,18 +761,18 @@ public class StubCache implements Cache { when(ds.getDistributedMember()).thenReturn(dm); return ds; } - + DistributedMember mockDistributedMember() { DistributedMember dm = mock(DistributedMember.class); when(dm.getHost()).thenReturn("mockDistributedMember.host"); when(dm.getName()).thenReturn("mockDistributedMember"); return dm; } - + CacheServer mockCacheServer() { return new StubCacheServer(); } - + GatewayHub mockGatewayHub() { final Gateway gw = mock(Gateway.class); final GatewayQueueAttributes queueAttributes= mock(GatewayQueueAttributes.class); @@ -793,7 +789,7 @@ public class StubCache implements Cache { }); return gwh; } - + QueryService mockQueryService() throws RegionNotFoundException, IndexInvalidException, IndexNameConflictException, IndexExistsException, UnsupportedOperationException { QueryService qs = mock(QueryService.class); @@ -857,7 +853,7 @@ public class StubCache implements Cache { return qs; } - + @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) Index mockIndex(String indexName, com.gemstone.gemfire.cache.query.IndexType indexType, String indexedExpression, String fromClause, String imports){ @@ -876,14 +872,14 @@ public class StubCache implements Cache { } return idx; } - + @SuppressWarnings("rawtypes") public Map allRegions() { return this.allRegions; } - + public void setProperties(Properties props) { this.properties = props; } - + } diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml new file mode 100644 index 00000000..abc1859d --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + +