Author: mircea.markus
Date: 2008-08-20 08:04:27 -0400 (Wed, 20 Aug 2008)
New Revision: 6583
Added:
core/trunk/src/test/java/org/jboss/cache/config/parsing/Eviction2xto3xCompatibilityTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/resources/config2to3.xslt
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java
core/trunk/src/test/resources/configs/conf2x/eviction-enabled-cache.xml
Log:
updated 2.x eviction parsing and .xslt to accomodate recent API changes
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-08-19 11:26:03 UTC
(rev 6582)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-08-20 12:04:27 UTC
(rev 6583)
@@ -34,6 +34,7 @@
import org.jboss.cache.util.reflect.ReflectionUtil;
import org.jboss.cache.jmx.annotations.ManagedOperation;
import org.jboss.cache.jmx.annotations.ManagedAttribute;
+import org.jboss.cache.jmx.annotations.MBean;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.ChannelException;
@@ -64,6 +65,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
*/
+@MBean (objectName = "RPCManager")
public class RPCManagerImpl implements RPCManager
{
private Channel channel;
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-19 11:26:03
UTC (rev 6582)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-20 12:04:27
UTC (rev 6583)
@@ -714,16 +714,6 @@
if (evictionConfig.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig() !=
null &&
!ercs.contains(evictionConfig.getDefaultEvictionRegionConfig())) // then the
default is a real region too; not just a template for others
ercs.add(0, evictionConfig.getDefaultEvictionRegionConfig());
-// if (needDefault)
-// {
-// // This may throw ConfigurationException if there is no default
-// // eviction policy class
-// EvictionRegionConfig dflt =
evictionConfig.createDefaultEvictionRegionConfig();
-// ercs.add(0, dflt); // put it first
-// // Need to pass this back into the evictionConfig so it knows
-// // about the new region
-// evictionConfig.setEvictionRegionConfigs(ercs);
-// }
// create regions for the regions defined in the evictionConfig.
// scan to be sure the _default_ region isn't added twice
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-19
11:26:03 UTC (rev 6582)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-20
12:04:27 UTC (rev 6583)
@@ -239,6 +239,7 @@
if (defaultEventQueueSize != that.defaultEventQueueSize) return false;
if (wakeupInterval != that.wakeupInterval) return false;
+ if (defaultEvictionRegionConfig != null ?
!defaultEvictionRegionConfig.equals(that.defaultEvictionRegionConfig) :
that.defaultEvictionRegionConfig != null) return false;
if (evictionRegionConfigs != null ?
!evictionRegionConfigs.equals(that.evictionRegionConfigs) : that.evictionRegionConfigs !=
null)
return false;
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-08-19
11:26:03 UTC (rev 6582)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-08-20
12:04:27 UTC (rev 6583)
@@ -9,19 +9,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
-import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
import
org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.config.*;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.eviction.EvictionAlgorithm;
import org.jboss.cache.util.FileLookup;
import org.jboss.cache.util.Util;
+import org.jboss.cache.RegionManagerImpl;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -29,11 +24,8 @@
import org.w3c.dom.NodeList;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
+import java.util.*;
/**
* Reads in XMLconfiguration files and spits out a {@link
org.jboss.cache.config.Configuration} object. When deployed as a
@@ -246,6 +238,7 @@
}
catch (Exception e)
{
+ if (log.isTraceEnabled()) log.trace(e.getMessage());
}
finally
{
@@ -337,20 +330,22 @@
return null;
}
-
- private static EvictionConfig parseEvictionConfig(Element element)
+ @SuppressWarnings("unchecked")
+ static EvictionConfig parseEvictionConfig(Element element)
{
- EvictionConfig ec = new EvictionConfig();
+ EvictionConfig evictionConfig = new EvictionConfig();
if (element != null)
{
// If they set the default eviction policy in the element, use that
// in preference to the external attribute
- String temp = XmlConfigHelper.getTagContents(element,
- "policyClass", ATTR, NAME);
+ String temp = XmlConfigHelper.getTagContents(element, "policyClass",
ATTR, NAME);
+ String defaultEvPolicyClassName = null;
if (temp != null && temp.length() > 0)
{
- ec.setDefaultEvictionPolicyClass(temp);
+ defaultEvPolicyClassName = temp;
+ EvictionAlgorithmConfig eac = getEvictionAlgorithmConfig(temp);
+
evictionConfig.getDefaultEvictionRegionConfig().setEvictionAlgorithmConfig(eac);
}
temp = XmlConfigHelper.getTagContents(element,
"wakeUpIntervalSeconds", ATTR, NAME);
@@ -366,11 +361,10 @@
wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
}
- ec.setWakeupInterval(wakeupIntervalSeconds * 1000);
+ evictionConfig.setWakeupInterval(wakeupIntervalSeconds * 1000);
int eventQueueSize = 0;
- temp = XmlConfigHelper.getTagContents(element,
- "eventQueueSize", ATTR, NAME);
+ temp = XmlConfigHelper.getTagContents(element, "eventQueueSize", ATTR,
NAME);
if (temp != null)
{
@@ -382,7 +376,7 @@
eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
}
- ec.getDefaultEvictionRegionConfig().setEventQueueSize(eventQueueSize);
+
evictionConfig.getDefaultEvictionRegionConfig().setEventQueueSize(eventQueueSize);
NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
if (list != null && list.getLength() > 0)
@@ -397,7 +391,16 @@
}
try
{
- regionConfigs.add(parseEvictionRegionConfig((Element) node,
ec.getDefaultEvictionPolicyClass(), eventQueueSize));
+ EvictionRegionConfig evictionRegionConfig =
parseEvictionRegionConfig((Element) node, defaultEvPolicyClassName, eventQueueSize);
+ if
(!evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
+ {
+ regionConfigs.add(evictionRegionConfig);
+ }
+ else
+ {
+
evictionConfig.getDefaultEvictionRegionConfig().setEventQueueSize(evictionRegionConfig.getEventQueueSize());
+
evictionConfig.getDefaultEvictionRegionConfig().setEvictionAlgorithmConfig(evictionRegionConfig.getEvictionAlgorithmConfig());
+ }
}
catch (MissingPolicyException missingPolicy)
{
@@ -406,17 +409,15 @@
}
}
- ec.setEvictionRegionConfigs(regionConfigs);
+ evictionConfig.setEvictionRegionConfigs(regionConfigs);
}
}
- return ec;
+ return evictionConfig;
}
- private static EvictionRegionConfig parseEvictionRegionConfig(Element element,
- String
defaultEvictionClass,
- int
defaultQueueCapacity)
+ private static EvictionRegionConfig parseEvictionRegionConfig(Element element, String
defaultEvPolicyClassName, int defaultQueueCapacity)
{
EvictionRegionConfig erc = new EvictionRegionConfig();
@@ -435,7 +436,7 @@
if (evictionClass == null || evictionClass.length() == 0)
{
- evictionClass = defaultEvictionClass;
+ evictionClass = defaultEvPolicyClassName;
// if it's still null... what do we setCache?
if (evictionClass == null || evictionClass.length() == 0)
{
@@ -444,10 +445,27 @@
}
}
- EvictionPolicy policy;
+ EvictionAlgorithmConfig algorithmConfig =
getEvictionAlgorithmConfig(evictionClass);
+
+ parseEvictionPolicyConfig(element, algorithmConfig);
+
+ erc.setEvictionAlgorithmConfig(algorithmConfig);
+ return erc;
+ }
+
+ private static EvictionAlgorithmConfig getEvictionAlgorithmConfig(String
evictionClass)
+ {
+ if (evictionClass.indexOf("org.jboss.cache.eviction") < 0)
+ {
+ throw new ConfigurationException("Unsupported custom eviction policy:
" + evictionClass +
+ ". Starting with 3.x the eviction API has changed, the code needs to
be manually migrated.");
+ }
+ String evictionAlgorithmClass = evictionClass.substring(0,evictionClass.length() -
"Policy".length()) + "Algorithm";
+
+ EvictionAlgorithm algorithm;
try
{
- policy = (EvictionPolicy) Util.loadClass(evictionClass).newInstance();
+ algorithm = (EvictionAlgorithm)
Util.loadClass(evictionAlgorithmClass).newInstance();
}
catch (RuntimeException e)
{
@@ -458,10 +476,10 @@
throw new RuntimeException("Eviction class is not properly loaded in
classloader", e);
}
- EvictionPolicyConfig epc;
+ EvictionAlgorithmConfig algorithmConfig;
try
{
- epc = policy.getEvictionConfigurationClass().newInstance();
+ algorithmConfig = algorithm.getConfigurationClass().newInstance();
}
catch (RuntimeException e)
{
@@ -470,16 +488,35 @@
catch (Exception e)
{
throw new RuntimeException("Failed to instantiate eviction configuration of
class " +
- policy.getEvictionConfigurationClass(), e);
+ algorithm.getConfigurationClass(), e);
}
+ return algorithmConfig;
+ }
- // TODO FIX this!!!
-// EvictionElementParser.parseEvictionPolicyConfig(element, epc);
-
- erc.setEvictionPolicyConfig(epc);
- return erc;
+ @SuppressWarnings("unchecked")
+ private static void parseEvictionPolicyConfig(Element element, EvictionAlgorithmConfig
target)
+ {
+ target.reset();
+ ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
+ Map updatedElements = new HashMap();
+ for (Map.Entry entry : attributes.stringAttribs.entrySet())
+ {
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+ if (key.indexOf("Seconds") > 0)
+ {
+ key = key.substring(0, key.length() - "Seconds".length());
+ value = value.trim() + "000";
+ }
+ updatedElements.put(key, value);
+ }
+ attributes.stringAttribs.clear();
+ attributes.stringAttribs.putAll(updatedElements);
+ XmlConfigHelper.setValues(target, attributes.stringAttribs, false, true);
+ XmlConfigHelper.setValues(target, attributes.xmlAttribs, true, true);
}
+
/**
* Parses the cluster config which is used to start a JGroups channel
*
@@ -531,5 +568,4 @@
buffer.setLength(buffer.length() - 1);
return buffer.toString();
}
-
}
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-08-19
11:26:03 UTC (rev 6582)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-08-20
12:04:27 UTC (rev 6583)
@@ -80,7 +80,7 @@
}
String algorithmClassName = getAttributeValue(element,
"algorithmClass");
- EvictionAlgorithmConfig eac = null; // every eviction region config needs an
algorithm config.
+ EvictionAlgorithmConfig algorithmConfig = null; // every eviction region config
needs an algorithm config.
if (existsAttribute(algorithmClassName))
{
@@ -109,7 +109,7 @@
try
{
- eac = Util.getInstance(algorithm.getConfigurationClass());
+ algorithmConfig = Util.getInstance(algorithm.getConfigurationClass());
}
catch (Exception e)
{
@@ -129,7 +129,7 @@
{
try
{
- eac = defaultRegion.getEvictionAlgorithmConfig().clone();
+ algorithmConfig = defaultRegion.getEvictionAlgorithmConfig().clone();
}
catch (CloneNotSupportedException e)
{
@@ -139,11 +139,11 @@
}
}
- if (eac != null)
+ if (algorithmConfig != null)
{
- parseEvictionPolicyConfig(element, eac);
+ parseEvictionPolicyConfig(element, algorithmConfig);
- erc.setEvictionAlgorithmConfig(eac);
+ erc.setEvictionAlgorithmConfig(algorithmConfig);
}
String actionPolicyClass = getAttributeValue(element,
"actionPolicyClass");
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-08-19
11:26:03 UTC (rev 6582)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-08-20
12:04:27 UTC (rev 6583)
@@ -7,7 +7,6 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.jmx.annotations.ManagedAttribute;
import org.jboss.cache.jmx.annotations.ManagedOperation;
-import org.jboss.cache.jmx.annotations.MBean;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
import org.jboss.cache.commands.read.GetDataMapCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
@@ -26,7 +25,6 @@
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.interceptors.base.JmxStatsCommandInterceptor;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.loader.CacheLoader;
Modified: core/trunk/src/main/resources/config2to3.xslt
===================================================================
--- core/trunk/src/main/resources/config2to3.xslt 2008-08-19 11:26:03 UTC (rev 6582)
+++ core/trunk/src/main/resources/config2to3.xslt 2008-08-20 12:04:27 UTC (rev 6583)
@@ -275,14 +275,27 @@
</xsl:if>
<xsl:if test="./config/region[@name='/_default_']">
<default>
+ <xsl:choose>
+ <xsl:when test="./config/region[@name='/_default_' and
@policyClass]">
+ <xsl:if test="./config/region[@name='/_default_' and
not(starts-with((a)policyClass,'org.jboss.cache.eviction'))]">
+ <xsl:message terminate="yes">A custom eviction
policy is used for '/_default_' region. Starting with JBossCache 3.x the eviction
API changed, so this config file will require manual transformation.</xsl:message>
+ </xsl:if>
+ <xsl:attribute name="algorithmClass">
+ <xsl:value-of
+
select="concat(substring-before(./config/region[@name='/_default_']/@policyClass,'Policy'),
'Algorithm')"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if
+ test="./config/attribute[@name='policyClass' and
starts-with(string(.), 'org.jboss.cache.eviction')]">
+ <xsl:attribute name="algorithmClass">
+ <xsl:value-of
+
select="concat(substring-before(./config/attribute[@name='policyClass'],'Policy'),
'Algorithm')"/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
<xsl:if
- test="./config/attribute[@name='policyClass' and
starts-with(string(.), 'org.jboss.cache.eviction')]">
- <xsl:attribute name="algorithmClass">
- <xsl:value-of
-
select="concat(substring-before(./config/attribute[@name='policyClass'],'Policy'),
'Algorithm')"/>
- </xsl:attribute>
- </xsl:if>
- <xsl:if
test="./config/attribute[@name='policyClass' and
not(starts-with(string(.), 'org.jboss.cache.eviction'))]">
<xsl:message terminate="yes">Custom eviction policies
require manual transformation.</xsl:message>
</xsl:if>
@@ -344,14 +357,16 @@
<attribute>
<xsl:choose>
<xsl:when test="contains($attr/@name,'Seconds')">
- <xsl:attribute
name="{substring-before($attr/@name,'Seconds')}">
- <xsl:value-of select="concat($attr,'000')"/>
+ <xsl:attribute name="name">
+ <xsl:value-of
select="substring-before($attr/@name,'Seconds')"/>
</xsl:attribute>
+ <xsl:value-of select="concat($attr,'000')"/>
</xsl:when>
<xsl:otherwise>
- <xsl:attribute name="{string($attr/@name)}">
- <xsl:value-of select="$attr"/>
+ <xsl:attribute name="name">
+ <xsl:value-of select="string($attr/@name)"/>
</xsl:attribute>
+ <xsl:value-of select="$attr"/>
</xsl:otherwise>
</xsl:choose>
</attribute>
Modified:
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java 2008-08-19
11:26:03 UTC (rev 6582)
+++
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java 2008-08-20
12:04:27 UTC (rev 6583)
@@ -34,7 +34,7 @@
*/
public void testSingleFile() throws Exception
{
- String fileName = getFileName("/default-test-config2x.xml");
+ String fileName = getFileName("/policyPerRegion-eviction.xml");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
convertor.parse(fileName, baos, XSLT_FILE);
System.out.println("result = \n" + baos);
@@ -51,12 +51,42 @@
public void testEqualityOnTransformedFiles() throws Exception
{
String[] fileNames = {
-// "buddy-replication-cache.xml",
-// "cacheloader-enabled-cache.xml",
+ "buddy-replication-cache.xml",
+ "local-cache.xml",
+ "multiplexer-enabled-cache.xml",
+ "total-replication-cache.xml",
+ };
+ for (String file : fileNames)
+ {
+ System.out.println("Processing file = " + file);
+ String fileName = getFileName(file);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ convertor.parse(fileName, baos, XSLT_FILE);
+// System.out.println("result = \n" + baos);
+
+ XmlConfigurationParser newParser = new XmlConfigurationParser();
+ XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
+
+ Configuration newConfig = newParser.parseStream(new
ByteArrayInputStream(baos.toByteArray()));
+ Configuration oldConfig = oldParser.parseFile(fileName);
+
+ assert newConfig.equals(oldConfig);
+ }
+ }
+
+ /**
+ * Not like the rest of elements, eviction was also changed in 3.x.
+ * As the parser produces different results, we semantically check here that eviction
is transformed corectly.
+ */
+ public void testEqualityOnEvictionTransformedFiles() throws Exception
+ {
+ String[] fileNames = {
+ "cacheloader-enabled-cache.xml",
+ "clonable-config.xml",
+ "default-test-config2x.xml",
"eviction-enabled-cache.xml",
-// "local-cache.xml", "multiplexer-enabled-cache.xml",
-// "optimistically-locked-cache.xml",
"total-replication-cache.xml", "clonable-config.xml",
-// "policyPerRegion-eviction.xml" ,
"default-test-config2x.xml"
+ "optimistically-locked-cache.xml",
+ "policyPerRegion-eviction.xml" ,
};
for (String file : fileNames)
{
@@ -64,7 +94,7 @@
String fileName = getFileName(file);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
convertor.parse(fileName, baos, XSLT_FILE);
- System.out.println("result = \n" + baos);
+// System.out.println("result = \n" + baos);
XmlConfigurationParser newParser = new XmlConfigurationParser();
XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
Added:
core/trunk/src/test/java/org/jboss/cache/config/parsing/Eviction2xto3xCompatibilityTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/parsing/Eviction2xto3xCompatibilityTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/config/parsing/Eviction2xto3xCompatibilityTest.java 2008-08-20
12:04:27 UTC (rev 6583)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.cache.config.parsing;
+
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+import org.testng.reporters.XMLUtils;
+import org.w3c.dom.Element;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.MRUAlgorithmConfig;
+
+/**
+ * Eviction was internally changed from version 2.x to version 3.x.
+ * This is a tests to check eviction compatibility between these two versions.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+@Test(groups = "unit")
+public class Eviction2xto3xCompatibilityTest
+{
+ private EvictionElementParser evictionElementParser;
+
+ @BeforeMethod
+ public void setUp()
+ {
+ evictionElementParser = new EvictionElementParser();
+ }
+
+ public void testDefaultValues1() throws Exception
+ {
+ String oldFormat =
+ " <attribute
name=\"EvictionPolicyConfig\">\n" +
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
+ " <attribute
name=\"eventQueueSize\">200000</attribute>\n" +
+ " <attribute
name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n"
+
+ " <region name=\"/_default_\"
eventQueueSize=\"1234\"
policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
+ " <attribute
name=\"maxNodes\">5001</attribute>\n" +
+ " <attribute
name=\"minTimeToLiveSeconds\">1001</attribute>\n" +
+ " </region>\n" +
+ " <region
name=\"/org/jboss/data\">\n" +
+ " <attribute
name=\"minTimeToLiveSeconds\">1000</attribute>\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+ Element oldEl = XmlConfigHelper.stringToElementInCoreNS(oldFormat);
+ EvictionConfig oldEvConfig = XmlConfigurationParser2x.parseEvictionConfig(oldEl);
+ //this will be transformed in root region, so make sure that the root region will
be corectly set up
+ MRUAlgorithmConfig defaultAlgorithmConfig = (MRUAlgorithmConfig)
oldEvConfig.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig();
+ assert oldEvConfig.getDefaultEvictionRegionConfig().getEventQueueSize() == 1234;
+ assert
defaultAlgorithmConfig.getEvictionAlgorithmClassName().equals("org.jboss.cache.eviction.MRUAlgorithm");
+ assert defaultAlgorithmConfig.getMaxNodes() == 5001;
+ assert defaultAlgorithmConfig.getMinTimeToLive() == 1001000;
+
+
+ assert oldEvConfig.getEvictionRegionConfigs().size() == 1;
+ EvictionRegionConfig orgJbossData = oldEvConfig.getEvictionRegionConfigs().get(0);
+ assert
orgJbossData.getRegionFqn().equals(Fqn.fromString("org/jboss/data"));
+ assert
orgJbossData.getEvictionAlgorithmConfig().getEvictionAlgorithmClassName().equals("org.jboss.cache.eviction.LRUAlgorithm");
+ assert orgJbossData.getEventQueueSize() == 200000;
+ }
+
+ public void simpleTest() throws Exception
+ {
+ String oldFormat =
+ " <attribute name=\"EvictionPolicyConfig\">\n"
+
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
+ " <attribute
name=\"eventQueueSize\">200000</attribute>\n" +
+ " <attribute
name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n"
+
+ " <region name=\"/_default_\">\n"
+
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute
name=\"timeToLiveSeconds\">1000</attribute>\n" +
+ " </region>\n" +
+ " <region name=\"/org/jboss/data\"
policyClass=\"org.jboss.cache.eviction.LFUPolicy\">\n" +
+ " <attribute
name=\"minTimeToLiveSeconds\">1000</attribute>\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+ String newFormat =
+ "<eviction wakeUpInterval=\"5000\">\n" +
+ " <default
algorithmClass=\"org.jboss.cache.eviction.LRUAlgorithm\"
eventQueueSize=\"200000\">\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute
name=\"timeToLive\">1000000</attribute>\n" +
+ " </default>\n" +
+ " <region name=\"/org/jboss/data\"
algorithmClass=\"org.jboss.cache.eviction.LFUAlgorithm\"
eventQueueSize=\"200000\">\n" +
+ " <attribute
name=\"minTimeToLive\">1000000</attribute>\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " </region>\n" +
+ "</eviction>";
+ Element oldEl = XmlConfigHelper.stringToElementInCoreNS(oldFormat);
+ Element newEl = XmlConfigHelper.stringToElementInCoreNS(newFormat);
+ EvictionConfig oldEvConfig = XmlConfigurationParser2x.parseEvictionConfig(oldEl);
+ EvictionConfig newEvConfig = evictionElementParser.parseEvictionElement(newEl);
+ assert
oldEvConfig.getDefaultEvictionRegionConfig().equals(newEvConfig.getDefaultEvictionRegionConfig());
+
+ EvictionRegionConfig oldRegionConfig =
oldEvConfig.getEvictionRegionConfigs().get(0);
+ EvictionRegionConfig newRegionConfig =
newEvConfig.getEvictionRegionConfigs().get(0);
+ EvictionAlgorithmConfig oldEvictionAlgorithmConfig =
oldRegionConfig.getEvictionAlgorithmConfig();
+ EvictionAlgorithmConfig newEvictionAlgorithmConfig =
newRegionConfig.getEvictionAlgorithmConfig();
+ assert oldEvictionAlgorithmConfig.equals(newEvictionAlgorithmConfig);
+
+ assert oldEvConfig.equals(newEvConfig);
+ }
+
+ public void testFailureOnCustomEvictionPolicy() throws Exception
+ {
+ String oldFormat =
+ " <attribute name=\"EvictionPolicyConfig\">\n"
+
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
+ " <attribute
name=\"eventQueueSize\">200000</attribute>\n" +
+ " <attribute
name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n"
+
+ " <region name=\"/_default_\">\n"
+
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute
name=\"timeToLiveSeconds\">1000</attribute>\n" +
+ " </region>\n" +
+ " <region name=\"/org/jboss/data\"
policyClass=\"org.custom.eviction.policy.LFUPolicy\">\n" +
+ " <attribute
name=\"minTimeToLiveSeconds\">1000</attribute>\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+ Element element = XmlConfigHelper.stringToElementInCoreNS(oldFormat);
+ try
+ {
+ XmlConfigurationParser2x.parseEvictionConfig(element);
+ assert false : "custom eviction config not supported for the old
parser";
+ } catch (Exception e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ public void testFailureOnCustomDefaultEvictionPolicy() throws Exception
+ {
+ String oldFormat =
+ " <attribute name=\"EvictionPolicyConfig\">\n"
+
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
+ " <attribute
name=\"eventQueueSize\">200000</attribute>\n" +
+ " <attribute
name=\"policyClass\">org.custom.eviction.policy.LFUPolicy</attribute>\n"
+
+ " <region name=\"/_default_\">\n"
+
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute
name=\"timeToLiveSeconds\">1000</attribute>\n" +
+ " </region>\n" +
+ " <region name=\"/org/jboss/data\"
policyClass=\"org.jboss.cache.eviction.LRUPolicy\">\n" +
+ " <attribute
name=\"minTimeToLiveSeconds\">1000</attribute>\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+ Element element = XmlConfigHelper.stringToElementInCoreNS(oldFormat);
+ try
+ {
+ XmlConfigurationParser2x.parseEvictionConfig(element);
+ assert false : "default custom eviction config not supported for the old
parser";
+ } catch (Exception e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+}
Modified: core/trunk/src/test/resources/configs/conf2x/eviction-enabled-cache.xml
===================================================================
--- core/trunk/src/test/resources/configs/conf2x/eviction-enabled-cache.xml 2008-08-19
11:26:03 UTC (rev 6582)
+++ core/trunk/src/test/resources/configs/conf2x/eviction-enabled-cache.xml 2008-08-20
12:04:27 UTC (rev 6583)
@@ -62,25 +62,12 @@
<!-- Cache wide default -->
<region name="/_default_">
<attribute name="maxNodes">5000</attribute>
- <attribute
name="timeToLiveSeconds">1000</attribute>
+ <attribute
name="minTimeToLiveSeconds">1000</attribute>
</region>
<region name="/org/jboss/data"
policyClass="org.jboss.cache.eviction.LFUPolicy">
- <attribute
name="timeToLiveSeconds">1000</attribute>
+ <attribute
name="minTimeToLiveSeconds">1000</attribute>
<attribute name="maxNodes">5000</attribute>
</region>
- <!--<region name="/org/jboss/test/data">-->
- <!--<attribute
name="maxNodes">5</attribute>-->
- <!--<attribute
name="timeToLiveSeconds">4</attribute>-->
- <!--</region>-->
- <!--<region name="/test">-->
- <!--<attribute
name="maxNodes">10000</attribute>-->
- <!--<attribute
name="timeToLiveSeconds">4</attribute>-->
- <!--</region>-->
- <!--<region name="/maxAgeTest">-->
- <!--<attribute
name="maxNodes">10000</attribute>-->
- <!--<attribute
name="timeToLiveSeconds">8</attribute>-->
- <!--<attribute
name="maxAgeSeconds">10</attribute>-->
- <!--</region>-->
</config>
</attribute>