Merge branch 'client-cache'
This commit is contained in:
@@ -38,6 +38,7 @@ import com.gemstone.gemfire.GemFireException;
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.distributed.DistributedMember;
|
||||
import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
import com.gemstone.gemfire.pdx.PdxSerializable;
|
||||
@@ -57,8 +58,13 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanClassLoaderAware, DisposableBean,
|
||||
InitializingBean, FactoryBean<Cache>, PersistenceExceptionTranslator {
|
||||
InitializingBean, FactoryBean<GemFireCache>, PersistenceExceptionTranslator {
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on the GemFire 6.6 API.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
private class PdxOptions implements Runnable {
|
||||
|
||||
private CacheFactory factory;
|
||||
@@ -69,6 +75,7 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
|
||||
public void run() {
|
||||
Assert.isAssignable(PdxSerializer.class, pdxSerializer.getClass(), "Invalid pdx serializer used");
|
||||
|
||||
factory.setPdxSerializer((PdxSerializer) pdxSerializer);
|
||||
factory.setPdxDiskStore(pdxDiskStoreName);
|
||||
factory.setPdxIgnoreUnreadFields(pdxIgnoreUnreadFields);
|
||||
@@ -77,9 +84,9 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
}
|
||||
}
|
||||
|
||||
private static final Log log = LogFactory.getLog(CacheFactoryBean.class);
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private Cache cache;
|
||||
private GemFireCache cache;
|
||||
private Resource cacheXml;
|
||||
private Properties properties;
|
||||
private ClassLoader beanClassLoader;
|
||||
@@ -89,11 +96,11 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
private String beanName;
|
||||
private boolean useBeanFactoryLocator = true;
|
||||
// PDX options
|
||||
private Object pdxSerializer;
|
||||
private Boolean pdxPersistent;
|
||||
private Boolean pdxReadSerialized;
|
||||
private Boolean pdxIgnoreUnreadFields;
|
||||
private String pdxDiskStoreName;
|
||||
protected Object pdxSerializer;
|
||||
protected Boolean pdxPersistent;
|
||||
protected Boolean pdxReadSerialized;
|
||||
protected Boolean pdxIgnoreUnreadFields;
|
||||
protected String pdxDiskStoreName;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// initialize locator
|
||||
@@ -104,7 +111,6 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
factoryLocator.afterPropertiesSet();
|
||||
}
|
||||
Properties cfgProps = mergeProperties();
|
||||
CacheFactory factory = new CacheFactory(cfgProps);
|
||||
|
||||
// use the bean class loader to load Declarable classes
|
||||
Thread th = Thread.currentThread();
|
||||
@@ -115,19 +121,21 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
// first look for open caches
|
||||
String msg = null;
|
||||
try {
|
||||
cache = CacheFactory.getAnyInstance();
|
||||
cache = fetchCache();
|
||||
msg = "Retrieved existing";
|
||||
} catch (CacheClosedException ex) {
|
||||
Object factory = createFactory(cfgProps);
|
||||
|
||||
// GemFire 6.6 specific options
|
||||
if (pdxSerializer != null || pdxPersistent != null || pdxReadSerialized != null
|
||||
|| pdxIgnoreUnreadFields != null || pdxDiskStoreName != null) {
|
||||
Assert.isTrue(ClassUtils.isPresent("com.gemstone.gemfire.pdx.PdxSerializer", beanClassLoader),
|
||||
"Cannot set PDX options since GemFire 6.6 not detected");
|
||||
new PdxOptions(factory).run();
|
||||
applyPdxOptions(factory);
|
||||
}
|
||||
|
||||
// fall back to cache creation
|
||||
cache = factory.create();
|
||||
cache = createCache(factory);
|
||||
msg = "Created";
|
||||
}
|
||||
|
||||
@@ -136,7 +144,6 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
log.info("Connected to Distributed System [" + system.getName() + "=" + member.getId() + "@"
|
||||
+ member.getHost() + "]");
|
||||
|
||||
|
||||
log.info(msg + " GemFire v." + CacheFactory.getVersion() + " Cache [" + cache.getName() + "]");
|
||||
|
||||
// load/init cache.xml
|
||||
@@ -146,10 +153,34 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Initialized cache from " + cacheXml);
|
||||
|
||||
} finally {
|
||||
th.setContextClassLoader(oldTCCL);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets the PDX properties for the given object. Note this is implementation specific as it depends on the type
|
||||
* of the factory passed in.
|
||||
*
|
||||
* @param factory
|
||||
*/
|
||||
protected void applyPdxOptions(Object factory) {
|
||||
if (factory instanceof CacheFactory) {
|
||||
new PdxOptions((CacheFactory) factory).run();
|
||||
}
|
||||
}
|
||||
|
||||
protected Object createFactory(Properties props) {
|
||||
return new CacheFactory(props);
|
||||
}
|
||||
|
||||
protected GemFireCache fetchCache() {
|
||||
return CacheFactory.getAnyInstance();
|
||||
}
|
||||
|
||||
protected GemFireCache createCache(Object factory) {
|
||||
return ((CacheFactory) factory).create();
|
||||
}
|
||||
|
||||
private Properties mergeProperties() {
|
||||
Properties cfgProps = (properties != null ? (Properties) properties.clone() : new Properties());
|
||||
@@ -184,11 +215,11 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
return null;
|
||||
}
|
||||
|
||||
public Cache getObject() throws Exception {
|
||||
public GemFireCache getObject() throws Exception {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public Class<? extends Cache> getObjectType() {
|
||||
public Class<? extends GemFireCache> getObjectType() {
|
||||
return (cache != null ? cache.getClass() : Cache.class);
|
||||
}
|
||||
|
||||
@@ -282,4 +313,11 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
public void setPdxDiskStoreName(String pdxDiskStoreName) {
|
||||
this.pdxDiskStoreName = pdxDiskStoreName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the beanFactory
|
||||
*/
|
||||
protected BeanFactory getBeanFactory() {
|
||||
return beanFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2011 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.client;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
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).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class ClientCacheFactoryBean extends CacheFactoryBean {
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on the GemFire 6.6 API.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
private class PdxOptions implements Runnable {
|
||||
|
||||
private ClientCacheFactory factory;
|
||||
|
||||
PdxOptions(ClientCacheFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Assert.isAssignable(PdxSerializer.class, pdxSerializer.getClass(), "Invalid pdx serializer used");
|
||||
|
||||
factory.setPdxSerializer((PdxSerializer) pdxSerializer);
|
||||
factory.setPdxDiskStore(pdxDiskStoreName);
|
||||
factory.setPdxIgnoreUnreadFields(pdxIgnoreUnreadFields);
|
||||
factory.setPdxPersistent(pdxPersistent);
|
||||
factory.setPdxReadSerialized(pdxReadSerialized);
|
||||
}
|
||||
}
|
||||
|
||||
private String poolName;
|
||||
private Pool pool;
|
||||
|
||||
@Override
|
||||
protected GemFireCache createCache(Object factory) {
|
||||
ClientCacheFactory ccf = (ClientCacheFactory) factory;
|
||||
initializePool(ccf);
|
||||
return ccf.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties props) {
|
||||
return new ClientCacheFactory(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GemFireCache fetchCache() {
|
||||
return ClientCacheFactory.getAnyInstance();
|
||||
}
|
||||
|
||||
private void initializePool(ClientCacheFactory ccf) {
|
||||
Pool p = pool;
|
||||
|
||||
if (p == null && StringUtils.hasText(poolName)) {
|
||||
BeanFactory beanFactory = getBeanFactory();
|
||||
|
||||
// try to eagerly initialize the pool name, if defined as a bean
|
||||
if (beanFactory.isTypeMatch(poolName, Pool.class)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Found bean definition for pool '" + poolName + "'. Eagerly initializing it...");
|
||||
}
|
||||
p = beanFactory.getBean(poolName, Pool.class);
|
||||
}
|
||||
}
|
||||
|
||||
if (p != null) {
|
||||
// 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());
|
||||
ccf.setPoolMaxConnections(p.getMaxConnections());
|
||||
ccf.setPoolMinConnections(p.getMinConnections());
|
||||
ccf.setPoolMultiuserAuthentication(p.getMultiuserAuthentication());
|
||||
ccf.setPoolPingInterval(p.getPingInterval());
|
||||
ccf.setPoolPRSingleHopEnabled(p.getPRSingleHopEnabled());
|
||||
ccf.setPoolReadTimeout(p.getReadTimeout());
|
||||
ccf.setPoolRetryAttempts(p.getRetryAttempts());
|
||||
ccf.setPoolServerGroup(p.getServerGroup());
|
||||
ccf.setPoolSocketBufferSize(p.getSocketBufferSize());
|
||||
ccf.setPoolStatisticInterval(p.getStatisticInterval());
|
||||
ccf.setPoolSubscriptionAckInterval(p.getSubscriptionAckInterval());
|
||||
ccf.setPoolSubscriptionEnabled(p.getSubscriptionEnabled());
|
||||
ccf.setPoolSubscriptionMessageTrackingTimeout(p.getSubscriptionMessageTrackingTimeout());
|
||||
ccf.setPoolSubscriptionRedundancy(p.getSubscriptionRedundancy());
|
||||
ccf.setPoolThreadLocalConnections(p.getThreadLocalConnections());
|
||||
|
||||
List<InetSocketAddress> locators = p.getLocators();
|
||||
if (locators != null) {
|
||||
for (InetSocketAddress inet : locators) {
|
||||
ccf.addPoolLocator(inet.getHostName(), inet.getPort());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<InetSocketAddress> servers = p.getServers();
|
||||
if (locators != null) {
|
||||
for (InetSocketAddress inet : servers) {
|
||||
ccf.addPoolLocator(inet.getHostName(), inet.getPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pool name used by this client.
|
||||
*
|
||||
* @param poolName
|
||||
*/
|
||||
public void setPoolName(String poolName) {
|
||||
Assert.hasText(poolName, "pool name is required");
|
||||
this.poolName = poolName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pool used by this client.
|
||||
*
|
||||
* @param pool
|
||||
*/
|
||||
public void setPool(Pool pool) {
|
||||
Assert.notNull(pool, "pool cannot be null");
|
||||
this.pool = pool;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPdxOptions(Object factory) {
|
||||
if (factory instanceof ClientCacheFactory) {
|
||||
new PdxOptions((ClientCacheFactory) factory).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
|
||||
|
||||
private static final Log log = LogFactory.getLog(PoolFactoryBean.class);
|
||||
|
||||
// whether the pool has been created internaly or not
|
||||
// whether the pool has been created internally or not
|
||||
private boolean internalPool = true;
|
||||
|
||||
private Pool pool;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2011 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;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <client-cache;gt; definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class ClientCacheParser extends CacheParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return ClientCacheFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "pool-name", "poolName");
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("cache", new CacheParser());
|
||||
registerBeanDefinitionParser("client-cache", new ClientCacheParser());
|
||||
|
||||
registerBeanDefinitionParser("lookup-region", new LookupRegionParser());
|
||||
registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser());
|
||||
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
|
||||
|
||||
@@ -17,7 +17,42 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="cache">
|
||||
|
||||
<xsd:complexType name="cacheType">
|
||||
<xsd:attribute name="id" type="xsd:ID" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the cache definition (by default "gemfire-cache").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="cache-xml-location" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.core.io.Resource"><![CDATA[
|
||||
The location of the GemFire cache xml file, as a Spring resource location: a URL, a "classpath:" pseudo URL,
|
||||
or a relative file path.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="properties-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java.util.Properties"><![CDATA[
|
||||
The bean name of a Java Properties object that will be used for property substitution. For loading properties
|
||||
consider using a dedicated utility such as the <util:*/> namespace and its 'properties' element.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="use-bean-factory-locator" type="xsd:string" default="true" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether a bean factory locator is enabled (default) for this cache definition or not. The locator stores
|
||||
the enclosing bean factory reference to allow auto-wiring of Spring beans into GemFire managed classes. Usually disabled
|
||||
when the same cache is used in multiple application context/bean factories inside the same VM.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="cache" type="cacheType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.data.gemfire.CacheFactoryBean"><![CDATA[
|
||||
Defines a GemFire Cache instance used for creating or retrieving 'regions'.
|
||||
@@ -28,38 +63,31 @@ Defines a GemFire Cache instance used for creating or retrieving 'regions'.
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="client-cache">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.data.gemfire.client.ClientCacheFactoryBean"><![CDATA[
|
||||
Defines a GemFire Client Cache instance used for creating or retrieving 'regions'.
|
||||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="com.gemstone.gemfire.cache.client.ClientCache" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:ID" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the cache definition (by default "gemfire-cache").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="cache-xml-location" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.core.io.Resource"><![CDATA[
|
||||
The location of the GemFire cache xml file, as a Spring resource location: a URL, a "classpath:" pseudo URL,
|
||||
or a relative file path.
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="cacheType">
|
||||
<xsd:attribute name="pool-name" use="optional" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the pool used by this client.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="properties-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java.util.Properties"><![CDATA[
|
||||
The bean name of a Java Properties object that will be used for property substitution. For loading properties
|
||||
consider using a dedicated utility such as the <util:*/> namespace and its 'properties' element.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="use-bean-factory-locator" type="xsd:string" default="true" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether a bean factory locator is enabled (default) for this cache definition or not. The locator stores
|
||||
the enclosing bean factory reference to allow auto-wiring of Spring beans into GemFire managed classes. Usually disabled
|
||||
when the same cache is used in multiple application context/bean factories inside the same VM.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
@@ -805,10 +833,10 @@ cache to differ from other caches.
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="pool-name" use="required" type="xsd:string">
|
||||
<xsd:attribute name="pool-name" use="optional" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the pool used by this client.
|
||||
The name of the pool used by this client. If not set, a default pool (initialized when using client-cache) will be used.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("client-cache.xml")
|
||||
public class ClientCacheTest {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.GemfireBeanFactoryLocator;
|
||||
import org.springframework.data.gemfire.RecreatingContextTest;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -76,4 +77,19 @@ public class CacheNamespaceTest extends RecreatingContextTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicClientCache() throws Exception {
|
||||
assertTrue(ctx.containsBean("client-cache"));
|
||||
ClientCacheFactoryBean cfb = (ClientCacheFactoryBean) ctx.getBean("&client-cache");
|
||||
assertNull(TestUtils.readField("cacheXml", cfb));
|
||||
assertNull(TestUtils.readField("properties", cfb));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicClientCacheWithXml() throws Exception {
|
||||
assertTrue(ctx.containsBean("client-cache-with-xml"));
|
||||
ClientCacheFactoryBean cfb = (ClientCacheFactoryBean) ctx.getBean("&client-cache-with-xml");
|
||||
Resource res = TestUtils.readField("cacheXml", cfb);
|
||||
assertEquals("gemfire-client-cache.xml", res.getFilename());
|
||||
}
|
||||
}
|
||||
11
src/test/resources/gemfire-client-cache.xml
Normal file
11
src/test/resources/gemfire-client-cache.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE client-cache PUBLIC
|
||||
"-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
|
||||
"http://www.gemstone.com/dtd/cache6_5.dtd">
|
||||
|
||||
<client-cache>
|
||||
<region name="myRegion" refid="PROXY"/>
|
||||
<!-- you can override or add to the PROXY attributes by adding
|
||||
a region-attributes sub element here -->
|
||||
</client-cache>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean class="org.springframework.data.gemfire.client.ClientCacheFactoryBean"/>
|
||||
<property name="pool" ref="pool"/>
|
||||
</bean>
|
||||
|
||||
<gfe:pool id="pool">
|
||||
<gfe:locator host="localhost" port="12345"/>
|
||||
</gfe:pool>
|
||||
</beans>
|
||||
@@ -23,4 +23,8 @@
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache id="no-bl" use-bean-factory-locator="false" />
|
||||
|
||||
<gfe:client-cache id="client-cache"/>
|
||||
|
||||
<gfe:client-cache id="client-cache-with-xml" cache-xml-location="classpath:gemfire-client-cache.xml"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user