SGF-398 - Provide early support of Apache Geode (Pivotal GemFire OSS).
Additional test cleanup related to Pivotal GemFire specific features (e.g. WAN).
This commit is contained in:
@@ -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<String> 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<String> toStrings(Object[] objects) {
|
||||
List<String> cacheListenerNames = new ArrayList<String>(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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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<String, String> PROFILE_VALUES = new ConcurrentHashMap<String, String>();
|
||||
public static final Map<String, String> PROFILE_VALUES;
|
||||
|
||||
static {
|
||||
PROFILE_VALUES.put(PRODUCT_NAME_KEY, System.getProperty(PRODUCT_NAME_KEY, GemfireUtils.GEMFIRE_NAME));
|
||||
Map<String, String> profileValues = new ConcurrentHashMap<String, String>(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user