[jbosscache-commits] JBoss Cache SVN: r5559 - in core/branches/1.4.X: tests/functional/org/jboss/cache/eviction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Apr 14 11:39:38 EDT 2008


Author: galder.zamarreno at jboss.com
Date: 2008-04-14 11:39:38 -0400 (Mon, 14 Apr 2008)
New Revision: 5559

Added:
   core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
Modified:
   core/branches/1.4.X/src/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
Log:
[JBCACHE-1316] offer() is called instead of put() on the recycle queue to avoid blocking forever. Added unit test that forces recycle queue to fill up completely.

Modified: core/branches/1.4.X/src/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/eviction/BaseEvictionAlgorithm.java	2008-04-14 15:08:16 UTC (rev 5558)
+++ core/branches/1.4.X/src/org/jboss/cache/eviction/BaseEvictionAlgorithm.java	2008-04-14 15:39:38 UTC (rev 5559)
@@ -19,6 +19,7 @@
  * abstract methods and a policy.
  *
  * @author Daniel Huang - dhuang at jboss.org 10/2005
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  * @version $Revision$
  */
 public abstract class BaseEvictionAlgorithm implements EvictionAlgorithm
@@ -180,7 +181,14 @@
          {
             try
             {
-               recycleQueue.put(ne.getFqn());
+               boolean result = recycleQueue.offer(ne.getFqn(), 5000);
+               if (!result)
+               {
+                  log.warn("Unable to add Fqn[" + ne.getFqn() + "] to recycle " +
+                        "queue because it's full. This is often sign that " +
+                        "evictions are not occurring and nodes that should be " +
+                        "evicted are piling up waiting to be evicted.");
+               }
             }
             catch (InterruptedException e)
             {

Added: core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
===================================================================
--- core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java	                        (rev 0)
+++ core/branches/1.4.X/tests/functional/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java	2008-04-14 15:39:38 UTC (rev 5559)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.eviction;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.ConfigureException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+import org.w3c.dom.Element;
+
+import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
+import EDU.oswego.cs.dl.util.concurrent.Callable;
+import EDU.oswego.cs.dl.util.concurrent.Executor;
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+import EDU.oswego.cs.dl.util.concurrent.ThreadedExecutor;
+import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
+
+/**
+ * Tests BaseEvictionAlgorithm class.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class BaseEvictionAlgorithmTest extends TestCase
+{
+   private static final Log log = LogFactory.getLog(BaseEvictionAlgorithmTest.class);  
+   
+   private RegionManager regionManager;
+
+   public void setUp() throws Exception
+   {
+      regionManager = new RegionManager();
+   }
+   
+   public void testFillUpRecycleQueue() throws Exception
+   {
+      final int recycleQueueCapacity = 10;
+
+      /* override recycle queue capacity to make the test shorter */
+      BaseEvictionAlgorithm algorithm = new MockEvictionAlgorithm(recycleQueueCapacity);      
+      Region region = regionManager.createRegion("/a/b/c", new MockEvictionPolicy(), null);
+      
+      for (int i = 0; i < (recycleQueueCapacity + 1); i ++)
+      {
+         Fqn fqn = Fqn.fromString("/a/b/c/" + Integer.toString(i + 1));
+         region.putNodeEvent(new EvictedEventNode(fqn, EvictedEventNode.ADD_NODE_EVENT));         
+      }
+      
+      Executor executor = new ThreadedExecutor();
+      FutureResult future = new FutureResult();
+
+      Runnable command = future.setter(new ProcessEvictionRegion(region, algorithm));
+      executor.execute(command);
+      
+      try
+      {
+         future.timedGet(20000);
+      }
+      catch(TimeoutException te)
+      {
+         log.error("Region eviction processing did not finish on time", te);
+         fail("Region eviction processing should have finished by now, something is wrong. Recycle queue may have filled up.");
+      }
+      finally
+      {
+         log.info("recycle queue size: " + algorithm.recycleQueue.size());
+      }
+   }
+   
+   /** Classes **/
+   
+   public static class MockEvictionAlgorithm extends BaseEvictionAlgorithm
+   {
+      public MockEvictionAlgorithm(int recycleQueueCapacity)
+      {
+         recycleQueue = new BoundedBuffer(recycleQueueCapacity);
+      }
+      
+      protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+      {
+         return new LRUQueue();
+      }
+
+      protected boolean shouldEvictNode(NodeEntry ne)
+      {
+         /* all node entries need evicting */
+         return true;
+      }      
+   }
+
+   public static class MockEvictionPolicy extends BaseEvictionPolicy
+   {
+      
+      public void evict(Fqn fqn) throws Exception
+      {
+         throw new Exception("Unable to evict");
+      }
+
+      public void configure(TreeCache cache)
+      {
+         /* no op */
+      }
+
+      public EvictionAlgorithm getEvictionAlgorithm()
+      {
+         return null;
+      }
+
+      public Class getEvictionConfigurationClass()
+      {
+         return MockEvictionPolicyConfig.class;
+      }
+   }
+   
+   public static class MockEvictionPolicyConfig implements EvictionConfiguration
+   {
+      public void parseXMLConfig(Element element) throws ConfigureException
+      {
+         /* no op */
+      }      
+   }
+   
+   public class ProcessEvictionRegion implements Callable
+   {
+      private Region region;
+      
+      private EvictionAlgorithm algorithm;
+      
+      public ProcessEvictionRegion(Region region, EvictionAlgorithm algorithm)
+      {
+         this.region = region;
+         this.algorithm = algorithm;
+      }
+
+      public Object call() throws Exception
+      {
+         try
+         {
+            algorithm.process(region);
+         }
+         catch(EvictionException e)
+         {
+            log.error("Eviction exception reported", e);
+            fail("Eviction exception reported" + e);
+         }
+         
+         return null;
+      }
+   }
+}
\ No newline at end of file




More information about the jbosscache-commits mailing list