JBoss Cache SVN: r8393 - in core/trunk/src: test/java/org/jboss/cache/eviction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2010-04-22 05:01:39 -0400 (Thu, 22 Apr 2010)
New Revision: 8393
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
Log:
[JBCACHE-1578] (ExpirationAlgorithm doesn't seem to work properly when same fqns are modified and removed in parallel) Fixed.
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2010-04-21 11:20:52 UTC (rev 8392)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2010-04-22 09:01:39 UTC (rev 8393)
@@ -127,10 +127,17 @@
{
public void run()
{
- // Run the eviction thread.
- // This thread will synchronize the set of regions and iterate through every MarshRegion registered w/ the
- // Eviction thread. It also synchronizes on each individual region as it is being processed.
- processRegions();
+ try
+ {
+ // Run the eviction thread.
+ // This thread will synchronize the set of regions and iterate through every MarshRegion registered w/ the
+ // Eviction thread. It also synchronizes on each individual region as it is being processed.
+ processRegions();
+ }
+ catch (Throwable t)
+ {
+ log.warn("Eviction task encountered an unexpected error", t);
+ }
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2010-04-21 11:20:52 UTC (rev 8392)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2010-04-22 09:01:39 UTC (rev 8393)
@@ -98,6 +98,9 @@
private void addEvictionEntry(Fqn fqn)
{
Long l = getExpiration(fqn);
+ if (l == null)
+ return;
+
if (l == -1)
{
if (config.isWarnNoExpirationKey() && log.isWarnEnabled())
@@ -105,7 +108,7 @@
else if (log.isDebugEnabled())
log.debug("No expiration key for Node: " + fqn);
}
- else if (l != null)
+ else
{
setExpiration(fqn, l);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2010-04-21 11:20:52 UTC (rev 8392)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2010-04-22 09:01:39 UTC (rev 8393)
@@ -92,6 +92,28 @@
assertNull(cache.getNode(fqn3));
}
+ public void testAddRemoveEviction() throws Exception
+ {
+ cache.put(fqn4, "foo", "bar");
+ cache.removeNode(fqn4);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
+ cache.put(fqn2, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
+ cache.put(fqn3, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
+
+ ec.startEviction();
+ assertNotNull(cache.getNode(fqn1));
+ assertNull(cache.getNode(fqn2));
+ assertNotNull(cache.getNode(fqn3));
+ assertNull(cache.getNode(fqn4));
+
+ Thread.sleep(2000);
+ ec.startEviction();
+
+ log.info("should remove 1 and 3 now");
+ assertNull(cache.getNode(fqn1));
+ assertNull(cache.getNode(fqn3));
+ }
+
public void testUpdate() throws Exception
{
try