Author: dereed
Date: 2014-02-27 21:36:10 -0500 (Thu, 27 Feb 2014)
New Revision: 8581
Added:
core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java
Log:
[JBCACHE-1633] ExpirationAlgorithm ignores entries loaded from a cache loader
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2014-02-20
18:29:51 UTC (rev 8580)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2014-02-28
02:36:10 UTC (rev 8581)
@@ -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/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java 2014-02-20
18:29:51 UTC (rev 8580)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java 2014-02-28
02:36:10 UTC (rev 8581)
@@ -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/trunk/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationWithCacheLoaderTest.java 2014-02-28
02:36:10 UTC (rev 8581)
@@ -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 $
+ */
+@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);
+ }
+}