From fb46e560f431b2460dce0eaaf74884074ed13d7a Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 23 Apr 2015 17:08:04 -0700 Subject: [PATCH] SGF-196 - Support adding CacheListeners, CacheLoaders and CacheWriters, along with other mutable Region attributes to an existing Region. Adding additional test cases and test case refinements. --- .../gemfire/LookupRegionFactoryBeanTest.java | 11 +++++++ .../LookupRegionMutationIntegrationTest.java | 30 +++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/springframework/data/gemfire/LookupRegionFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/LookupRegionFactoryBeanTest.java index d5ae12a7..e222727c 100644 --- a/src/test/java/org/springframework/data/gemfire/LookupRegionFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/LookupRegionFactoryBeanTest.java @@ -206,4 +206,15 @@ public class LookupRegionFactoryBeanTest { } } + @Test + public void testIsLookupEnabledAlways() { + LookupRegionFactoryBean factoryBean = new LookupRegionFactoryBean(); + + assertTrue(factoryBean.isLookupEnabled()); + + factoryBean.setLookupEnabled(false); + + assertTrue(factoryBean.isLookupEnabled()); + } + } diff --git a/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java index 487d00a1..66be8464 100644 --- a/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java @@ -40,6 +40,9 @@ import com.gemstone.gemfire.cache.CacheWriterException; import com.gemstone.gemfire.cache.CustomExpiry; import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.EntryEvent; +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.ExpirationAttributes; import com.gemstone.gemfire.cache.LoaderHelper; @@ -71,9 +74,19 @@ public class LookupRegionMutationIntegrationTest { @Resource(name = "Example") private Region example; - protected void assertGemFireComponent(Object gemfireComponent, String expectedName) { - assertNotNull("The GemFire component must not be null!", gemfireComponent); - assertEquals(expectedName, gemfireComponent.toString()); + protected void assertCacheListeners(CacheListener[] cacheListeners, Collection expectedCacheListenerNames) { + if (!expectedCacheListenerNames.isEmpty()) { + assertNotNull("CacheListeners must not be null!", cacheListeners); + assertEquals(expectedCacheListenerNames.size(), cacheListeners.length); + assertTrue(toStrings(cacheListeners).containsAll(expectedCacheListenerNames)); + } + } + + protected void assertEvictionAttributes(EvictionAttributes evictionAttributes, EvictionAction expectedAction, EvictionAlgorithm expectedAlgorithm, int expectedMaximum) { + assertNotNull("EvictionAttributes must not be null!", evictionAttributes); + assertEquals(expectedAction, evictionAttributes.getAction()); + assertEquals(expectedAlgorithm, evictionAttributes.getAlgorithm()); + assertEquals(expectedMaximum, evictionAttributes.getMaximum()); } protected void assertExpirationAttributes(ExpirationAttributes expirationAttributes, @@ -83,12 +96,9 @@ public class LookupRegionMutationIntegrationTest { assertEquals(expectedTimeout, expirationAttributes.getTimeout()); } - protected void assertCacheListeners(CacheListener[] cacheListeners, Collection expectedCacheListenerNames) { - if (!expectedCacheListenerNames.isEmpty()) { - assertNotNull("CacheListeners must not be null!", cacheListeners); - assertEquals(expectedCacheListenerNames.size(), cacheListeners.length); - assertTrue(toStrings(cacheListeners).containsAll(expectedCacheListenerNames)); - } + protected void assertGemFireComponent(Object gemfireComponent, String expectedName) { + assertNotNull("The GemFire component must not be null!", gemfireComponent); + assertEquals(expectedName, gemfireComponent.toString()); } protected Collection toStrings(Object[] objects) { @@ -113,6 +123,8 @@ public class LookupRegionMutationIntegrationTest { assertCacheListeners(example.getAttributes().getCacheListeners(), Arrays.asList("A", "B")); assertGemFireComponent(example.getAttributes().getCacheLoader(), "C"); assertGemFireComponent(example.getAttributes().getCacheWriter(), "D"); + assertEvictionAttributes(example.getAttributes().getEvictionAttributes(), EvictionAction.OVERFLOW_TO_DISK, + EvictionAlgorithm.LRU_ENTRY, 1000); assertExpirationAttributes(example.getAttributes().getRegionTimeToLive(), "Region TTL", 120, ExpirationAction.LOCAL_DESTROY); assertExpirationAttributes(example.getAttributes().getRegionIdleTimeout(), "Region TTI",