From 6ba90d8048dc4f7f3c170ebe2f45ea2fc2a78083 Mon Sep 17 00:00:00 2001 From: John Blum Date: Sat, 23 May 2015 14:45:42 -0700 Subject: [PATCH] SGF-398 - Provide early support of Apache Geode (Pivotal GemFire OSS). Additional test cleanup related to Pivotal GemFire specific features (e.g. WAN). --- build.gradle | 3 +- .../LookupRegionMutationIntegrationTest.java | 35 +++++-- .../gemfire/config/CacheNamespaceTest.java | 6 ++ .../SubRegionSubElementNamespaceTest.java | 16 ++- .../config/TemplateRegionsNamespaceTests.java | 22 +++-- .../test/GemfireProfileValueSource.java | 21 +++- ...pRegionMutationIntegrationTest-context.xml | 88 ++++++++++++----- .../TemplateRegionsNamespaceTests-context.xml | 98 ++++++++++++------- .../data/gemfire/config/cache-ns.xml | 14 +-- .../gemfire/config/subregionsubelement-ns.xml | 12 ++- 10 files changed, 221 insertions(+), 94 deletions(-) diff --git a/build.gradle b/build.gradle index ee28ab9b..3052fa7c 100644 --- a/build.gradle +++ b/build.gradle @@ -52,9 +52,10 @@ if (project.hasProperty('platformVersion')) { tasks.withType(Test).all { forkEvery = 1 - systemProperties['product.name'] = 'Apache Geode' systemProperties['gemfire.disableShutdownHook'] = 'true' + systemProperties['product.name'] = 'Apache Geode' systemProperties['org.springframework.data.gemfire.test.GemfireTestRunner.nomock'] = System.getProperty('org.springframework.data.gemfire.test.GemfireTestRunner.nomock') + systemProperties['spring.profiles.active'] = 'apache-geode' } // Common dependencies diff --git a/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java index 66be8464..7f28901e 100644 --- a/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest.java @@ -29,6 +29,7 @@ import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanNameAware; +import org.springframework.data.gemfire.test.GemfireProfileValueSource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -96,11 +97,35 @@ public class LookupRegionMutationIntegrationTest { assertEquals(expectedTimeout, expirationAttributes.getTimeout()); } + protected void assertGatewaySenders(Region region, List expectedGatewaySenderIds) { + if (GemfireProfileValueSource.isPivotalGemFire()) { + assertNotNull(region.getAttributes()); + assertNotNull(region.getAttributes().getGatewaySenderIds()); + assertEquals(expectedGatewaySenderIds.size(), region.getAttributes().getGatewaySenderIds().size()); + assertTrue(expectedGatewaySenderIds.containsAll(region.getAttributes().getGatewaySenderIds())); + } + } + protected void assertGemFireComponent(Object gemfireComponent, String expectedName) { assertNotNull("The GemFire component must not be null!", gemfireComponent); assertEquals(expectedName, gemfireComponent.toString()); } + protected void assertRegionAttributes(Region region, String expectedName, DataPolicy expectedDataPolicy) { + assertRegionAttributes(region, expectedName, String.format("%1$s%2$s", Region.SEPARATOR, expectedName), + expectedDataPolicy); + } + + protected void assertRegionAttributes(Region region, String expectedName, String expectedFullPath, + DataPolicy expectedDataPolicy) { + + assertNotNull(String.format("'%1$s' Region was not properly initialized!", region)); + assertEquals(expectedName, region.getName()); + assertEquals(expectedFullPath, region.getFullPath()); + assertNotNull(region.getAttributes()); + assertEquals(expectedDataPolicy, region.getAttributes().getDataPolicy()); + } + protected Collection toStrings(Object[] objects) { List cacheListenerNames = new ArrayList(objects.length); @@ -113,11 +138,7 @@ public class LookupRegionMutationIntegrationTest { @Test public void testRegionConfiguration() { - assertNotNull("'/Example' Region was not properly initialized!", example); - assertEquals("Example", example.getName()); - assertEquals("/Example", example.getFullPath()); - assertNotNull(example.getAttributes()); - assertEquals(DataPolicy.REPLICATE, example.getAttributes().getDataPolicy()); + assertRegionAttributes(example, "Example", DataPolicy.REPLICATE); assertEquals(13, example.getAttributes().getInitialCapacity()); assertEquals(0.85f, example.getAttributes().getLoadFactor(), 0.0f); assertCacheListeners(example.getAttributes().getCacheListeners(), Arrays.asList("A", "B")); @@ -132,12 +153,10 @@ public class LookupRegionMutationIntegrationTest { assertExpirationAttributes(example.getAttributes().getEntryTimeToLive(), "Entry TTL", 30, ExpirationAction.DESTROY); assertGemFireComponent(example.getAttributes().getCustomEntryIdleTimeout(), "E"); - assertNotNull(example.getAttributes().getGatewaySenderIds()); - assertEquals(1, example.getAttributes().getGatewaySenderIds().size()); - assertEquals("GWS", example.getAttributes().getGatewaySenderIds().iterator().next()); assertNotNull(example.getAttributes().getAsyncEventQueueIds()); assertEquals(1, example.getAttributes().getAsyncEventQueueIds().size()); assertEquals("AEQ", example.getAttributes().getAsyncEventQueueIds().iterator().next()); + assertGatewaySenders(example, Arrays.asList("GWS")); } protected static interface Nameable extends BeanNameAware { diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java index f91033bb..a5a9e148 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java @@ -36,7 +36,10 @@ import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.GemfireBeanFactoryLocator; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; +import org.springframework.data.gemfire.test.GemfireProfileValueSource; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.test.annotation.IfProfileValue; +import org.springframework.test.annotation.ProfileValueSourceConfiguration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.ReflectionTestUtils; @@ -51,6 +54,7 @@ import com.gemstone.gemfire.cache.util.TimestampedEntryEvent; * @author John Blum */ @RunWith(SpringJUnit4ClassRunner.class) +@ProfileValueSourceConfiguration(GemfireProfileValueSource.class) @ContextConfiguration(locations = "cache-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) @SuppressWarnings("unused") public class CacheNamespaceTest{ @@ -121,6 +125,8 @@ public class CacheNamespaceTest{ } @Test + @IfProfileValue(name = GemfireProfileValueSource.PRODUCT_NAME_KEY, + value = GemfireProfileValueSource.PIVOTAL_GEMFIRE_PRODUCT_NAME) public void testCacheWithGatewayConflictResolver() { Cache cache = context.getBean("cache-with-gateway-conflict-resolver", Cache.class); diff --git a/src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java index 7f34570f..b6c978d9 100644 --- a/src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java @@ -24,7 +24,12 @@ import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.test.GemfireProfileValueSource; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.test.annotation.IfProfileValue; +import org.springframework.test.annotation.ProfileValueSourceConfiguration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -50,17 +55,18 @@ import com.gemstone.gemfire.cache.util.CacheListenerAdapter; * @since 1.3.3 */ @RunWith(SpringJUnit4ClassRunner.class) +@ProfileValueSourceConfiguration(GemfireProfileValueSource.class) @ContextConfiguration(locations = "subregionsubelement-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) @SuppressWarnings("unused") public class SubRegionSubElementNamespaceTest { + @Autowired + private ApplicationContext applicationContext; + @Resource(name = "/Customers/Accounts") private Region customersAccountsRegion; - @Resource(name = "/Orders/Items") - private Region orderItemsRegion; - @Resource(name = "/Parent/Child") private Region parentChildRegion; @@ -81,7 +87,11 @@ public class SubRegionSubElementNamespaceTest { } @Test + @IfProfileValue(name = GemfireProfileValueSource.PRODUCT_NAME_KEY, + value = GemfireProfileValueSource.PIVOTAL_GEMFIRE_PRODUCT_NAME) public void testOrderItemsSubRegionGatewaySender() { + Region orderItemsRegion = applicationContext.getBean("/Orders/Items", Region.class); + assertNotNull(orderItemsRegion); assertNotNull(orderItemsRegion.getAttributes()); assertNotNull(orderItemsRegion.getAttributes().getGatewaySenderIds()); diff --git a/src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java b/src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java index 3a0282db..bfde037c 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java @@ -35,6 +35,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanIsAbstractException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.test.GemfireProfileValueSource; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -180,14 +181,13 @@ public class TemplateRegionsNamespaceTests { assertEquals(expectedTimeout, expirationAttributes.getTimeout()); } - protected void assertGatewaySenders(final Region region, final String... gatewaySenderNames) { - assertNotNull(region); - assertNotNull(region.getAttributes()); - assertNotNull(region.getAttributes().getGatewaySenderIds()); - assertEquals(gatewaySenderNames.length, region.getAttributes().getGatewaySenderIds().size()); - - for (String gatewaySenderId : region.getAttributes().getGatewaySenderIds()) { - assertTrue(Arrays.asList(gatewaySenderNames).contains(gatewaySenderId)); + protected void assertGatewaySenders(final Region region, final String... gatewaySenderIds) { + if (GemfireProfileValueSource.isPivotalGemFire()) { + assertNotNull(region); + assertNotNull(region.getAttributes()); + assertNotNull(region.getAttributes().getGatewaySenderIds()); + assertEquals(gatewaySenderIds.length, region.getAttributes().getGatewaySenderIds().size()); + assertTrue(Arrays.asList(gatewaySenderIds).containsAll(region.getAttributes().getGatewaySenderIds())); } } @@ -447,11 +447,13 @@ public class TemplateRegionsNamespaceTests { assertEquals(String.class, templateBasedReplicateRegionNoOverrides.getAttributes().getKeyConstraint()); assertEquals(0.85f, templateBasedReplicateRegionNoOverrides.getAttributes().getLoadFactor(), 0.0f); assertFalse(templateBasedReplicateRegionNoOverrides.getAttributes().isLockGrantor()); - assertDefaultMembershipAttributes(templateBasedReplicateRegionNoOverrides.getAttributes().getMembershipAttributes()); + assertDefaultMembershipAttributes( + templateBasedReplicateRegionNoOverrides.getAttributes().getMembershipAttributes()); assertNull(templateBasedReplicateRegionNoOverrides.getAttributes().getPartitionAttributes()); assertEquals(Scope.DISTRIBUTED_ACK, templateBasedReplicateRegionNoOverrides.getAttributes().getScope()); assertTrue(templateBasedReplicateRegionNoOverrides.getAttributes().getStatisticsEnabled()); - assertSubscriptionAttributes(templateBasedReplicateRegionNoOverrides.getAttributes().getSubscriptionAttributes(), + assertSubscriptionAttributes( + templateBasedReplicateRegionNoOverrides.getAttributes().getSubscriptionAttributes(), InterestPolicy.CACHE_CONTENT); assertEquals(Object.class, templateBasedReplicateRegionNoOverrides.getAttributes().getValueConstraint()); } diff --git a/src/test/java/org/springframework/data/gemfire/test/GemfireProfileValueSource.java b/src/test/java/org/springframework/data/gemfire/test/GemfireProfileValueSource.java index 3be08236..432001b4 100644 --- a/src/test/java/org/springframework/data/gemfire/test/GemfireProfileValueSource.java +++ b/src/test/java/org/springframework/data/gemfire/test/GemfireProfileValueSource.java @@ -16,6 +16,7 @@ package org.springframework.data.gemfire.test; +import java.util.Collections; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -37,15 +38,29 @@ public class GemfireProfileValueSource implements ProfileValueSource { public static final String PIVOTAL_GEMFIRE_PRODUCT_NAME = "Pivotal GemFire"; public static final String PRODUCT_NAME_KEY = "product.name"; - private static final Map PROFILE_VALUES = new ConcurrentHashMap(); + public static final Map PROFILE_VALUES; static { - PROFILE_VALUES.put(PRODUCT_NAME_KEY, System.getProperty(PRODUCT_NAME_KEY, GemfireUtils.GEMFIRE_NAME)); + Map profileValues = new ConcurrentHashMap(1); + profileValues.put(PRODUCT_NAME_KEY, System.getProperty(PRODUCT_NAME_KEY, GemfireUtils.GEMFIRE_NAME)); + PROFILE_VALUES = Collections.unmodifiableMap(profileValues); + } + + public static boolean isApacheGeode() { + return APACHE_GEODE_PRODUCT_NAME.equals(getProfileValue(PRODUCT_NAME_KEY)); + } + + public static boolean isPivotalGemFire() { + return PIVOTAL_GEMFIRE_PRODUCT_NAME.equals(getProfileValue(PRODUCT_NAME_KEY)); + } + + public static String getProfileValue(final String profileKey) { + return PROFILE_VALUES.get(profileKey); } @Override public String get(final String key) { - return PROFILE_VALUES.get(key); + return getProfileValue(key); } } diff --git a/src/test/resources/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest-context.xml b/src/test/resources/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest-context.xml index 5a7076d7..b815113e 100644 --- a/src/test/resources/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/LookupRegionMutationIntegrationTest-context.xml @@ -20,29 +20,69 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests-context.xml b/src/test/resources/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests-context.xml index 158f31c1..77785f68 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests-context.xml @@ -25,9 +25,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -133,4 +99,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/cache-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/cache-ns.xml index 5f4a8173..ba309a7a 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/cache-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/cache-ns.xml @@ -23,12 +23,6 @@ - - - - - - @@ -45,4 +39,12 @@ + + + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/subregionsubelement-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/subregionsubelement-ns.xml index 926cf659..21172970 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/subregionsubelement-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/subregionsubelement-ns.xml @@ -36,11 +36,13 @@ - - - + + + + + - +