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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Nov 10 05:17:39 EST 2008


Author: mircea.markus
Date: 2008-11-10 05:17:39 -0500 (Mon, 10 Nov 2008)
New Revision: 7101

Modified:
   core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
Log:
fixed intermittent failure - controlled eviction

Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java	2008-11-10 10:07:39 UTC (rev 7100)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java	2008-11-10 10:17:39 UTC (rev 7101)
@@ -8,23 +8,19 @@
 
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.config.EvictionConfig;
 import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
 import org.jboss.cache.lock.IsolationLevel;
 import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.util.internals.EvictionWatcher;
+import org.jboss.cache.util.internals.EvictionController;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import org.jboss.cache.UnitTestCacheFactory;
-
 /**
  * Unit tests for LFU Policy.
  *
@@ -35,23 +31,16 @@
 public class LFUPolicyTest extends EvictionTestsBase
 {
    CacheSPI<Object, Object> cache;
-   long wakeupIntervalMillis = 0;
    final String ROOT_STR = "/test";
    Throwable t1_ex, t2_ex;
    boolean isTrue;
    int maxNodesDefault = 500, minNodesDefault = 10, maxNodesR1 = 200, minNodesR1 = 100, maxNodesR2 = -1, minNodesR2 = 5;
+   private EvictionController evController;
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
       initCaches();
-      wakeupIntervalMillis = cache.getConfiguration().getEvictionConfig().getWakeupInterval();
-      log("wakeupInterval is " + wakeupIntervalMillis);
-      if (wakeupIntervalMillis < 0)
-      {
-         fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis);
-      }
-
       t1_ex = t2_ex = null;
       isTrue = true;
    }
@@ -59,13 +48,14 @@
    void initCaches() throws Exception
    {
       Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
-      EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new LFUAlgorithmConfig(maxNodesDefault, minNodesDefault), 200000), 200);
+      EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new LFUAlgorithmConfig(maxNodesDefault, minNodesDefault), 200000), 0);
       evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new LFUAlgorithmConfig(maxNodesR1, minNodesR1)));
       evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new LFUAlgorithmConfig(maxNodesR2, minNodesR2)));
       config.setEvictionConfig(evConfig);
       config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
       config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
       cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(config, true);
+      evController = new EvictionController(cache);
    }
 
    @AfterMethod(alwaysRun = true)
@@ -131,9 +121,7 @@
    public void testNodeVisited() throws InterruptedException
    {
       String rootStr = "/org/jboss/test/data/";
-      List<Fqn> fqns = new ArrayList<Fqn>();
-      for (int i = 0; i < 5; i++) fqns.add(Fqn.fromString(rootStr + i));
-      EvictionWatcher ew = new EvictionWatcher(cache, fqns);
+
       for (int i = 0; i < 10; i++)
       {
          String str = rootStr + i;
@@ -149,7 +137,7 @@
          }
       }
 
-      assert ew.waitForEviction(30, TimeUnit.SECONDS);
+      evController.startEviction();
 
       try
       {
@@ -197,11 +185,7 @@
             }
          }
 
-         assert waitForEviction(cache, 30, TimeUnit.SECONDS,
-               Fqn.fromString(rootStr + 7),
-               Fqn.fromString(rootStr + 8),
-               Fqn.fromString(rootStr + 9)
-         );
+         evController.startEviction();
 
          // now make sure we still only have 5 nodes and they are the ones we expect based on LFU
          for (int i = 5; i < 7; i++)
@@ -251,9 +235,7 @@
          }
       }
 
-      long period = (wakeupIntervalMillis + 500);
-      log("period is " + period);
-      TestingUtil.sleepThread(period);
+      evController.startEviction();
 
       for (int i = 0; i < (maxNodesR1 - minNodesR1); i++)
       {
@@ -279,7 +261,7 @@
          }
       }
 
-      TestingUtil.sleepThread(period);
+      evController.startEviction();
 
 
       for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)




More information about the jbosscache-commits mailing list