From ea0e9931d342d2b69b167cd48036e83d25c2113b Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 23 Jan 2020 22:12:13 -0800 Subject: [PATCH] Remove use of internal Apache Geode APIs. Resolves gh-48. --- .../data/gemfire/support/GemFireUtils.java | 22 ++++++++++--------- .../gemfire/support/GemFireUtilsTests.java | 17 ++++++++++++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/spring-session-data-geode/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java b/spring-session-data-geode/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java index 77374a4..562f17f 100644 --- a/spring-session-data-geode/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java +++ b/spring-session-data-geode/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java @@ -25,12 +25,11 @@ import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.apache.geode.internal.cache.AbstractRegion; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.springframework.data.gemfire.util.CacheUtils; import org.springframework.lang.Nullable; +import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; /** @@ -76,12 +75,7 @@ public abstract class GemFireUtils { * @see org.apache.geode.cache.GemFireCache */ public static boolean isClient(@Nullable GemFireCache gemfireCache) { - - boolean client = gemfireCache instanceof ClientCache; - - client &= (!(gemfireCache instanceof GemFireCacheImpl) || ((GemFireCacheImpl) gemfireCache).isClient()); - - return client; + return CacheUtils.isClient(gemfireCache); } /** @@ -142,7 +136,15 @@ public abstract class GemFireUtils { } private static boolean hasServerProxy(@Nullable Region region) { - return region instanceof AbstractRegion && ((AbstractRegion) region).hasServerProxy(); + + //return region instanceof AbstractRegion && ((AbstractRegion) region).hasServerProxy(); + + return Optional.ofNullable(region) + .map(Object::getClass) + .map(regionType -> ReflectionUtils.findMethod(regionType, "hasServerProxy")) + .map(hasServerProxyMethod -> ReflectionUtils.invokeMethod(hasServerProxyMethod, region)) + .map(Boolean.TRUE::equals) + .orElse(false); } /** diff --git a/spring-session-data-geode/src/test/java/org/springframework/session/data/gemfire/support/GemFireUtilsTests.java b/spring-session-data-geode/src/test/java/org/springframework/session/data/gemfire/support/GemFireUtilsTests.java index 60086fa..1748be0 100644 --- a/spring-session-data-geode/src/test/java/org/springframework/session/data/gemfire/support/GemFireUtilsTests.java +++ b/spring-session-data-geode/src/test/java/org/springframework/session/data/gemfire/support/GemFireUtilsTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.session.data.gemfire.support; import static org.assertj.core.api.Assertions.assertThat; @@ -42,10 +41,11 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.internal.cache.AbstractRegion; /** - * Unit tests for {@link GemFireUtils}. + * Unit Tests for {@link GemFireUtils}. * * @author John Blum * @see org.junit.Test + * @see org.mockito.Mock * @see org.mockito.Mockito * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.GemFireCache @@ -153,6 +153,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void clientRegionWithPoolIsNonLocalClientRegion() { ClientCache mockClientCache = mock(ClientCache.class); @@ -173,6 +174,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void clientRegionWithServerProxyIsNonLocalClientRegion() { ClientCache mockClientCache = mock(ClientCache.class); @@ -195,6 +197,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void clientRegionWithNoPoolAndNoServerProxyIsNotNonLocalClientRegion() { ClientCache mockClientCache = mock(ClientCache.class); @@ -217,6 +220,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void nonClientRegionWithPoolIsNotNonLocalClientRegion() { GemFireCache mockGemFireCache = mock(GemFireCache.class); @@ -237,6 +241,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void peerRegionWithServerProxyIsNotNonLocalClientRegion() { Cache mockPeerCache = mock(Cache.class); @@ -258,6 +263,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void emptyRegionIsProxy() { Region mockRegion = mock(Region.class); @@ -274,6 +280,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void partitionRegionWithNoLocalMaxMemoryIsProxy() { Region mockRegion = mock(Region.class); @@ -296,6 +303,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void partitionRegionWithNegativeLocalMaxMemoryIsProxy() { Region mockRegion = mock(Region.class); @@ -318,6 +326,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void normalRegionIsNotProxy() { Region mockRegion = mock(Region.class); @@ -334,6 +343,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void partitionRegionWithLocalMaxMemoryIsNotProxy() { Region mockRegion = mock(Region.class); @@ -356,6 +366,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void partitionRegionWithNoPartitionAttributesIsNotProxy() { Region mockRegion = mock(Region.class); @@ -374,6 +385,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void preloadedRegionIsNotProxy() { Region mockRegion = mock(Region.class); @@ -390,6 +402,7 @@ public class GemFireUtilsTests { } @Test + @SuppressWarnings("rawtypes") public void replicateRegionIsNotProxy() { Region mockRegion = mock(Region.class);