[jbosscache-commits] JBoss Cache SVN: r8584 - in core/support-branches/3.2.8.GA_JBCACHE-1633/src: test/java/org/jboss/cache/eviction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Feb 27 21:47:42 EST 2014


Author: dereed
Date: 2014-02-27 21:47:41 -0500 (Thu, 27 Feb 2014)
New Revision: 8584

Added:
   core/support-branches/3.2.8.GA_JBCACHE-1633/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java
Modified:
   core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
   core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java
Log:
[JBPAPP-11017] Backport JBCACHE-1633


Modified: core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
===================================================================
--- core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java	2014-02-28 02:46:53 UTC (rev 8583)
+++ core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java	2014-02-28 02:47:41 UTC (rev 8584)
@@ -173,6 +173,7 @@
          {
             case ADD_NODE_EVENT:
             case ADD_ELEMENT_EVENT:
+            case VISIT_NODE_EVENT: // JBCACHE-1633
                addEvictionEntry(node);
                break;
             case REMOVE_ELEMENT_EVENT:
@@ -181,9 +182,6 @@
                // Removals will be noticed when double-checking expiry time
                // removeEvictionEntry(node);
                break;
-            case VISIT_NODE_EVENT:
-               // unused
-               break;
             case MARK_IN_USE_EVENT:
                markInUse(node);
                break;
@@ -287,12 +285,6 @@
       throw new UnsupportedOperationException();
    }
 
-   @Override
-   public boolean canIgnoreEvent(Type eventType)
-   {
-      return (eventType == EvictionEvent.Type.VISIT_NODE_EVENT);
-   }
-
    public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
    {
       return ExpirationAlgorithmConfig.class;

Modified: core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java
===================================================================
--- core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java	2014-02-28 02:46:53 UTC (rev 8583)
+++ core/support-branches/3.2.8.GA_JBCACHE-1633/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java	2014-02-28 02:47:41 UTC (rev 8584)
@@ -50,15 +50,6 @@
       return ExpirationConfiguration.class;
    }
 
-   /**
-    * Returns true if it's a visit node event.
-    */
-   @Override
-   public boolean canIgnoreEvent(Fqn fqn, EvictionEventType eventType)
-   {
-      return (eventType == EvictionEventType.VISIT_NODE_EVENT);
-   }
-
    public Class<? extends EvictionAlgorithm> modernizePolicy()
    {
       return ExpirationAlgorithm.class;

Added: core/support-branches/3.2.8.GA_JBCACHE-1633/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java
===================================================================
--- core/support-branches/3.2.8.GA_JBCACHE-1633/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java	                        (rev 0)
+++ core/support-branches/3.2.8.GA_JBCACHE-1633/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java	2014-02-28 02:47:41 UTC (rev 8584)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.factories.UnitTestConfigurationFactory;
+import org.jboss.cache.loader.testloaders.DummyInMemoryCacheLoader;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
+import org.jboss.cache.util.internals.EvictionWatcher;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Test for JBCACHE-1633 
+ *
+ * @author Dennis Reed
+ * @version $Revision: 8393 $
+ */
+ at Test(groups = {"functional"}, sequential = true, testName = "eviction.ExpirationWithCacheLoaderTest")
+public class ExpirationWithCacheLoaderTest extends EvictionTestsBase
+{
+   private static final Log log = LogFactory.getLog(ExpirationPolicyTest.class);
+
+   private CacheSPI<Object, Object> cache;
+   private EvictionController ec;
+
+   Fqn fqn1 = Fqn.fromString("/node/1");
+
+   Long future;
+   Long past;
+
+   @BeforeMethod(alwaysRun = true)
+   public void setUp() throws Exception
+   {
+      Configuration conf = new Configuration();
+      ExpirationAlgorithmConfig eAC = new ExpirationAlgorithmConfig();
+      EvictionRegionConfig eRC = new EvictionRegionConfig(Fqn.ROOT, eAC);
+      EvictionConfig econf = new EvictionConfig(eRC);
+      econf.setWakeupInterval(0);
+      conf.setEvictionConfig(econf);
+      cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(conf, false, getClass());
+
+      CacheLoaderConfig clc = UnitTestConfigurationFactory.buildSingleCacheLoaderConfig(false, "", DummyInMemoryCacheLoader.class.getName(), "", false, true, false, true, false);
+      cache.getConfiguration().setCacheLoaderConfig(clc);
+
+      cache.start();
+      ec = new EvictionController(cache);
+
+      future = System.currentTimeMillis() + 1500;
+      past = System.currentTimeMillis() - 1500;
+   }
+
+   @AfterMethod(alwaysRun = true)
+   public void tearDown() throws Exception
+   {
+      TestingUtil.killCaches(cache);
+      cache = null;
+   }
+
+   public void testExpirationWithCacheLoader() throws Exception
+   {
+      cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
+
+      EvictionWatcher w = new EvictionWatcher(cache, fqn1);
+      ec.startEviction();
+      assert w.waitForEviction(30, TimeUnit.SECONDS);
+
+      // loads into memory again
+      assertNotNull(cache.get(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY));
+
+      EvictionWatcher w2 = new EvictionWatcher(cache, fqn1);
+      ec.startEviction();
+      assert w2.waitForEviction(30, TimeUnit.SECONDS);
+   }
+}



More information about the jbosscache-commits mailing list