[jbosscache-commits] JBoss Cache SVN: r7033 - in core/trunk/src: test/java/org/jboss/cache/config and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Oct 30 12:57:53 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-10-30 12:57:53 -0400 (Thu, 30 Oct 2008)
New Revision: 7033

Added:
   core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml
Modified:
   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/optimistically-locked-cache.xml
Log:
Updated to take into account new meanings of 0 in eviction config and translate old 0's to -1's to denote no limit.

Modified: core/trunk/src/main/resources/config2to3.xslt
===================================================================
--- core/trunk/src/main/resources/config2to3.xslt	2008-10-30 04:53:19 UTC (rev 7032)
+++ core/trunk/src/main/resources/config2to3.xslt	2008-10-30 16:57:53 UTC (rev 7033)
@@ -373,7 +373,14 @@
                   <xsl:value-of select="substring-before($attr/@name,'Seconds')"/>
                </xsl:attribute>
                <xsl:attribute name="value">
-                  <xsl:value-of select="concat($attr,'000')"/>
+	               <xsl:choose>
+               		<xsl:when test="$attr = '0'">
+               			<xsl:value-of select="-1"/>
+               		</xsl:when>
+               		<xsl:otherwise>
+               			<xsl:value-of select="concat($attr,'000')"/>
+               		</xsl:otherwise>
+               	</xsl:choose>
                </xsl:attribute>
             </xsl:when>
             <xsl:otherwise>
@@ -381,7 +388,17 @@
                   <xsl:value-of select="string($attr/@name)"/>
                </xsl:attribute>
                <xsl:attribute name="value">
-                  <xsl:value-of select="$attr"/>
+                  <xsl:choose>
+                     <xsl:when test="$attr/@name = 'maxNodes' and $attr = '0'">
+                        <xsl:value-of select="-1"/>
+                     </xsl:when>
+                     <xsl:when test="$attr/@name = 'minNodes' and $attr = '0'">
+                        <xsl:value-of select="-1"/>
+                     </xsl:when>
+                     <xsl:otherwise>
+                        <xsl:value-of select="$attr"/>
+                     </xsl:otherwise>
+                  </xsl:choose>
                </xsl:attribute>
             </xsl:otherwise>
          </xsl:choose>

Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java	2008-10-30 04:53:19 UTC (rev 7032)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java	2008-10-30 16:57:53 UTC (rev 7033)
@@ -3,6 +3,7 @@
 import org.jboss.cache.config.parsing.ConfigFilesConvertor;
 import org.jboss.cache.config.parsing.XmlConfigurationParser;
 import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
 import org.testng.annotations.Test;
 
 import java.io.ByteArrayInputStream;
@@ -17,7 +18,7 @@
  * <li> it parses the file with 2.x parser
  * <li> it parses the transform with a 3.x parser
  * <li> checks that the two resulting <tt>Configuration</tt> objects are equal.
- * </ol>              
+ * </ol>
  *
  * @author Mircea.Markus at jboss.com
  * @since 3.0
@@ -86,7 +87,7 @@
             "default-test-config2x.xml",
             "eviction-enabled-cache.xml",
             "optimistically-locked-cache.xml",
-            "policyPerRegion-eviction.xml" ,
+            "policyPerRegion-eviction.xml",
       };
       for (String file : fileNames)
       {
@@ -106,6 +107,38 @@
       }
    }
 
+   public void testUnlimitedValues() throws Exception
+   {
+      // in 3.x, unlimited values in eviction are denoted by -1 and not 0!
+      String fileName = getFileName("/zeroTTL.xml");
+      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);
+
+      for (EvictionRegionConfig erc : oldConfig.getEvictionConfig().getEvictionRegionConfigs())
+      {
+         correctUnlimitedValues(erc);
+      }
+      correctUnlimitedValues(oldConfig.getEvictionConfig().getDefaultEvictionRegionConfig());
+
+      assert oldConfig.equals(newConfig);
+   }
+
+   private void correctUnlimitedValues(EvictionRegionConfig erc)
+   {
+      LRUAlgorithmConfig eac = (LRUAlgorithmConfig) erc.getEvictionAlgorithmConfig();
+      if (eac.getMaxAge() == 0) eac.setMaxAge(-1);
+      if (eac.getMaxNodes() == 0) eac.setMaxNodes(-1);
+      if (eac.getMinTimeToLive() == 0) eac.setMinTimeToLive(-1);
+      if (eac.getTimeToLive() == 0) eac.setTimeToLive(-1);
+   }
+
    private String getFileName(String s)
    {
       return BASE_DIR + File.separator + s;

Modified: core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml
===================================================================
--- core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml	2008-10-30 04:53:19 UTC (rev 7032)
+++ core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml	2008-10-30 16:57:53 UTC (rev 7033)
@@ -66,13 +66,13 @@
 
             <region name="/_default_">
                <attribute name="maxNodes">10</attribute>
-               <attribute name="timeToLiveSeconds">0</attribute>
-               <attribute name="maxAgeSeconds">0</attribute>
+               <attribute name="timeToLiveSeconds">8</attribute>
+               <attribute name="maxAgeSeconds">5</attribute>
             </region>
             <region name="/testingRegion">
                <attribute name="maxNodes">10</attribute>
-               <attribute name="timeToLiveSeconds">0</attribute>
-               <attribute name="maxAgeSeconds">0</attribute>
+               <attribute name="timeToLiveSeconds">1</attribute>
+               <attribute name="maxAgeSeconds">2</attribute>
             </region>
             <region name="/timeBased">
                <attribute name="maxNodes">10</attribute>

Added: core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml
===================================================================
--- core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml	                        (rev 0)
+++ core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml	2008-10-30 16:57:53 UTC (rev 7033)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+
+   <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
+          name="jboss.cache:service=Cache">
+
+      <depends>jboss:service=Naming</depends>
+      <depends>jboss:service=TransactionManager</depends>
+
+      <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
+      </attribute>
+
+      <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
+
+      <attribute name="CacheMode">LOCAL</attribute>
+
+      <attribute name="LockAcquisitionTimeout">15000</attribute>
+
+      <attribute name="EvictionPolicyConfig">
+         <config>
+            <attribute name="wakeUpIntervalSeconds">10</attribute>
+            <attribute name="eventQueueSize">200000</attribute>
+            <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
+
+            <!-- Cache wide default -->
+            <region name="/_default_">
+               <attribute name="maxNodes">5000</attribute>
+               <attribute name="minTimeToLiveSeconds">0</attribute>
+            </region>
+            <region name="/org/jboss/data">
+               <attribute name="minTimeToLiveSeconds">1000</attribute>
+               <attribute name="maxNodes">0</attribute>
+            </region>
+         </config>
+      </attribute>
+   </mbean>
+</server>




More information about the jbosscache-commits mailing list