From 7efa90800fdf2720c240bfa03dbe989909d7742a Mon Sep 17 00:00:00 2001 From: David Turanski Date: Wed, 27 Jun 2012 07:18:47 -0400 Subject: [PATCH] Complete disk store refactoring and added region attributes --- .../data/gemfire/DiskStoreFactoryBean.java | 2 - .../gemfire/RegionAttributesFactoryBean.java | 39 +- .../data/gemfire/RegionFactoryBean.java | 49 +- .../client/ClientRegionFactoryBean.java | 84 +- .../gemfire/config/AbstractRegionParser.java | 61 + .../AliasReplacingBeanDefinitionParser.java | 3 +- .../gemfire/config/ClientRegionParser.java | 17 +- .../gemfire/config/LocalRegionParser.java | 79 +- .../data/gemfire/config/ParsingUtils.java | 89 +- .../config/PartitionedRegionParser.java | 66 +- .../config/ReplicatedRegionParser.java | 68 +- .../gemfire/config/spring-gemfire-1.2.xsd | 2883 +++++++++-------- .../config/ClientRegionNamespaceTest.java | 30 +- ...DiskStoreAndEvictionRegionParsingTest.java | 61 +- .../config/DiskStoreNamespaceTest.java | 72 - .../config/LocalRegionNamespaceTest.java | 22 +- .../PartitionedRegionNamespaceTest.java | 2 +- .../config/ReplicatedRegionNamespaceTest.java | 19 + .../data/gemfire/config/client-ns.xml | 18 +- .../data/gemfire/config/diskstore-ns-new.xml | 29 - .../data/gemfire/config/diskstore-ns.xml | 52 +- .../data/gemfire/config/local-ns.xml | 10 + .../data/gemfire/config/replicated-ns.xml | 15 + 23 files changed, 1968 insertions(+), 1802 deletions(-) delete mode 100644 src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java delete mode 100644 src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml diff --git a/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java b/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java index 6684727b..da37c01d 100644 --- a/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/DiskStoreFactoryBean.java @@ -109,7 +109,6 @@ public class DiskStoreFactoryBean implements FactoryBean, Initializin } diskStoreFactory.setDiskDirsAndSizes(diskDirFiles, diskDirSizes); } - } public void setCache(GemFireCache cache) { @@ -168,5 +167,4 @@ public class DiskStoreFactoryBean implements FactoryBean, Initializin this.maxSize = null; } } - } diff --git a/src/main/java/org/springframework/data/gemfire/RegionAttributesFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionAttributesFactoryBean.java index 23febbc9..27b1c194 100644 --- a/src/main/java/org/springframework/data/gemfire/RegionAttributesFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/RegionAttributesFactoryBean.java @@ -16,67 +16,40 @@ package org.springframework.data.gemfire; -import java.io.File; - import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.ObjectUtils; import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.RegionAttributes; /** - * Spring-friendly bean for creating {@link RegionAttributes}. Eliminates the need of using - * a XML 'factory-method' tag. + * Spring-friendly bean for creating {@link RegionAttributes}. Eliminates the + * need of using a XML 'factory-method' tag. * * @author Costin Leau */ public class RegionAttributesFactoryBean extends AttributesFactory implements FactoryBean, InitializingBean { - private int[] diskSizes; - private File[] diskDirs; - private RegionAttributes attributes; + @Override public void afterPropertiesSet() throws Exception { - if (diskSizes!= null){ - super.setDiskDirsAndSizes(diskDirs, diskSizes); - } - else{ - if (!ObjectUtils.isEmpty(diskDirs)) { - super.setDiskDirs(diskDirs); - } - } - attributes = super.create(); } + @Override public RegionAttributes getObject() throws Exception { return attributes; } + @Override public Class getObjectType() { return (attributes != null ? attributes.getClass() : RegionAttributes.class); } + @Override public boolean isSingleton() { return true; } - - - @Override - public void setDiskDirs(File[] diskDirs) { - this.diskDirs = diskDirs; - } - - /** - * Sets the sizes (in megabytes) for each disk directory. - * Used only disk directories are specified. - * - * @param sizes - */ - public void setDiskSizes(int[] sizes) { - this.diskSizes = sizes; - } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java index 51a4438b..87e62529 100644 --- a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,6 +52,7 @@ import com.gemstone.gemfire.cache.Scope; * defaults. * * @author Costin Leau + * @author David Turanski */ public class RegionFactoryBean extends RegionLookupFactoryBean implements DisposableBean { @@ -73,8 +74,12 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple private Scope scope; + private String diskStoreName; + private DataPolicy dataPolicy; + private String dataPolicyName; + private Region region; private List> subRegions; @@ -116,10 +121,31 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple regionFactory.setDataPolicy(dataPolicy); } + if (dataPolicyName != null) { + Assert.isNull(dataPolicy, "'dataPolicy' and 'dataPolicyName' are mutually exclusive."); + if ("NORMAL".equals(dataPolicyName)) { + regionFactory.setDataPolicy(DataPolicy.NORMAL); + } + else if ("PRELOADED".equals(dataPolicyName)) { + regionFactory.setDataPolicy(DataPolicy.PRELOADED); + } + else { + throw new IllegalArgumentException("Data policy '" + dataPolicyName + "' is unsupported or invalid."); + } + + } + if (scope != null) { regionFactory.setScope(scope); } + if (diskStoreName != null) { + regionFactory.setDiskStoreName(diskStoreName); + } + + Assert.state(!attributes.isLockGrantor() || scope.isGlobal(), + "Lock grantor only applies to a global scoped region"); + // get underlying AttributesFactory postProcess(findAttrFactory(regionFactory)); @@ -129,8 +155,8 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple reg.loadSnapshot(snapshot.getInputStream()); } - if (subRegions != null) { - System.out.println("**********************************************" + subRegions.get(0)); + if (attributes.isLockGrantor()) { + reg.becomeLockGrantor(); } return reg; @@ -291,6 +317,23 @@ public class RegionFactoryBean extends RegionLookupFactoryBean imple this.scope = scope; } + /** + * Sets the dataPolicy as a String. Required to support property + * placeholders + * @param dataPolicyName the dataPolicy name (NORMAL, PRELOADED, etc) + */ + public void setDataPolicyName(String dataPolicyName) { + this.dataPolicyName = dataPolicyName; + } + + /** + * Sets the name of disk store to use for overflow and persistence + * @param diskStoreName + */ + public void setDiskStoreName(String diskStoreName) { + this.diskStoreName = diskStoreName; + } + /** * Sets the region attributes used for the region used by this factory. * Allows maximum control in specifying the region settings. Used only when diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java index 705d7b84..5271cac8 100644 --- a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; * Client extension for GemFire regions. * * @author Costin Leau + * @author David Turanski */ public class ClientRegionFactoryBean extends RegionLookupFactoryBean implements BeanFactoryAware, DisposableBean { @@ -51,19 +52,28 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean private static final Log log = LogFactory.getLog(ClientRegionFactoryBean.class); private boolean destroy = false; + private boolean close = true; + private Resource snapshot; private CacheListener cacheListeners[]; + private Interest[] interests; + private String poolName; + private BeanFactory beanFactory; + private ClientRegionShortcut shortcut = null; + private DataPolicy dataPolicy; private RegionAttributes attributes; + private Region region; + private String diskStoreName; @Override public void afterPropertiesSet() throws Exception { @@ -76,12 +86,11 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean protected Region lookupFallback(GemFireCache cache, String regionName) throws Exception { Assert.isTrue(cache instanceof ClientCache, "Unable to create regions from " + cache); ClientCache c = (ClientCache) cache; - + if (cache instanceof GemFireCacheImpl) { Assert.isTrue(((GemFireCacheImpl) cache).isClient(), "A client-cache instance is required"); } - // first look at shortcut ClientRegionShortcut s = null; @@ -103,7 +112,8 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean else { s = ClientRegionShortcut.LOCAL; } - } else { + } + else { s = shortcut; } @@ -154,6 +164,10 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean factory.setPoolName(poolName); } + if (diskStoreName != null) { + factory.setDiskStoreName(diskStoreName); + } + Region reg = factory.create(regionName); log.info("Created new cache region [" + regionName + "]"); if (snapshot != null) { @@ -179,6 +193,7 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } } + @Override public void destroy() throws Exception { Region region = getObject(); // unregister interests @@ -193,8 +208,10 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } } } - // should not really happen since interests are validated at start/registration - } catch (UnsupportedOperationException ex) { + // should not really happen since interests are validated at + // start/registration + } + catch (UnsupportedOperationException ex) { log.warn("Cannot unregister cache interests", ex); } @@ -203,7 +220,8 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean if (!region.getCache().isClosed()) { try { region.close(); - } catch (CacheClosedException cce) { + } + catch (CacheClosedException cce) { // nothing to see folks, move on. } } @@ -215,13 +233,14 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean region = null; } + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; } - /** - * Set the interests for this client region. Both key and regex interest are supported. + * Set the interests for this client region. Both key and regex interest are + * supported. * * @param interests the interests to set */ @@ -257,9 +276,9 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } /** - * Initializes the client using a GemFire {@link ClientRegionShortcut}. - * The recommended way for creating clients since it covers all the major scenarios with minimal - * configuration. + * Initializes the client using a GemFire {@link ClientRegionShortcut}. The + * recommended way for creating clients since it covers all the major + * scenarios with minimal configuration. * * @param shortcut */ @@ -268,9 +287,9 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } /** - * Indicates whether the region referred by this factory bean, - * will be destroyed on shutdown (default false). - * Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other. + * Indicates whether the region referred by this factory bean, will be + * destroyed on shutdown (default false). Note: destroy and close are + * mutually exclusive. Enabling one will automatically disable the other. * * @param destroy whether or not to destroy the region * @@ -285,9 +304,9 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } /** - * Indicates whether the region referred by this factory bean, - * will be closed on shutdown (default true). - * Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other. + * Indicates whether the region referred by this factory bean, will be + * closed on shutdown (default true). Note: destroy and close are mutually + * exclusive. Enabling one will automatically disable the other. * * @param close whether to close or not the region * @see #setDestroy(boolean) @@ -300,9 +319,9 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } /** - * Sets the snapshots used for loading a newly created region. - * That is, the snapshot will be used only when a new region is created - if the region - * already exists, no loading will be performed. + * Sets the snapshots used for loading a newly created region. That + * is, the snapshot will be used only when a new region is created - + * if the region already exists, no loading will be performed. * * @see #setName(String) * @param snapshot the snapshot to set @@ -312,9 +331,9 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean } /** - * Sets the cache listeners used for the region used by this factory. - * Used only when a new region is created.Overrides the settings - * specified through {@link #setAttributes(RegionAttributes)}. + * Sets the cache listeners used for the region used by this factory. Used + * only when a new region is created.Overrides the settings specified + * through {@link #setAttributes(RegionAttributes)}. * * @param cacheListeners the cacheListeners to set on a newly created region */ @@ -331,12 +350,21 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean this.dataPolicy = dataPolicy; } + /** + * Sets the name of disk store to use for overflow and persistence + * @param diskStoreName + */ + public void setDiskStoreName(String diskStoreName) { + this.diskStoreName = diskStoreName; + } + /** * Sets the region attributes used for the region used by this factory. - * Allows maximum control in specifying the region settings. - * Used only when a new region is created. - * Note that using this method allows for advanced customization of the region - while it provides a lot of flexibility, - * note that it's quite easy to create misconfigured regions (especially in a client/server scenario). + * Allows maximum control in specifying the region settings. Used only when + * a new region is created. Note that using this method allows for advanced + * customization of the region - while it provides a lot of flexibility, + * note that it's quite easy to create misconfigured regions (especially in + * a client/server scenario). * * @param attributes the attributes to set on a newly created region */ diff --git a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java index 877edc85..12e54aa5 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java @@ -16,6 +16,8 @@ package org.springframework.data.gemfire.config; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.config.BeanDefinition; @@ -23,6 +25,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** @@ -86,6 +89,52 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { this.registerBeanDefinition(new BeanDefinitionHolder(subRegionDef, regionPath), parserContext.getRegistry()); } + protected void doParseRegionCommon(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, + BeanDefinitionBuilder attrBuilder, boolean subRegion) { + + if (!subRegion) { + String cacheRef = element.getAttribute("cache-ref"); + // add cache reference (fallback to default if nothing is specified) + builder.addPropertyReference("cache", (StringUtils.hasText(cacheRef) ? cacheRef : "gemfire-cache")); + } + // add attributes + ParsingUtils.setPropertyValue(element, builder, "name"); + ParsingUtils.parseOptionalRegionAttributes(parserContext, element, attrBuilder); + ParsingUtils.parseStatistics(element, attrBuilder); + ParsingUtils.setPropertyValue(element, attrBuilder, "publisher"); + + if (StringUtils.hasText(element.getAttribute("disk-store-ref"))) { + ParsingUtils.setPropertyValue(element, builder, "disk-store-ref", "diskStoreName"); + builder.addDependsOn(element.getAttribute("disk-store-ref")); + } + + ParsingUtils.parseExpiration(parserContext, element, attrBuilder); + ParsingUtils.parseEviction(parserContext, element, attrBuilder); + + List subElements = DomUtils.getChildElements(element); + + // parse nested elements + for (Element subElement : subElements) { + String name = subElement.getLocalName(); + + if ("cache-listener".equals(name)) { + builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder)); + } + + else if ("cache-loader".equals(name)) { + builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder)); + } + + else if ("cache-writer".equals(name)) { + builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder)); + } + // subregion + else if (name.endsWith("region")) { + doParseSubRegion(element, subElement, parserContext, builder, subRegion); + } + } + } + private BeanDefinition parseSubRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(element, builder.getBeanDefinition()); @@ -96,4 +145,16 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { String name = element.getAttribute(NAME_ATTRIBUTE); return StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE); } + + private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); + } + + private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); + } + + private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); + } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java index e8d2f951..b744507a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * 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. @@ -32,6 +32,7 @@ import org.w3c.dom.Element; * parsing method is final). * * @author Costin Leau + * @author David Turanski */ abstract class AliasReplacingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java index 65270ac7..fd4f6774 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,12 +34,15 @@ import com.gemstone.gemfire.cache.DataPolicy; /** * Parser for <client-region;gt; definitions. * - * To avoid eager evaluations, the region interests are declared as nested definition. + * To avoid eager evaluations, the region interests are declared as nested + * definition. * * @author Costin Leau + * @author David Turanski */ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { + @Override protected Class getBeanClass(Element element) { return ClientRegionFactoryBean.class; } @@ -58,7 +61,6 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { ParsingUtils.setPropertyValue(element, builder, "pool-name", "poolName"); ParsingUtils.setPropertyValue(element, builder, "shortcut", "shortcut"); - // set the persistent policy String attr = element.getAttribute("persistent"); @@ -76,14 +78,19 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { // eviction + overflow attributes // client attributes - BeanDefinitionBuilder attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); + BeanDefinitionBuilder attrBuilder = BeanDefinitionBuilder + .genericBeanDefinition(RegionAttributesFactoryBean.class); ParsingUtils.parseStatistics(element, attrBuilder); + if (StringUtils.hasText(element.getAttribute("disk-store-ref"))) { + ParsingUtils.setPropertyValue(element, builder, "disk-store-ref", "diskStoreName"); + builder.addDependsOn(element.getAttribute("disk-store-ref")); + } + boolean overwriteDataPolicy = false; overwriteDataPolicy |= ParsingUtils.parseEviction(parserContext, element, attrBuilder); - overwriteDataPolicy |= ParsingUtils.parseDiskStorage(element, attrBuilder); if (!frozenDataPolicy && overwriteDataPolicy) { builder.addPropertyValue("dataPolicy", DataPolicy.NORMAL); diff --git a/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java index 0111be65..c5bfbb31 100644 --- a/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java @@ -16,15 +16,13 @@ package org.springframework.data.gemfire.config; -import java.util.List; - import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.RegionAttributesFactoryBean; import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; +import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.Scope; /** @@ -39,78 +37,23 @@ class LocalRegionParser extends AbstractRegionParser { boolean subRegion) { // set the data policy - String attr = element.getAttribute("persistent"); - // if (Boolean.parseBoolean(attr)) { - // builder.addPropertyValue("dataPolicy", - // DataPolicy.PERSISTENT_REPLICATE); - // } - // else { - // builder.addPropertyValue("dataPolicy", DataPolicy.REPLICATE); - // } + String attr = element.getAttribute("data-policy"); + if (StringUtils.hasText(attr)) { + builder.addPropertyValue("dataPolicyName", attr.toUpperCase()); + } + else { + builder.addPropertyValue("dataPolicy", DataPolicy.NORMAL); + } builder.addPropertyValue("scope", Scope.LOCAL); - ParsingUtils.setPropertyValue(element, builder, "name", "name"); - - BeanDefinitionBuilder attrBuilder = builder; - - if (!subRegion) { - attr = element.getAttribute("cache-ref"); - // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache")); - attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); - } - // add attributes - - ParsingUtils.parseStatistics(element, attrBuilder); - - attr = element.getAttribute("publisher"); - if (StringUtils.hasText(attr)) { - attrBuilder.addPropertyValue("publisher", Boolean.valueOf(attr)); - } - - ParsingUtils.parseExpiration(parserContext, element, attrBuilder); - ParsingUtils.parseEviction(parserContext, element, attrBuilder); - ParsingUtils.parseDiskStorage(element, attrBuilder); + BeanDefinitionBuilder attrBuilder = subRegion ? builder : BeanDefinitionBuilder + .genericBeanDefinition(RegionAttributesFactoryBean.class); + super.doParseRegionCommon(element, parserContext, builder, attrBuilder, subRegion); if (!subRegion) { builder.addPropertyValue("attributes", attrBuilder.getBeanDefinition()); } - - List subElements = DomUtils.getChildElements(element); - - // parse nested elements - for (Element subElement : subElements) { - String name = subElement.getLocalName(); - - if ("cache-listener".equals(name)) { - builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder)); - } - - else if ("cache-loader".equals(name)) { - builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder)); - } - - else if ("cache-writer".equals(name)) { - builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder)); - } - // subregion - else if (name.endsWith("region")) { - doParseSubRegion(element, subElement, parserContext, builder, subRegion); - } - } - } - - private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java index ad809893..59e5eb5a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,19 +28,19 @@ import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.Conventions; -import org.springframework.data.gemfire.DiskStoreFactoryBean; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; -import com.gemstone.gemfire.cache.DiskStoreFactory; import com.gemstone.gemfire.cache.ExpirationAction; import com.gemstone.gemfire.cache.ExpirationAttributes; +import com.gemstone.gemfire.cache.Scope; /** * Various minor utility used by the parser. * * @author Costin Leau + * @author David Turanski */ abstract class ParsingUtils { @@ -156,54 +156,6 @@ abstract class ParsingUtils { return list; } - /** - * Parses disk store sub-element. Populates the given attribute factory with - * the proper attributes. - * - * @param element - element enclosing the disk-store definition - * @param beanBuilder - beanbuilder for a RegionAttributesFactoryBean - * instance - * @return true if parsing actually occured, false otherwise - */ - static boolean parseDiskStorage(Element element, BeanDefinitionBuilder beanBuilder) { - Element diskStoreElement = DomUtils.getChildElementByTagName(element, "disk-store"); - - if (diskStoreElement == null) - return false; - - if (diskStoreElement.getParentNode().getLocalName().endsWith("region")) { - System.out.println("This is a nested disk-store"); - } - - BeanDefinitionBuilder diskDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskStoreFactory.class); - setPropertyValue(diskStoreElement, diskDefBuilder, "auto-compact", "rollOplogs"); - setPropertyValue(diskStoreElement, diskDefBuilder, "max-oplog-size", "maxOplogSize"); - setPropertyValue(diskStoreElement, diskDefBuilder, "time-interval", "timeInterval"); - setPropertyValue(diskStoreElement, diskDefBuilder, "queue-size", "bytesThreshold"); - - // parse nested disk-dir - List list = DomUtils.getChildElementsByTagName(diskStoreElement, "disk-dir"); - ManagedList locations = new ManagedList(list.size()); - ManagedList sizes = new ManagedList(list.size()); - - for (Element diskDirElement : list) { - locations.add(diskDirElement.getAttribute("location")); - - String attr = diskDirElement.getAttribute("max-size"); - sizes.add(StringUtils.hasText(attr) ? attr : "10240"); - } - - // wrap up the disk attributes factory to call 'create' - - BeanDefinitionBuilder factoryWrapper = BeanDefinitionBuilder.genericBeanDefinition(DiskStoreFactoryBean.class); - factoryWrapper.addPropertyValue("diskAttributesFactory", diskDefBuilder.getBeanDefinition()); - beanBuilder.addPropertyValue("diskWriteAttributes", factoryWrapper.getBeanDefinition()); - beanBuilder.addPropertyValue("diskDirs", locations); - beanBuilder.addPropertyValue("diskSizes", sizes); - - return true; - } - /** * Parses the eviction sub-element. Populates the given attribute factory * with the proper attributes. @@ -228,8 +180,8 @@ abstract class ParsingUtils { evictionDefBuilder.addPropertyValue("type", EvictionType.valueOf(attr.toUpperCase())); } - setPropertyValue(evictionElement, evictionDefBuilder, "threshold", "threshold"); - setPropertyValue(evictionElement, evictionDefBuilder, "action", "action"); + setPropertyValue(evictionElement, evictionDefBuilder, "threshold"); + setPropertyValue(evictionElement, evictionDefBuilder, "action"); // get object sizer (if declared) Element objectSizerElement = DomUtils.getChildElementByTagName(evictionElement, "object-sizer"); @@ -270,16 +222,21 @@ abstract class ParsingUtils { return result; } - static void parseAdditionalAttributes(ParserContext parserContext, Element element, + static void parseOptionalRegionAttributes(ParserContext parserContext, Element element, BeanDefinitionBuilder attrBuilder) { - setPropertyValue(element, attrBuilder, "persistent", "persistBackup"); + if (!("partitioned-region".equals(element.getLocalName()))) { + setPropertyValue(element, attrBuilder, "persistent", "persistBackup"); + } setPropertyValue(element, attrBuilder, "ignore-jta", "ignoreJTA"); - setPropertyValue(element, attrBuilder, "key-constraint", "keyConstraint"); - setPropertyValue(element, attrBuilder, "value-constraint", "valueConstraint"); - setPropertyValue(element, attrBuilder, "lock-grantor", "lockGrantor"); - setPropertyValue(element, attrBuilder, "enable-subscription-conflation", "enableSubscriptionConflation"); - setPropertyValue(element, attrBuilder, "enable-async-conflation", "enableAsyncConflation"); - setPropertyValue(element, attrBuilder, "initial-capacity", "initialCapacity"); + setPropertyValue(element, attrBuilder, "key-constraint"); + setPropertyValue(element, attrBuilder, "value-constraint"); + setPropertyValue(element, attrBuilder, "is-lock-grantor", "lockGrantor"); + setPropertyValue(element, attrBuilder, "enable-subscription-conflation"); + setPropertyValue(element, attrBuilder, "enable-async-conflation"); + setPropertyValue(element, attrBuilder, "initial-capacity"); + setPropertyValue(element, attrBuilder, "load-factor"); + setPropertyValue(element, attrBuilder, "cloning-enabled"); + String indexUpdateType = element.getAttribute("index-update-type"); if (StringUtils.hasText(indexUpdateType)) { attrBuilder.addPropertyValue("indexMaintenanceSynchronous", "synchronous".equals(indexUpdateType)); @@ -287,6 +244,16 @@ abstract class ParsingUtils { } + static void parseScope(Element element, BeanDefinitionBuilder builder) { + String scope = element.getAttribute("scope"); + if (StringUtils.hasText(scope)) { + builder.addPropertyValue("scope", Scope.fromString(scope.toUpperCase().replace("-", "_"))); + } + else { + builder.addPropertyValue("scope", Scope.DISTRIBUTED_ACK); + } + } + private static boolean parseExpiration(Element rootElement, String elementName, String propertyName, BeanDefinitionBuilder attrBuilder) { Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName); diff --git a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java index 78e504c3..9acbe69b 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java @@ -65,21 +65,13 @@ class PartitionedRegionParser extends AbstractRegionParser { builder.addPropertyValue("dataPolicy", DataPolicy.PARTITION); } - BeanDefinitionBuilder attrBuilder = builder; + ParsingUtils.parseScope(element, builder); - if (!subRegion) { - attr = element.getAttribute("cache-ref"); - // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache")); - attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); - } - ParsingUtils.setPropertyValue(element, builder, "name", "name"); - - ParsingUtils.parseStatistics(element, attrBuilder); - ParsingUtils.parseExpiration(parserContext, element, attrBuilder); - ParsingUtils.parseEviction(parserContext, element, attrBuilder); - ParsingUtils.parseDiskStorage(element, attrBuilder); + BeanDefinitionBuilder attrBuilder = subRegion ? builder : BeanDefinitionBuilder + .genericBeanDefinition(RegionAttributesFactoryBean.class); + super.doParseRegionCommon(element, parserContext, builder, attrBuilder, subRegion); + // // partition attributes BeanDefinitionBuilder parAttrBuilder = BeanDefinitionBuilder .genericBeanDefinition(PartitionAttributesFactoryBean.class); @@ -120,36 +112,16 @@ class PartitionedRegionParser extends AbstractRegionParser { if (StringUtils.hasText(attr)) { parAttrBuilder.addPropertyValue("totalNumBuckets", Integer.valueOf(attr)); } - - List subElements = DomUtils.getChildElements(element); - - // parse nested cache-listener elements + // + List subElements = DomUtils.getChildElementsByTagName(element, "partition-resolver"); + // + // // parse nested cache-listener elements for (Element subElement : subElements) { - String name = subElement.getLocalName(); - - if ("cache-listener".equals(name)) { - builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder)); - } - - else if ("cache-loader".equals(name)) { - builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder)); - } - - else if ("cache-writer".equals(name)) { - builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder)); - } - - else if ("partition-resolver".equals(name)) { - parAttrBuilder.addPropertyValue("partitionResolver", - parsePartitionResolver(parserContext, subElement, builder)); - } - // subregion - else if (name.endsWith("region")) { - doParseSubRegion(element, subElement, parserContext, builder, subRegion); - } + parAttrBuilder.addPropertyValue("partitionResolver", + parsePartitionResolver(parserContext, subElement, builder)); } - - // add partition attributes attributes + // + // // add partition attributes attributes attrBuilder.addPropertyValue("partitionAttributes", parAttrBuilder.getBeanDefinition()); // add partition/overflow settings as attributes if (!subRegion) { @@ -157,18 +129,6 @@ class PartitionedRegionParser extends AbstractRegionParser { } } - private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - private Object parsePartitionResolver(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); } diff --git a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java index bb40f29a..1dba8a8f 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java @@ -16,17 +16,12 @@ package org.springframework.data.gemfire.config; -import java.util.List; - import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.RegionAttributesFactoryBean; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.Scope; /** * Parser for <replicated-region;gt; definitions. @@ -48,69 +43,14 @@ class ReplicatedRegionParser extends AbstractRegionParser { builder.addPropertyValue("dataPolicy", DataPolicy.REPLICATE); } - builder.addPropertyValue("scope", Scope.DISTRIBUTED_ACK); + ParsingUtils.parseScope(element, builder); - ParsingUtils.setPropertyValue(element, builder, "name", "name"); - - BeanDefinitionBuilder attrBuilder = builder; - - if (!subRegion) { - attr = element.getAttribute("cache-ref"); - // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache")); - attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); - } - // add attributes - ParsingUtils.parseAdditionalAttributes(parserContext, element, attrBuilder); - ParsingUtils.parseStatistics(element, attrBuilder); - - attr = element.getAttribute("publisher"); - if (StringUtils.hasText(attr)) { - attrBuilder.addPropertyValue("publisher", Boolean.valueOf(attr)); - } - - ParsingUtils.parseExpiration(parserContext, element, attrBuilder); - ParsingUtils.parseEviction(parserContext, element, attrBuilder); - ParsingUtils.parseDiskStorage(element, attrBuilder); + BeanDefinitionBuilder attrBuilder = subRegion ? builder : BeanDefinitionBuilder + .genericBeanDefinition(RegionAttributesFactoryBean.class); + super.doParseRegionCommon(element, parserContext, builder, attrBuilder, subRegion); if (!subRegion) { builder.addPropertyValue("attributes", attrBuilder.getBeanDefinition()); } - - List subElements = DomUtils.getChildElements(element); - - // parse nested elements - for (Element subElement : subElements) { - String name = subElement.getLocalName(); - - if ("cache-listener".equals(name)) { - builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder)); - } - - else if ("cache-loader".equals(name)) { - builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder)); - } - - else if ("cache-writer".equals(name)) { - builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder)); - } - // subregion - else if (name.endsWith("region")) { - doParseSubRegion(element, subElement, parserContext, builder, subRegion); - } - } } - - private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - } \ No newline at end of file diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd index 0f351362..85f4a2b6 100644 --- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd @@ -1,76 +1,92 @@ - - - - - - - - + + + + + + + - - - - - - + + + + + - - - - - + + + + - - - - - + + + + namespace and its 'properties' element. ]]> - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + - - - - - - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - - + + + + + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The reference to a GemfireTemplate. Will default to 'gemfireTemplate'. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java index e7e4ae7e..57fac6a3 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import java.io.File; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -42,11 +40,13 @@ import com.gemstone.gemfire.cache.EvictionAction; import com.gemstone.gemfire.cache.EvictionAlgorithm; import com.gemstone.gemfire.cache.EvictionAttributes; import com.gemstone.gemfire.cache.InterestResultPolicy; +import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.util.ObjectSizer; /** * @author Costin Leau + * @author David Turanski */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("client-ns.xml") @@ -72,7 +72,7 @@ public class ClientRegionNamespaceTest { assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", fb)); } - //@Test + // @Test public void testComplexClient() throws Exception { assertTrue(context.containsBean("complex")); ClientRegionFactoryBean fb = context.getBean("&complex", ClientRegionFactoryBean.class); @@ -87,7 +87,8 @@ public class ClientRegionNamespaceTest { Interest keyInt = ints[0]; assertTrue((Boolean) TestUtils.readField("durable", keyInt)); assertEquals(InterestResultPolicy.KEYS, TestUtils.readField("policy", keyInt)); - //assertEquals(Object.class, TestUtils.readField("key", keyInt).getClass()); + // assertEquals(Object.class, TestUtils.readField("key", + // keyInt).getClass()); // regex interest RegexInterest regexInt = (RegexInterest) ints[1]; @@ -99,14 +100,10 @@ public class ClientRegionNamespaceTest { @Test public void testPersistent() throws Exception { assertTrue(context.containsBean("persistent")); - ClientRegionFactoryBean fb = context.getBean("&persistent", ClientRegionFactoryBean.class); - assertEquals(DataPolicy.PERSISTENT_REPLICATE, TestUtils.readField("dataPolicy", fb)); - RegionAttributes attrs = TestUtils.readField("attributes", fb); - File[] diskDirs = attrs.getDiskDirs(); - assertEquals(1, diskDirs.length); - int[] diskDirSizes = attrs.getDiskDirSizes(); - assertEquals(1, diskDirSizes.length); - assertEquals(1, diskDirSizes[0]); + Region region = context.getBean("persistent", Region.class); + RegionAttributes attrs = region.getAttributes(); + assertEquals("diskStore", attrs.getDiskStoreName()); + assertEquals(1, attrs.getDiskDirSizes()[0]); } @Test @@ -116,10 +113,11 @@ public class ClientRegionNamespaceTest { assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb)); RegionAttributes attrs = TestUtils.readField("attributes", fb); EvictionAttributes evicAttr = attrs.getEvictionAttributes(); - assertEquals(EvictionAction.LOCAL_DESTROY, evicAttr.getAction()); + assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction()); assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm()); - // for some reason GemFire resets this to 56 on my machine (not sure why) - //assertEquals(10, evicAttr.getMaximum()); + // for some reason GemFire resets this to 56 on my machine (not sure + // why) + // assertEquals(10, evicAttr.getMaximum()); ObjectSizer sizer = evicAttr.getObjectSizer(); assertEquals(SimpleObjectSizer.class, sizer.getClass()); } diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java b/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java index c4e0bec8..cf262d2c 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java @@ -18,10 +18,13 @@ package org.springframework.data.gemfire.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; 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.beans.factory.annotation.Autowired; @@ -32,12 +35,16 @@ import org.springframework.data.gemfire.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.gemstone.gemfire.cache.Cache; 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.RegionAttributes; import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.cache.util.ObjectSizer; @@ -52,20 +59,50 @@ public class DiskStoreAndEvictionRegionParsingTest { @Autowired private ApplicationContext context; + @Autowired + DiskStore diskStore1; + + private static File diskStoreDir; + + @BeforeClass + public static void setUp() { + String path = "./build/tmp"; + diskStoreDir = new File(path); + if (!diskStoreDir.exists()) { + diskStoreDir.mkdir(); + } + } + + @AfterClass + public static void tearDown() { + for (File file : diskStoreDir.listFiles()) { + file.delete(); + } + diskStoreDir.delete(); + } + + @Test + public void testDiskStore() { + assertEquals("diskStore1", diskStore1.getName()); + assertEquals(50, diskStore1.getQueueSize()); + assertEquals(true, diskStore1.getAutoCompact()); + assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore1.getCompactionThreshold()); + assertEquals(9999, diskStore1.getTimeInterval()); + assertEquals(10, diskStore1.getMaxOplogSize()); + assertEquals(diskStoreDir, diskStore1.getDiskDirs()[0]); + Cache cache = context.getBean("gemfire-cache", Cache.class); + assertSame(diskStore1, cache.findDiskStore("diskStore1")); + } + @Test public void testReplicaDataOptions() throws Exception { assertTrue(context.containsBean("replicated-data")); RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class); - assertEquals(DataPolicy.PERSISTENT_REPLICATE, TestUtils.readField("dataPolicy", fb)); + assertEquals(DataPolicy.REPLICATE, TestUtils.readField("dataPolicy", fb)); assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb)); - RegionAttributes attrs = TestUtils.readField("attributes", fb); - File[] diskDirs = attrs.getDiskDirs(); - assertEquals(1, diskDirs.length); - int[] diskDirSizes = attrs.getDiskDirSizes(); - assertEquals(1, diskDirSizes.length); - assertEquals(1, diskDirSizes[0]); - + Region region = context.getBean("replicated-data", Region.class); // eviction tests + RegionAttributes attrs = TestUtils.readField("attributes", fb); EvictionAttributes evicAttr = attrs.getEvictionAttributes(); assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction()); assertEquals(EvictionAlgorithm.LRU_ENTRY, evicAttr.getAlgorithm()); @@ -77,13 +114,14 @@ public class DiskStoreAndEvictionRegionParsingTest { public void testPartitionDataOptions() throws Exception { assertTrue(context.containsBean("partition-data")); RegionFactoryBean fb = context.getBean("&partition-data", RegionFactoryBean.class); - assertEquals(DataPolicy.PARTITION, TestUtils.readField("dataPolicy", fb)); + assertEquals(DataPolicy.PERSISTENT_PARTITION, TestUtils.readField("dataPolicy", fb)); RegionAttributes attrs = TestUtils.readField("attributes", fb); EvictionAttributes evicAttr = attrs.getEvictionAttributes(); assertEquals(EvictionAction.LOCAL_DESTROY, evicAttr.getAction()); assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm()); - // for some reason GemFire resets this to 56 on my machine (not sure why) - //assertEquals(10, evicAttr.getMaximum()); + // for some reason GemFire resets this to 56 on my machine (not sure + // why) + // assertEquals(10, evicAttr.getMaximum()); ObjectSizer sizer = evicAttr.getObjectSizer(); assertEquals(SimpleObjectSizer.class, sizer.getClass()); } @@ -109,6 +147,5 @@ public class DiskStoreAndEvictionRegionParsingTest { ExpirationAttributes regionTTI = attrs.getRegionIdleTimeout(); assertEquals(400, regionTTI.getTimeout()); assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction()); - } } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java deleted file mode 100644 index dff269dc..00000000 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2010-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.config; - -import static org.junit.Assert.assertEquals; - -import java.io.File; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.gemstone.gemfire.cache.DiskStore; -import com.gemstone.gemfire.cache.DiskStoreFactory; - -/** - * @author David Turanski - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("diskstore-ns-new.xml") -public class DiskStoreNamespaceTest { - private static File diskStoreDir; - - @Autowired - DiskStore diskStore1; - - @Test - public void testDiskStore() { - assertEquals("diskStore1", diskStore1.getName()); - assertEquals(50, diskStore1.getQueueSize()); - assertEquals(true, diskStore1.getAutoCompact()); - assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore1.getCompactionThreshold()); - assertEquals(9999, diskStore1.getTimeInterval()); - assertEquals(10, diskStore1.getMaxOplogSize()); - assertEquals(diskStoreDir, diskStore1.getDiskDirs()[0]); - } - - @BeforeClass - public static void setUp() { - String path = "./build/tmp"; - diskStoreDir = new File(path); - if (!diskStoreDir.exists()) { - diskStoreDir.mkdir(); - } - } - - @AfterClass - public static void tearDown() { - for (File file : diskStoreDir.listFiles()) { - file.delete(); - } - diskStoreDir.delete(); - } -} diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java index 3d93d42f..d646e752 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java @@ -34,7 +34,6 @@ import org.springframework.util.ObjectUtils; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheListener; -import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.Scope; @@ -50,15 +49,15 @@ public class LocalRegionNamespaceTest { private ApplicationContext context; @Test - public void testBasicReplica() throws Exception { + public void testBasicLocal() throws Exception { assertTrue(context.containsBean("simple")); } @Test - public void testPublishingReplica() throws Exception { + public void testPublishingLocal() throws Exception { assertTrue(context.containsBean("pub")); RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class); - assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb)); + assertEquals("NORMAL", TestUtils.readField("dataPolicyName", fb)); assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb)); assertEquals("publisher", TestUtils.readField("name", fb)); RegionAttributes attrs = TestUtils.readField("attributes", fb); @@ -66,7 +65,7 @@ public class LocalRegionNamespaceTest { } @Test - public void testComplexReplica() throws Exception { + public void testComplexLocal() throws Exception { assertTrue(context.containsBean("complex")); RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); CacheListener[] listeners = TestUtils.readField("cacheListeners", fb); @@ -78,6 +77,19 @@ public class LocalRegionNamespaceTest { assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); } + @Test + public void testLocalWithAttributes() throws Exception { + assertTrue(context.containsBean("local-with-attributes")); + Region region = context.getBean("local-with-attributes", Region.class); + RegionAttributes attrs = region.getAttributes(); + assertEquals(10, attrs.getInitialCapacity()); + assertEquals(true, attrs.getIgnoreJTA()); + assertEquals(false, attrs.getIndexMaintenanceSynchronous()); + assertEquals(String.class, attrs.getKeyConstraint()); + assertEquals(String.class, attrs.getValueConstraint()); + assertEquals(true, attrs.isDiskSynchronous()); + } + @Test public void testRegionLookup() throws Exception { Cache cache = context.getBean(Cache.class); diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java index 15b6624b..d04d0527 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -48,7 +48,7 @@ public class PartitionedRegionNamespaceTest { private ApplicationContext context; @Test - public void testBasicReplica() throws Exception { + public void testBasicPartition() throws Exception { assertTrue(context.containsBean("simple")); } diff --git a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java index 415dc7ea..2d08792c 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java @@ -78,6 +78,25 @@ public class ReplicatedRegionNamespaceTest { assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); } + @Test + public void testReplicaWithAttributes() throws Exception { + assertTrue(context.containsBean("replicated-with-attributes")); + Region region = context.getBean("replicated-with-attributes", Region.class); + RegionAttributes attrs = region.getAttributes(); + assertEquals(10, attrs.getInitialCapacity()); + assertEquals(true, attrs.getIgnoreJTA()); + assertEquals(false, attrs.getIndexMaintenanceSynchronous()); + assertEquals(String.class, attrs.getKeyConstraint()); + assertEquals(String.class, attrs.getValueConstraint()); + assertEquals(true, attrs.isDiskSynchronous()); + assertEquals(Scope.GLOBAL, attrs.getScope()); + assertEquals(true, attrs.isLockGrantor()); + assertEquals(true, attrs.getEnableAsyncConflation()); + assertEquals(true, attrs.getEnableSubscriptionConflation()); + assertEquals(0.50, attrs.getLoadFactor(), 0.001); + assertEquals(false, attrs.getCloningEnabled()); + } + @Test public void testRegionLookup() throws Exception { Cache cache = context.getBean(Cache.class); diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml index bce2ec77..e8b675c9 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml @@ -32,18 +32,14 @@ - - - - - + + + + + - - - - - - + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml deleted file mode 100644 index 0ce704d0..00000000 --- a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns-new.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - ./build/tmp - 50 - true - 10 - 9999 - 1 - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml index ba11cf0c..b9941aae 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/diskstore-ns.xml @@ -10,44 +10,48 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> - - 300 - - + + + ./build/tmp + 50 + true + 10 + 9999 + 1 + 300 + + - - - - - - - - - - - - + + + + + + + + + - + - - - - - - + - + + + + + \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml index 7fc7f302..e3656389 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml @@ -22,6 +22,16 @@ + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml index 3fe3436a..855beec5 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml @@ -23,6 +23,21 @@ + +