SGF-538 - Reorganize the XML configuration classes and support in SDG.
(cherry picked from commit d914f7427483d3e583aea13f061f3cdc20be84f8) Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
@@ -25,7 +25,7 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -43,7 +43,7 @@ import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* Spring FactoryBean for easy declarative creation of GemFire Indexes.
|
||||
*
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
@@ -267,7 +267,7 @@ public class IndexFactoryBean implements InitializingBean, FactoryBean<Index>, B
|
||||
|
||||
/**
|
||||
* Sets the underlying cache used for creating indexes.
|
||||
*
|
||||
*
|
||||
* @param cache cache used for creating indexes.
|
||||
*/
|
||||
public void setCache(RegionService cache) {
|
||||
@@ -276,7 +276,7 @@ public class IndexFactoryBean implements InitializingBean, FactoryBean<Index>, B
|
||||
|
||||
/**
|
||||
* Sets the query service used for creating indexes.
|
||||
*
|
||||
*
|
||||
* @param service query service used for creating indexes.
|
||||
*/
|
||||
public void setQueryService(QueryService service) {
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.client.support.DefaultableDelegatingPoolAdapter;
|
||||
import org.springframework.data.gemfire.client.support.DelegatingPoolAdapter;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.DataPolicyConverter;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.RegionLookupFactoryBean;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -371,7 +371,7 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
||||
/**
|
||||
* Set the interests for this client region. Both key and regex interest are
|
||||
* supported.
|
||||
*
|
||||
*
|
||||
* @param interests the interests to set
|
||||
*/
|
||||
public void setInterests(Interest<K>[] interests) {
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.function.config.GemfireFunctionBeanPostProcessor;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
|
||||
*/
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
registerGemfireFunctionBeanPostProcessor(element, parserContext);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void registerGemfireFunctionBeanPostProcessor(Element element, ParserContext parserContext) {
|
||||
Object source = parserContext.extractSource(element);
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(GemfireFunctionBeanPostProcessor.class);
|
||||
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
beanDefinition.setSource(source);
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, parserContext.getRegistry());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* The CreateDefinedIndexesApplicationListener class is a Spring ApplicationListener used to create
|
||||
* all the GemFire Cache Region Indexes "defined" using the QueryService.defineXXXX(..) methods.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.context.ApplicationListener
|
||||
* @see org.springframework.context.event.ContextRefreshedEvent
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public class CreateDefinedIndexesApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
protected final Log logger = initLogger();
|
||||
|
||||
/**
|
||||
* Attempts to create all defined Indexes using the QueryService, defineXXXX(..) API once
|
||||
* the Spring ApplicationContext has been refreshed.
|
||||
*
|
||||
* @param event the ContextRefreshedEvent fired when the Spring ApplicationContext gets refreshed.
|
||||
* @see #getCache(org.springframework.context.event.ContextRefreshedEvent)
|
||||
* @see org.springframework.context.event.ContextRefreshedEvent
|
||||
* @see com.gemstone.gemfire.cache.Cache#getQueryService()
|
||||
* @see com.gemstone.gemfire.cache.client.ClientCache#getLocalQueryService()
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService#createDefinedIndexes()
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(final ContextRefreshedEvent event) {
|
||||
try {
|
||||
QueryService localQueryService = getQueryService(event);
|
||||
|
||||
if (localQueryService != null) {
|
||||
localQueryService.createDefinedIndexes();
|
||||
}
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
logger.warn(String.format("unable to create defined Indexes (if any): %1$s", ignore.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Log initLogger() {
|
||||
return LogFactory.getLog(getClass());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private QueryService getQueryService(final ContextRefreshedEvent event) {
|
||||
ApplicationContext localApplicationContext = event.getApplicationContext();
|
||||
|
||||
return (localApplicationContext.containsBean(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE) ?
|
||||
localApplicationContext.getBean(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE,
|
||||
QueryService.class) : null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* Simple utility class used for defining nested factory-method like definitions
|
||||
* w/o polluting the container with useless beans.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
class DiskWriteAttributesFactoryBean implements FactoryBean<com.gemstone.gemfire.cache.DiskWriteAttributes>, InitializingBean {
|
||||
|
||||
private com.gemstone.gemfire.cache.DiskWriteAttributes attributes;
|
||||
|
||||
private com.gemstone.gemfire.cache.DiskWriteAttributesFactory attrFactory;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
attributes = attrFactory.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.gemstone.gemfire.cache.DiskWriteAttributes getObject() throws Exception {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return (attributes != null ? attributes.getClass() : com.gemstone.gemfire.cache.DiskWriteAttributes.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setDiskAttributesFactory(com.gemstone.gemfire.cache.DiskWriteAttributesFactory dwaf) {
|
||||
this.attrFactory = dwaf;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
@@ -27,20 +30,17 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* The AutoRegionLookupBeanPostProcessor class is a Spring BeanPostProcessor that post processes a GemFireCache by
|
||||
* registering all Cache Regions that have not been explicitly defined in the Spring application context. This is
|
||||
* usually the case for Regions that have been defined in GemFire's native cache.xml or defined use GemFire 8's new
|
||||
* cluster-based configuration service.
|
||||
* The AutoRegionLookupBeanPostProcessor class is a Spring {@link BeanPostProcessor} that post processes
|
||||
* a {@link GemFireCache} by registering all cache {@link Region Regions} that have not been explicitly
|
||||
* defined in the Spring application context. This is usually the case for {@link Region Regions} that
|
||||
* have been defined in GemFire's native {@literal cache.xml} or defined using GemFire 8's cluster-based
|
||||
* configuration service.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.BeanFactory
|
||||
* @see org.springframework.beans.factory.BeanFactoryAware
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor
|
||||
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
|
||||
* @see com.gemstone.gemfire.cache.GemFireCache
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @since 1.5.0
|
||||
@@ -49,26 +49,37 @@ public class AutoRegionLookupBeanPostProcessor implements BeanPostProcessor, Bea
|
||||
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public final void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
|
||||
public final void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory,
|
||||
String.format("The BeanFactory reference (%1$s) must be an instance of ConfigurableListableBeanFactory!",
|
||||
ObjectUtils.nullSafeClassName(beanFactory)));
|
||||
String.format("BeanFactory [%1$s] must be an instance of %2$s",
|
||||
ObjectUtils.nullSafeClassName(beanFactory), ConfigurableListableBeanFactory.class.getSimpleName()));
|
||||
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected ConfigurableListableBeanFactory getBeanFactory() {
|
||||
Assert.state(this.beanFactory != null, "A reference to the BeanFactory was not properly configured and initialized!");
|
||||
Assert.state(this.beanFactory != null, "BeanFactory was not properly initialized");
|
||||
return this.beanFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof GemFireCache) {
|
||||
registerCacheRegionsAsBeans((GemFireCache) bean);
|
||||
}
|
||||
@@ -76,13 +87,15 @@ public class AutoRegionLookupBeanPostProcessor implements BeanPostProcessor, Bea
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void registerCacheRegionsAsBeans(final GemFireCache cache) {
|
||||
/* (non-Javadoc) */
|
||||
void registerCacheRegionsAsBeans(GemFireCache cache) {
|
||||
for (Region region : cache.rootRegions()) {
|
||||
registerRegionAsBean(region);
|
||||
registerCacheRegionAsBean(region);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerRegionAsBean(final Region<?, ?> region) {
|
||||
/* (non-Javadoc) */
|
||||
void registerCacheRegionAsBean(Region<?, ?> region) {
|
||||
if (region != null) {
|
||||
String regionBeanName = getBeanName(region);
|
||||
|
||||
@@ -91,19 +104,20 @@ public class AutoRegionLookupBeanPostProcessor implements BeanPostProcessor, Bea
|
||||
}
|
||||
|
||||
for (Region<?, ?> subregion : nullSafeSubregions(region)) {
|
||||
registerRegionAsBean(subregion);
|
||||
registerCacheRegionAsBean(subregion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Region<?, ?>> nullSafeSubregions(final Region<?, ?> parentRegion) {
|
||||
Set<Region<?, ?>> subregions = parentRegion.subregions(false);
|
||||
return (subregions != null ? subregions : Collections.<Region<?, ?>>emptySet());
|
||||
}
|
||||
|
||||
private String getBeanName(final Region region) {
|
||||
/* (non-Javadoc) */
|
||||
String getBeanName(Region region) {
|
||||
String regionFullPath = region.getFullPath();
|
||||
return (regionFullPath.lastIndexOf(Region.SEPARATOR) > 0 ? regionFullPath : region.getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Set<Region<?, ?>> nullSafeSubregions(Region<?, ?> parentRegion) {
|
||||
Set<Region<?, ?>> subregions = parentRegion.subregions(false);
|
||||
return (subregions != null ? subregions : Collections.<Region<?, ?>>emptySet());
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -30,22 +27,26 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
|
||||
/**
|
||||
* The ClientRegionAndPoolBeanFactoryPostProcessor class is a Spring {@link BeanFactoryPostProcessor} that ensures
|
||||
* a proper dependency is declared between a GemFire client Region and the GemFire Pool it references and uses, if
|
||||
* the GemFire Pool has been defined and configured in Spring (Data GemFire) configuration meta-data (XML).
|
||||
* {@link ClientRegionPoolBeanFactoryPostProcessor} is a Spring {@link BeanFactoryPostProcessor} implementation
|
||||
* ensuring a proper dependency is declared between a GemFire client {@link com.gemstone.gemfire.cache.Region}
|
||||
* and the GemFire client {@link com.gemstone.gemfire.cache.client.Pool} it references and uses, providing
|
||||
* the GemFire client {@link com.gemstone.gemfire.cache.client.Pool} has been defined and configured with
|
||||
* Spring (Data GemFire) configuration meta-data (e.g. XML).
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor
|
||||
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
|
||||
* @since 1.8.2
|
||||
*/
|
||||
public class ClientRegionAndPoolBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
public class ClientRegionPoolBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
protected static final String POOL_NAME_PROPERTY = "poolName";
|
||||
|
||||
/* (non-Javadoc)*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
Set<String> clientRegionBeanNames = new HashSet<String>();
|
||||
@@ -67,7 +68,7 @@ public class ClientRegionAndPoolBeanFactoryPostProcessor implements BeanFactoryP
|
||||
String poolName = getPoolName(clientRegionBean);
|
||||
|
||||
if (poolBeanNames.contains(poolName)) {
|
||||
addDependsOn(clientRegionBean, poolName);
|
||||
SpringUtils.addDependsOn(clientRegionBean, poolName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,19 +88,4 @@ public class ClientRegionAndPoolBeanFactoryPostProcessor implements BeanFactoryP
|
||||
PropertyValue poolNameProperty = clientRegionBean.getPropertyValues().getPropertyValue(POOL_NAME_PROPERTY);
|
||||
return (poolNameProperty != null ? String.valueOf(poolNameProperty.getValue()) : null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
BeanDefinition addDependsOn(BeanDefinition bean, String beanName) {
|
||||
String[] dependsOn = bean.getDependsOn();
|
||||
List<String> dependsOnList = new ArrayList<String>();
|
||||
|
||||
if (dependsOn != null) {
|
||||
Collections.addAll(dependsOnList, dependsOn);
|
||||
}
|
||||
|
||||
dependsOnList.add(beanName);
|
||||
bean.setDependsOn(dependsOnList.toArray(new String[dependsOnList.size()]));
|
||||
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
@@ -35,35 +42,32 @@ import org.springframework.data.gemfire.ScopeConverter;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.data.gemfire.wan.OrderPolicyConverter;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
/**
|
||||
* The CustomEditorRegisteringBeanFactoryPostProcessor class is a Spring {@link BeanFactoryPostProcessor} used
|
||||
* to register custom GemFire-specific JavaBeans {@link java.beans.PropertyEditor}s and Spring {@link Converter}s
|
||||
* {@link CustomEditorBeanFactoryPostProcessor} is a Spring {@link BeanFactoryPostProcessor} implementation
|
||||
* used to register custom {@link java.beans.PropertyEditor PropertyEditors} / Spring {@link Converter Converters}
|
||||
* that are used to perform type conversions between String-based configuration meta-data and actual GemFire
|
||||
* or Spring Data GemFire defined enumerated types.
|
||||
* or Spring Data GemFire defined (enumerated) types.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor
|
||||
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
class CustomEditorRegisteringBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
public class CustomEditorBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
beanFactory.registerCustomEditor(ConnectionEndpoint.class, StringToConnectionEndpointConverter.class);
|
||||
//beanFactory.registerCustomEditor(ConnectionEndpoint[].class, ConnectionEndpointArrayToIterableConverter.class);
|
||||
beanFactory.registerCustomEditor(ConnectionEndpointList.class, StringToConnectionEndpointListConverter.class);
|
||||
beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class);
|
||||
beanFactory.registerCustomEditor(EvictionPolicyType.class, EvictionPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class);
|
||||
@@ -80,10 +84,39 @@ class CustomEditorRegisteringBeanFactoryPostProcessor implements BeanFactoryPost
|
||||
public static class ConnectionEndpointArrayToIterableConverter extends PropertyEditorSupport
|
||||
implements Converter<ConnectionEndpoint[], Iterable> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Iterable convert(ConnectionEndpoint[] source) {
|
||||
return ConnectionEndpointList.from(source);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static class StringToConnectionEndpointConverter
|
||||
extends AbstractPropertyEditorConverterSupport<ConnectionEndpoint> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ConnectionEndpoint convert(String source) {
|
||||
return assertConverted(source, ConnectionEndpoint.parse(source), ConnectionEndpoint.class);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static class StringToConnectionEndpointListConverter
|
||||
extends AbstractPropertyEditorConverterSupport<ConnectionEndpointList> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ConnectionEndpointList convert(String source) {
|
||||
return assertConverted(source, ConnectionEndpointList.parse(0, source.split(",")),
|
||||
ConnectionEndpointList.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.support;
|
||||
|
||||
import com.gemstone.gemfire.cache.query.MultiIndexCreationException;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
|
||||
/**
|
||||
* {@link DefinedIndexesApplicationListener} is a Spring {@link ApplicationListener} used to create all
|
||||
* "defined" GemFire {@link com.gemstone.gemfire.cache.query.Index Indexes} by using the {@link QueryService},
|
||||
* {@literal defineXxxIndex(..)} methods.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.context.ApplicationContext
|
||||
* @see org.springframework.context.ApplicationListener
|
||||
* @see org.springframework.context.event.ContextRefreshedEvent
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public class DefinedIndexesApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
protected final Log logger = initLogger();
|
||||
|
||||
/**
|
||||
* Attempts to create all defined {@link com.gemstone.gemfire.cache.query.Index Indexes} using
|
||||
* the {@link QueryService}, {@literal defineXxxIndex(..)} API once the Spring {@link ApplicationContext}
|
||||
* has been refreshed.
|
||||
*
|
||||
* @param event {@link ContextRefreshedEvent} fired when the Spring {@link ApplicationContext} gets refreshed.
|
||||
* @see org.springframework.context.event.ContextRefreshedEvent
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService#createDefinedIndexes()
|
||||
* @see #getQueryService(ContextRefreshedEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
try {
|
||||
QueryService queryService = getQueryService(event);
|
||||
|
||||
if (queryService != null) {
|
||||
queryService.createDefinedIndexes();
|
||||
}
|
||||
}
|
||||
catch (MultiIndexCreationException ignore) {
|
||||
logger.warn(String.format("Failed to create pre-defined Indexes: %s", ignore.getMessage()), ignore);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Log initLogger() {
|
||||
return LogFactory.getLog(getClass());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private QueryService getQueryService(ContextRefreshedEvent event) {
|
||||
ApplicationContext applicationContext = event.getApplicationContext();
|
||||
String queryServiceBeanName = getQueryServiceBeanName();
|
||||
|
||||
return (applicationContext.containsBean(queryServiceBeanName) ?
|
||||
applicationContext.getBean(queryServiceBeanName, QueryService.class) : null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String getQueryServiceBeanName() {
|
||||
return GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -28,13 +28,13 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* The DiskStoreBeanPostProcessor class post processes any GemFire Disk Store DiskDir Spring beans defined
|
||||
* in the application context to ensure that the Disk Store directory location (disk-dir) actually exists
|
||||
* before creating the Disk Store.
|
||||
* The {@link DiskStoreBeanPostProcessor} processes any GemFire {@link com.gemstone.gemfire.cache.DiskStore},
|
||||
* {@link DiskDir} Spring beans defined in the application context to ensure that the directory actually exists
|
||||
* before creating the {@link com.gemstone.gemfire.cache.DiskStore}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor
|
||||
* @see org.springframework.data.gemfire.DiskStoreFactoryBean.DiskDir
|
||||
* @see com.gemstone.gemfire.cache.DiskStore
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@@ -42,11 +42,14 @@ public class DiskStoreBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("Post Processing Bean (%1$s) of Type (%2$s) with Name (%3$s)...%n", bean,
|
||||
ObjectUtils.nullSafeClassName(bean), beanName));
|
||||
log.debug(String.format("Processing Bean [%1$s] of Type [%2$s] with Name [%3$s] before initialization%n",
|
||||
bean, ObjectUtils.nullSafeClassName(bean), beanName));
|
||||
}
|
||||
|
||||
if (bean instanceof DiskDir) {
|
||||
@@ -56,33 +59,43 @@ public class DiskStoreBeanPostProcessor implements BeanPostProcessor {
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void createIfNotExists(final DiskDir diskDirectory) {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void createIfNotExists(DiskDir diskDirectory) {
|
||||
String location = readField(diskDirectory, "location");
|
||||
|
||||
File diskDirectoryFile = new File(location);
|
||||
|
||||
Assert.isTrue(diskDirectoryFile.isDirectory() || diskDirectoryFile.mkdirs(),
|
||||
String.format("Failed to create Disk Directory (%1$s)%n!", location));
|
||||
String.format("Failed to create Disk Directory [%s]%n", location));
|
||||
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info(String.format("The Disk Directory either exists or was created @ Location (%1$s).%n", location));
|
||||
log.info(String.format("Disk Directory is @ Location [%s].%n", location));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T readField(final Object obj, final String fieldName) {
|
||||
private <T> T readField(Object obj, String fieldName) {
|
||||
try {
|
||||
Class type = obj.getClass();
|
||||
Field field;
|
||||
|
||||
do {
|
||||
field = type.getDeclaredField(fieldName);
|
||||
type = type.getSuperclass(); // traverse up the object class hierarchy
|
||||
type = type.getSuperclass();
|
||||
}
|
||||
while (field == null && !Object.class.equals(type));
|
||||
|
||||
if (field == null) {
|
||||
throw new NoSuchFieldException(String.format("Field (%1$s) does not exist on Object of type (%2$s)!",
|
||||
throw new NoSuchFieldException(String.format("No field with name [%1$s] found on object of type [%2$s]",
|
||||
fieldName, ObjectUtils.nullSafeClassName(obj)));
|
||||
}
|
||||
|
||||
@@ -91,14 +104,8 @@ public class DiskStoreBeanPostProcessor implements BeanPostProcessor {
|
||||
return (T) field.get(obj);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(String.format("Failed to read field (%1$s) on Object of type (%2$s)!",
|
||||
throw new RuntimeException(String.format("Failed to read field [%1$s] from object of type [%2$s]",
|
||||
fieldName, ObjectUtils.nullSafeClassName(obj)), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,23 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
|
||||
/**
|
||||
* The PdxDiskStoreAwareBeanFactoryPostProcessor class is a BeanFactoryPostProcessor that modifies all Async Event Queue,
|
||||
* Region and Disk Store beans in the Spring container to form a dependency on the Cache's PDX Disk Store bean.
|
||||
* {@link PdxDiskStoreAwareBeanFactoryPostProcessor} is a Spring {@link BeanFactoryPostProcessor} that modifies
|
||||
* all GemFire Async Event Queue, Region and Disk Store beans in the Spring container to form a dependency on
|
||||
* the Cache's PDX {@link DiskStore} bean.
|
||||
*
|
||||
* A persistent Region may contain PDX typed data, in which case, the PDX type meta-data stored to disk needs to be
|
||||
* loaded before the Region having PDX data is loaded from disk.
|
||||
*
|
||||
@@ -48,17 +50,32 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos
|
||||
|
||||
private final String pdxDiskStoreName;
|
||||
|
||||
public PdxDiskStoreAwareBeanFactoryPostProcessor(final String pdxDiskStoreName) {
|
||||
Assert.isTrue(StringUtils.hasText(pdxDiskStoreName), "The name of the PDX Disk Store must be specified!");
|
||||
/**
|
||||
* Constructs an instance of the {@link PdxDiskStoreAwareBeanFactoryPostProcessor} class initialized with
|
||||
* the given PDX {@link DiskStore} name.
|
||||
*
|
||||
* @param pdxDiskStoreName name of the GemFire PDX {@link DiskStore}.
|
||||
* @throws IllegalArgumentException if the GemFire PDX {@link DiskStore} name is unspecified.
|
||||
*/
|
||||
public PdxDiskStoreAwareBeanFactoryPostProcessor(String pdxDiskStoreName) {
|
||||
Assert.hasText(pdxDiskStoreName, "The PDX DiskStore name must be specified");
|
||||
this.pdxDiskStoreName = pdxDiskStoreName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the GemFire PDX {@link DiskStore}.
|
||||
*
|
||||
* @return the name of the GemFire PDX {@link DiskStore}.
|
||||
*/
|
||||
public String getPdxDiskStoreName() {
|
||||
return pdxDiskStoreName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
postProcessPdxDiskStoreDependencies(beanFactory, AsyncEventQueue.class, DiskStore.class, Region.class);
|
||||
}
|
||||
|
||||
@@ -72,7 +89,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos
|
||||
* @param beanTypes an array of Class types indicating the type of beans to evaluate.
|
||||
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getBeanNamesForType(Class)
|
||||
*/
|
||||
private void postProcessPdxDiskStoreDependencies(final ConfigurableListableBeanFactory beanFactory,
|
||||
private void postProcessPdxDiskStoreDependencies(ConfigurableListableBeanFactory beanFactory,
|
||||
final Class<?>... beanTypes) {
|
||||
for (Class<?> beanType : beanTypes) {
|
||||
for (String beanName : beanFactory.getBeanNamesForType(beanType)) {
|
||||
@@ -99,7 +116,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos
|
||||
* @see #getDependsOn(org.springframework.beans.factory.config.BeanDefinition)
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition#setDependsOn(String[])
|
||||
*/
|
||||
private void addPdxDiskStoreDependency(final BeanDefinition beanDefinition) {
|
||||
private void addPdxDiskStoreDependency(BeanDefinition beanDefinition) {
|
||||
String[] newDependsOn = (String[]) ArrayUtils.insert(getDependsOn(beanDefinition), 0, getPdxDiskStoreName());
|
||||
beanDefinition.setDependsOn(newDependsOn);
|
||||
}
|
||||
@@ -114,8 +131,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos
|
||||
* @see #addPdxDiskStoreDependency(org.springframework.beans.factory.config.BeanDefinition)
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition#getDependsOn()
|
||||
*/
|
||||
private String[] getDependsOn(final BeanDefinition beanDefinition) {
|
||||
return (beanDefinition.getDependsOn() != null ? beanDefinition.getDependsOn() : EMPTY_STRING_ARRAY);
|
||||
private String[] getDependsOn(BeanDefinition beanDefinition) {
|
||||
return SpringUtils.defaultIfNull(beanDefinition.getDependsOn(), EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,12 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
@@ -36,42 +39,53 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
/**
|
||||
* Abstract base class encapsulating functionality common to all Region Parsers.
|
||||
* Abstract base class encapsulating functionality common to all Region parsers.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.RegionFactoryBean
|
||||
*/
|
||||
abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return getRegionFactoryClass();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected abstract Class<?> getRegionFactoryClass();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String getParentName(final Element element) {
|
||||
protected String getParentName(Element element) {
|
||||
String regionTemplate = element.getAttribute("template");
|
||||
return (StringUtils.hasText(regionTemplate) ? regionTemplate : super.getParentName(element));
|
||||
}
|
||||
|
||||
protected boolean isRegionTemplate(final Element element) {
|
||||
/* (non-Javadoc) */
|
||||
protected boolean isRegionTemplate(Element element) {
|
||||
String localName = element.getLocalName();
|
||||
return (localName != null && localName.endsWith("-template"));
|
||||
}
|
||||
|
||||
protected boolean isSubRegion(final Element element) {
|
||||
/* (non-Javadoc) */
|
||||
protected boolean isSubRegion(Element element) {
|
||||
String localName = element.getParentNode().getLocalName();
|
||||
return (localName != null && localName.endsWith("region"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
@@ -79,13 +93,15 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
doParseRegion(element, parserContext, builder, isSubRegion(element));
|
||||
}
|
||||
|
||||
protected abstract void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion);
|
||||
/* (non-Javadoc) */
|
||||
protected abstract void doParseRegion(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder, boolean subRegion);
|
||||
|
||||
protected void doParseCommonRegionConfiguration(Element element, ParserContext parserContext,
|
||||
/* (non-Javadoc) */
|
||||
protected void doParseRegionConfiguration(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder, boolean subRegion) {
|
||||
|
||||
mergeTemplateRegionAttributes(element, parserContext, regionBuilder, regionAttributesBuilder);
|
||||
mergeRegionTemplateAttributes(element, parserContext, regionBuilder, regionAttributesBuilder);
|
||||
|
||||
String resolvedCacheRef = ParsingUtils.resolveCacheReference(element.getAttribute("cache-ref"));
|
||||
|
||||
@@ -163,7 +179,8 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
void mergeTemplateRegionAttributes(Element element, ParserContext parserContext,
|
||||
/* (non-Javadoc) */
|
||||
void mergeRegionTemplateAttributes(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder) {
|
||||
|
||||
String regionTemplateName = getParentName(element);
|
||||
@@ -183,13 +200,15 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
else {
|
||||
parserContext.getReaderContext().error(String.format(
|
||||
"The Region template [%1$s] must be 'defined before' the Region [%2$s] referring to the template!",
|
||||
regionTemplateName, resolveId(element, regionBuilder.getRawBeanDefinition(), parserContext)), element);
|
||||
regionTemplateName, resolveId(element, regionBuilder.getRawBeanDefinition(), parserContext)),
|
||||
element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BeanDefinition getRegionAttributesBeanDefinition(final BeanDefinition region) {
|
||||
Assert.notNull(region, "The 'Region' BeanDefinition must not be null!");
|
||||
/* (non-Javadoc) */
|
||||
BeanDefinition getRegionAttributesBeanDefinition(BeanDefinition region) {
|
||||
Assert.notNull(region, "BeanDefinition must not be null");
|
||||
|
||||
Object regionAttributes = null;
|
||||
|
||||
@@ -201,10 +220,12 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
return (regionAttributes instanceof BeanDefinition ? (BeanDefinition) regionAttributes : null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void parseCollectionOfCustomSubElements(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder, String className, String subElementName, String propertyName) {
|
||||
List<Element> subElements = DomUtils.getChildElementsByTagName(element, subElementName,
|
||||
subElementName + "-ref");
|
||||
|
||||
List<Element> subElements = DomUtils.getChildElementsByTagName(
|
||||
element, subElementName, subElementName + "-ref");
|
||||
|
||||
if (!CollectionUtils.isEmpty(subElements)) {
|
||||
ManagedArray array = new ManagedArray(className, subElements.size());
|
||||
@@ -217,6 +238,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void parseSubRegions(Element element, ParserContext parserContext, String resolvedCacheRef) {
|
||||
Map<String, Element> allSubRegionElements = new HashMap<String, Element>();
|
||||
|
||||
@@ -229,6 +251,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void findSubRegionElements(Element parent, String parentPath, Map<String, Element> allSubRegionElements) {
|
||||
for (Element element : DomUtils.getChildElements(parent)) {
|
||||
if (element.getLocalName().endsWith("region")) {
|
||||
@@ -240,11 +263,13 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String getRegionNameFromElement(Element element) {
|
||||
String name = element.getAttribute(NAME_ATTRIBUTE);
|
||||
return (StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String buildSubRegionPath(String parentName, String regionName) {
|
||||
String regionPath = StringUtils.arrayToDelimitedString(new String[] { parentName, regionName }, "/");
|
||||
if (!regionPath.startsWith("/")) {
|
||||
@@ -253,6 +278,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
return regionPath;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private BeanDefinition parseSubRegion(Element element, ParserContext parserContext, String subRegionPath,
|
||||
String cacheRef) {
|
||||
|
||||
@@ -271,6 +297,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
return beanDefinition;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String getParentRegionPathFrom(String regionPath) {
|
||||
int index = regionPath.lastIndexOf("/");
|
||||
String parentPath = regionPath.substring(0, index);
|
||||
@@ -280,13 +307,12 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
return parentPath;
|
||||
}
|
||||
|
||||
protected void validateDataPolicyShortcutAttributesMutualExclusion(final Element element,
|
||||
final ParserContext parserContext) {
|
||||
/* (non-Javadoc) */
|
||||
protected void validateDataPolicyShortcutAttributesMutualExclusion(Element element, ParserContext parserContext) {
|
||||
if (element.hasAttribute("data-policy") && element.hasAttribute("shortcut")) {
|
||||
parserContext.getReaderContext().error(String.format(
|
||||
"Only one of [data-policy, shortcut] may be specified with element '%1$s'.", element.getTagName()),
|
||||
element);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.function.config.GemfireFunctionBeanPostProcessor;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* A Spring {@link BeanDefinitionParser} to enable Spring Data GemFire Function annotation support.
|
||||
*
|
||||
* Bean definition parser for the <gfe:annotation-driven> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.BeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.function.config.GemfireFunctionBeanPostProcessor
|
||||
*/
|
||||
class AnnotationDrivenParser implements BeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
registerGemfireFunctionBeanPostProcessor(element, parserContext);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the {@link GemfireFunctionBeanPostProcessor} as a bean with the Spring application context.
|
||||
*
|
||||
* @param element {@link Element} being parsed.
|
||||
* @param parserContext {@link ParserContext} used capture contextual information while parsing.
|
||||
*/
|
||||
private void registerGemfireFunctionBeanPostProcessor(Element element, ParserContext parserContext) {
|
||||
AbstractBeanDefinition gemfireFunctionBeanPostProcessor = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(GemfireFunctionBeanPostProcessor.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition();
|
||||
|
||||
gemfireFunctionBeanPostProcessor.setSource(parserContext.extractSource(element));
|
||||
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(gemfireFunctionBeanPostProcessor,
|
||||
parserContext.getRegistry());
|
||||
}
|
||||
}
|
||||
@@ -13,33 +13,40 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Bean definition parse for the <gfe:async-event-queue> SDG XML namespace element.
|
||||
* Bean definition parser for the <gfe:async-event-queue> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean
|
||||
*/
|
||||
class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return AsyncEventQueueFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
@@ -82,8 +89,8 @@ class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseAsyncEventListener(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
Element asyncEventListenerElement = DomUtils.getChildElementByTagName(element, "async-event-listener");
|
||||
|
||||
Object asyncEventListener = ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext,
|
||||
@@ -96,15 +103,16 @@ class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseCache(Element element, BeanDefinitionBuilder builder) {
|
||||
String cacheRefAttribute = element.getAttribute("cache-ref");
|
||||
|
||||
String cacheName = (StringUtils.hasText(cacheRefAttribute) ? cacheRefAttribute
|
||||
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
|
||||
String cacheName = SpringUtils.defaultIfEmpty(cacheRefAttribute,
|
||||
GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
|
||||
|
||||
builder.addConstructorArgReference(cacheName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseDiskStore(Element element, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyValue(element, builder, "disk-store-ref");
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -22,34 +22,37 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* The AutoRegionLookupBeanDefinitionParser class is a Spring BeanDefinitionParser that registers a BeanPostProcessor
|
||||
* that auto registers Regions defined in GemFire's native cache.xml format, or when using GemFire 8's cluster-based
|
||||
* configuration service to define Regions, creating corresponding beans in the Spring context.
|
||||
* Bean definition parser for the <gfe:auto-region-lookup> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* This parser will register a Spring {@link org.springframework.beans.factory.config.BeanPostProcessor)
|
||||
* that discovers all Regions defined in GemFire's native {@literal cache.xml} file, or when using
|
||||
* GemFire 8's cluster-based configuration service to define Regions, to create corresponding beans
|
||||
* in the Spring application context.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.BeanDefinitionParser
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.springframework.data.gemfire.config.AutoRegionLookupBeanPostProcessor
|
||||
* @see org.w3c.dom.Element
|
||||
* @see org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class AutoRegionLookupBeanDefinitionParser implements BeanDefinitionParser {
|
||||
class AutoRegionLookupParser implements BeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BeanDefinition parse(final Element element, final ParserContext parserContext) {
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
registerAutoRegionLookupBeanPostProcessor(element, parserContext);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void registerAutoRegionLookupBeanPostProcessor(final Element element, final ParserContext parserContext) {
|
||||
/* (non-Javadoc) */
|
||||
private void registerAutoRegionLookupBeanPostProcessor(Element element, ParserContext parserContext) {
|
||||
AbstractBeanDefinition autoRegionLookupBeanPostProcessor = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(AutoRegionLookupBeanPostProcessor.class)
|
||||
.rootBeanDefinition(AutoRegionLookupBeanPostProcessor.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition();
|
||||
|
||||
@@ -58,5 +61,4 @@ class AutoRegionLookupBeanDefinitionParser implements BeanDefinitionParser {
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(autoRegionLookupBeanPostProcessor,
|
||||
parserContext.getRegistry());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.gemstone.gemfire.internal.datasource.ConfigProperty;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
@@ -28,7 +30,9 @@ import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.config.support.CustomEditorBeanFactoryPostProcessor;
|
||||
import org.springframework.data.gemfire.config.support.GemfireFeature;
|
||||
import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
@@ -36,23 +40,29 @@ import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
|
||||
import com.gemstone.gemfire.internal.datasource.ConfigProperty;
|
||||
|
||||
/**
|
||||
* Parser for <cache> bean definitions.
|
||||
*
|
||||
* Bean definition parser for the <gfe:cache> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Oliver Gierke
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
*/
|
||||
class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return CacheFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
@@ -119,9 +129,10 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
/* (non-Javadoc) */
|
||||
void registerGemFireBeanFactoryPostProcessors(BeanDefinitionRegistry registry) {
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(BeanDefinitionBuilder.genericBeanDefinition(
|
||||
CustomEditorRegisteringBeanFactoryPostProcessor.class).getBeanDefinition(), registry);
|
||||
CustomEditorBeanFactoryPostProcessor.class).getBeanDefinition(), registry);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyValue(element, builder, "pdx-disk-store", "pdxDiskStoreName");
|
||||
|
||||
@@ -138,6 +149,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(pdxDiskStoreName), registry);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private AbstractBeanDefinition createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(String pdxDiskStoreName) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
PdxDiskStoreAwareBeanFactoryPostProcessor.class);
|
||||
@@ -145,6 +157,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseDynamicRegionFactory(Element element, BeanDefinitionBuilder builder) {
|
||||
Element dynamicRegionFactory = DomUtils.getChildElementByTagName(element, "dynamic-region-factory");
|
||||
|
||||
@@ -155,6 +168,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private BeanDefinitionBuilder buildDynamicRegionSupport(Element dynamicRegionFactory) {
|
||||
if (dynamicRegionFactory != null) {
|
||||
BeanDefinitionBuilder dynamicRegionSupport = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
@@ -185,11 +199,12 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dynamicRegionSupport BDB for <dynamic-region-factory> element.
|
||||
* @param dynamicRegionSupport {@link BeanDefinitionBuilder} for <gfe:dynamic-region-factory> element.
|
||||
*/
|
||||
protected void postProcessDynamicRegionSupport(Element element, BeanDefinitionBuilder dynamicRegionSupport) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseJndiBindings(Element element, BeanDefinitionBuilder builder) {
|
||||
List<Element> jndiBindings = DomUtils.getChildElementsByTagName(element, "jndi-binding");
|
||||
|
||||
@@ -240,6 +255,9 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
@@ -253,5 +271,4 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -22,48 +22,49 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Namespace parser for "cache-server" element.
|
||||
* Bean definition parser for the <gfe:cache-server< SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return CacheServerFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
String name = super.resolveId(element, definition, parserContext);
|
||||
return (StringUtils.hasText(name) ? name : "gemfireServer");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
|
||||
return (super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName())
|
||||
&& !"cache-ref".equals(attribute.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
String cacheRefAttribute = element.getAttribute("cache-ref");
|
||||
String cacheRefAttribute = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME);
|
||||
|
||||
builder.addPropertyReference("cache", (StringUtils.hasText(cacheRefAttribute) ? cacheRefAttribute
|
||||
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
builder.addPropertyReference("cache", SpringUtils.defaultIfEmpty(
|
||||
cacheRefAttribute, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
|
||||
String groupsAttribute = element.getAttribute("groups");
|
||||
|
||||
@@ -74,6 +75,7 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
parseSubscription(element, builder);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseSubscription(Element element, BeanDefinitionBuilder builder) {
|
||||
Element subscriptionConfigElement = DomUtils.getChildElementByTagName(element, "subscription-config");
|
||||
|
||||
@@ -89,4 +91,14 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
|
||||
String name = super.resolveId(element, definition, parserContext);
|
||||
return (StringUtils.hasText(name) ? name : "gemfireServer");
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -22,23 +22,32 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <client-cache;gt; definitions.
|
||||
*
|
||||
* Bean definition parser for the <gfe:client-cache> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author Lyndon Adams
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see CacheParser
|
||||
*/
|
||||
class ClientCacheParser extends CacheParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return ClientCacheFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "durable-client-id");
|
||||
ParsingUtils.setPropertyValue(element, builder, "durable-client-timeout");
|
||||
ParsingUtils.setPropertyValue(element, builder, "keep-alive");
|
||||
@@ -46,9 +55,11 @@ class ClientCacheParser extends CacheParser {
|
||||
ParsingUtils.setPropertyValue(element, builder, "ready-for-events");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void postProcessDynamicRegionSupport(Element element, BeanDefinitionBuilder dynamicRegionSupport) {
|
||||
ParsingUtils.setPropertyValue(element, dynamicRegionSupport, "pool-name");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,21 +30,29 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <client-region;gt; bean definitions.
|
||||
* Bean definition parser for the <gfe:client-region> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* To avoid eager evaluations, the region interests are declared as nested definition.
|
||||
* To avoid eager evaluations, Region interests are declared as nested bean definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
|
||||
* @see AbstractRegionParser
|
||||
*/
|
||||
class ClientRegionParser extends AbstractRegionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return ClientRegionFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder,
|
||||
boolean subRegion) {
|
||||
@@ -72,7 +80,7 @@ class ClientRegionParser extends AbstractRegionParser {
|
||||
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
RegionAttributesFactoryBean.class);
|
||||
|
||||
mergeTemplateRegionAttributes(element, parserContext, regionBuilder, regionAttributesBuilder);
|
||||
mergeRegionTemplateAttributes(element, parserContext, regionBuilder, regionAttributesBuilder);
|
||||
|
||||
ParsingUtils.parseOptionalRegionAttributes(parserContext, element, regionAttributesBuilder);
|
||||
ParsingUtils.parseStatistics(element, regionAttributesBuilder);
|
||||
@@ -118,7 +126,8 @@ class ClientRegionParser extends AbstractRegionParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseDiskStoreAttribute(final Element element, final BeanDefinitionBuilder builder) {
|
||||
/* (non-Javadoc) */
|
||||
private void parseDiskStoreAttribute(Element element, BeanDefinitionBuilder builder) {
|
||||
String diskStoreRefAttribute = element.getAttribute("disk-store-ref");
|
||||
|
||||
if (StringUtils.hasText(diskStoreRefAttribute)) {
|
||||
@@ -127,12 +136,14 @@ class ClientRegionParser extends AbstractRegionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseCommonInterestAttributes(Element element, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyValue(element, builder, "durable", "durable");
|
||||
ParsingUtils.setPropertyValue(element, builder, "result-policy", "policy");
|
||||
ParsingUtils.setPropertyValue(element, builder, "receive-values", "receiveValues");
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private Object parseKeyInterest(Element keyInterestElement, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder keyInterestBuilder = BeanDefinitionBuilder.genericBeanDefinition(Interest.class);
|
||||
|
||||
@@ -143,6 +154,7 @@ class ClientRegionParser extends AbstractRegionParser {
|
||||
return keyInterestBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private Object parseRegexInterest(Element regexInterestElement) {
|
||||
BeanDefinitionBuilder regexInterestBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegexInterest.class);
|
||||
|
||||
@@ -151,5 +163,4 @@ class ClientRegionParser extends AbstractRegionParser {
|
||||
|
||||
return regexInterestBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -27,29 +28,28 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean.DiskDir;
|
||||
import org.springframework.data.gemfire.config.support.DiskStoreBeanPostProcessor;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <disk-store> bean definitions.
|
||||
* Bean definition parser for the <gfe:disk-store> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.DiskStoreFactoryBean
|
||||
* @see org.w3c.dom.Element
|
||||
*/
|
||||
public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
private static final AtomicBoolean registered = new AtomicBoolean(false);
|
||||
private static final AtomicBoolean REGISTERED = new AtomicBoolean(false);
|
||||
|
||||
private static void registerDiskStoreBeanPostProcessor(final ParserContext parserContext) {
|
||||
if (registered.compareAndSet(false, true)) {
|
||||
/* (non-Javadoc) */
|
||||
private static void registerDiskStoreBeanPostProcessor(ParserContext parserContext) {
|
||||
if (REGISTERED.compareAndSet(false, true)) {
|
||||
AbstractBeanDefinition diskStoreBeanPostProcessor = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DiskStoreBeanPostProcessor.class)
|
||||
.rootBeanDefinition(DiskStoreBeanPostProcessor.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition();
|
||||
|
||||
@@ -58,11 +58,17 @@ public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DiskStoreFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
@@ -102,5 +108,4 @@ public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
builder.addPropertyValue("diskDirs", diskDirs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -22,26 +22,35 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.FunctionServiceFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <function-service;gt; definitions.
|
||||
* Bean definition parser for the <gfe:function-service> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.FunctionServiceFactoryBean
|
||||
*/
|
||||
class FunctionServiceParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FunctionServiceFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
|
||||
builder.setLazyInit(false);
|
||||
|
||||
Element functionElement = DomUtils.getChildElementByTagName(element, "function");
|
||||
@@ -52,12 +61,15 @@ class FunctionServiceParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
protected String resolveId(Element element, AbstractBeanDefinition beanDefinition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
|
||||
String resolvedId = super.resolveId(element, definition, parserContext);
|
||||
return (StringUtils.hasText(resolvedId) ? resolvedId : GemfireConstants.DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME);
|
||||
}
|
||||
String resolvedId = super.resolveId(element, beanDefinition, parserContext);
|
||||
|
||||
return SpringUtils.defaultIfEmpty(resolvedId, GemfireConstants.DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME);
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Spring BeanDefinitionParser for the <gfe:gateway-receiver> SDG (GFE) XML XSD namespace element.
|
||||
* Bean definition parser for the <gfe:gateway-receiver> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
@@ -32,17 +33,24 @@ import org.w3c.dom.Element;
|
||||
*/
|
||||
class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return GatewayReceiverFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String cacheRef = element.getAttribute("cache-ref");
|
||||
String cacheRef = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME);
|
||||
|
||||
builder.addConstructorArgReference(SpringUtils.defaultIfEmpty(
|
||||
cacheRef, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
|
||||
builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef
|
||||
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
builder.setLazyInit(false);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "bind-address");
|
||||
@@ -54,5 +62,4 @@ class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser {
|
||||
ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size");
|
||||
ParsingUtils.parseTransportFilters(element, parserContext, builder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,35 +13,45 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Bean definition parser for the <gfe:gateway-sender> element in the SDG XML namespace.
|
||||
* Bean definition parser for the <gfe:gateway-sender> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean
|
||||
*/
|
||||
class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return GatewaySenderFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
parseCache(element, builder);
|
||||
String cacheRef = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME);
|
||||
|
||||
builder.addConstructorArgReference(SpringUtils.defaultIfEmpty(
|
||||
cacheRef, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, NAME_ATTRIBUTE);
|
||||
ParsingUtils.setPropertyValue(element, builder, "alert-threshold");
|
||||
@@ -97,12 +107,4 @@ class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCache(final Element element, final BeanDefinitionBuilder builder) {
|
||||
String cacheRef = element.getAttribute("cache-ref");
|
||||
|
||||
builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef
|
||||
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
/**
|
||||
* The GemfireConstants class define constants for Spring GemFire component bean names.
|
||||
@@ -24,13 +24,10 @@ package org.springframework.data.gemfire.config;
|
||||
@SuppressWarnings("unused")
|
||||
public interface GemfireConstants {
|
||||
|
||||
static final String DEFAULT_GEMFIRE_CACHE_NAME = "gemfireCache";
|
||||
static final String DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE = "gemfireIndexDefinitionQueryService";
|
||||
static final String DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME = "gemfireFunctionService";
|
||||
static final String DEFAULT_GEMFIRE_POOL_NAME = "gemfirePool";
|
||||
static final String DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME = "gemfireTransactionManager";
|
||||
|
||||
@Deprecated
|
||||
static final String DEFAULT_GEMFIRE_TXMANAGER_NAME = DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME;
|
||||
String DEFAULT_GEMFIRE_CACHE_NAME = "gemfireCache";
|
||||
String DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE = "gemfireIndexDefinitionQueryService";
|
||||
String DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME = "gemfireFunctionService";
|
||||
String DEFAULT_GEMFIRE_POOL_NAME = "gemfirePool";
|
||||
String DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME = "gemfireTransactionManager";
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
import org.springframework.data.gemfire.function.config.FunctionExecutionBeanDefinitionParser;
|
||||
@@ -23,18 +23,22 @@ import org.springframework.data.repository.config.RepositoryBeanDefinitionParser
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
|
||||
/**
|
||||
* Namespace handler for GemFire definitions.
|
||||
*
|
||||
* Spring {@link org.springframework.beans.factory.xml.NamespaceHandler} for Spring Data GemFire
|
||||
* XML namespace (XSD) bean definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author Oliver Gierke
|
||||
* @author John Blum
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
class GemfireDataNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
// Repository namespace
|
||||
RepositoryConfigurationExtension extension = new GemfireRepositoryConfigurationExtension();
|
||||
registerBeanDefinitionParser("datasource", new GemfireDataSourceParser());
|
||||
registerBeanDefinitionParser("function-executions", new FunctionExecutionBeanDefinitionParser());
|
||||
@@ -1,16 +1,17 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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;
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -25,8 +26,14 @@ import org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Bean definition parser for the <gfe-data:datasource> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor
|
||||
* @see ClientCacheParser
|
||||
* @see PoolParser
|
||||
*/
|
||||
class GemfireDataSourceParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
@@ -35,8 +42,8 @@ class GemfireDataSourceParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
@@ -69,5 +76,4 @@ class GemfireDataSourceParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,18 +31,26 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for SGF <code><cq-listener-container></code> element.
|
||||
*
|
||||
* Bean definition parser for the <gfe:cq-listener-container> element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer
|
||||
*/
|
||||
class GemfireListenerContainerParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<ContinuousQueryListenerContainer> getBeanClass(Element element) {
|
||||
return ContinuousQueryListenerContainer.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache", "cache");
|
||||
@@ -67,10 +75,13 @@ class GemfireListenerContainerParser extends AbstractSingleBeanDefinitionParser
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a listener definition. Returns the listener bean reference definition (of a {@link ContinuousQueryDefinition}).
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
* Parses a listener bean definition. Returns the listener bean definition
|
||||
* (of type {@link ContinuousQueryDefinition)).
|
||||
*
|
||||
* @param element XML DOM {@link Element} to parse.
|
||||
* @return a Spring {@link BeanDefinition} for the GemFire Continuous Query (CQ) listener configuration.
|
||||
* @see org.springframework.beans.factory.xml.BeanDefinition
|
||||
* @see org.w3c.dom.Element
|
||||
*/
|
||||
private BeanDefinition parseListener(Element element) {
|
||||
BeanDefinitionBuilder continuousQueryListenerBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
@@ -104,5 +115,4 @@ class GemfireListenerContainerParser extends AbstractSingleBeanDefinitionParser
|
||||
|
||||
return continuousQueryBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,16 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Spring NamespaceHandler for GemFire XML namespace (XSD) bean definitions.
|
||||
*
|
||||
* Spring {@link org.springframework.beans.factory.xml.NamespaceHandler} for Spring GemFire
|
||||
* XML namespace (XSD) bean definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
@@ -32,38 +30,31 @@ import org.w3c.dom.Element;
|
||||
@SuppressWarnings("unused")
|
||||
class GemfireNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
ParsingUtils.assertGemFireFeatureAvailable(element, parserContext);
|
||||
return super.parse(element, parserContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenParser());
|
||||
registerBeanDefinitionParser("async-event-queue", new AsyncEventQueueParser());
|
||||
registerBeanDefinitionParser("auto-region-lookup", new AutoRegionLookupParser());
|
||||
registerBeanDefinitionParser("cache", new CacheParser());
|
||||
registerBeanDefinitionParser("cache-server", new CacheServerParser());
|
||||
registerBeanDefinitionParser("auto-region-lookup", new AutoRegionLookupBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("lookup-region", new LookupRegionParser());
|
||||
registerBeanDefinitionParser("region-template", new TemplateRegionParser());
|
||||
registerBeanDefinitionParser("local-region", new LocalRegionParser());
|
||||
registerBeanDefinitionParser("local-region-template", new LocalRegionParser());
|
||||
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
|
||||
registerBeanDefinitionParser("partitioned-region-template", new PartitionedRegionParser());
|
||||
registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser());
|
||||
registerBeanDefinitionParser("replicated-region-template", new ReplicatedRegionParser());
|
||||
registerBeanDefinitionParser("async-event-queue", new AsyncEventQueueParser());
|
||||
registerBeanDefinitionParser("client-cache", new ClientCacheParser());
|
||||
registerBeanDefinitionParser("client-region", new ClientRegionParser());
|
||||
registerBeanDefinitionParser("client-region-template", new ClientRegionParser());
|
||||
registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser());
|
||||
registerBeanDefinitionParser("disk-store", new DiskStoreParser());
|
||||
registerBeanDefinitionParser("function-service", new FunctionServiceParser());
|
||||
registerBeanDefinitionParser("gateway-receiver", new GatewayReceiverParser());
|
||||
registerBeanDefinitionParser("gateway-sender", new GatewaySenderParser());
|
||||
registerBeanDefinitionParser("index", new IndexParser());
|
||||
registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser());
|
||||
registerBeanDefinitionParser("client-cache", new ClientCacheParser());
|
||||
registerBeanDefinitionParser("client-region", new ClientRegionParser());
|
||||
registerBeanDefinitionParser("client-region-template", new ClientRegionParser());
|
||||
registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser());
|
||||
registerBeanDefinitionParser("local-region", new LocalRegionParser());
|
||||
registerBeanDefinitionParser("local-region-template", new LocalRegionParser());
|
||||
registerBeanDefinitionParser("lookup-region", new LookupRegionParser());
|
||||
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
|
||||
registerBeanDefinitionParser("partitioned-region-template", new PartitionedRegionParser());
|
||||
registerBeanDefinitionParser("pool", new PoolParser());
|
||||
registerBeanDefinitionParser("region-template", new TemplateRegionParser());
|
||||
registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser());
|
||||
registerBeanDefinitionParser("replicated-region-template", new ReplicatedRegionParser());
|
||||
registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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;
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.aop.config.AopNamespaceUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -24,30 +27,40 @@ import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* Bean definition parser for the <gfe-data:json-region-auto-proxy< SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.BeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.support.JSONRegionAdvice
|
||||
*/
|
||||
public class GemfireRegionAutoProxyParser implements BeanDefinitionParser {
|
||||
class GemfireRegionAutoProxyParser implements BeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(parserContext, element);
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(JSONRegionAdvice.class);
|
||||
ParsingUtils.setPropertyValue(element, builder, "pretty-print");
|
||||
ParsingUtils.setPropertyValue(element, builder, "convert-returned-collections");
|
||||
|
||||
BeanDefinitionBuilder jsonRegionAdviceBuilder = BeanDefinitionBuilder.rootBeanDefinition(
|
||||
JSONRegionAdvice.class).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, jsonRegionAdviceBuilder, "pretty-print");
|
||||
ParsingUtils.setPropertyValue(element, jsonRegionAdviceBuilder, "convert-returned-collections");
|
||||
|
||||
String regionNames = element.getAttribute("included-regions");
|
||||
|
||||
if (StringUtils.hasText(regionNames)) {
|
||||
String[] regions = StringUtils.commaDelimitedListToStringArray(regionNames);
|
||||
ManagedList<String> regionList = new ManagedList<String>(regions.length);
|
||||
for (String regionRef : regions) {
|
||||
regionList.add(regionRef);
|
||||
}
|
||||
builder.addPropertyValue("includedRegions", regionList);
|
||||
Collections.addAll(regionList, regions);
|
||||
jsonRegionAdviceBuilder.addPropertyValue("includedRegions", regionList);
|
||||
}
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
return builder.getBeanDefinition();
|
||||
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(jsonRegionAdviceBuilder.getBeanDefinition(),
|
||||
parserContext.getRegistry());
|
||||
|
||||
return jsonRegionAdviceBuilder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -25,26 +25,27 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.IndexFactoryBean;
|
||||
import org.springframework.data.gemfire.config.support.DefinedIndexesApplicationListener;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Namespace parser for <index;gt; bean definitions.
|
||||
*
|
||||
* Bean definition parser for <gfe:index> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class IndexParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
private static final AtomicBoolean registered = new AtomicBoolean(false);
|
||||
private static final AtomicBoolean REGISTERED = new AtomicBoolean(false);
|
||||
|
||||
protected static void registerCreateDefinedIndexesApplicationListener(ParserContext parserContext) {
|
||||
if (registered.compareAndSet(false, true)) {
|
||||
/* (non-Javadoc) */
|
||||
protected static void registerDefinedIndexesApplicationListener(ParserContext parserContext) {
|
||||
if (REGISTERED.compareAndSet(false, true)) {
|
||||
AbstractBeanDefinition createDefinedIndexesApplicationListener = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(CreateDefinedIndexesApplicationListener.class)
|
||||
.rootBeanDefinition(DefinedIndexesApplicationListener.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition();
|
||||
|
||||
@@ -53,20 +54,27 @@ class IndexParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return IndexFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
registerDefinedIndexesApplicationListener(parserContext);
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return (!"cache-ref".equals(attributeName) && super.isEligibleAttribute(attributeName));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
registerCreateDefinedIndexesApplicationListener(parserContext);
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
super.doParse(element, parserContext, builder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -23,18 +23,26 @@ import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <local-region> bean definitions.
|
||||
* Bean definition parser for the <gfe:local-region> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.LocalRegionFactoryBean
|
||||
* @see AbstractRegionParser
|
||||
*/
|
||||
class LocalRegionParser extends AbstractRegionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return LocalRegionFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion) {
|
||||
@@ -44,9 +52,8 @@ class LocalRegionParser extends AbstractRegionParser {
|
||||
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
RegionAttributesFactoryBean.class);
|
||||
|
||||
doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
|
||||
doParseRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
|
||||
|
||||
builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -26,28 +26,35 @@ import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
/**
|
||||
* Parser for GFE <lookup-region> bean definitions.
|
||||
* Bean definition parser for the <gfe:lookup-region> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.LookupRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.AbstractRegionParser
|
||||
* @see AbstractRegionParser
|
||||
*/
|
||||
class LookupRegionParser extends AbstractRegionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return LookupRegionFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion) {
|
||||
|
||||
super.doParse(element, builder);
|
||||
|
||||
String resolvedCacheRef = ParsingUtils.resolveCacheReference(element.getAttribute("cache-ref"));
|
||||
String resolvedCacheRef = ParsingUtils.resolveCacheReference(
|
||||
element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME));
|
||||
|
||||
builder.addPropertyReference("cache", resolvedCacheRef);
|
||||
|
||||
@@ -87,5 +94,4 @@ class LookupRegionParser extends AbstractRegionParser {
|
||||
parseSubRegions(element, parserContext, resolvedCacheRef);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,10 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.gemstone.gemfire.cache.LossAction;
|
||||
import com.gemstone.gemfire.cache.MembershipAttributes;
|
||||
import com.gemstone.gemfire.cache.ResumptionAction;
|
||||
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
@@ -30,14 +34,11 @@ import org.springframework.data.gemfire.ExpirationAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.SubscriptionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.config.support.GemfireFeature;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.gemstone.gemfire.cache.LossAction;
|
||||
import com.gemstone.gemfire.cache.MembershipAttributes;
|
||||
import com.gemstone.gemfire.cache.ResumptionAction;
|
||||
|
||||
/**
|
||||
* Utilities used by the Spring Data GemFire XML Namespace parsers.
|
||||
*
|
||||
@@ -110,19 +111,19 @@ abstract class ParsingUtils {
|
||||
|
||||
/**
|
||||
* Utility method handling parsing of nested definition of the type:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* <tag ref="someBean"/>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* or
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* <tag>
|
||||
* <bean .... />
|
||||
* </tag>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param element the XML element.
|
||||
* @return Bean reference or nested Bean definition.
|
||||
*/
|
||||
@@ -237,7 +238,7 @@ abstract class ParsingUtils {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the subscription sub-element. Populates the given attribute factory with the proper attributes.
|
||||
*
|
||||
@@ -336,7 +337,7 @@ abstract class ParsingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
static void parseMembershipAttributes(ParserContext parserContext, Element element,
|
||||
BeanDefinitionBuilder regionAttributesBuilder) {
|
||||
|
||||
@@ -389,7 +390,7 @@ abstract class ParsingUtils {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean parseCustomExpiration(Element rootElement, ParserContext parserContext, String elementName,
|
||||
String propertyName, BeanDefinitionBuilder regionAttributesBuilder) {
|
||||
Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName);
|
||||
@@ -415,6 +416,7 @@ abstract class ParsingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static void assertGemFireFeatureAvailable(Element element, ParserContext parserContext) {
|
||||
if (GemfireUtils.isGemfireFeatureUnavailable(element)) {
|
||||
parserContext.getReaderContext().error(String.format("'%1$s' is not supported in %2$s v%3$s",
|
||||
@@ -431,7 +433,7 @@ abstract class ParsingUtils {
|
||||
}
|
||||
|
||||
static String resolveCacheReference(String cacheReference) {
|
||||
return (StringUtils.hasText(cacheReference) ? cacheReference : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
|
||||
return SpringUtils.defaultIfEmpty(cacheReference, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
|
||||
}
|
||||
|
||||
static void setRegionReference(Element element, BeanDefinitionBuilder builder) {
|
||||
@@ -454,5 +456,4 @@ abstract class ParsingUtils {
|
||||
messagePrefix, GemfireUtils.GEMFIRE_VERSION), null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,21 +33,29 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <partitioned-region> bean definitions.
|
||||
* Bean definition parser for the <gfe:partitioned-region> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* To avoid eager evaluations, the region attributes are declared as a nested definition.
|
||||
* To avoid eager evaluations, Region attributes are declared as a nested bean definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
|
||||
* @see AbstractRegionParser
|
||||
*/
|
||||
class PartitionedRegionParser extends AbstractRegionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return PartitionedRegionFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder,
|
||||
@@ -58,7 +66,7 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
RegionAttributesFactoryBean.class);
|
||||
|
||||
doParseCommonRegionConfiguration(element, parserContext, regionBuilder, regionAttributesBuilder, subRegion);
|
||||
doParseRegionConfiguration(element, parserContext, regionBuilder, regionAttributesBuilder, subRegion);
|
||||
|
||||
regionBuilder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
|
||||
|
||||
@@ -110,6 +118,7 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
regionAttributesBuilder.addPropertyValue("partitionAttributes", partitionAttributesBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
void mergeTemplateRegionPartitionAttributes(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder partitionAttributesBuilder) {
|
||||
|
||||
@@ -143,6 +152,7 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void parseColocatedWith(Element element, BeanDefinitionBuilder regionBuilder,
|
||||
BeanDefinitionBuilder partitionAttributesBuilder, String attributeName) {
|
||||
// NOTE rather than using a dependency (with depends-on) we could also set the colocatedWith property of the
|
||||
@@ -160,14 +170,17 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private Object parsePartitionResolver(Element subElement, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
|
||||
return ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, subElement, builder);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private Object parsePartitionListeners(Element subElement, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
|
||||
return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.config.support.ClientRegionPoolBeanFactoryPostProcessor;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
@@ -39,14 +40,11 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <gfe:pool> bean definitions.
|
||||
* Bean definition parser for the <gfe:pool> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionRegistry
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.client.PoolFactoryBean
|
||||
*/
|
||||
@@ -69,7 +67,7 @@ class PoolParser extends AbstractSingleBeanDefinitionParser {
|
||||
static void registerInfrastructureComponents(ParserContext parserContext) {
|
||||
if (INFRASTRUCTURE_COMPONENTS_REGISTERED.compareAndSet(false, true)) {
|
||||
AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(ClientRegionAndPoolBeanFactoryPostProcessor.class)
|
||||
.rootBeanDefinition(ClientRegionPoolBeanFactoryPostProcessor.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
.getBeanDefinition();
|
||||
|
||||
@@ -77,11 +75,17 @@ class PoolParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return PoolFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -23,19 +23,27 @@ import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <replicated-region;gt; definitions.
|
||||
* Bean definition parser for the <gfe:replicated-region> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean
|
||||
* @see AbstractRegionParser
|
||||
*/
|
||||
class ReplicatedRegionParser extends AbstractRegionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return ReplicatedRegionFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion) {
|
||||
@@ -47,9 +55,8 @@ class ReplicatedRegionParser extends AbstractRegionParser {
|
||||
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
RegionAttributesFactoryBean.class);
|
||||
|
||||
doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
|
||||
doParseRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
|
||||
|
||||
builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
@@ -26,23 +26,26 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <gfe-data:snapshot-service> bean definition elements in Spring XML config.
|
||||
* Bean definition parser for the <gfe-data:snapshot-service> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(final Element element) {
|
||||
return SnapshotServiceFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
@@ -54,14 +57,17 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser {
|
||||
builder.addPropertyValue("imports", parseImports(element, parserContext));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private ManagedList<BeanDefinition> parseExports(Element element, ParserContext parserContext) {
|
||||
return parseSnapshots(element, parserContext, "snapshot-export");
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private ManagedList<BeanDefinition> parseImports(Element element, ParserContext parserContext) {
|
||||
return parseSnapshots(element, parserContext, "snapshot-import");
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private ManagedList<BeanDefinition> parseSnapshots(Element element, ParserContext parserContext,
|
||||
String childTagName) {
|
||||
|
||||
@@ -74,6 +80,7 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser {
|
||||
return snapshotBeans;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private BeanDefinition parseSnapshotMetadata(Element snapshotMetadataElement, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder snapshotMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
SnapshotServiceFactoryBean.SnapshotMetadata.class);
|
||||
@@ -90,8 +97,8 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser {
|
||||
return snapshotMetadataBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private boolean isSnapshotFilterSpecified(final Element snapshotMetadataElement) {
|
||||
return (snapshotMetadataElement.hasAttribute("filter-ref") || snapshotMetadataElement.hasChildNodes());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -23,31 +23,34 @@ import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* The TemplateRegionParser class is a generic Region parser used to parse Region Template bean definitions in the
|
||||
* Spring context configuration meta-data to encapsulate common Region 'attribute' configuration irrespective of the
|
||||
* Region's Data Policy (e.g. REPLICATE, PARTITION).
|
||||
* Bean definition parser for <gfe:*-region-template> SDG XML namespace (XSD) elements.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.RegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.AbstractRegionParser
|
||||
* @see AbstractRegionParser
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class TemplateRegionParser extends AbstractRegionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return RegionFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion) {
|
||||
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
RegionAttributesFactoryBean.class);
|
||||
|
||||
doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
|
||||
doParseRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
|
||||
|
||||
builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -26,33 +26,41 @@ import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <transaction-manager> element bean definitions.
|
||||
*
|
||||
* Bean definition parser for the <gfe:transaction-manager> SDG XML namespace (XSD) element.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.GemfireTransactionManager
|
||||
*/
|
||||
class TransactionManagerParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return GemfireTransactionManager.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "copy-on-read", "copyOnRead");
|
||||
|
||||
String attr = element.getAttribute("cache-ref");
|
||||
// add cache reference (fallback to default if nothing is specified)
|
||||
builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
|
||||
|
||||
builder.addPropertyReference("cache", ParsingUtils.resolveCacheReference(element));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
|
||||
String name = super.resolveId(element, definition, parserContext);
|
||||
|
||||
if (!StringUtils.hasText(name)) {
|
||||
@@ -64,5 +72,4 @@ class TransactionManagerParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* This package provides classes and components for configuring GemFire using Spring Data GemFire's XML namespace
|
||||
* support. See more details here...
|
||||
* This package provides classes and components for configuring GemFire using Spring Data GemFire's
|
||||
* XML namespace support. See more details here...
|
||||
*
|
||||
* <a href="http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#_spring_data_gemfire_core_schema_gfe">Spring Data GemFire Core Schema (gfe)</a>
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -14,7 +14,7 @@ package org.springframework.data.gemfire.function.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.gemfire.function.execution.GemfireFunctionProxyFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.data.gemfire.GemfireQueryException;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.client.support.DefaultableDelegatingPoolAdapter;
|
||||
import org.springframework.data.gemfire.client.support.DelegatingPoolAdapter;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
@@ -35,32 +35,32 @@ public abstract class AbstractPropertyEditorConverterSupport<T> extends Property
|
||||
implements Converter<String, T> {
|
||||
|
||||
/**
|
||||
* Asserts that the given String was successfully converted into an instance of Class type T.
|
||||
* Asserts that the given {@link String} was converted into an instance of {@link Class type} T.
|
||||
*
|
||||
* @param source the String to convert.
|
||||
* @param convertedValue the value of the String converted into instance of Class type T.
|
||||
* @param type the target Class type of the converted value.
|
||||
* @return the converted value of Class type T if not null.
|
||||
* @throws java.lang.IllegalArgumentException if the String could not be converted into
|
||||
* an instance of Class type T.
|
||||
* @param source {@link String} to convert.
|
||||
* @param convertedValue converted value of {@link Class type} T.
|
||||
* @param type {@link Class type} of the converted value.
|
||||
* @return the converted value.
|
||||
* @throws java.lang.IllegalArgumentException if the {@link String} could not be converted into
|
||||
* an instance of {@link Class type} T.
|
||||
*/
|
||||
protected T assertConverted(final String source, final T convertedValue, final Class<T> type) {
|
||||
Assert.notNull(convertedValue, String.format("(%1$s) is not a valid %2$s!", source, type.getSimpleName()));
|
||||
protected T assertConverted(String source, T convertedValue, Class<T> type) {
|
||||
Assert.notNull(convertedValue, String.format("[%1$s] is not a valid %2$s", source, type.getSimpleName()));
|
||||
return convertedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this PropertyEditor with the given String converted to the appropriate Class type.
|
||||
* Sets the value of this {@link java.beans.PropertyEditor} to the given {@link String}
|
||||
* converted to the appropriate {@link Class type}.
|
||||
*
|
||||
* @param text the String to convert.
|
||||
* @throws java.lang.IllegalArgumentException if the String could not be converted into
|
||||
* an instance of Class type T.
|
||||
* @param text {@link String} to convert.
|
||||
* @throws java.lang.IllegalArgumentException if the {@link String} could not be converted into
|
||||
* an instance of {@link Class type} T.
|
||||
* @see #convert(Object)
|
||||
* @see #setValue(Object)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(final String text) throws IllegalArgumentException {
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(convert(text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ConnectionEndpointList extends AbstractList<ConnectionEndpoint> {
|
||||
*/
|
||||
public static ConnectionEndpointList parse(int defaultPort, String... hostsPorts) {
|
||||
List<ConnectionEndpoint> connectionEndpoints = new ArrayList<ConnectionEndpoint>(
|
||||
ArrayUtils.length((Object) hostsPorts));
|
||||
ArrayUtils.length(hostsPorts));
|
||||
|
||||
for (String hostPort : ArrayUtils.nullSafeArray(hostsPorts, String.class)) {
|
||||
connectionEndpoints.add(ConnectionEndpoint.parse(hostPort, defaultPort));
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class ArrayUtils {
|
||||
* @return a boolean value indicating whether the given array is empty.
|
||||
* @see #length(Object...)
|
||||
*/
|
||||
public static boolean isEmpty(Object... array) {
|
||||
public static boolean isEmpty(Object[] array) {
|
||||
return (length(array) == 0);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class ArrayUtils {
|
||||
* @param array the array to determine it's length.
|
||||
* @return the length of the given array or 0 if the array reference is null.
|
||||
*/
|
||||
public static int length(Object... array) {
|
||||
public static int length(Object[] array) {
|
||||
return (array != null ? array.length : 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
|
||||
package org.springframework.data.gemfire.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -27,9 +32,22 @@ import org.springframework.util.StringUtils;
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
// TODO rename this utiltiy class using a more intuitive, meaningful name
|
||||
// TODO rename this utiltiy class using a more descriptive, intuitive and meaningful name
|
||||
public abstract class SpringUtils {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static BeanDefinition addDependsOn(BeanDefinition bean, String beanName) {
|
||||
String[] dependsOn = bean.getDependsOn();
|
||||
List<String> dependsOnList = new ArrayList<String>();
|
||||
|
||||
Collections.addAll(dependsOnList, ArrayUtils.nullSafeArray(dependsOn, String.class));
|
||||
|
||||
dependsOnList.add(beanName);
|
||||
bean.setDependsOn(dependsOnList.toArray(new String[dependsOnList.size()]));
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static String defaultIfEmpty(String value, String defaultValue) {
|
||||
return (StringUtils.hasText(value) ? value : defaultValue);
|
||||
@@ -40,6 +58,11 @@ public abstract class SpringUtils {
|
||||
return (value != null ? value : defaultValue);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static boolean equalsIgnoreNull(Object obj1, Object obj2) {
|
||||
return (obj1 == null ? obj2 == null : obj1.equals(obj2));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static String dereferenceBean(String beanName) {
|
||||
return String.format("%1$s%2$s", BeanFactory.FACTORY_BEAN_PREFIX, beanName);
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
http\://www.springframework.org/schema/gemfire=org.springframework.data.gemfire.config.GemfireNamespaceHandler
|
||||
http\://www.springframework.org/schema/data/gemfire=org.springframework.data.gemfire.config.GemfireDataNamespaceHandler
|
||||
http\://www.springframework.org/schema/gemfire=org.springframework.data.gemfire.config.xml.GemfireNamespaceHandler
|
||||
http\://www.springframework.org/schema/data/gemfire=org.springframework.data.gemfire.config.xml.GemfireDataNamespaceHandler
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
|
||||
/**
|
||||
* The EvictionActionTypeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the EvictionActionTypeConverter.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see EvictionActionConverter
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionActionConverterTest {
|
||||
|
||||
private EvictionActionConverter converter = new EvictionActionConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(EvictionAction.LOCAL_DESTROY, converter.convert("local_destroy"));
|
||||
assertEquals(EvictionAction.NONE, converter.convert("None"));
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, converter.convert("OverFlow_TO_dIsk"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid_value) is not a valid EvictionAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("Local_Destroy");
|
||||
assertEquals(EvictionAction.LOCAL_DESTROY, converter.getValue());
|
||||
converter.setAsText("overflow_to_disk");
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("destroy");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(destroy) is not a valid EvictionAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EvictionActionConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.EvictionActionConverter
|
||||
* @see com.gemstone.gemfire.cache.EvictionAction
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionActionConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private EvictionActionConverter converter = new EvictionActionConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("local_destroy")).isEqualTo(EvictionAction.LOCAL_DESTROY);
|
||||
assertThat(converter.convert("None")).isEqualTo(EvictionAction.NONE);
|
||||
assertThat(converter.convert("OverFlow_TO_dIsk")).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[invalid_value] is not a valid EvictionAction");
|
||||
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("Local_Destroy");
|
||||
assertThat(converter.getValue()).isEqualTo(EvictionAction.LOCAL_DESTROY);
|
||||
converter.setAsText("overflow_to_disk");
|
||||
assertThat(converter.getValue()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[destroy] is not a valid EvictionAction");
|
||||
|
||||
converter.setAsText("destroy");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* The EvictionTypeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the EvictionTypeConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.EvictionPolicyConverter
|
||||
* @see org.springframework.data.gemfire.EvictionPolicyType
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionPolicyConverterTest {
|
||||
|
||||
private final EvictionPolicyConverter converter = new EvictionPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(EvictionPolicyType.ENTRY_COUNT, converter.convert("entry_count"));
|
||||
assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, converter.convert("Heap_Percentage"));
|
||||
assertEquals(EvictionPolicyType.MEMORY_SIZE, converter.convert("MEMorY_SiZe"));
|
||||
assertEquals(EvictionPolicyType.NONE, converter.convert("NONE"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("LIFO_MEMORY");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(LIFO_MEMORY) is not a valid EvictionPolicyType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("heap_percentage");
|
||||
assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, converter.getValue());
|
||||
converter.setAsText("NOne");
|
||||
assertEquals(EvictionPolicyType.NONE, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("LRU_COUNT");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(LRU_COUNT) is not a valid EvictionPolicyType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EvictionPolicyConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.EvictionPolicyConverter
|
||||
* @see org.springframework.data.gemfire.EvictionPolicyType
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionPolicyConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final EvictionPolicyConverter converter = new EvictionPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("entry_count")).isEqualTo(EvictionPolicyType.ENTRY_COUNT);
|
||||
assertThat(converter.convert("Heap_Percentage")).isEqualTo(EvictionPolicyType.HEAP_PERCENTAGE);
|
||||
assertThat(converter.convert("MEMorY_SiZe")).isEqualTo(EvictionPolicyType.MEMORY_SIZE);
|
||||
assertThat(converter.convert("NONE")).isEqualTo(EvictionPolicyType.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[LIFO_MEMORY] is not a valid EvictionPolicyType");
|
||||
|
||||
converter.convert("LIFO_MEMORY");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("heap_percentage");
|
||||
assertThat(converter.getValue()).isEqualTo(EvictionPolicyType.HEAP_PERCENTAGE);
|
||||
converter.setAsText("NOne");
|
||||
assertThat(converter.getValue()).isEqualTo(EvictionPolicyType.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[LRU_COUNT] is not a valid EvictionPolicyType");
|
||||
|
||||
converter.setAsText("LRU_COUNT");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
|
||||
/**
|
||||
* The ExpirationActionTypeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the ExpirationActionTypeConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see ExpirationActionConverter
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class ExpirationActionConverterTest {
|
||||
|
||||
private final ExpirationActionConverter converter = new ExpirationActionConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(ExpirationAction.DESTROY, converter.convert("destroy"));
|
||||
assertEquals(ExpirationAction.INVALIDATE, converter.convert("inValidAte"));
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, converter.convert("LOCAL_dEsTrOy"));
|
||||
assertEquals(ExpirationAction.LOCAL_INVALIDATE, converter.convert("Local_Invalidate"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid ExpirationAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
converter.setAsText("InValidAte");
|
||||
assertEquals(ExpirationAction.INVALIDATE, converter.getValue());
|
||||
converter.setAsText("Local_Destroy");
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("destruction");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(destruction) is not a valid ExpirationAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ExpirationActionConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.ExpirationActionConverter
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class ExpirationActionConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final ExpirationActionConverter converter = new ExpirationActionConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("destroy")).isEqualTo(ExpirationAction.DESTROY);
|
||||
assertThat(converter.convert("inValidAte")).isEqualTo(ExpirationAction.INVALIDATE);
|
||||
assertThat(converter.convert("LOCAL_dEsTrOy")).isEqualTo(ExpirationAction.LOCAL_DESTROY);
|
||||
assertThat(converter.convert("Local_Invalidate")).isEqualTo(ExpirationAction.LOCAL_INVALIDATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[illegal_value] is not a valid ExpirationAction");
|
||||
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("InValidAte");
|
||||
assertThat(converter.getValue()).isEqualTo(ExpirationAction.INVALIDATE);
|
||||
converter.setAsText("Local_Destroy");
|
||||
assertThat(converter.getValue()).isEqualTo(ExpirationAction.LOCAL_DESTROY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[destruction] is not a valid ExpirationAction");
|
||||
|
||||
converter.setAsText("destruction");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* The IndexMaintenanceTypeConverterTest class is a test suite of test case testing the contract and functionality
|
||||
* of the IndexMaintenancePolicyConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.IndexMaintenancePolicyConverter
|
||||
* @see org.springframework.data.gemfire.IndexMaintenancePolicyType
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class IndexMaintenancePolicyConverterTest {
|
||||
|
||||
private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(IndexMaintenancePolicyType.ASYNCHRONOUS, converter.convert("asynchronous"));
|
||||
assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, converter.convert("Synchronous"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("sync");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(sync) is not a valid IndexMaintenancePolicyType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
converter.setAsText("aSynchronous");
|
||||
assertEquals(IndexMaintenancePolicyType.ASYNCHRONOUS, converter.getValue());
|
||||
converter.setAsText("synchrONoUS");
|
||||
assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("async");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(async) is not a valid IndexMaintenancePolicyType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link IndexMaintenancePolicyConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.IndexMaintenancePolicyConverter
|
||||
* @see org.springframework.data.gemfire.IndexMaintenancePolicyType
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class IndexMaintenancePolicyConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("asynchronous")).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS);
|
||||
assertThat(converter.convert("Synchronous")).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[sync] is not a valid IndexMaintenancePolicyType");
|
||||
|
||||
converter.convert("sync");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("aSynchronous");
|
||||
assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS);
|
||||
converter.setAsText("synchrONoUS");
|
||||
assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[async] is not a valid IndexMaintenancePolicyType");
|
||||
|
||||
converter.setAsText("async");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* The IndexTypeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the IndexTypeConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.IndexType
|
||||
* @see org.springframework.data.gemfire.IndexTypeConverter
|
||||
* @since 1.5.2
|
||||
*/
|
||||
public class IndexTypeConverterTest {
|
||||
|
||||
private final IndexTypeConverter converter = new IndexTypeConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(IndexType.FUNCTIONAL, converter.convert("FUNCTIONAL"));
|
||||
assertEquals(IndexType.HASH, converter.convert("hASh"));
|
||||
assertEquals(IndexType.KEY, converter.convert("Key"));
|
||||
assertEquals(IndexType.PRIMARY_KEY, converter.convert("primary_KEY"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertWithIllegalValue() {
|
||||
try {
|
||||
converter.convert("function");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(function) is not a valid IndexType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("HasH");
|
||||
assertEquals(IndexType.HASH, converter.getValue());
|
||||
converter.setAsText("key");
|
||||
assertEquals(IndexType.KEY, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("invalid");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid) is not a valid IndexType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link IndexTypeConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.IndexType
|
||||
* @see org.springframework.data.gemfire.IndexTypeConverter
|
||||
* @since 1.5.2
|
||||
*/
|
||||
public class IndexTypeConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final IndexTypeConverter converter = new IndexTypeConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("FUNCTIONAL")).isEqualTo(IndexType.FUNCTIONAL);
|
||||
assertThat(converter.convert("hASh")).isEqualTo(IndexType.HASH);
|
||||
assertThat(converter.convert("hASH")).isEqualTo(IndexType.HASH);
|
||||
assertThat(converter.convert("Key")).isEqualTo(IndexType.KEY);
|
||||
assertThat(converter.convert("primary_KEY")).isEqualTo(IndexType.PRIMARY_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertWithIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[function] is not a valid IndexType");
|
||||
|
||||
converter.convert("function");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("HasH");
|
||||
assertThat(converter.getValue()).isEqualTo(IndexType.HASH);
|
||||
converter.setAsText("key");
|
||||
assertThat(converter.getValue()).isEqualTo(IndexType.KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[invalid] is not a valid IndexType");
|
||||
|
||||
converter.setAsText("invalid");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
|
||||
/**
|
||||
* The InterestPolicyConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the InterestPolicyConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.InterestPolicyConverter
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestPolicyConverterTest {
|
||||
|
||||
private InterestPolicyConverter converter = new InterestPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(InterestPolicy.ALL, converter.convert("all"));
|
||||
assertEquals(InterestPolicy.CACHE_CONTENT, converter.convert("Cache_Content"));
|
||||
assertEquals(InterestPolicy.CACHE_CONTENT, converter.convert("CACHE_ConTent"));
|
||||
assertEquals(InterestPolicy.ALL, converter.convert("ALL"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid_value) is not a valid InterestPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
converter.setAsText("aLl");
|
||||
assertEquals(InterestPolicy.ALL, converter.getValue());
|
||||
converter.setAsText("Cache_CoNTeNT");
|
||||
assertEquals(InterestPolicy.CACHE_CONTENT, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithInvalidValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("none");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(none) is not a valid InterestPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link InterestPolicyConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.InterestPolicyConverter
|
||||
* @see com.gemstone.gemfire.cache.InterestPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestPolicyConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private InterestPolicyConverter converter = new InterestPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("all")).isEqualTo(InterestPolicy.ALL);
|
||||
assertThat(converter.convert("Cache_Content")).isEqualTo(InterestPolicy.CACHE_CONTENT);
|
||||
assertThat(converter.convert("CACHE_ConTent")).isEqualTo(InterestPolicy.CACHE_CONTENT);
|
||||
assertThat(converter.convert("ALL")).isEqualTo(InterestPolicy.ALL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[invalid_value] is not a valid InterestPolicy");
|
||||
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("aLl");
|
||||
assertThat(converter.getValue()).isEqualTo(InterestPolicy.ALL);
|
||||
converter.setAsText("Cache_CoNTeNT");
|
||||
assertThat(converter.getValue()).isEqualTo(InterestPolicy.CACHE_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithInvalidValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[none] is not a valid InterestPolicy");
|
||||
|
||||
converter.setAsText("none");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
/**
|
||||
* The ScopeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the ScopeConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.ScopeConverter
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class ScopeConverterTest {
|
||||
|
||||
private final ScopeConverter converter = new ScopeConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(Scope.DISTRIBUTED_ACK, converter.convert("distributed-ACK"));
|
||||
assertEquals(Scope.DISTRIBUTED_NO_ACK, converter.convert(" Distributed_NO-aCK"));
|
||||
assertEquals(Scope.LOCAL, converter.convert("loCAL "));
|
||||
assertEquals(Scope.GLOBAL, converter.convert(" GLOBal "));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("illegal-value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal-value) is not a valid Scope!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("DisTributeD-nO_Ack");
|
||||
assertEquals(Scope.DISTRIBUTED_NO_ACK, converter.getValue());
|
||||
converter.setAsText("distributed-ack");
|
||||
assertEquals(Scope.DISTRIBUTED_ACK, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("d!5tr!but3d-n0_@ck");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(d!5tr!but3d-n0_@ck) is not a valid Scope!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ScopeConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.ScopeConverter
|
||||
* @see com.gemstone.gemfire.cache.Scope
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class ScopeConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final ScopeConverter converter = new ScopeConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("distributed-ACK")).isEqualTo(Scope.DISTRIBUTED_ACK);
|
||||
assertThat(converter.convert(" Distributed_NO-aCK")).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
|
||||
assertThat(converter.convert("loCAL ")).isEqualTo(Scope.LOCAL);
|
||||
assertThat(converter.convert(" GLOBal ")).isEqualTo(Scope.GLOBAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[illegal-value] is not a valid Scope");
|
||||
|
||||
converter.convert("illegal-value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("DisTributeD-nO_Ack");
|
||||
assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
|
||||
converter.setAsText("distributed-ack");
|
||||
assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_ACK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[d!5tr!but3d-n0_@ck] is not a valid Scope");
|
||||
|
||||
converter.setAsText("d!5tr!but3d-n0_@ck");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.data.gemfire.util.DistributedSystemUtils;
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the InterestResultPolicyConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyConverter
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyType
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyConverterTest {
|
||||
|
||||
private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(InterestResultPolicy.NONE, converter.convert("NONE"));
|
||||
assertEquals(InterestResultPolicy.KEYS, converter.convert("Keys"));
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, converter.convert("kEyS_ValUes"));
|
||||
assertEquals(InterestResultPolicy.NONE, converter.convert("nONe"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("NOne");
|
||||
assertEquals(InterestResultPolicy.NONE, converter.getValue());
|
||||
converter.setAsText("KeYs");
|
||||
assertEquals(InterestResultPolicy.KEYS, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link InterestResultPolicyConverter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyConverter
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyType
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyConverterUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert() {
|
||||
assertThat(converter.convert("NONE")).isEqualTo(InterestResultPolicy.NONE);
|
||||
assertThat(converter.convert("kEyS_ValUes")).isEqualTo(InterestResultPolicy.KEYS_VALUES);
|
||||
assertThat(converter.convert("nONe")).isEqualTo(InterestResultPolicy.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertIllegalValue() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[illegal_value] is not a valid InterestResultPolicy");
|
||||
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsText() {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
converter.setAsText("NOne");
|
||||
assertThat(converter.getValue()).isEqualTo(InterestResultPolicy.NONE);
|
||||
converter.setAsText("KeYs");
|
||||
assertThat(converter.getValue()).isEqualTo(InterestResultPolicy.KEYS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsTextWithIllegalValue() {
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("[illegal_value] is not a valid InterestResultPolicy");
|
||||
|
||||
converter.setAsText("illegal_value");
|
||||
}
|
||||
finally {
|
||||
assertThat(converter.getValue()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.matches;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.beans.factory.xml.XmlReaderContext;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* The AbstractRegionParserTest class is a test suite of test cases testing the contract and functionality of the
|
||||
* AbstractRegionParser class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.config.AbstractRegionParser
|
||||
* @since 1.3.3
|
||||
*/
|
||||
public class AbstractRegionParserTest {
|
||||
|
||||
private AbstractRegionParser regionParser = new TestRegionParser();
|
||||
|
||||
@Test
|
||||
public void testIsSubRegionWhen() {
|
||||
Element mockElement = mock(Element.class);
|
||||
Node mockNode = mock(Node.class);
|
||||
|
||||
when(mockElement.getParentNode()).thenReturn(mockNode);
|
||||
when(mockNode.getLocalName()).thenReturn("partitioned-region");
|
||||
|
||||
assertTrue(regionParser.isSubRegion(mockElement));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSubRegionWhenLocalNameIsNull() {
|
||||
Element mockElement = mock(Element.class);
|
||||
Node mockNode = mock(Node.class);
|
||||
|
||||
when(mockElement.getParentNode()).thenReturn(mockNode);
|
||||
when(mockNode.getLocalName()).thenReturn(null);
|
||||
|
||||
assertFalse(regionParser.isSubRegion(mockElement));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSubRegionWhenLocalNameDoesNotEndWithRegion() {
|
||||
Element mockElement = mock(Element.class);
|
||||
Node mockNode = mock(Node.class);
|
||||
|
||||
when(mockElement.getParentNode()).thenReturn(mockNode);
|
||||
when(mockNode.getLocalName()).thenReturn("disk-store");
|
||||
|
||||
assertFalse(regionParser.isSubRegion(mockElement));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDataPolicyShortcutAttributesMutualExclusion() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
|
||||
|
||||
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
|
||||
|
||||
verify(mockElement).hasAttribute(eq("data-policy"));
|
||||
verify(mockElement, never()).hasAttribute(eq("shortcut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDataPolicyShortcutAttributesMutualExclusionWithDataPolicy() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
|
||||
|
||||
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
|
||||
|
||||
verify(mockElement).hasAttribute(eq("data-policy"));
|
||||
verify(mockElement).hasAttribute(eq("shortcut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDataPolicyShortcutAttributesMutualExclusionWithShortcut() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
|
||||
|
||||
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
|
||||
|
||||
verify(mockElement).hasAttribute(eq("data-policy"));
|
||||
verify(mockElement, never()).hasAttribute(eq("shortcut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDataPolicyShortcutAttributesMutualExclusionWithDataPolicyAndShortcut() {
|
||||
Element mockElement = mock(Element.class);
|
||||
XmlReaderContext mockReaderContext = mock(XmlReaderContext.class);
|
||||
|
||||
ParserContext mockParserContext = new ParserContext(mockReaderContext, null);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
|
||||
when(mockElement.getTagName()).thenReturn("local-region");
|
||||
|
||||
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, mockParserContext);
|
||||
|
||||
verify(mockReaderContext).error(
|
||||
eq("Only one of [data-policy, shortcut] may be specified with element 'local-region'."),
|
||||
eq(mockElement));
|
||||
}
|
||||
|
||||
protected static class TestRegionParser extends AbstractRegionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParseRegion(final Element element, final ParserContext parserContext,
|
||||
final BeanDefinitionBuilder builder, final boolean subRegion) {
|
||||
throw new UnsupportedOperationException("Not Implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.startsWith;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
|
||||
import com.gemstone.gemfire.cache.query.MultiIndexCreationException;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* The CreateDefinedIndexesApplicationListenerTest class is a test suite of test cases testing the contract
|
||||
* and functionality of the CreateDefinedIndexesApplicationListener class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.context.ApplicationContext
|
||||
* @see org.springframework.context.event.ContextRefreshedEvent
|
||||
* @see org.springframework.data.gemfire.config.CreateDefinedIndexesApplicationListener
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public class CreateDefinedIndexesApplicationListenerTest {
|
||||
|
||||
private CreateDefinedIndexesApplicationListener listener = new CreateDefinedIndexesApplicationListener();
|
||||
|
||||
@Test
|
||||
public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception {
|
||||
ApplicationContext mockApplicationContext = mock(ApplicationContext.class,
|
||||
"testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockApplicationContext");
|
||||
|
||||
ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,
|
||||
"testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockContextRefreshedEvent");
|
||||
|
||||
QueryService mockQueryService = mock(QueryService.class,
|
||||
"testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockQueryService");
|
||||
|
||||
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
|
||||
when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)))
|
||||
.thenReturn(true);
|
||||
when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE),
|
||||
eq(QueryService.class))).thenReturn(mockQueryService);
|
||||
|
||||
listener.onApplicationEvent(mockEvent);
|
||||
|
||||
verify(mockEvent, times(1)).getApplicationContext();
|
||||
verify(mockApplicationContext, times(1)).containsBean(
|
||||
eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE));
|
||||
verify(mockApplicationContext, times(1)).getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class));
|
||||
verify(mockQueryService, times(1)).createDefinedIndexes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception {
|
||||
ApplicationContext mockApplicationContext = mock(ApplicationContext.class,
|
||||
"testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockApplicationContext");
|
||||
|
||||
ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,
|
||||
"testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockContextRefreshedEvent");
|
||||
|
||||
QueryService mockQueryService = mock(QueryService.class,
|
||||
"testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockQueryService");
|
||||
|
||||
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
|
||||
when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)))
|
||||
.thenReturn(false);
|
||||
when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE),
|
||||
eq(QueryService.class))).thenReturn(mockQueryService);
|
||||
|
||||
listener.onApplicationEvent(mockEvent);
|
||||
|
||||
verify(mockEvent, times(1)).getApplicationContext();
|
||||
verify(mockApplicationContext, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE));
|
||||
verify(mockApplicationContext, never()).getBean(anyString(), any(QueryService.class));
|
||||
verify(mockQueryService, never()).createDefinedIndexes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception {
|
||||
ApplicationContext mockApplicationContext = mock(ApplicationContext.class,
|
||||
"testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockApplicationContext");
|
||||
|
||||
ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,
|
||||
"testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockContextRefreshedEvent");
|
||||
|
||||
QueryService mockQueryService = mock(QueryService.class,
|
||||
"testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockQueryService");
|
||||
|
||||
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
|
||||
when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)))
|
||||
.thenReturn(true);
|
||||
when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE),
|
||||
eq(QueryService.class))).thenReturn(mockQueryService);
|
||||
when(mockQueryService.createDefinedIndexes()).thenThrow(new MultiIndexCreationException(
|
||||
new HashMap<String, Exception>(Collections.singletonMap("TestKey", new RuntimeException("TEST")))));
|
||||
|
||||
final Log mockLog = mock(Log.class, "testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockLog");
|
||||
|
||||
CreateDefinedIndexesApplicationListener listener = new CreateDefinedIndexesApplicationListener() {
|
||||
@Override Log initLogger() {
|
||||
return mockLog;
|
||||
}
|
||||
};
|
||||
|
||||
listener.onApplicationEvent(mockEvent);
|
||||
|
||||
verify(mockEvent, times(1)).getApplicationContext();
|
||||
verify(mockApplicationContext, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE));
|
||||
verify(mockApplicationContext, times(1)).getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class));
|
||||
verify(mockLog, times(1)).warn(startsWith("unable to create defined Indexes (if any):"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.data.gemfire.test.support.IdentifierSequence;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.Index;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* The CreateDefinedIndexesIntegrationTest class is a test suite of test cases testing the functional behavior
|
||||
* of the GemFire Cache Region Index "definition" and subsequent "creation" step in a SDG-configured application
|
||||
* using a combination of "defined" and "created" Index beans in a Spring context.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @see com.gemstone.gemfire.cache.query.Index
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class CreateDefinedIndexesIntegrationTest {
|
||||
|
||||
private static final List<String> definedIndexNames = new ArrayList<String>(3);
|
||||
|
||||
@Autowired
|
||||
private Cache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("IdIdx")
|
||||
private Index id;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("BirthDateIdx")
|
||||
private Index birthDate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("FullNameIdx")
|
||||
private Index fullName;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("LastNameIdx")
|
||||
private Index lastName;
|
||||
|
||||
@Resource(name = "People")
|
||||
private Region<Long, Person> people;
|
||||
|
||||
protected static Date createBirthDate(final int year, final int month, final int dayOfMonth) {
|
||||
Calendar birthDate = Calendar.getInstance();
|
||||
birthDate.clear();
|
||||
birthDate.set(Calendar.YEAR, year);
|
||||
birthDate.set(Calendar.MONTH, month);
|
||||
birthDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||
return birthDate.getTime();
|
||||
}
|
||||
|
||||
protected static Person createPerson(final String firstName, final String lastName, final Date birthDate) {
|
||||
return createPerson(IdentifierSequence.nextId(), firstName, lastName, birthDate);
|
||||
}
|
||||
|
||||
protected static Person createPerson(final Long id, final String firstName, final String lastName, final Date birthDate) {
|
||||
return new Person(id, firstName, lastName, birthDate);
|
||||
}
|
||||
|
||||
protected static Person put(final Region<Long, Person> people, final Person person) {
|
||||
people.put(person.getId(), person);
|
||||
return person;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
put(people, createPerson("Jon", "Doe", createBirthDate(1989, Calendar.NOVEMBER, 11)));
|
||||
put(people, createPerson("Jane", "Doe", createBirthDate(1991, Calendar.APRIL, 4)));
|
||||
put(people, createPerson("Pie", "Doe", createBirthDate(2008, Calendar.JUNE, 21)));
|
||||
put(people, createPerson("Cookie", "Doe", createBirthDate(2008, Calendar.AUGUST, 14)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexesCreated() {
|
||||
QueryService queryService = gemfireCache.getQueryService();
|
||||
|
||||
//System.out.printf("GemFire Cache Indexes: %1$s%n", queryService.getIndexes());
|
||||
//System.out.printf("/Example Region Indexes: %1$s%n", queryService.getIndexes(people));
|
||||
|
||||
assertTrue(definedIndexNames.containsAll(Arrays.asList(id.getName(), birthDate.getName(), fullName.getName())));
|
||||
assertEquals(id, queryService.getIndex(people, id.getName()));
|
||||
assertEquals(birthDate, queryService.getIndex(people, birthDate.getName()));
|
||||
assertEquals(fullName, queryService.getIndex(people, fullName.getName()));
|
||||
assertEquals(lastName, queryService.getIndex(people, lastName.getName()));
|
||||
}
|
||||
|
||||
public static class IndexBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof Index) {
|
||||
if ("LastNameIdx".equals(beanName)) {
|
||||
assertTrue(CacheFactory.getAnyInstance().getQueryService().getIndexes().contains(bean));
|
||||
assertTrue(beanName.equalsIgnoreCase(((Index) bean).getName()));
|
||||
}
|
||||
else {
|
||||
definedIndexNames.add(beanName);
|
||||
}
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Person implements Serializable {
|
||||
|
||||
protected static final String BIRTH_DATE_FORMAT_PATTERN = "yyyy/MM/dd";
|
||||
|
||||
private Date birthDate;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Person(final String firstName, final String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Person(final String firstName, final String lastName, final Date birthDate) {
|
||||
this(firstName, lastName);
|
||||
this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null);
|
||||
}
|
||||
|
||||
public Person(final Long id, final String firstName, final String lastName, final Date birthDate) {
|
||||
this(firstName, lastName, birthDate);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return String.format("%1$s %2$s", getFirstName(), getLastName());
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
protected static boolean equalsIgnoreNull(final Object obj1, final Object obj2) {
|
||||
return (obj1 == null ? obj2 == null : obj1.equals(obj2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof Person)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Person that = (Person) obj;
|
||||
|
||||
return equalsIgnoreNull(getId(), that.getId())
|
||||
&& (ObjectUtils.nullSafeEquals(getBirthDate(), that.getBirthDate()))
|
||||
&& (ObjectUtils.nullSafeEquals(getFirstName(), that.getFirstName())
|
||||
&& (ObjectUtils.nullSafeEquals(getLastName(), that.getLastName())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashValue = 17;
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getId());
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getBirthDate());
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName());
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName());
|
||||
return hashValue;
|
||||
}
|
||||
|
||||
protected static String toString(final Date dateTime, final String DATE_FORMAT_PATTERN) {
|
||||
return (dateTime == null ? null : new SimpleDateFormat(DATE_FORMAT_PATTERN).format(dateTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{ @type = %1$s, id = %2$d, firstName = %3$s, lastName = %4$s, birthDate = %5$s }",
|
||||
getClass().getName(), getId(), getFirstName(), getLastName(),
|
||||
toString(getBirthDate(), BIRTH_DATE_FORMAT_PATTERN));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
/**
|
||||
* The DiskStoreBeanPostProcessorTest class is a test suite of test cases testing the contract and functionality of
|
||||
* the DiskStoreBeanPostProcessor class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.config.DiskStoreBeanPostProcessor
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
|
||||
public class DiskStoreBeanPostProcessorTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void testSuiteSetup() {
|
||||
assertTrue("Failed to created directory './gemfire/disk-stores/local/ds2'!",
|
||||
new File("./gemfire/disk-stores/local/ds2").mkdirs());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void testSuiteTearDown() {
|
||||
assertTrue("Failed to delete directory './gemfire'!", FileSystemUtils.deleteRecursively(new File("./gemfire")));
|
||||
assertTrue("Failed to delete directory './gfe'!", FileSystemUtils.deleteRecursively(new File("./gfe")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiskStoreDirectoryLocationsExist() {
|
||||
assertTrue(new File("./gemfire/disk-stores/ds1").isDirectory());
|
||||
assertTrue(new File("./gemfire/disk-stores/local/ds2").isDirectory());
|
||||
assertTrue(new File("./gemfire/disk-stores/remote/ds2").isDirectory());
|
||||
assertTrue(new File("./gfe/ds/local/store3").isDirectory());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Copyright 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.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AutoRegionLookupBeanPostProcessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AutoRegionLookupBeanPostProcessorUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessor;
|
||||
|
||||
@Mock
|
||||
private ConfigurableListableBeanFactory mockBeanFactory;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
autoRegionLookupBeanPostProcessor = new AutoRegionLookupBeanPostProcessor();
|
||||
}
|
||||
|
||||
protected Region<?, ?> mockRegion(String regionFullPath) {
|
||||
Region<?, ?> mockRegion = mock(Region.class);
|
||||
when(mockRegion.getFullPath()).thenReturn(regionFullPath);
|
||||
when(mockRegion.getName()).thenReturn(toRegionName(regionFullPath));
|
||||
return mockRegion;
|
||||
}
|
||||
|
||||
protected String toRegionName(String regionFullPath) {
|
||||
int index = regionFullPath.lastIndexOf(Region.SEPARATOR);
|
||||
return (index > -1 ? regionFullPath.substring(index + 1) : regionFullPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetBeanFactory() {
|
||||
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessor.getBeanFactory()).isSameAs(mockBeanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBeanFactoryToIncompatibleBeanFactoryType() {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(String.format("BeanFactory [%1$s] must be an instance of %2$s",
|
||||
mockBeanFactory.getClass().getName(), ConfigurableListableBeanFactory.class.getSimpleName()));
|
||||
|
||||
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBeanFactoryToNull() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(String.format("BeanFactory [null] must be an instance of %s",
|
||||
ConfigurableListableBeanFactory.class.getSimpleName()));
|
||||
|
||||
autoRegionLookupBeanPostProcessor.setBeanFactory(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanFactoryUninitialized() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("BeanFactory was not properly initialized");
|
||||
|
||||
autoRegionLookupBeanPostProcessor.getBeanFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeInitializationReturnsBean() {
|
||||
Object bean = new Object();
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessor.postProcessBeforeInitialization(bean, "test")).isSameAs(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessAfterInitializationWithNonGemFireCacheBean() {
|
||||
Object bean = new Object();
|
||||
|
||||
AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessorSpy =
|
||||
spy(this.autoRegionLookupBeanPostProcessor);
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessorSpy.postProcessAfterInitialization(bean, "test")).isSameAs(bean);
|
||||
|
||||
verify(autoRegionLookupBeanPostProcessorSpy, never()).registerCacheRegionsAsBeans(any(GemFireCache.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerCacheRegionsAsBeansIsSuccessful() {
|
||||
Set<Region<?, ?>> expected = CollectionUtils.asSet(mockRegion("one"), mockRegion("two"), mockRegion("three"));
|
||||
final Set<Region<?, ?>> actual = new HashSet<Region<?, ?>>(expected.size());
|
||||
|
||||
AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessor = new AutoRegionLookupBeanPostProcessor() {
|
||||
@Override void registerCacheRegionAsBean(Region<?, ?> region) {
|
||||
actual.add(region);
|
||||
}
|
||||
};
|
||||
|
||||
GemFireCache mockGemFireCache = mock(GemFireCache.class);
|
||||
|
||||
when(mockGemFireCache.rootRegions()).thenReturn(expected);
|
||||
|
||||
autoRegionLookupBeanPostProcessor.registerCacheRegionsAsBeans(mockGemFireCache);
|
||||
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
|
||||
verify(mockGemFireCache, times(1)).rootRegions();
|
||||
|
||||
for (Region<?, ?> region : expected) {
|
||||
verifyZeroInteractions(region);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerCacheRegionAsBeanIsSuccessful() {
|
||||
Region<?, ?> mockRegion = mockRegion("Example");
|
||||
|
||||
when(mockRegion.subregions(anyBoolean())).thenReturn(Collections.<Region<?, ?>>emptySet());
|
||||
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
|
||||
|
||||
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
|
||||
autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(mockRegion);
|
||||
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq("Example"));
|
||||
verify(mockBeanFactory, times(1)).registerSingleton(eq("Example"), eq(mockRegion));
|
||||
verify(mockRegion, times(1)).getFullPath();
|
||||
verify(mockRegion, times(1)).getName();
|
||||
verify(mockRegion, times(1)).subregions(eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerCacheRegionAsBeanRegistersSubRegionIgnoresRootRegion() {
|
||||
Region<?, ?> mockRootRegion = mockRegion("Root");
|
||||
Region<?, ?> mockSubRegion = mockRegion("/Root/Sub");
|
||||
|
||||
when(mockRootRegion.subregions(anyBoolean())).thenReturn(CollectionUtils.<Region<?, ?>>asSet(mockSubRegion));
|
||||
when(mockSubRegion.subregions(anyBoolean())).thenReturn(Collections.<Region<?, ?>>emptySet());
|
||||
when(mockBeanFactory.containsBean(eq("Root"))).thenReturn(true);
|
||||
when(mockBeanFactory.containsBean(eq("/Root/Sub"))).thenReturn(false);
|
||||
|
||||
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
|
||||
autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(mockRootRegion);
|
||||
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq("Root"));
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq("/Root/Sub"));
|
||||
verify(mockBeanFactory, never()).registerSingleton(eq("Root"), eq(mockRootRegion));
|
||||
verify(mockBeanFactory, times(1)).registerSingleton(eq("/Root/Sub"), eq(mockSubRegion));
|
||||
verify(mockRootRegion, times(1)).getFullPath();
|
||||
verify(mockRootRegion, times(1)).getName();
|
||||
verify(mockRootRegion, times(1)).subregions(eq(false));
|
||||
verify(mockSubRegion, times(1)).getFullPath();
|
||||
verify(mockSubRegion, never()).getName();
|
||||
verify(mockSubRegion, times(1)).subregions(eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerNullCacheRegionAsBeanDoesNothing() {
|
||||
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
|
||||
autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(null);
|
||||
|
||||
verifyZeroInteractions(mockBeanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanNameReturnsRegionFullPath() {
|
||||
Region mockRegion = mockRegion("/Parent/Child");
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessor.getBeanName(mockRegion)).isEqualTo("/Parent/Child");
|
||||
|
||||
verify(mockRegion, times(1)).getFullPath();
|
||||
verify(mockRegion, never()).getName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanNameReturnsRegionName() {
|
||||
Region mockRegion = mockRegion("/Example");
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessor.getBeanName(mockRegion)).isEqualTo("Example");
|
||||
|
||||
verify(mockRegion, times(1)).getFullPath();
|
||||
verify(mockRegion, times(1)).getName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSafeSubRegionsWhenSubRegionsIsNotNull() {
|
||||
Set<Region<?, ?>> mockSubRegions = CollectionUtils.asSet(mockRegion("one"), mockRegion("two"));
|
||||
Region mockRegion = mockRegion("parent");
|
||||
|
||||
when(mockRegion.subregions(anyBoolean())).thenReturn(mockSubRegions);
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessor.nullSafeSubregions(mockRegion)).isEqualTo(mockSubRegions);
|
||||
|
||||
verify(mockRegion, times(1)).subregions(eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSafeSubRegionsWhenSubRegionsIsNull() {
|
||||
Region mockRegion = mockRegion("parent");
|
||||
|
||||
when(mockRegion.subregions(anyBoolean())).thenReturn(null);
|
||||
|
||||
assertThat(autoRegionLookupBeanPostProcessor.nullSafeSubregions(mockRegion)).isEqualTo(Collections.emptySet());
|
||||
|
||||
verify(mockRegion, times(1)).subregions(eq(false));
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isA;
|
||||
@@ -33,13 +29,9 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.internal.matchers.VarargMatcher;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
@@ -47,32 +39,28 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.test.support.MockitoMatchers;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
|
||||
/**
|
||||
* The ClientRegionAndPoolBeanFactoryPostProcessorTests class is a test suite of test cases testing the contract
|
||||
* and functionality of the {@link ClientRegionAndPoolBeanFactoryPostProcessor} class.
|
||||
* Unit tests for {@link ClientRegionPoolBeanFactoryPostProcessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.config.ClientRegionAndPoolBeanFactoryPostProcessor
|
||||
* @see ClientRegionPoolBeanFactoryPostProcessor
|
||||
* @since 1.8.2
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
|
||||
public class ClientRegionPoolBeanFactoryPostProcessorUnitTests {
|
||||
|
||||
@Mock
|
||||
private BeanDefinition mockBeanDefinition;
|
||||
|
||||
private ClientRegionAndPoolBeanFactoryPostProcessor beanFactoryPostProcessor =
|
||||
new ClientRegionAndPoolBeanFactoryPostProcessor();
|
||||
|
||||
protected static <T> T[] asArray(T... array) {
|
||||
return array;
|
||||
}
|
||||
private ClientRegionPoolBeanFactoryPostProcessor beanFactoryPostProcessor =
|
||||
new ClientRegionPoolBeanFactoryPostProcessor();
|
||||
|
||||
protected PropertyValue newPropertyValue(String name, Object value) {
|
||||
return new PropertyValue(name, value);
|
||||
@@ -82,10 +70,6 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
|
||||
return new MutablePropertyValues(Arrays.asList(propertyValues));
|
||||
}
|
||||
|
||||
protected Matcher<String> stringArrayMatcher(String... expected) {
|
||||
return new ArrayMatcher<String>(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessBeanFactory() {
|
||||
BeanDefinition mockClientRegionBeanOne = mock(BeanDefinition.class, "MockClientRegionBeanOne");
|
||||
@@ -99,16 +83,16 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
|
||||
when(mockPoolBean.getBeanClassName()).thenReturn(PoolFactoryBean.class.getName());
|
||||
when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName());
|
||||
when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(
|
||||
asArray("mockClientRegionBeanOne", "mockClientRegionBeanTwo", "mockGenericBean", "mockPoolBean"));
|
||||
ArrayUtils.asArray("mockClientRegionBeanOne", "mockClientRegionBeanTwo", "mockGenericBean", "mockPoolBean"));
|
||||
when(mockBeanFactory.getBeanDefinition(eq("mockClientRegionBeanOne"))).thenReturn(mockClientRegionBeanOne);
|
||||
when(mockBeanFactory.getBeanDefinition(eq("mockClientRegionBeanTwo"))).thenReturn(mockClientRegionBeanTwo);
|
||||
when(mockBeanFactory.getBeanDefinition(eq("mockGenericBean"))).thenReturn(mockBeanDefinition);
|
||||
when(mockBeanFactory.getBeanDefinition(eq("mockPoolBean"))).thenReturn(mockPoolBean);
|
||||
when(mockClientRegionBeanOne.getDependsOn()).thenReturn(asArray("mockClientCacheBean"));
|
||||
when(mockClientRegionBeanOne.getDependsOn()).thenReturn(ArrayUtils.asArray("mockClientCacheBean"));
|
||||
when(mockClientRegionBeanOne.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
|
||||
ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "mockPoolBean")));
|
||||
ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "mockPoolBean")));
|
||||
when(mockClientRegionBeanTwo.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
|
||||
ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "DEFAULT")));
|
||||
ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "DEFAULT")));
|
||||
|
||||
beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory);
|
||||
|
||||
@@ -121,8 +105,8 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
|
||||
verify(mockClientRegionBeanOne, times(1)).getBeanClassName();
|
||||
verify(mockClientRegionBeanOne, times(1)).getPropertyValues();
|
||||
verify(mockClientRegionBeanOne, times(1)).getDependsOn();
|
||||
verify(mockClientRegionBeanOne, times(1)).setDependsOn(argThat(stringArrayMatcher(
|
||||
"mockClientCacheBean", "mockPoolBean")));
|
||||
verify(mockClientRegionBeanOne, times(1)).setDependsOn(argThat(
|
||||
MockitoMatchers.stringArrayMatcher("mockClientCacheBean", "mockPoolBean")));
|
||||
verify(mockClientRegionBeanTwo, times(1)).getBeanClassName();
|
||||
verify(mockClientRegionBeanTwo, times(1)).getPropertyValues();
|
||||
verify(mockClientRegionBeanTwo, never()).getDependsOn();
|
||||
@@ -133,83 +117,43 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
|
||||
@Test
|
||||
public void isClientRegionBeanReturnsFalse() {
|
||||
when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName());
|
||||
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition), is(false));
|
||||
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition)).isFalse();
|
||||
verify(mockBeanDefinition, times(1)).getBeanClassName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isClientRegionBeanReturnsTrue() {
|
||||
when(mockBeanDefinition.getBeanClassName()).thenReturn(ClientRegionFactoryBean.class.getName());
|
||||
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition), is(true));
|
||||
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition)).isTrue();
|
||||
verify(mockBeanDefinition, times(1)).getBeanClassName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPoolBeanReturnsFalse() {
|
||||
when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName());
|
||||
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition), is(false));
|
||||
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition)).isFalse();
|
||||
verify(mockBeanDefinition, times(1)).getBeanClassName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPoolBeanReturnsTrue() {
|
||||
when(mockBeanDefinition.getBeanClassName()).thenReturn(PoolFactoryBean.class.getName());
|
||||
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition), is(true));
|
||||
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition)).isTrue();
|
||||
verify(mockBeanDefinition, times(1)).getBeanClassName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolNameWhenPoolNamePropertyIsSpecifiedReturnsPoolBeanName() {
|
||||
when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
|
||||
ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "testPoolName")));
|
||||
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition)).isEqualTo("testPoolName");
|
||||
verify(mockBeanDefinition, times(1)).getPropertyValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolNameWhenPoolNamePropertyIsUnspecifiedReturnsNull() {
|
||||
when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues());
|
||||
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition), is(nullValue(String.class)));
|
||||
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition)).isNull();
|
||||
verify(mockBeanDefinition, times(1)).getPropertyValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolNameReturnsPoolBeanName() {
|
||||
when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
|
||||
ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "testPoolName")));
|
||||
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition), is(equalTo("testPoolName")));
|
||||
verify(mockBeanDefinition, times(1)).getPropertyValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDependsOnToExistingDependencies() {
|
||||
when(mockBeanDefinition.getDependsOn()).thenReturn(asArray("testBeanNameOne", "testBeanNameTwo"));
|
||||
assertThat(beanFactoryPostProcessor.addDependsOn(mockBeanDefinition, "testBeanNameThree"),
|
||||
is(sameInstance(mockBeanDefinition)));
|
||||
verify(mockBeanDefinition, times(1)).getDependsOn();
|
||||
verify(mockBeanDefinition, times(1)).setDependsOn(argThat(stringArrayMatcher(
|
||||
"testBeanNameOne", "testBeanNameTwo", "testBeanNameThree")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDependsOnToNonExistingDependencies() {
|
||||
when(mockBeanDefinition.getDependsOn()).thenReturn(null);
|
||||
assertThat(beanFactoryPostProcessor.addDependsOn(mockBeanDefinition, "testBeanName"),
|
||||
is(sameInstance(mockBeanDefinition)));
|
||||
verify(mockBeanDefinition, times(1)).getDependsOn();
|
||||
verify(mockBeanDefinition, times(1)).setDependsOn(argThat(stringArrayMatcher("testBeanName")));
|
||||
}
|
||||
|
||||
protected static final class ArrayMatcher<T> extends BaseMatcher<T> implements VarargMatcher {
|
||||
|
||||
private final T[] expected;
|
||||
|
||||
protected ArrayMatcher(T... expected) {
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object item) {
|
||||
Object[] actual = (item instanceof Object[] ? (Object[]) item : asArray(item));
|
||||
|
||||
return Arrays.equals(actual, expected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(String.format("expected (%1$s)", this.expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,16 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
@@ -41,34 +46,38 @@ import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.data.gemfire.wan.OrderPolicyConverter;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The CustomEditorRegisteringBeanFactoryPostProcessorTest class...
|
||||
* Unit tests for {@link CustomEditorBeanFactoryPostProcessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see CustomEditorRegisteringBeanFactoryPostProcessor
|
||||
* @see org.mockito.Mockito
|
||||
* @see CustomEditorBeanFactoryPostProcessor
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CustomEditorRegisteringBeanFactoryPostProcessorTest {
|
||||
public class CustomEditorBeanFactoryPostProcessorUnitTests {
|
||||
|
||||
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customEditorRegistration() {
|
||||
public void customEditorRegistrationIsSuccessful() {
|
||||
ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class);
|
||||
|
||||
new CustomEditorRegisteringBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
|
||||
new CustomEditorBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
|
||||
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint.class),
|
||||
eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointConverter.class));
|
||||
//verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class),
|
||||
// eq(CustomEditorRegisteringBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class));
|
||||
// eq(CustomEditorBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpointList.class),
|
||||
eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointListConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class),
|
||||
eq(EvictionActionConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class),
|
||||
@@ -89,32 +98,55 @@ public class CustomEditorRegisteringBeanFactoryPostProcessorTest {
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class),
|
||||
eq(SubscriptionEvictionPolicyConverter.class));
|
||||
}
|
||||
|
||||
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
verifyNoMoreInteractions(mockBeanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void connectionEndpointArrayToIterableConversion() {
|
||||
public void connectionEndpointArrayToIterableConversionIsSuccessful() {
|
||||
ConnectionEndpoint[] array = {
|
||||
newConnectionEndpoint("localhost", 10334),
|
||||
newConnectionEndpoint("localhost", 40404)
|
||||
};
|
||||
|
||||
Iterable<ConnectionEndpoint> iterable = new CustomEditorRegisteringBeanFactoryPostProcessor
|
||||
Iterable<ConnectionEndpoint> iterable = new CustomEditorBeanFactoryPostProcessor
|
||||
.ConnectionEndpointArrayToIterableConverter().convert(array);
|
||||
|
||||
assertThat(iterable, is(notNullValue()));
|
||||
assertThat(iterable).isNotNull();
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : iterable) {
|
||||
assertThat(connectionEndpoint, is(equalTo(array[index++])));
|
||||
assertThat(connectionEndpoint).isEqualTo(array[index++]);
|
||||
}
|
||||
|
||||
assertThat(index, is(equalTo(2)));
|
||||
assertThat(index).isEqualTo(array.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringToConnectionEndpointConversionIsSuccessful() {
|
||||
String hostPort = "skullbox[54321]";
|
||||
|
||||
ConnectionEndpoint connectionEndpoint = new CustomEditorBeanFactoryPostProcessor
|
||||
.StringToConnectionEndpointConverter().convert(hostPort);
|
||||
|
||||
assertThat(connectionEndpoint).isNotNull();
|
||||
assertThat(connectionEndpoint.getHost()).isEqualTo("skullbox");
|
||||
assertThat(connectionEndpoint.getPort()).isEqualTo(54321);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringToConnectionEndpointListConversionIsSuccessful() {
|
||||
String[] hostsPorts = { "toolbox[10334]", "skullbox", "[40404]" };
|
||||
String source = StringUtils.arrayToCommaDelimitedString(hostsPorts);
|
||||
|
||||
ConnectionEndpointList connectionEndpoints = new CustomEditorBeanFactoryPostProcessor
|
||||
.StringToConnectionEndpointListConverter().convert(source);
|
||||
|
||||
assertThat(connectionEndpoints).isNotNull();
|
||||
assertThat(connectionEndpoints.size()).isEqualTo(hostsPorts.length);
|
||||
assertThat(connectionEndpoints.findOne("toolbox").getPort()).isEqualTo(10334);
|
||||
assertThat(connectionEndpoints.findOne("skullbox").getPort()).isEqualTo(0);
|
||||
assertThat(connectionEndpoints.findOne(40404).getHost()).isEqualTo("localhost");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.support;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Matchers.startsWith;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.gemstone.gemfire.cache.query.MultiIndexCreationException;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefinedIndexesApplicationListener}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see DefinedIndexesApplicationListener
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefinedIndexesApplicationListenerUnitTests {
|
||||
|
||||
private static final String QUERY_SERVICE_BEAN_NAME =
|
||||
GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE;
|
||||
|
||||
@Mock
|
||||
private ApplicationContext mockApplicationContext;
|
||||
|
||||
@Mock
|
||||
private ContextRefreshedEvent mockEvent;
|
||||
|
||||
private DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener();
|
||||
|
||||
@Mock
|
||||
private QueryService mockQueryService;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
|
||||
}
|
||||
|
||||
protected <K, V> HashMap<K, V> newHashMap(K key, V value) {
|
||||
return new HashMap<K, V>(Collections.singletonMap(key, value));
|
||||
}
|
||||
|
||||
protected MultiIndexCreationException newMultiIndexCreationException(String key, Exception cause) {
|
||||
return new MultiIndexCreationException(newHashMap(key, cause));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception {
|
||||
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
|
||||
when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
|
||||
.thenReturn(mockQueryService);
|
||||
|
||||
listener.onApplicationEvent(mockEvent);
|
||||
|
||||
verify(mockEvent, times(1)).getApplicationContext();
|
||||
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
|
||||
verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class));
|
||||
verify(mockQueryService, times(1)).createDefinedIndexes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception {
|
||||
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(false);
|
||||
|
||||
listener.onApplicationEvent(mockEvent);
|
||||
|
||||
verify(mockEvent, times(1)).getApplicationContext();
|
||||
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
|
||||
verify(mockApplicationContext, never()).getBean(anyString(), any(QueryService.class));
|
||||
verify(mockQueryService, never()).createDefinedIndexes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception {
|
||||
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
|
||||
when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
|
||||
.thenReturn(mockQueryService);
|
||||
when(mockQueryService.createDefinedIndexes())
|
||||
.thenThrow(newMultiIndexCreationException("TestKey", new RuntimeException("TEST")));
|
||||
|
||||
final Log mockLog = mock(Log.class);
|
||||
|
||||
DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener() {
|
||||
@Override Log initLogger() {
|
||||
return mockLog;
|
||||
}
|
||||
};
|
||||
|
||||
listener.onApplicationEvent(mockEvent);
|
||||
|
||||
verify(mockEvent, times(1)).getApplicationContext();
|
||||
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
|
||||
verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class));
|
||||
verify(mockQueryService, times(1)).createDefinedIndexes();
|
||||
verify(mockLog, times(1)).warn(startsWith("Failed to create pre-defined Indexes:"),
|
||||
isA(MultiIndexCreationException.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.gemfire.test.model.Person.newBirthDate;
|
||||
import static org.springframework.data.gemfire.test.model.Person.newPerson;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.Index;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.data.gemfire.IndexFactoryBean;
|
||||
import org.springframework.data.gemfire.IndexType;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
|
||||
import org.springframework.data.gemfire.test.model.Gender;
|
||||
import org.springframework.data.gemfire.test.model.Person;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link DefinedIndexesApplicationListener}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @see com.gemstone.gemfire.cache.query.Index
|
||||
* @see com.gemstone.gemfire.cache.query.QueryService
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class DefinedIndexesIntegrationTests {
|
||||
|
||||
private static final List<String> definedIndexNames = new ArrayList<String>(3);
|
||||
|
||||
@Autowired
|
||||
private Cache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("IdIdx")
|
||||
private Index id;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("BirthDateIdx")
|
||||
private Index birthDate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("LastNameIdx")
|
||||
private Index lastName;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("NameIdx")
|
||||
private Index name;
|
||||
|
||||
@Resource(name = "People")
|
||||
private Region<Long, Person> people;
|
||||
|
||||
protected static Person put(Region<Long, Person> people, Person person) {
|
||||
people.put(person.getId(), person);
|
||||
return person;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
put(people, newPerson("Jon", "Doe", newBirthDate(1989, Calendar.NOVEMBER, 11), Gender.MALE));
|
||||
put(people, newPerson("Jane", "Doe", newBirthDate(1991, Calendar.APRIL, 4), Gender.FEMALE));
|
||||
put(people, newPerson("Pie", "Doe", newBirthDate(2008, Calendar.JUNE, 21), Gender.FEMALE));
|
||||
put(people, newPerson("Cookie", "Doe", newBirthDate(2008, Calendar.AUGUST, 14), Gender.FEMALE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexesCreated() {
|
||||
QueryService queryService = gemfireCache.getQueryService();
|
||||
|
||||
List<String> expectedDefinedIndexNames = Arrays.asList(id.getName(), birthDate.getName(), name.getName());
|
||||
|
||||
assertThat(definedIndexNames).isEqualTo(expectedDefinedIndexNames);
|
||||
assertThat(id).isEqualTo(queryService.getIndex(people, id.getName()));
|
||||
assertThat(birthDate).isEqualTo(queryService.getIndex(people, birthDate.getName()));
|
||||
assertThat(lastName).isEqualTo(queryService.getIndex(people, lastName.getName()));
|
||||
assertThat(name).isEqualTo(queryService.getIndex(people, name.getName()));
|
||||
}
|
||||
|
||||
@PeerCacheApplication(logLevel = "warning")
|
||||
static class DefinedIndexesConfiguration {
|
||||
|
||||
@Bean
|
||||
// TODO remove when the Annotation config model includes support
|
||||
DefinedIndexesApplicationListener indexApplicationListener() {
|
||||
return new DefinedIndexesApplicationListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
BeanPostProcessor indexBeanPostProcessor() {
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof Index) {
|
||||
if ("LastNameIdx".equals(beanName)) {
|
||||
assertThat(CacheFactory.getAnyInstance().getQueryService().getIndexes().contains(bean)).isTrue();
|
||||
assertThat(beanName).isEqualToIgnoringCase(((Index) bean).getName());
|
||||
}
|
||||
else {
|
||||
definedIndexNames.add(beanName);
|
||||
}
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean(name = "People")
|
||||
PartitionedRegionFactoryBean<Long, Person> peopleRegion(Cache gemfireCache) {
|
||||
PartitionedRegionFactoryBean<Long, Person> peopleRegion = new PartitionedRegionFactoryBean<Long, Person>();
|
||||
|
||||
peopleRegion.setCache(gemfireCache);
|
||||
peopleRegion.setClose(false);
|
||||
peopleRegion.setPersistent(false);
|
||||
|
||||
return peopleRegion;
|
||||
}
|
||||
|
||||
@Bean(name = "IdIdx")
|
||||
@DependsOn("People")
|
||||
IndexFactoryBean idIndex(GemFireCache gemFireCache) {
|
||||
IndexFactoryBean idIndex = new IndexFactoryBean();
|
||||
|
||||
idIndex.setCache(gemFireCache);
|
||||
idIndex.setDefine(true);
|
||||
idIndex.setExpression("id");
|
||||
idIndex.setFrom("/People");
|
||||
idIndex.setName("IdIdx");
|
||||
idIndex.setType(IndexType.KEY);
|
||||
|
||||
return idIndex;
|
||||
}
|
||||
|
||||
@Bean(name = "BirthDateIdx")
|
||||
@DependsOn("People")
|
||||
IndexFactoryBean birthDateIndex(GemFireCache gemFireCache) {
|
||||
IndexFactoryBean birthDateIndex = new IndexFactoryBean();
|
||||
|
||||
birthDateIndex.setCache(gemFireCache);
|
||||
birthDateIndex.setDefine(true);
|
||||
birthDateIndex.setExpression("birthDate");
|
||||
birthDateIndex.setFrom("/People");
|
||||
birthDateIndex.setName("BirthDateIdx");
|
||||
birthDateIndex.setType(IndexType.HASH);
|
||||
|
||||
return birthDateIndex;
|
||||
}
|
||||
|
||||
@Bean(name = "LastNameIdx")
|
||||
@DependsOn("People")
|
||||
IndexFactoryBean lastNameIndex(GemFireCache gemFireCache) {
|
||||
IndexFactoryBean lastNameIndex = new IndexFactoryBean();
|
||||
|
||||
lastNameIndex.setCache(gemFireCache);
|
||||
lastNameIndex.setExpression("lastName");
|
||||
lastNameIndex.setFrom("/People");
|
||||
lastNameIndex.setName("LastNameIdx");
|
||||
lastNameIndex.setType(IndexType.HASH);
|
||||
|
||||
return lastNameIndex;
|
||||
}
|
||||
|
||||
@Bean(name = "NameIdx")
|
||||
@DependsOn("People")
|
||||
IndexFactoryBean nameIndex(GemFireCache gemFireCache) {
|
||||
IndexFactoryBean nameIndex = new IndexFactoryBean();
|
||||
|
||||
nameIndex.setCache(gemFireCache);
|
||||
nameIndex.setDefine(true);
|
||||
nameIndex.setExpression("name");
|
||||
nameIndex.setFrom("/People");
|
||||
nameIndex.setName("NameIdx");
|
||||
nameIndex.setType(IndexType.FUNCTIONAL);
|
||||
|
||||
return nameIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link DiskStoreBeanPostProcessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.config.support.DiskStoreBeanPostProcessor
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class DiskStoreBeanPostProcessorIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void testSuiteSetup() {
|
||||
assertThat(new File("./gemfire/disk-stores/ds2/local").mkdirs()).isTrue();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void testSuiteTearDown() {
|
||||
assertThat(FileSystemUtils.deleteRecursively(new File("./gemfire"))).isTrue();
|
||||
assertThat(FileSystemUtils.deleteRecursively(new File("./gfe"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diskStoreDirectoriesExist() {
|
||||
assertThat(new File("./gemfire/disk-stores/ds1").isDirectory()).isTrue();
|
||||
assertThat(new File("./gemfire/disk-stores/ds2/local").isDirectory()).isTrue();
|
||||
assertThat(new File("./gemfire/disk-stores/ds2/remote").isDirectory()).isTrue();
|
||||
assertThat(new File("./gfe/ds/store3/local").isDirectory()).isTrue();
|
||||
}
|
||||
|
||||
@PeerCacheApplication(logLevel = "warning")
|
||||
@SuppressWarnings("unused")
|
||||
static class DiskStoreBeanPostProcessorConfiguration {
|
||||
|
||||
DiskStoreFactoryBean.DiskDir newDiskDir(String location) {
|
||||
return new DiskStoreFactoryBean.DiskDir(location);
|
||||
}
|
||||
|
||||
@Bean
|
||||
// TODO remove when the Annotation config model includes support
|
||||
DiskStoreBeanPostProcessor diskStoreBeanPostProcessor() {
|
||||
return new DiskStoreBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
DiskStoreFactoryBean diskStoreOne(GemFireCache gemfireCache) {
|
||||
DiskStoreFactoryBean diskStoreOne = new DiskStoreFactoryBean();
|
||||
diskStoreOne.setCache(gemfireCache);
|
||||
diskStoreOne.setDiskDirs(Collections.singletonList(newDiskDir("./gemfire/disk-stores/ds1")));
|
||||
return diskStoreOne;
|
||||
}
|
||||
|
||||
@Bean
|
||||
DiskStoreFactoryBean diskStoreTwo(GemFireCache gemfireCache) {
|
||||
DiskStoreFactoryBean diskStoreTwo = new DiskStoreFactoryBean();
|
||||
diskStoreTwo.setCache(gemfireCache);
|
||||
diskStoreTwo.setDiskDirs(Arrays.asList(newDiskDir("./gemfire/disk-stores/ds2/local"),
|
||||
newDiskDir("./gemfire/disk-stores/ds2/remote")));
|
||||
return diskStoreTwo;
|
||||
}
|
||||
|
||||
@Bean
|
||||
DiskStoreFactoryBean diskStoreThree(GemFireCache gemfireCache) {
|
||||
DiskStoreFactoryBean diskStoreThree = new DiskStoreFactoryBean();
|
||||
diskStoreThree.setCache(gemfireCache);
|
||||
diskStoreThree.setDiskDirs(Collections.singletonList(newDiskDir("./gfe/ds/store3/local")));
|
||||
return diskStoreThree;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -32,6 +29,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -40,54 +42,45 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
|
||||
/**
|
||||
* The PdxDiskStoreAwareBeanFactoryPostProcessorTest class is a test suite of test cases testing the functionality
|
||||
* of the PdxDiskStoreAwareBeanFactoryPostProcessor class.
|
||||
* Unit tests for {@link PdxDiskStoreAwareBeanFactoryPostProcessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.config.PdxDiskStoreAwareBeanFactoryPostProcessor
|
||||
* @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor
|
||||
* @see com.gemstone.gemfire.cache.DiskStore
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @see com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue
|
||||
* @since 1.3.3
|
||||
*/
|
||||
public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests {
|
||||
|
||||
protected static String[] toStringArray(final Collection<String> collection) {
|
||||
protected static boolean isBeanType(BeanDefinition beanDefinition, Class<?> beanType) {
|
||||
return (beanDefinition instanceof AbstractBeanDefinition
|
||||
&& ((AbstractBeanDefinition) beanDefinition).hasBeanClass()
|
||||
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass()));
|
||||
}
|
||||
|
||||
protected static String[] toStringArray(Collection<String> collection) {
|
||||
return collection.toArray(new String[collection.size()]);
|
||||
}
|
||||
|
||||
protected static boolean isEmpty(final Object[] array) {
|
||||
return (array == null || array.length == 0);
|
||||
}
|
||||
|
||||
protected static boolean isBeanType(final BeanDefinition beanDefinition, final Class<?> beanType) {
|
||||
return (beanDefinition instanceof AbstractBeanDefinition
|
||||
&& ((AbstractBeanDefinition) beanDefinition).hasBeanClass()
|
||||
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass()));
|
||||
}
|
||||
|
||||
protected ConfigurableListableBeanFactory createMockBeanFactory(final Map<String, BeanDefinition> beanDefinitions) {
|
||||
protected ConfigurableListableBeanFactory mockBeanFactory(final Map<String, BeanDefinition> beanDefinitions) {
|
||||
final ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class);
|
||||
|
||||
when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toStringArray(beanDefinitions.keySet()));
|
||||
|
||||
when(mockBeanFactory.getBeanNamesForType(isA(Class.class))).then(new Answer<String[]>() {
|
||||
@Override
|
||||
public String[] answer(final InvocationOnMock invocation) throws Throwable {
|
||||
public String[] answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] arguments = invocation.getArguments();
|
||||
|
||||
assertNotNull(arguments);
|
||||
assertTrue(arguments.length == 1);
|
||||
assertTrue(arguments[0] instanceof Class);
|
||||
assertThat(arguments).isNotNull();
|
||||
assertThat(arguments.length).isEqualTo(1);
|
||||
assertThat(arguments[0]).isInstanceOf(Class.class);
|
||||
|
||||
Class beanType = (Class) arguments[0];
|
||||
|
||||
@@ -107,10 +100,10 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
|
||||
when(mockBeanFactory.getBeanDefinition(anyString())).then(new Answer<BeanDefinition>() {
|
||||
@Override
|
||||
public BeanDefinition answer(final InvocationOnMock invocation) throws Throwable {
|
||||
public BeanDefinition answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] arguments = invocation.getArguments();
|
||||
assertNotNull(arguments);
|
||||
assertTrue(arguments.length == 1);
|
||||
assertThat(arguments).isNotNull();
|
||||
assertThat(arguments.length).isEqualTo(1);
|
||||
return beanDefinitions.get(String.valueOf(arguments[0]));
|
||||
}
|
||||
});
|
||||
@@ -118,7 +111,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
return mockBeanFactory;
|
||||
}
|
||||
|
||||
protected static BeanDefinitionBuilder createBeanDefinitionBuilder(Object beanClassObject, String... dependencies) {
|
||||
protected static BeanDefinitionBuilder newBeanDefinitionBuilder(Object beanClassObject, String... dependencies) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
if (beanClassObject instanceof Class) {
|
||||
@@ -140,28 +133,28 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
}
|
||||
|
||||
protected static void assertDependencies(BeanDefinition beanDefinition, String... expectedDependencies) {
|
||||
assertFalse(isEmpty(beanDefinition.getDependsOn()));
|
||||
assertTrue(Arrays.asList(beanDefinition.getDependsOn()).equals(Arrays.asList(expectedDependencies)));
|
||||
assertThat(ArrayUtils.isEmpty(beanDefinition.getDependsOn())).isFalse();
|
||||
assertThat(Arrays.asList(beanDefinition.getDependsOn()).equals(Arrays.asList(expectedDependencies))).isTrue();
|
||||
}
|
||||
|
||||
protected BeanDefinition defineBean(String beanClassName, String... dependencies) {
|
||||
return createBeanDefinitionBuilder(beanClassName, dependencies).getBeanDefinition();
|
||||
return newBeanDefinitionBuilder(beanClassName, dependencies).getBeanDefinition();
|
||||
}
|
||||
|
||||
protected BeanDefinition defineCache() {
|
||||
return createBeanDefinitionBuilder(CacheFactoryBean.class).getBeanDefinition();
|
||||
return newBeanDefinitionBuilder(CacheFactoryBean.class).getBeanDefinition();
|
||||
}
|
||||
|
||||
protected BeanDefinition defineAsyncEventQueue(String... dependencies) {
|
||||
return createBeanDefinitionBuilder(AsyncEventQueue.class, dependencies).getBeanDefinition();
|
||||
return newBeanDefinitionBuilder(AsyncEventQueue.class, dependencies).getBeanDefinition();
|
||||
}
|
||||
|
||||
protected BeanDefinition defineDiskStore(String... dependencies) {
|
||||
return createBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition();
|
||||
return newBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition();
|
||||
}
|
||||
|
||||
protected BeanDefinition defineRegion(Class regionClass, String... dependencies) {
|
||||
return createBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition();
|
||||
return newBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition();
|
||||
}
|
||||
|
||||
protected BeanDefinition definePartitionedRegion(String... dependencies) {
|
||||
@@ -173,32 +166,33 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithBlankDiskStoreName() {
|
||||
public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithBlankDiskStoreName() {
|
||||
new PdxDiskStoreAwareBeanFactoryPostProcessor(" ");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithEmptyDiskStoreName() {
|
||||
public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithEmptyDiskStoreName() {
|
||||
new PdxDiskStoreAwareBeanFactoryPostProcessor("");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithNullDiskStoreName() {
|
||||
public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithNullDiskStoreName() {
|
||||
new PdxDiskStoreAwareBeanFactoryPostProcessor(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializedPdxDiskStoreAwareBeanFactoryPostProcessor() {
|
||||
public void initializedPdxDiskStoreAwareBeanFactoryPostProcessor() {
|
||||
PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
|
||||
new PdxDiskStoreAwareBeanFactoryPostProcessor("testPdxDiskStoreName");
|
||||
|
||||
assertNotNull(postProcessor);
|
||||
assertEquals("testPdxDiskStoreName", postProcessor.getPdxDiskStoreName());
|
||||
assertThat(postProcessor).isNotNull();
|
||||
assertThat(postProcessor.getPdxDiskStoreName()).isEqualTo("testPdxDiskStoreName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeanFactory() {
|
||||
final Map<String, BeanDefinition> beanDefinitions = new HashMap<String, BeanDefinition>(13);
|
||||
@SuppressWarnings("all")
|
||||
public void postProcessBeanFactory() {
|
||||
Map<String, BeanDefinition> beanDefinitions = new HashMap<String, BeanDefinition>(13);
|
||||
|
||||
beanDefinitions.put("someBean", defineBean("org.company.app.domain.SomeBean", "someOtherBean"));
|
||||
beanDefinitions.put("gemfireCache", defineCache());
|
||||
@@ -217,17 +211,17 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
beanDefinitions.put("region3", definePartitionedRegion());
|
||||
beanDefinitions.put("region4", definePartitionedRegion("queue2"));
|
||||
|
||||
final ConfigurableListableBeanFactory mockBeanFactory = createMockBeanFactory(beanDefinitions);
|
||||
ConfigurableListableBeanFactory mockBeanFactory = mockBeanFactory(beanDefinitions);
|
||||
|
||||
final PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
|
||||
PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
|
||||
new PdxDiskStoreAwareBeanFactoryPostProcessor("pdxDiskStore");
|
||||
|
||||
postProcessor.postProcessBeanFactory(mockBeanFactory);
|
||||
|
||||
assertDependencies(beanDefinitions.get("someBean"), "someOtherBean");
|
||||
assertTrue(isEmpty(beanDefinitions.get("gemfireCache").getDependsOn()));
|
||||
assertTrue(isEmpty(beanDefinitions.get("pdxDiskStore").getDependsOn()));
|
||||
assertTrue(isEmpty(beanDefinitions.get("someOtherBean").getDependsOn()));
|
||||
assertThat(ArrayUtils.isEmpty(beanDefinitions.get("gemfireCache").getDependsOn())).isTrue();
|
||||
assertThat(ArrayUtils.isEmpty(beanDefinitions.get("pdxDiskStore").getDependsOn())).isTrue();
|
||||
assertThat(ArrayUtils.isEmpty(beanDefinitions.get("someOtherBean").getDependsOn())).isTrue();
|
||||
assertDependencies(beanDefinitions.get("queue1"), "pdxDiskStore", "someOtherBean");
|
||||
assertDependencies(beanDefinitions.get("overflowDiskStore"), "pdxDiskStore");
|
||||
assertDependencies(beanDefinitions.get("region1"), "pdxDiskStore", "overflowDiskStore");
|
||||
@@ -241,5 +235,4 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
|
||||
assertDependencies(beanDefinitions.get("region3"), "pdxDiskStore");
|
||||
assertDependencies(beanDefinitions.get("region4"), "pdxDiskStore", "queue2");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
import static org.mockito.Matchers.matches;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.beans.factory.xml.XmlReaderContext;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractRegionParser}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.config.xml.AbstractRegionParser
|
||||
* @since 1.3.3
|
||||
*/
|
||||
// TODO add more tests
|
||||
public class AbstractRegionParserUnitTests {
|
||||
|
||||
private AbstractRegionParser regionParser = new TestRegionParser();
|
||||
|
||||
protected void assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate(String localName) {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getLocalName()).thenReturn(localName);
|
||||
assertThat(regionParser.isRegionTemplate(mockElement)).isEqualTo(nullSafeEndsWith(localName, "-template"));
|
||||
verify(mockElement, times(1)).getLocalName();
|
||||
}
|
||||
|
||||
protected void assertIsSubRegionWhenElementLocalNameEndsWithRegion(String localName) {
|
||||
Element mockElement = mock(Element.class);
|
||||
Node mockNode = mock(Node.class);
|
||||
|
||||
when(mockElement.getParentNode()).thenReturn(mockNode);
|
||||
when(mockNode.getLocalName()).thenReturn(localName);
|
||||
|
||||
assertThat(regionParser.isSubRegion(mockElement)).isEqualTo(nullSafeEndsWith(localName, "region"));
|
||||
|
||||
verify(mockElement, times(1)).getParentNode();
|
||||
verify(mockNode, times(1)).getLocalName();
|
||||
}
|
||||
|
||||
protected boolean nullSafeEndsWith(String localName, String suffix) {
|
||||
return (localName != null && localName.endsWith(suffix));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanClassIsEqualToTestRegionFactoryBean() {
|
||||
AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class);
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
doReturn(AbstractRegionParserUnitTests.class).when(regionParserSpy).getRegionFactoryClass();
|
||||
|
||||
assertThat(regionParserSpy.getBeanClass(mockElement)).isEqualTo(AbstractRegionParserUnitTests.class);
|
||||
|
||||
verify(regionParserSpy, times(1)).getBeanClass(eq(mockElement));
|
||||
verify(regionParserSpy, times(1)).getRegionFactoryClass();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentNameWhenTemplateIsSet() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq("template"))).thenReturn("test");
|
||||
assertThat(regionParser.getParentName(mockElement)).isEqualTo("test");
|
||||
verify(mockElement, times(1)).getAttribute(eq("template"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentNameWhenTemplateIsUnset() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq("template"))).thenReturn(null);
|
||||
assertThat(regionParser.getParentName(mockElement)).isNull();
|
||||
verify(mockElement, times(1)).getAttribute(eq("template"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isRegionTemplateWithRegionTemplateElementsIsTrue() {
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("client-region-template");
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("local-region-template");
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("partitioned-region-template");
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("replicated-region-template");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isRegionTemplateWithRegionElementsIsFalse() {
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("client-region");
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("local-region");
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("partitioned-region");
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("replicated-region");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isRegionTemplateWhenElementLocalNameDoesNotEndWithTemplateIsFalse() {
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("disk-store");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isRegionTemplateWhenElementLocalNameIsNullIsFalse() {
|
||||
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubRegionWithRegionElementIsTrue() {
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("client-region");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("local-region");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("partitioned-region");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("replicated-region");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubRegionWithRegionTemplateElementIsFalse() {
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("client-region-template");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("local-region-template");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("partitioned-region-template");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("replicated-region-template");
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("region-template");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubRegionWhenElementLocalNameDoesNotEndWithRegionIsFalse() {
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion("disk-store");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubRegionWhenElementLocalNameIsNullIsFalse() {
|
||||
assertIsSubRegionWhenElementLocalNameEndsWithRegion(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doParseWithAbstractRegionTemplate() {
|
||||
AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class);
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
Node mockNode = mock(Node.class);
|
||||
|
||||
when(mockElement.getLocalName()).thenReturn("partitioned-region-template");
|
||||
when(mockElement.getParentNode()).thenReturn(mockNode);
|
||||
when(mockNode.getLocalName()).thenReturn("cache");
|
||||
|
||||
regionParserSpy.doParse(mockElement, null, builder);
|
||||
|
||||
assertThat(builder.getRawBeanDefinition().isAbstract()).isTrue();
|
||||
|
||||
verify(regionParserSpy, times(1)).doParse(eq(mockElement), isNull(ParserContext.class), eq(builder));
|
||||
verify(regionParserSpy, times(1)).doParseRegion(eq(mockElement), isNull(ParserContext.class),
|
||||
eq(builder), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doParseWithNonAbstractSubRegion() {
|
||||
AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class);
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
Node mockNode = mock(Node.class);
|
||||
|
||||
when(mockElement.getLocalName()).thenReturn("replicated-region");
|
||||
when(mockElement.getParentNode()).thenReturn(mockNode);
|
||||
when(mockNode.getLocalName()).thenReturn("replicated-region");
|
||||
|
||||
regionParserSpy.doParse(mockElement, null, builder);
|
||||
|
||||
assertThat(builder.getRawBeanDefinition().isAbstract()).isFalse();
|
||||
|
||||
verify(regionParserSpy, times(1)).doParse(eq(mockElement), isNull(ParserContext.class), eq(builder));
|
||||
verify(regionParserSpy, times(1)).doParseRegion(eq(mockElement), isNull(ParserContext.class),
|
||||
eq(builder), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateDataPolicyShortcutAttributesMutualExclusion() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
|
||||
|
||||
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
|
||||
|
||||
verify(mockElement).hasAttribute(eq("data-policy"));
|
||||
verify(mockElement, never()).hasAttribute(eq("shortcut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateDataPolicyShortcutAttributesMutualExclusionWithDataPolicy() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
|
||||
|
||||
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
|
||||
|
||||
verify(mockElement).hasAttribute(eq("data-policy"));
|
||||
verify(mockElement).hasAttribute(eq("shortcut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateDataPolicyShortcutAttributesMutualExclusionWithShortcut() {
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
|
||||
|
||||
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
|
||||
|
||||
verify(mockElement).hasAttribute(eq("data-policy"));
|
||||
verify(mockElement, never()).hasAttribute(eq("shortcut"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateDataPolicyShortcutAttributesMutualExclusionWithDataPolicyAndShortcut() {
|
||||
Element mockElement = mock(Element.class);
|
||||
XmlReaderContext mockReaderContext = mock(XmlReaderContext.class);
|
||||
|
||||
ParserContext mockParserContext = new ParserContext(mockReaderContext, null);
|
||||
|
||||
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
|
||||
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
|
||||
when(mockElement.getTagName()).thenReturn("local-region");
|
||||
|
||||
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, mockParserContext);
|
||||
|
||||
verify(mockReaderContext).error(
|
||||
eq("Only one of [data-policy, shortcut] may be specified with element 'local-region'."),
|
||||
eq(mockElement));
|
||||
}
|
||||
|
||||
protected static class TestRegionParser extends AbstractRegionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getRegionFactoryClass() {
|
||||
return getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder, boolean subRegion) {
|
||||
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
@@ -27,6 +27,11 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictHelper;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
|
||||
import com.gemstone.gemfire.cache.util.TimestampedEntryEvent;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -36,17 +41,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.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictHelper;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
|
||||
import com.gemstone.gemfire.cache.util.TimestampedEntryEvent;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
@@ -223,5 +221,4 @@ public class CacheNamespaceTest{
|
||||
throw new UnsupportedOperationException("Not Implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,12 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.gemstone.gemfire.cache.server.CacheServer;
|
||||
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,9 +32,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.server.CacheServer;
|
||||
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
|
||||
|
||||
/**
|
||||
* The CacheServerNamespaceTest class is a test suite of test cases testing the functionality of the SDG XML namespace
|
||||
* when configuring a GemFire Cache Servers and Client Subscription.
|
||||
@@ -14,12 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,13 +33,9 @@ import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
|
||||
/**
|
||||
* Test to ensure subscription policy can be applied to server regions.
|
||||
*
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @author John Blum
|
||||
* @since 1.3.0
|
||||
@@ -44,10 +44,10 @@ import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
@ContextConfiguration("subscription-ns.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheSubscriptionTest{
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
@Test
|
||||
public void testReplicatedRegionSubscriptionAllPolicy() throws Exception {
|
||||
assertTrue(context.containsBean("replicALL"));
|
||||
@@ -77,7 +77,7 @@ public class CacheSubscriptionTest{
|
||||
assertNotNull(subscriptionAttributes);
|
||||
assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPartitionRegionSubscriptionDefaultPolicy() throws Exception {
|
||||
assertTrue(context.containsBean("partDEFAULT"));
|
||||
@@ -92,5 +92,5 @@ public class CacheSubscriptionTest{
|
||||
assertNotNull(subscriptionAttributes);
|
||||
assertEquals(InterestPolicy.DEFAULT, subscriptionAttributes.getInterestPolicy());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,24 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
|
||||
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.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
|
||||
/**
|
||||
* The CacheUsingPdxNamespaceTest class is a test suite of test case testing the Spring Data GemFire XML namespace
|
||||
* when PDX is configured in GemFire.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,8 +33,6 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
|
||||
/**
|
||||
* The ClientCacheNamespaceTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the Spring Data GemFire ClientCacheParser.
|
||||
@@ -15,13 +15,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -43,48 +39,62 @@ import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* The ClientCacheParserTest class is a test suite of test cases testing the contract and functionality of the
|
||||
* ClientCacheParser class.
|
||||
* Unit tests for {@link ClientCacheParser}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.config.xml.ClientCacheParser
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ClientCacheParserTest {
|
||||
public class ClientCacheParserUnitTests {
|
||||
|
||||
@Mock
|
||||
private Element mockElement;
|
||||
|
||||
protected void assertPropertyIsPresent(BeanDefinition beanDefinition, String propertyName) {
|
||||
assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isTrue();
|
||||
}
|
||||
|
||||
protected void assertPropertyIsNotPresent(BeanDefinition beanDefinition, String propertyName) {
|
||||
assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isFalse();
|
||||
}
|
||||
|
||||
protected void assertPropertyValueEquals(BeanDefinition beanDefinition, String propertyName,
|
||||
Object expectedPropertyValue) {
|
||||
|
||||
assertPropertyIsPresent(beanDefinition, propertyName);
|
||||
assertThat(beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue())
|
||||
.isEqualTo(expectedPropertyValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("all")
|
||||
public void beanClassEqualsClientCacheFactoryBean() {
|
||||
assertThat((Class<ClientCacheFactoryBean>) new ClientCacheParser().getBeanClass(mockElement),
|
||||
is(equalTo(ClientCacheFactoryBean.class)));
|
||||
assertThat(new ClientCacheParser().getBeanClass(mockElement)).isEqualTo(ClientCacheFactoryBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doParseSetsProperties() {
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
when(mockElement.getAttribute(eq("durable-client-id"))).thenReturn("123");
|
||||
when(mockElement.getAttribute(eq("durable-client-timeout"))).thenReturn("60");
|
||||
when(mockElement.getAttribute(eq("keep-alive"))).thenReturn("false");
|
||||
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("testPool");
|
||||
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("TestPool");
|
||||
when(mockElement.getAttribute(eq("ready-for-events"))).thenReturn(null);
|
||||
when(mockElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
|
||||
BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
final BeanDefinitionRegistry mockRegistry = mock(BeanDefinitionRegistry.class);
|
||||
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
ClientCacheParser clientCacheParser = new ClientCacheParser() {
|
||||
@Override protected BeanDefinitionRegistry getRegistry(ParserContext parserContext) {
|
||||
return mockRegistry;
|
||||
@@ -95,16 +105,16 @@ public class ClientCacheParserTest {
|
||||
|
||||
BeanDefinition clientCacheBeanDefinition = clientCacheBuilder.getBeanDefinition();
|
||||
|
||||
assertThat(clientCacheBeanDefinition, is(notNullValue()));
|
||||
assertThat(clientCacheBeanDefinition).isNotNull();
|
||||
|
||||
PropertyValues propertyValues = clientCacheBeanDefinition.getPropertyValues();
|
||||
|
||||
assertThat(propertyValues, is(notNullValue()));
|
||||
assertThat((String) propertyValues.getPropertyValue("durableClientId").getValue(), is(equalTo("123")));
|
||||
assertThat((String) propertyValues.getPropertyValue("durableClientTimeout").getValue(), is(equalTo("60")));
|
||||
assertThat((String) propertyValues.getPropertyValue("keepAlive").getValue(), is(equalTo("false")));
|
||||
assertThat((String) propertyValues.getPropertyValue("poolName").getValue(), is(equalTo("testPool")));
|
||||
assertThat(propertyValues.getPropertyValue("readyForEvents"), is(nullValue()));
|
||||
assertThat(propertyValues).isNotNull();
|
||||
assertPropertyValueEquals(clientCacheBeanDefinition, "durableClientId", "123");
|
||||
assertPropertyValueEquals(clientCacheBeanDefinition, "durableClientTimeout", "60");
|
||||
assertPropertyValueEquals(clientCacheBeanDefinition, "keepAlive", "false");
|
||||
assertPropertyValueEquals(clientCacheBeanDefinition, "poolName", "TestPool");
|
||||
assertPropertyIsNotPresent(clientCacheBeanDefinition, "readyForEvents");
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq("durable-client-id"));
|
||||
verify(mockElement, times(1)).getAttribute(eq("durable-client-timeout"));
|
||||
@@ -115,7 +125,7 @@ public class ClientCacheParserTest {
|
||||
|
||||
@Test
|
||||
public void postProcessDynamicRegionSupportParsesPoolName() {
|
||||
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("testPool");
|
||||
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("TestPool");
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
@@ -123,12 +133,9 @@ public class ClientCacheParserTest {
|
||||
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
|
||||
assertThat(beanDefinition, is(notNullValue()));
|
||||
assertThat(beanDefinition.getPropertyValues(), is(notNullValue()));
|
||||
assertThat(beanDefinition.getPropertyValues().getPropertyValue("poolName"), is(notNullValue()));
|
||||
assertThat((String) beanDefinition.getPropertyValues().getPropertyValue("poolName").getValue(), is(equalTo("testPool")));
|
||||
assertThat(beanDefinition).isNotNull();
|
||||
assertPropertyValueEquals(beanDefinition, "poolName", "TestPool");
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq("pool-name"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -33,22 +33,6 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
import com.gemstone.gemfire.cache.CacheLoaderException;
|
||||
@@ -66,6 +50,22 @@ import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
|
||||
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
|
||||
import com.gemstone.gemfire.compression.Compressor;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* The ClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
|
||||
* of GemFire Client Region namespace support in SDG.
|
||||
@@ -74,7 +74,7 @@ import com.gemstone.gemfire.compression.Compressor;
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.ClientRegionParser
|
||||
* @see org.springframework.data.gemfire.config.xml.ClientRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="client-ns.xml")
|
||||
@@ -374,5 +374,4 @@ public class ClientRegionNamespaceTest {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -35,7 +35,8 @@ public class ClientRegionUsingDataPolicyAndShortcutTest {
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testClientRegionBeanDefinitionWithDataPolicyAndShortcut() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/client-region-using-datapolicy-and-shortcut.xml");
|
||||
new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml");
|
||||
}
|
||||
catch (BeanDefinitionParsingException e) {
|
||||
assertTrue(e.getMessage().contains("Only one of [data-policy, shortcut] may be specified with element"));
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -26,8 +26,13 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.query.CqListener;
|
||||
import com.gemstone.gemfire.cache.query.CqQuery;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -43,10 +48,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.query.CqListener;
|
||||
import com.gemstone.gemfire.cache.query.CqQuery;
|
||||
|
||||
/**
|
||||
* The ContinuousQueryListenerContainerNamespaceTest class is a test suite of test cases testing the SDG XML namespace
|
||||
* for proper configuration and initialization of a ContinuousQueryListenerContainer bean component
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -26,6 +26,22 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CustomExpiry;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.EvictionAlgorithm;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAttributes;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.Region.Entry;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.util.ObjectSizer;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -43,22 +59,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CustomExpiry;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.EvictionAlgorithm;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAttributes;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.Region.Entry;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.util.ObjectSizer;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
@@ -186,7 +186,7 @@ public class DiskStoreAndEvictionRegionParsingTest {
|
||||
assertEquals(400, regionTTI.getTimeout());
|
||||
assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -194,10 +194,10 @@ public class DiskStoreAndEvictionRegionParsingTest {
|
||||
assertTrue(applicationContext.containsBean("replicated-data-custom-expiry"));
|
||||
RegionFactoryBean fb = applicationContext.getBean("&replicated-data-custom-expiry", RegionFactoryBean.class);
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
|
||||
|
||||
assertNotNull(attrs.getCustomEntryIdleTimeout());
|
||||
assertNotNull(attrs.getCustomEntryTimeToLive());
|
||||
|
||||
|
||||
assertTrue(attrs.getCustomEntryIdleTimeout() instanceof TestCustomExpiry);
|
||||
assertTrue(attrs.getCustomEntryTimeToLive() instanceof TestCustomExpiry);
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import java.io.File;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,8 +32,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
|
||||
/**
|
||||
* The DiskStoreNamespaceTest class is a test suite of test cases testing the contract and functionality of using
|
||||
* Spring Data GemFire's XML namespace to configure GemFire Disk Stores.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -23,6 +23,9 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.DynamicRegionFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,20 +33,17 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.DynamicRegionFactory;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*
|
||||
* This requires a real cache
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("/org/springframework/data/gemfire/config/dynamic-region-ns.xml")
|
||||
@ContextConfiguration("/org/springframework/data/gemfire/config/xml/dynamic-region-ns.xml")
|
||||
public class DynamicRegionNamespaceTest {
|
||||
|
||||
@Autowired ApplicationContext ctx;
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicCache() throws Exception {
|
||||
DynamicRegionFactory drf = DynamicRegionFactory.get();
|
||||
@@ -56,4 +56,4 @@ public class DynamicRegionNamespaceTest {
|
||||
assertFalse(config.registerInterest);
|
||||
assertEquals(File.separator + "foo", config.diskDir.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,21 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import com.gemstone.gemfire.cache.execute.FunctionAdapter;
|
||||
import com.gemstone.gemfire.cache.execute.FunctionContext;
|
||||
import com.gemstone.gemfire.cache.execute.FunctionService;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.execute.FunctionAdapter;
|
||||
import com.gemstone.gemfire.cache.execute.FunctionContext;
|
||||
import com.gemstone.gemfire.cache.execute.FunctionService;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
@@ -31,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
|
||||
/**
|
||||
* The GatewayReceiverAutoStartNamespaceTest class is a test suite of test cases testing the contract
|
||||
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
@@ -31,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
|
||||
/**
|
||||
* The GatewayReceiverDefaultStartNamespaceTest class is a test suite of test cases testing the contract
|
||||
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
@@ -30,8 +32,6 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
|
||||
/**
|
||||
* The GatewayReceiverManualStartNamespaceTest class is a test suite of test cases testing the contract
|
||||
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -27,15 +27,6 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
|
||||
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
|
||||
@@ -47,6 +38,15 @@ import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender.OrderPolicy;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
|
||||
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
|
||||
/**
|
||||
* The GemfireV7GatewayNamespaceTest class is a test suite of test cases testing the GemFire 7.0 WAN functionality
|
||||
* by configuring various Gateway senders and receivers.
|
||||
@@ -90,7 +90,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
*/
|
||||
@Override
|
||||
protected String location() {
|
||||
return "/org/springframework/data/gemfire/config/gateway-v7-ns.xml";
|
||||
return "/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -275,5 +275,4 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,13 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.gemstone.gemfire.cache.EntryEvent;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,10 +33,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.EntryEvent;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
/**
|
||||
* The GemfireV8GatewayNamespaceTest class is a test suite of test cases testing the contract and functionality of
|
||||
* GemFire 8 Gateway Sender/Receiver support.
|
||||
@@ -63,7 +63,7 @@ public class GemfireV8GatewayNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testGatewaySenderEventSubstitutionFilter() {
|
||||
assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!",
|
||||
assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!",
|
||||
gatewaySenderWithEventSubstitutionFilter);
|
||||
assertEquals("gateway-sender-with-event-substitution-filter", gatewaySenderWithEventSubstitutionFilter.getId());
|
||||
assertEquals(3, gatewaySenderWithEventSubstitutionFilter.getRemoteDSId());
|
||||
@@ -14,21 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.Index;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.Index;
|
||||
|
||||
/**
|
||||
* The IndexNamespaceTest is a test suite of test cases testing the functionality of GemFire Index creation using
|
||||
* the Spring Data GemFire XML namespace (XSD).
|
||||
@@ -37,7 +37,7 @@ import com.gemstone.gemfire.cache.query.Index;
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.IndexParser
|
||||
* @see org.springframework.data.gemfire.config.xml.IndexParser
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user