[jbosscache-commits] JBoss Cache SVN: r5476 - core/trunk/src/test/java/org/jboss/cache/eviction.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Mar 28 13:22:40 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-03-28 13:22:39 -0400 (Fri, 28 Mar 2008)
New Revision: 5476

Modified:
   core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
   core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
Log:
JBCACHE-1315 - Cleaned up unit tests - removed arbitrary sleep times to work around the imprecision described in JBCACHE-1315

Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java	2008-03-28 15:43:37 UTC (rev 5475)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java	2008-03-28 17:22:39 UTC (rev 5476)
@@ -1,15 +1,13 @@
 package org.jboss.cache.eviction;
 
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -19,177 +17,129 @@
  * @author Ben Wang, Feb 11, 2004
  * @author Daniel Huang (dhuang at jboss.org)
  */
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 public class LRUAlgorithmTest
 {
-   RegionManager regionManager_;
-   LRUAlgorithm algo_;
-   LRUConfiguration config_;
+   RegionManager regionManager;
+   LRUAlgorithm algorithm;
+   LRUConfiguration config;
    Log log = LogFactory.getLog(LRUAlgorithm.class);
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
-      algo_ = new LRUAlgorithm();
-      config_ = new LRUConfiguration();
-      config_.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
+      algorithm = new LRUAlgorithm();
+      config = new LRUConfiguration();
+      config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
       // We have to setCache timeToLiveSeconds!!
-      config_.setTimeToLiveSeconds(0);
+      config.setTimeToLiveSeconds(0);
 
-      regionManager_ = new RegionManager();
-      regionManager_.getRegion("/a/b", true).setEvictionPolicy(config_);
-      /*
-      try {
-         Thread.sleep(10000);
-      } catch (InterruptedException e) {
-         e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-      }
-      */
+      regionManager = new RegionManager();
+      regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
    }
 
    /**
     * maxNodes = 1. Eception is evictFromCacheNode. Should be commented for now.
     */
-   public void XtestEvictException()
+   public void testEvictException() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(1);
       region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
 
+      assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
+
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
+
+      assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
 
    /**
     * maxNodes = 0 case
     */
-   public void testMaxNode1()
+   public void testMaxNode1() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(0);
       region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size should be ", 2, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
 
+      assertEquals("Queue size should be ", 2, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
     * maxNodes = 1
     */
-   public void testMaxNode2()
+   public void testMaxNode2() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(1);
       region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
 
+      assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
+
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+
+      algorithm.process(region);
+
+      assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
     * TimeToIdleSeconds = 0
     */
-   public void testIdleTimeSeconds1()
+   public void testIdleTimeSeconds1() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(0);
       config.setTimeToLiveSeconds(0);
       region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
-      TestingUtil.sleepThread(2000);
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size should be ", 2, algo_.getEvictionQueue().getNumberOfNodes());
 
+      TestingUtil.sleepThread(500);
+
+      algorithm.process(region);
+
+      assertEquals("Queue size should be ", 2, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
     * TimeToIdleSeconds = 1
     */
-   public void testIdleTimeSeconds2()
+   public void testIdleTimeSeconds2() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(0);
       config.setTimeToLiveSeconds(1);
@@ -197,38 +147,25 @@
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
-      TestingUtil.sleepThread(2000);
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #2: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
+
+      assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+      TestingUtil.sleepThread(1100);
+
+      algorithm.process(region);
+
+      assertEquals("Queue size #2: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
     * TimeToIdleSeconds = 1 with node visited in between.
     */
-   public void testIdleTimeSeconds3()
+   public void testIdleTimeSeconds3() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(0);
       config.setTimeToLiveSeconds(1);
@@ -236,28 +173,14 @@
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
-      TestingUtil.sleepThread(2000);
+      algorithm.process(region);
+
+      assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+      TestingUtil.sleepThread(1100);
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.VISIT_NODE_EVENT));
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #2: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+
+      algorithm.process(region);
+      assertEquals("Queue size #2: ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
@@ -270,7 +193,7 @@
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
       config.setMaxNodes(0);
       config.setTimeToLiveSeconds(0);
@@ -279,11 +202,11 @@
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      algo_.process(region);
-      assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
-      TestingUtil.sleepThread(2000);
-      algo_.process(region);
-      assertEquals("Queue size #2: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
+      assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+      TestingUtil.sleepThread(1100);
+      algorithm.process(region);
+      assertEquals("Queue size #2: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
@@ -291,43 +214,44 @@
     *
     * @throws Exception
     */
-   public void testMaxAgeSeconds2() throws Exception
+   public void testMaxAgeSeconds2() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
 
       config.setMaxNodes(0);
       config.setTimeToLiveSeconds(0);
-      config.setMaxAgeSeconds(2);
+      config.setMaxAgeSeconds(1);
       region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      algo_.process(region);
-      assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
-      TestingUtil.sleepThread(1000);
-      algo_.process(region);
-      assertEquals("Queue size #2: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
-      TestingUtil.sleepThread(1500);
-      algo_.process(region);
-      assertEquals("Queue size #3: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
+      assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+      TestingUtil.sleepThread(500);
+      algorithm.process(region);
+      assertEquals("Queue size #2: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+      TestingUtil.sleepThread(600);
+      algorithm.process(region);
+      assertEquals("Queue size #3: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
    }
 
    /**
     * Generic combo case.
     */
-   public void testCombo1()
+   public void testCombo1() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
       Fqn fqn4 = Fqn.fromString("/a/b/f");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
 
+      // Should have a maximum of 2 nodes.
       config.setMaxNodes(2);
       config.setTimeToLiveSeconds(1);
       config.setMaxAgeSeconds(3);
@@ -335,55 +259,42 @@
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
 
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #1: ", 2, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
+      EvictionQueue eq = algorithm.getEvictionQueue();
+
+      int numNodesInQueue = eq.getNumberOfNodes();
+      assert 2 == numNodesInQueue : "Queue size #1: expected 2 but was " + numNodesInQueue;
+
+      // make sure all nodes now expire
+      TestingUtil.sleepThread(1100);
+
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      TestingUtil.sleepThread(2000);
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #2: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
 
-      TestingUtil.sleepThread(3500);
+      numNodesInQueue = eq.getNumberOfNodes();
+      assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;
+
+      TestingUtil.sleepThread(3100);
       // visit the node now to prevent the idle time from doing the pruning - node still gets pruned but by
       // max age.
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxAge: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #3: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+
+      algorithm.process(region);
+
+      numNodesInQueue = eq.getNumberOfNodes();
+      assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " + numNodesInQueue;
    }
 
    /**
     * Generic combo case with newly added node should be around.
     */
-   public void testCombo2()
+   public void testCombo2() throws EvictionException
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/d");
       Fqn fqn3 = Fqn.fromString("/a/b/e");
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
 
       config.setMaxNodes(2);
@@ -392,50 +303,34 @@
       region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
       region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.REMOVE_NODE_EVENT));
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #1: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+
+      algorithm.process(region);
+
+      EvictionQueue eq = algorithm.getEvictionQueue();
+      int numNodesInQueue = eq.getNumberOfNodes();
+      assert 1 == numNodesInQueue : "Queue size #1: expected 1 but was " + numNodesInQueue;
+
+      // make sure existing events all time out
+      TestingUtil.sleepThread(1100);
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
 
-      TestingUtil.sleepThread(2000);
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testMaxNode: process failed " + e);
-         e.printStackTrace();
-      }
-      assertEquals("Queue size #2: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
 
-      TestingUtil.sleepThread(3000);
+      numNodesInQueue = eq.getNumberOfNodes();
+      assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;
+
+      TestingUtil.sleepThread(3100);
       region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
-      TestingUtil.sleepThread(500);
-      try
-      {
-         algo_.process(region);
-      }
-      catch (EvictionException e)
-      {
-         fail("testCombo: process failed " + e);
-         e.printStackTrace();
-      }
 
-      TestingUtil.sleepThread(1000); // Fairly random ?
-      assertEquals("Queue size #3: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+      algorithm.process(region);
+
+      numNodesInQueue = eq.getNumberOfNodes();
+      assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " + numNodesInQueue;
    }
 
-   public void testEvictionSortOrder() throws Exception
+   public void testEvictionSortOrder() throws EvictionException
    {
-      Region region = regionManager_.getRegion("/a/b", true);
+      Region region = regionManager.getRegion("/a/b", true);
       LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
 
       config.setMaxAgeSeconds(1000);
@@ -448,10 +343,8 @@
          region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
       }
 
-      algo_.process(region);
+      algorithm.process(region);
 
-      TestingUtil.sleepThread(5000);
-
       for (int i = 0; i < 100; i++)
       {
          Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
@@ -461,9 +354,9 @@
          }
       }
 
-      algo_.process(region);
+      algorithm.process(region);
 
-      LRUQueue queue = (LRUQueue) algo_.getEvictionQueue();
+      LRUQueue queue = (LRUQueue) algorithm.getEvictionQueue();
 
       NodeEntry ne;
       int count = 0;
@@ -487,7 +380,7 @@
          region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
       }
 
-      algo_.process(region);
+      algorithm.process(region);
       long lastCreateTimestamp = 0;
       while ((ne = queue.getFirstMaxAgeNodeEntry()) != null)
       {

Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java	2008-03-28 15:43:37 UTC (rev 5475)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java	2008-03-28 17:22:39 UTC (rev 5476)
@@ -15,8 +15,8 @@
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Unit tests for LRU Policy.
@@ -25,10 +25,10 @@
  * @author Daniel Huang - dhuang at jboss.org
  * @version $Revision$
  */
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 public class LRUPolicyTest
 {
-   CacheSPI<Object, Object> cache_;
+   CacheSPI<Object, Object> cache;
    int wakeupIntervalMillis_ = 0;
    final String ROOT_STR = "/test";
    Throwable t1_ex, t2_ex;
@@ -39,7 +39,7 @@
    public void setUp() throws Exception
    {
       initCaches();
-      wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+      wakeupIntervalMillis_ = cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
       log("wakeupInterval is " + wakeupIntervalMillis_);
       if (wakeupIntervalMillis_ < 0)
       {
@@ -52,37 +52,23 @@
 
    public void initCaches() throws Exception
    {
-      Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,true);
+      Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
       EvictionConfig evConfig = conf.getEvictionConfig();
       evConfig.setWakeupIntervalSeconds(5);
       List<EvictionRegionConfig> regionConfigs = new ArrayList<EvictionRegionConfig>();
-      regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data", 5, 4));
+      regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data", 5, 6));
       regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/test", 10000, 4));
       evConfig.setEvictionRegionConfigs(regionConfigs);
       conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
       conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
-      cache_ = (CacheSPI) new DefaultCacheFactory().createCache(conf);
+      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(conf);
    }
 
 
-   private EvictionRegionConfig buildEvictionRegionConfig(String regionName, int timeToLive, int maxNodes)
-   {
-      EvictionRegionConfig erc = new EvictionRegionConfig();
-      erc.setRegionName(regionName);
-      LRUConfiguration lruConfig = new LRUConfiguration();
-      lruConfig.setMaxNodes(5000);
-      lruConfig.setTimeToLiveSeconds(1000);
-      erc.setEvictionPolicyConfig(lruConfig);
-      List<EvictionRegionConfig> erConfigs = new ArrayList<EvictionRegionConfig>();
-      erConfigs.add(erc);
-      return null;
-
-   }
-
    @AfterMethod(alwaysRun = true)
    public void tearDown() throws Exception
    {
-      cache_.stop();
+      cache.stop();
    }
 
    public void testInUseEviction() throws Exception
@@ -96,36 +82,40 @@
       {
          String str = rootStr + i;
          fqn = Fqn.fromString(str);
-         cache_.put(fqn, str, str);
+         cache.put(fqn, str, str);
       }
 
-      TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
       System.out.println("***************************** marking as in-use");
-      cache_.getRegionManager().getRegion(Fqn.fromString(rootStr + 5), false).markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);
+      cache.getRegionManager().getRegion(Fqn.fromString(rootStr + 5), false).markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);
 
+//      TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
+
       for (int i = 10; i < 15; i++)
       {
          String str = rootStr + i;
          fqn = Fqn.fromString(str);
-         cache_.put(fqn, str, str);
+         cache.put(fqn, str, str);
       }
 
       TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
 
       for (int i = 0; i < 5; i++)
       {
-         assertNull(cache_.getNode(Fqn.fromString(rootStr + i)));
+         Fqn f = Fqn.fromString(rootStr + i);
+         assert null == cache.getNode(f) : f + " should be null";
       }
 
-      assertNotNull(cache_.getNode(Fqn.fromString(rootStr + 5)));
+      assertNotNull(cache.getNode(Fqn.fromString(rootStr + 5)));
 
       for (int i = 6; i < 11; i++)
       {
-         assertNull(cache_.getNode(Fqn.fromString(rootStr + i)));
+         Fqn f = Fqn.fromString(rootStr + i);
+         assert null == cache.getNode(f) : f + " should be null";
       }
       for (int i = 11; i < 15; i++)
       {
-         assertNotNull(cache_.getNode(Fqn.fromString(rootStr + i)));
+         Fqn f = Fqn.fromString(rootStr + i);
+         assert null != cache.getNode(f) : f + " should not be null";
       }
    }
 
@@ -138,7 +128,7 @@
          Fqn fqn = Fqn.fromString(str);
          try
          {
-            cache_.put(fqn, str, str);
+            cache.put(fqn, str, str);
          }
          catch (Exception e)
          {
@@ -146,12 +136,12 @@
             e.printStackTrace();
          }
       }
-      System.out.println(cache_.toString());
+      System.out.println(cache.toString());
       TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
-      System.out.println(cache_.toString());
+      System.out.println(cache.toString());
       try
       {
-         String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+         String val = (String) cache.get(rootStr + "3", rootStr + "3");
          assertNull("DataNode should be empty ", val);
       }
       catch (Exception e)
@@ -165,7 +155,7 @@
    {
       String rootStr = "/org/jboss/test/data/";
 
-      System.out.println("REGIONS: " + cache_.getRegionManager().dumpRegions());
+      System.out.println("REGIONS: " + cache.getRegionManager().dumpRegions());
 
       for (int i = 0; i < 10; i++)
       {
@@ -173,7 +163,7 @@
          Fqn fqn = Fqn.fromString(str);
          try
          {
-            cache_.put(fqn, str, str);
+            cache.put(fqn, str, str);
          }
          catch (Exception e)
          {
@@ -189,21 +179,21 @@
       Fqn fqn = Fqn.fromString(str);
       try
       {
-         cache_.get(fqn, str);// just to keep it fresh
+         cache.get(fqn, str);// just to keep it fresh
          System.out.println("-- sleeping for " + period + "ms");
          TestingUtil.sleepThread(period);// it really depends the eviction thread time.
-         cache_.get(fqn, str);// just to keep it fresh
+         cache.get(fqn, str);// just to keep it fresh
          System.out.println("-- sleeping for " + period + "ms");
          TestingUtil.sleepThread(period);// it really depends the eviction thread time.
-         String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+         String val = (String) cache.get(rootStr + "3", rootStr + "3");
          System.out.println("-- val=" + val);
          assertNull("DataNode should be empty ", val);
-         val = (String) cache_.get(rootStr + "7", rootStr + "7");
+         val = (String) cache.get(rootStr + "7", rootStr + "7");
          System.out.println("-- val=" + val);
          assertNotNull("DataNode should not be empty ", val);
          System.out.println("-- sleeping for " + (wakeupIntervalMillis_ + 1000) + "ms");
          TestingUtil.sleepThread(wakeupIntervalMillis_ + 1000);
-         val = (String) cache_.get(rootStr + "7", rootStr + "7");
+         val = (String) cache.get(rootStr + "7", rootStr + "7");
          System.out.println("-- val=" + val);
          assertNull("DataNode should be empty ", val);
       }
@@ -223,7 +213,7 @@
          Fqn fqn = Fqn.fromString(str);
          try
          {
-            cache_.put(fqn, str, str);
+            cache.put(fqn, str, str);
          }
          catch (Exception e)
          {
@@ -241,17 +231,17 @@
       Fqn fqn2 = Fqn.fromString(str2);
       try
       {
-         cache_.get(fqn1, str1);// just to keep it fresh
-         cache_.get(fqn2, str2);// just to keep it fresh
+         cache.get(fqn1, str1);// just to keep it fresh
+         cache.get(fqn2, str2);// just to keep it fresh
          TestingUtil.sleepThread(period);// it really depends the eviction thread time.
-         cache_.get(fqn1, str1);// just to keep it fresh
-         cache_.get(fqn2, str2);// just to keep it fresh
+         cache.get(fqn1, str1);// just to keep it fresh
+         cache.get(fqn2, str2);// just to keep it fresh
          TestingUtil.sleepThread(period);// it really depends the eviction thread time.
-         String val = (String) cache_.get(rootStr + "7/7", rootStr + "7/7");
+         String val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
          assertNotNull("DataNode should not be empty ", val);
-         cache_.removeNode(fqn1);
+         cache.removeNode(fqn1);
          TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
-         val = (String) cache_.get(rootStr + "7/7", rootStr + "7/7");
+         val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
          assertNull("DataNode should be empty ", val);
       }
       catch (Exception e)
@@ -268,13 +258,13 @@
       // Add a parent, then a child. LRU will evict the parent,
       // then the child, leaving behind an empty parent
       Fqn<String> parent = Fqn.fromString(rootStr + "parent");
-      cache_.put(parent, "key", "value");
-      cache_.put(new Fqn<String>(parent, "child"), "key", "value");
+      cache.put(parent, "key", "value");
+      cache.put(new Fqn<String>(parent, "child"), "key", "value");
 
       // Give eviction time to run a few times, then confirm parent
       // is completely gone
       TestingUtil.sleepThread((wakeupIntervalMillis_ * 4) + 100);
-      assertFalse("Parent completely removed", cache_.getRoot().hasChild(parent));
+      assertFalse("Parent completely removed", cache.getRoot().hasChild(parent));
    }
 
 
@@ -294,7 +284,7 @@
          {
             try
             {
-               cache_.put(myName + i++, "value", i);
+               cache.put(myName + i++, "value", i);
                sleep(1);
             }
             catch (Throwable e)
@@ -312,12 +302,12 @@
 
    public void testConcurrentPutAndEvict() throws Exception
    {
-      cache_.stop();
-      cache_.destroy();
-      cache_.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
-      cache_.create();
-      cache_.start();
-      cache_.put(ROOT_STR + "/concurrentPutAndEvict", "value", 1);
+      cache.stop();
+      cache.destroy();
+      cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+      cache.create();
+      cache.start();
+      cache.put(ROOT_STR + "/concurrentPutAndEvict", "value", 1);
 
       for (int i = 0; i < 10; i++)
       {
@@ -332,7 +322,7 @@
          {
             fail("Exception generated in put() " + t1_ex);
          }
-         log("nodes/locks: " + cache_.getNumberOfNodes() + "/" + cache_.getNumberOfLocksHeld());
+         log("nodes/locks: " + cache.getNumberOfNodes() + "/" + cache.getNumberOfLocksHeld());
          TestingUtil.sleepThread(1000);
          if (counter > 10)
          {// run for 10 seconds
@@ -355,7 +345,7 @@
             Fqn fqn = Fqn.fromString(str);
             try
             {
-               cache_.put(fqn, str, str);
+               cache.put(fqn, str, str);
             }
             catch (Exception e)
             {
@@ -367,7 +357,7 @@
          // wait for an eviction
          TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 2000);
 
-         String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+         String val = (String) cache.get(rootStr + "3", rootStr + "3");
          assertNull("DataNode should be empty ", val);
 
          // reinsert the elements
@@ -377,7 +367,7 @@
             Fqn fqn = Fqn.fromString(str);
             try
             {
-               cache_.put(fqn, str, str);
+               cache.put(fqn, str, str);
             }
             catch (Exception e)
             {
@@ -387,12 +377,12 @@
          }
 
          // clear the root
-         cache_.removeNode(Fqn.ROOT);
+         cache.removeNode(Fqn.ROOT);
 
          // wait for an eviction
          TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 1000);
 
-         val = (String) cache_.get(rootStr + "3", rootStr + "3");
+         val = (String) cache.get(rootStr + "3", rootStr + "3");
          assertNull("DataNode should be empty ", val);
 
       }




More information about the jbosscache-commits mailing list