[jbosscache-commits] JBoss Cache SVN: r8116 - in core/support-branches/1.4.1.SP11_JBCACHE-1515: tests/functional/org/jboss/cache/eviction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Jun 22 00:05:25 EDT 2009


Author: jiwils
Date: 2009-06-22 00:05:24 -0400 (Mon, 22 Jun 2009)
New Revision: 8116

Modified:
   core/support-branches/1.4.1.SP11_JBCACHE-1515/src/org/jboss/cache/eviction/LRUAlgorithm.java
   core/support-branches/1.4.1.SP11_JBCACHE-1515/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java
Log:
Fix for JBCACHE-1515.  Long idle seconds or max age seconds could cause overflow which resulted in instant eviction.

Modified: core/support-branches/1.4.1.SP11_JBCACHE-1515/src/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/support-branches/1.4.1.SP11_JBCACHE-1515/src/org/jboss/cache/eviction/LRUAlgorithm.java	2009-06-22 03:46:49 UTC (rev 8115)
+++ core/support-branches/1.4.1.SP11_JBCACHE-1515/src/org/jboss/cache/eviction/LRUAlgorithm.java	2009-06-22 04:05:24 UTC (rev 8116)
@@ -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/support-branches/1.4.1.SP11_JBCACHE-1515/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/support-branches/1.4.1.SP11_JBCACHE-1515/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java	2009-06-22 03:46:49 UTC (rev 8115)
+++ core/support-branches/1.4.1.SP11_JBCACHE-1515/tests/functional/org/jboss/cache/eviction/LRUAlgorithmTest.java	2009-06-22 04:05:24 UTC (rev 8116)
@@ -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