[jbosscache-commits] JBoss Cache SVN: r8114 - in core/branches/1.4.X: tests/functional/org/jboss/cache/eviction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Sun Jun 21 23:38:13 EDT 2009


Author: jiwils
Date: 2009-06-21 23:38:13 -0400 (Sun, 21 Jun 2009)
New Revision: 8114

Modified:
   core/branches/1.4.X/src/org/jboss/cache/eviction/LRUAlgorithm.java
   core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java
Log:
Corrected overflow situatios in LRUAlgorithm and added tests.

Modified: core/branches/1.4.X/src/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/eviction/LRUAlgorithm.java	2009-06-21 23:29:57 UTC (rev 8113)
+++ core/branches/1.4.X/src/org/jboss/cache/eviction/LRUAlgorithm.java	2009-06-22 03:38:13 UTC (rev 8114)
@@ -47,7 +47,7 @@
          {
             log.trace("Node " + entry.getFqn() + " has been idle for " + idleTime + "ms");
          }
-         if ((idleTime >= (config.getTimeToLiveSeconds() * 1000)))
+         if ((idleTime >= (config.getTimeToLiveSeconds() * 1000L)))
          {
             if (log.isTraceEnabled())
             {
@@ -64,7 +64,7 @@
          {
             log.trace("Node " + entry.getFqn() + " has been alive for " + objectLifeTime + "ms");
          }
-         if ((objectLifeTime >= (config.getMaxAgeSeconds() * 1000)))
+         if ((objectLifeTime >= (config.getMaxAgeSeconds() * 1000L)))
          {
             if (log.isTraceEnabled())
             {

Modified: core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java	2009-06-21 23:29:57 UTC (rev 8113)
+++ core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java	2009-06-22 03:38:13 UTC (rev 8114)
@@ -257,6 +257,33 @@
    }
 
    /**
+    * Tests what happens when the timeToLiveSeconds is set to 1/1000th of
+    * Integer.MAX_VALUE plus one as the algorithm multiples by 1000L as of now
+    * to avoid overrun situations.
+    */
+   public void testIdleTimeSecondsForOverflow()
+   {
+      Fqn fqn1 = Fqn.fromString("/a/b/c");
+      Region region = regionManager_.getRegion("/a/b");
+      LRUConfiguration config = (LRUConfiguration) region.getEvictionConfiguration();
+      config.setMaxNodes(0);
+      config.setTimeToLiveSeconds((Integer.MAX_VALUE / 1000) + 1);
+      region.setAddedNode(fqn1);
+
+      try
+      {
+         algo_.process(region);
+      }
+      catch (EvictionException e)
+      {
+         fail("testIdleTimeSecondsForOverflow: process failed " + e);
+         e.printStackTrace();
+      }
+
+      assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+   }
+
+   /**
     * MaxAgeSeconds = 1 with 3 nodes.
     *
     * @throws Exception
@@ -311,6 +338,34 @@
    }
 
    /**
+    * Tests what happens when the maxAgeSeconds is set to 1/1000th of
+    * Integer.MAX_VALUE plus one as the algorithm multiples by 1000L as of now
+    * to avoid overrun situations.
+    */
+   public void testMaxAgeSecondsForOverflow()
+   {
+      Fqn fqn1 = Fqn.fromString("/a/b/c");
+      Region region = regionManager_.getRegion("/a/b");
+      LRUConfiguration config = (LRUConfiguration) region.getEvictionConfiguration();
+      config.setMaxNodes(0);
+      config.setTimeToLiveSeconds(0);
+      config.setMaxAgeSeconds((Integer.MAX_VALUE / 1000) + 1);
+      region.setAddedNode(fqn1);
+
+      try
+      {
+         algo_.process(region);
+      }
+      catch (EvictionException e)
+      {
+         fail("testMaxAgeSecondsForOverflow: process failed " + e);
+         e.printStackTrace();
+      }
+
+      assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+   }
+
+   /**
     * Generic combo case.
     */
    public void testCombo1()




More information about the jbosscache-commits mailing list