diff --git a/gradle.properties b/gradle.properties index fd0c89e8..285ed81c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ slf4jVersion = 1.6.4 # Common libraries springVersion = 3.1.2.RELEASE -springDataCommonsVersion = 1.4.0.RC1 +springDataCommonsVersion = 1.4.0.RELEASE gemfireVersion = 6.6.3 gemfireVersion6x = 6.6.3 @@ -20,7 +20,7 @@ cglibVersion = 2.2 ## OSGi ranges spring.range = "[3.0.0, 4.0.0)" -gemfire.range = "[6.5, 7.0)" +gemfire.range = "[6.5, 8.0)" # -------------------- # Project wide version diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java index e9d5441d..86b168d0 100644 --- a/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java @@ -20,7 +20,9 @@ import java.net.InetSocketAddress; import java.util.List; import java.util.Properties; +import org.springframework.beans.factory.BeanInitializationException; import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.config.GemfireConstants; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -33,7 +35,8 @@ import com.gemstone.gemfire.pdx.PdxSerializer; /** * FactoryBean dedicated to creating client caches (caches for client JVMs). - * Acts an utility class (as client caches are a subset with a particular configuration of the generic cache). + * Acts an utility class (as client caches are a subset with a particular + * configuration of the generic cache). * * @author Costin Leau */ @@ -54,7 +57,8 @@ public class ClientCacheFactoryBean extends CacheFactoryBean { public void run() { if (pdxSerializer != null) { - Assert.isAssignable(PdxSerializer.class, pdxSerializer.getClass(), "Invalid pdx serializer used"); + Assert.isAssignable(PdxSerializer.class, + pdxSerializer.getClass(), "Invalid pdx serializer used"); factory.setPdxSerializer((PdxSerializer) pdxSerializer); } if (pdxDiskStoreName != null) { @@ -95,10 +99,12 @@ public class ClientCacheFactoryBean extends CacheFactoryBean { private void initializePool(ClientCacheFactory ccf) { Pool p = pool; - if (p == null && StringUtils.hasText(poolName)) { - p = PoolManager.find(poolName); - - // initialize a client-like Distributed System before initializing the pool + if (p == null) { + if (StringUtils.hasText(poolName)) { + p = PoolManager.find(poolName); + } + // initialize a client-like Distributed System before initializing + // the pool if (p == null) { Properties prop = mergeProperties(); prop.setProperty("mcast-port", "0"); @@ -107,16 +113,32 @@ public class ClientCacheFactoryBean extends CacheFactoryBean { DistributedSystem system = DistributedSystem.connect(prop); } - // trigger pool initialization - Assert.isTrue(getBeanFactory().isTypeMatch(poolName, Pool.class), "No bean named " + poolName + " of type " - + Pool.class.getName() + " found"); + if (StringUtils.hasText(poolName)) { + try { - p = getBeanFactory().getBean(poolName, Pool.class); - Assert.notNull(p, "No pool named [" + poolName + "] found"); + getBeanFactory().isTypeMatch(poolName, Pool.class); + } catch (Exception e) { + String msg = "No bean found with name " + poolName + + " of type " + Pool.class.getName(); + if (poolName + .equals(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME)) { + msg += ". A client cache requires a pool"; + } + throw new BeanInitializationException(msg); + } + p = getBeanFactory().getBean(poolName, Pool.class); + } else { + if (log.isDebugEnabled()) { + log.debug("Checking for a unique pool"); + } + p = getBeanFactory().getBean(Pool.class); + this.poolName = p.getName(); + } } if (p != null) { - // copy the pool settings - this way if the pool is not found, at least the cache will have a similar config + // copy the pool settings - this way if the pool is not found, at + // least the cache will have a similar config ccf.setPoolFreeConnectionTimeout(p.getFreeConnectionTimeout()); ccf.setPoolIdleTimeout(p.getIdleTimeout()); ccf.setPoolLoadConditioningInterval(p.getLoadConditioningInterval()); @@ -132,7 +154,8 @@ public class ClientCacheFactoryBean extends CacheFactoryBean { ccf.setPoolStatisticInterval(p.getStatisticInterval()); ccf.setPoolSubscriptionAckInterval(p.getSubscriptionAckInterval()); ccf.setPoolSubscriptionEnabled(p.getSubscriptionEnabled()); - ccf.setPoolSubscriptionMessageTrackingTimeout(p.getSubscriptionMessageTrackingTimeout()); + ccf.setPoolSubscriptionMessageTrackingTimeout(p + .getSubscriptionMessageTrackingTimeout()); ccf.setPoolSubscriptionRedundancy(p.getSubscriptionRedundancy()); ccf.setPoolThreadLocalConnections(p.getThreadLocalConnections()); @@ -143,7 +166,6 @@ public class ClientCacheFactoryBean extends CacheFactoryBean { } } - List servers = p.getServers(); if (locators != null) { for (InetSocketAddress inet : servers) { diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java index a0564e18..ca1b91da 100644 --- a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java @@ -173,6 +173,9 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } factory.setPoolName(poolName); + } else { + Pool pool = beanFactory.getBean(Pool.class); + factory.setPoolName(pool.getName()); } if (diskStoreName != null) { diff --git a/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java index 4b296192..1e1167ec 100644 --- a/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java @@ -20,7 +20,6 @@ import java.util.Collection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanNameAware; @@ -38,10 +37,11 @@ import com.gemstone.gemfire.cache.client.PoolManager; import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; /** - * Factory bean for easy declaration and configuration of a GemFire pool. - * If a new pool is created, its life-cycle is bound to that of the declaring container. + * Factory bean for easy declaration and configuration of a GemFire pool. If a + * new pool is created, its life-cycle is bound to that of the declaring + * container. * - * Note that if the pool already exists, it will be returned as is, without any + * Note that if the pool already exists, it will be returned as is, without any * modifications and its life cycle untouched by this factory. * * @see PoolManager @@ -50,8 +50,8 @@ import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; * * @author Costin Leau */ -public class PoolFactoryBean implements FactoryBean, InitializingBean, DisposableBean, BeanNameAware, - BeanClassLoaderAware, BeanFactoryAware { +public class PoolFactoryBean implements FactoryBean, InitializingBean, + DisposableBean, BeanNameAware, BeanFactoryAware { private static final Log log = LogFactory.getLog(PoolFactoryBean.class); @@ -66,7 +66,6 @@ public class PoolFactoryBean implements FactoryBean, InitializingBean, Dis private Collection locators; private Collection servers; - private ClassLoader classLoader = getClass().getClassLoader(); private BeanFactory beanFactory; private boolean keepAlive = false; @@ -120,14 +119,17 @@ public class PoolFactoryBean implements FactoryBean, InitializingBean, Dis pool = existingPool; internalPool = false; if (log.isDebugEnabled()) - log.debug("Pool '" + name + " already exists; using found instance..."); - } - else { + log.debug("Pool '" + name + + " already exists; using found instance..."); + } else { if (log.isDebugEnabled()) - log.debug("No pool named '" + name + "' found. Creating a new once..."); + log.debug("No pool named '" + name + + "' found. Creating a new once..."); - if (CollectionUtils.isEmpty(locators) && CollectionUtils.isEmpty(servers)) { - throw new IllegalArgumentException("at least one locator or server is required"); + if (CollectionUtils.isEmpty(locators) + && CollectionUtils.isEmpty(servers)) { + throw new IllegalArgumentException( + "at least one locator or server is required"); } internalPool = true; @@ -136,13 +138,15 @@ public class PoolFactoryBean implements FactoryBean, InitializingBean, Dis if (!CollectionUtils.isEmpty(locators)) { for (PoolConnection connection : locators) { - poolFactory.addLocator(connection.getHost(), connection.getPort()); + poolFactory.addLocator(connection.getHost(), + connection.getPort()); } } if (!CollectionUtils.isEmpty(servers)) { for (PoolConnection connection : servers) { - poolFactory.addServer(connection.getHost(), connection.getPort()); + poolFactory.addServer(connection.getHost(), + connection.getPort()); } } @@ -161,7 +165,8 @@ public class PoolFactoryBean implements FactoryBean, InitializingBean, Dis poolFactory.setStatisticInterval(statisticInterval); poolFactory.setSubscriptionEnabled(subscriptionEnabled); poolFactory.setSubscriptionAckInterval(subscriptionAckInterval); - poolFactory.setSubscriptionMessageTrackingTimeout(subscriptionMessageTrackingTimeout); + poolFactory + .setSubscriptionMessageTrackingTimeout(subscriptionMessageTrackingTimeout); poolFactory.setSubscriptionRedundancy(subscriptionRedundancy); poolFactory.setThreadLocalConnections(threadLocalConnections); @@ -185,169 +190,189 @@ public class PoolFactoryBean implements FactoryBean, InitializingBean, Dis } /** - * @param pool the pool to set + * @param pool + * the pool to set */ public void setPool(Pool pool) { this.pool = pool; } /** - * @param name the name to set + * @param name + * the name to set */ public void setName(String name) { this.name = name; } /** - * @param locators the locators to set + * @param locators + * the locators to set */ public void setLocators(Collection locators) { this.locators = locators; } /** - * @param servers the servers to set + * @param servers + * the servers to set */ public void setServers(Collection servers) { this.servers = servers; } /** - * @param keepAlive the keepAlive to set + * @param keepAlive + * the keepAlive to set */ public void setKeepAlive(boolean keepAlive) { this.keepAlive = keepAlive; } /** - * @param freeConnectionTimeout the freeConnectionTimeout to set + * @param freeConnectionTimeout + * the freeConnectionTimeout to set */ public void setFreeConnectionTimeout(int freeConnectionTimeout) { this.freeConnectionTimeout = freeConnectionTimeout; } /** - * @param idleTimeout the idleTimeout to set + * @param idleTimeout + * the idleTimeout to set */ public void setIdleTimeout(long idleTimeout) { this.idleTimeout = idleTimeout; } /** - * @param loadConditioningInterval the loadConditioningInterval to set + * @param loadConditioningInterval + * the loadConditioningInterval to set */ public void setLoadConditioningInterval(int loadConditioningInterval) { this.loadConditioningInterval = loadConditioningInterval; } /** - * @param maxConnections the maxConnections to set + * @param maxConnections + * the maxConnections to set */ public void setMaxConnections(int maxConnections) { this.maxConnections = maxConnections; } /** - * @param minConnections the minConnections to set + * @param minConnections + * the minConnections to set */ public void setMinConnections(int minConnections) { this.minConnections = minConnections; } /** - * @param pingInterval the pingInterval to set + * @param pingInterval + * the pingInterval to set */ public void setPingInterval(long pingInterval) { this.pingInterval = pingInterval; } /** - * @param readTimeout the readTimeout to set + * @param readTimeout + * the readTimeout to set */ public void setReadTimeout(int readTimeout) { this.readTimeout = readTimeout; } /** - * @param retryAttempts the retryAttempts to set + * @param retryAttempts + * the retryAttempts to set */ public void setRetryAttempts(int retryAttempts) { this.retryAttempts = retryAttempts; } /** - * @param serverGroup the serverGroup to set + * @param serverGroup + * the serverGroup to set */ public void setServerGroup(String serverGroup) { this.serverGroup = serverGroup; } /** - * @param socketBufferSize the socketBufferSize to set + * @param socketBufferSize + * the socketBufferSize to set */ public void setSocketBufferSize(int socketBufferSize) { this.socketBufferSize = socketBufferSize; } /** - * @param statisticInterval the statisticInterval to set + * @param statisticInterval + * the statisticInterval to set */ public void setStatisticInterval(int statisticInterval) { this.statisticInterval = statisticInterval; } /** - * @param subscriptionAckInterval the subscriptionAckInterval to set + * @param subscriptionAckInterval + * the subscriptionAckInterval to set */ public void setSubscriptionAckInterval(int subscriptionAckInterval) { this.subscriptionAckInterval = subscriptionAckInterval; } /** - * @param subscriptionEnabled the subscriptionEnabled to set + * @param subscriptionEnabled + * the subscriptionEnabled to set */ public void setSubscriptionEnabled(boolean subscriptionEnabled) { this.subscriptionEnabled = subscriptionEnabled; } /** - * @param subscriptionMessageTrackingTimeout the subscriptionMessageTrackingTimeout to set + * @param subscriptionMessageTrackingTimeout + * the subscriptionMessageTrackingTimeout to set */ - public void setSubscriptionMessageTrackingTimeout(int subscriptionMessageTrackingTimeout) { + public void setSubscriptionMessageTrackingTimeout( + int subscriptionMessageTrackingTimeout) { this.subscriptionMessageTrackingTimeout = subscriptionMessageTrackingTimeout; } /** - * @param subscriptionRedundancy the subscriptionRedundancy to set + * @param subscriptionRedundancy + * the subscriptionRedundancy to set */ public void setSubscriptionRedundancy(int subscriptionRedundancy) { this.subscriptionRedundancy = subscriptionRedundancy; } /** - * @param threadLocalConnections the threadLocalConnections to set + * @param threadLocalConnections + * the threadLocalConnections to set */ public void setThreadLocalConnections(boolean threadLocalConnections) { this.threadLocalConnections = threadLocalConnections; } - public void setBeanClassLoader(ClassLoader classLoader) { - this.classLoader = classLoader; - } - public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; } /** - * @param multiUserAuthentication the multiUserAuthentication to set + * @param multiUserAuthentication + * the multiUserAuthentication to set */ public void setMultiUserAuthentication(boolean multiUserAuthentication) { this.multiUserAuthentication = multiUserAuthentication; } /** - * @param prSingleHopEnabled the prSingleHopEnabled to set + * @param prSingleHopEnabled + * the prSingleHopEnabled to set */ public void setPrSingleHopEnabled(boolean prSingleHopEnabled) { this.prSingleHopEnabled = prSingleHopEnabled; diff --git a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java index 9c665aaf..6fa61600 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java @@ -97,7 +97,7 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { if (!subRegion) { String cacheRef = element.getAttribute("cache-ref"); // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(cacheRef) ? cacheRef : "gemfireCache")); + builder.addPropertyReference("cache", (StringUtils.hasText(cacheRef) ? cacheRef : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); } // add attributes ParsingUtils.setPropertyValue(element, builder, "name"); diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java b/src/main/java/org/springframework/data/gemfire/config/CacheParser.java index 88d541c1..e171102f 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/CacheParser.java @@ -180,9 +180,9 @@ class CacheParser extends AbstractSimpleBeanDefinitionParser { throws BeanDefinitionStoreException { String name = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(name)) { - name = "gemfireCache"; + name = GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME; //For backward compatibility - parserContext.getRegistry().registerAlias("gemfireCache", "gemfire-cache"); + parserContext.getRegistry().registerAlias(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME, "gemfire-cache"); } return name; } diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java b/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java index cadd4114..3a0fb8cb 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java @@ -60,7 +60,7 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { String attr = element.getAttribute("cache-ref"); // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfireCache")); + builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); attr = element.getAttribute("groups"); if (StringUtils.hasText(attr)) { diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java b/src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java index c38ec67c..b9339092 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java @@ -19,7 +19,6 @@ package org.springframework.data.gemfire.config; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.util.StringUtils; import org.w3c.dom.Element; /** @@ -38,15 +37,12 @@ class ClientCacheParser extends CacheParser { @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); - - ParsingUtils.setPropertyValue(element, builder, "pool-name", "poolName"); + ParsingUtils.setPropertyValue(element, builder, "pool-name"); } @Override protected void postProcessDynamicRegionSupport(Element element, BeanDefinitionBuilder dynamicRegionSupport) { - String poolName = element.getAttribute("pool-name"); - if (StringUtils.hasText(poolName)) { - dynamicRegionSupport.addPropertyValue("poolName", poolName); - } + ParsingUtils.setPropertyValue(element, dynamicRegionSupport, "pool-name"); + } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java index 125751ec..216da1bb 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java @@ -73,7 +73,7 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { attr = element.getAttribute("cache-ref"); // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfireCache")); + builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); // eviction + overflow attributes // client attributes diff --git a/src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java b/src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java index 78a346a2..f3bff546 100644 --- a/src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java @@ -53,7 +53,7 @@ class FunctionServiceParser extends AbstractSimpleBeanDefinitionParser { throws BeanDefinitionStoreException { String name = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(name)) { - name = "gemfireFunctionService"; + name = GemfireConstants.DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME; } return name; } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java b/src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java new file mode 100644 index 00000000..f9e087fa --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java @@ -0,0 +1,26 @@ +/* Copyright 2010-2012 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; +/** + * + * @author David Turanski + * + */ +public interface GemfireConstants { + static final String DEFAULT_GEMFIRE_POOL_NAME = "gemfirePool"; + static final String DEFAULT_GEMFIRE_CACHE_NAME = "gemfireCache"; + static final String DEFAULT_GEMFIRE_TXMANAGER_NAME = "gemfireTransactionManager"; + static final String DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME = "gemfireFunctionService"; +} diff --git a/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java index 921feaa8..b3dffdbc 100644 --- a/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java @@ -43,7 +43,7 @@ class LookupRegionParser extends AbstractRegionParser { if (!subRegion) { String attr = element.getAttribute("cache-ref"); // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfireCache")); + builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); } else { builder.addPropertyValue("lookupOnly", true); diff --git a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java index 72e24f41..f44a5e22 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java @@ -53,13 +53,25 @@ abstract class ParsingUtils { private static final String ALIASES_KEY = ParsingUtils.class.getName() + ":aliases"; + + static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName, - String propertyName) { + String propertyName, Object defaultValue) { String attr = element.getAttribute(attributeName); if (StringUtils.hasText(attr)) { builder.addPropertyValue(propertyName, attr); + } else { + if (defaultValue != null) { + builder.addPropertyValue(propertyName, defaultValue); + } } } + + static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName, + String propertyName) { + setPropertyValue(element, builder, attributeName, propertyName,null); + } + static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName) { setPropertyValue(element, builder, attributeName, Conventions.attributeNameToPropertyName(attributeName)); diff --git a/src/main/java/org/springframework/data/gemfire/config/PoolParser.java b/src/main/java/org/springframework/data/gemfire/config/PoolParser.java index ae54453b..bfa83e42 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PoolParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/PoolParser.java @@ -88,9 +88,9 @@ class PoolParser extends AbstractSimpleBeanDefinitionParser { throws BeanDefinitionStoreException { String name = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(name)) { - name = "gemfirePool"; + name = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME; //For backward compatibility - parserContext.getRegistry().registerAlias("gemfirePool", "gemfire-pool"); + parserContext.getRegistry().registerAlias(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME, "gemfire-pool"); } return name; } diff --git a/src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java b/src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java index 788ff03f..f767976e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java @@ -45,7 +45,7 @@ class TransactionManagerParser extends AbstractSingleBeanDefinitionParser { String attr = element.getAttribute("cache-ref"); // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfireCache")); + builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); } @@ -54,9 +54,9 @@ class TransactionManagerParser extends AbstractSingleBeanDefinitionParser { throws BeanDefinitionStoreException { String name = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(name)) { - name = "gemfireTransactionManager"; + name = GemfireConstants.DEFAULT_GEMFIRE_TXMANAGER_NAME; //For backward compatibility - parserContext.getRegistry().registerAlias("gemfireTransactionManager", "gemfire-transaction-manager"); + parserContext.getRegistry().registerAlias(GemfireConstants.DEFAULT_GEMFIRE_TXMANAGER_NAME, "gemfire-transaction-manager"); } return name; } diff --git a/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java b/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java index 42270477..d3979812 100644 --- a/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java @@ -1,15 +1,29 @@ package org.springframework.data.gemfire.client; +import static org.junit.Assert.*; + +import javax.annotation.Resource; + import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.client.ClientCache; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("client-cache.xml") public class ClientCacheTest { + @Resource(name="challengeQuestionsRegion") + Region region; + + @Autowired + ClientCache cache; + @Test public void test() { - + assertEquals("gemfirePool",region.getAttributes().getPoolName()); } } diff --git a/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java index 5c69a6b6..28f997e4 100644 --- a/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java @@ -4,11 +4,13 @@ import static org.junit.Assert.assertSame; import org.junit.Test; import org.mockito.Mockito; +import org.springframework.beans.factory.BeanFactory; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.client.ClientCache; import com.gemstone.gemfire.cache.client.ClientRegionFactory; import com.gemstone.gemfire.cache.client.ClientRegionShortcut; +import com.gemstone.gemfire.cache.client.Pool; public class ClientRegionFactoryBeanTest { @@ -17,6 +19,14 @@ public class ClientRegionFactoryBeanTest { throws Exception { ClientRegionFactoryBean fb = new ClientRegionFactoryBean(); fb.setShortcut(ClientRegionShortcut.CACHING_PROXY); + + Pool pool = Mockito.mock(Pool.class); + + BeanFactory beanFactory = Mockito.mock(BeanFactory.class); + + Mockito.when(beanFactory.getBean(Pool.class)).thenReturn(pool); + + fb.setBeanFactory(beanFactory); String regionName = "regionName"; ClientCache cache = Mockito.mock(ClientCache.class); @@ -36,5 +46,4 @@ public class ClientRegionFactoryBeanTest { assertSame(region, result); } - } diff --git a/src/test/resources/gemfire-client-cache.xml b/src/test/resources/gemfire-client-cache.xml index 11c3a381..aeb64a75 100644 --- a/src/test/resources/gemfire-client-cache.xml +++ b/src/test/resources/gemfire-client-cache.xml @@ -3,8 +3,11 @@ "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN" "http://www.gemstone.com/dtd/cache6_5.dtd"> - - + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/client/client-cache.xml b/src/test/resources/org/springframework/data/gemfire/client/client-cache.xml index c47bb027..b0a76411 100644 --- a/src/test/resources/org/springframework/data/gemfire/client/client-cache.xml +++ b/src/test/resources/org/springframework/data/gemfire/client/client-cache.xml @@ -7,4 +7,7 @@ + + + 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 2083b55f..a18521b0 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 @@ -27,7 +27,11 @@ - + + + + + \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml index fd0a91bf..42ffc613 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml @@ -11,7 +11,7 @@ - +