From jbosscache-commits at lists.jboss.org Wed Apr 9 12:16:53 2008 Content-Type: multipart/mixed; boundary="===============7168841619583791257==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r5525 - in core/trunk/src: test/java/org/jboss/cache/eviction and 1 other directory. Date: Wed, 09 Apr 2008 12:16:53 -0400 Message-ID: --===============7168841619583791257== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: galder.zamarreno(a)jboss.com Date: 2008-04-09 12:16:53 -0400 (Wed, 09 Apr 2008) New Revision: 5525 Added: core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmT= est.java Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.= java Log: [JBCACHE-1316] offer() is called instead of put() on the recycle queue to a= void blocking forever. Added unit test that forces recycle queue to fill up= completely. Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlg= orithm.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm= .java 2008-04-09 15:59:33 UTC (rev 5524) +++ core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm= .java 2008-04-09 16:16:53 UTC (rev 5525) @@ -24,6 +24,7 @@ * abstract methods and a policy. * * @author Daniel Huang - dhuang(a)jboss.org 10/2005 + * @author Galder Zamarren= o * @version $Revision$ */ public abstract class BaseEvictionAlgorithm implements EvictionAlgorithm @@ -193,7 +194,14 @@ { try { - recycleQueue.put(ne.getFqn()); + boolean result =3D recycleQueue.offer(ne.getFqn(), 5, TimeU= nit.SECONDS); + if (!result) + { + log.warn("Unable to add Fqn[" + ne.getFqn() + "] to recy= cle " + + "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/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgori= thmTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithm= Test.java (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithm= Test.java 2008-04-09 16:16:53 UTC (rev 5525) @@ -0,0 +1,193 @@ +/* + * 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 static org.testng.AssertJUnit.fail; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +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.RegionManager; +import org.jboss.cache.config.ConfigurationException; +import org.jboss.cache.config.EvictionPolicyConfig; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Tests BaseEvictionAlgorithm class. + * = + * @author Galder Zamarren= o + */ +(a)Test(groups =3D "functional") +public class BaseEvictionAlgorithmTest +{ + private static final Log log =3D LogFactory.getLog(BaseEvictionAlgorith= mTest.class); = + = + private RegionManager regionManager; + + @BeforeMethod(alwaysRun =3D true) + public void setUp() throws Exception + { + regionManager =3D new RegionManager(); + } + = + public void testFillUpRecycleQueue() throws Exception + { + final int recycleQueueCapacity =3D 10; + + /* override recycle queue capacity to make the test shorter */ + BaseEvictionAlgorithm algorithm =3D new MockEvictionAlgorithm(recycl= eQueueCapacity); + = + Region region =3D regionManager.getRegion("/a/b/c", true); + region.setEvictionPolicy(new MockEvictionPolicyConfig()); + = + for (int i =3D 0; i < (recycleQueueCapacity + 1); i ++) + { + Fqn fqn =3D Fqn.fromString("/a/b/c/" + Integer.toString(i= + 1)); + region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_N= ODE_EVENT)); = + } + = + ExecutorService executor =3D Executors.newSingleThreadExecutor(); + Future future =3D executor.submit(new ProcessEvictionRegion(re= gion, algorithm)); + = + try + { + future.get(20, TimeUnit.SECONDS); + } + catch(TimeoutException te) + { + log.error("Region eviction processing did not finish on time", te= ); + fail("Region eviction processing should have finished by now, som= ething 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 =3D new LinkedBlockingQueue(recycleQueueCapacit= y); + } + = + @Override + protected EvictionQueue setupEvictionQueue(Region region) throws Evi= ctionException + { + return new LRUQueue(); + } + + @Override + protected boolean shouldEvictNode(NodeEntry ne) + { + /* all node entries need evicting */ + return true; + } + = + } + + public static class MockEvictionPolicy extends BaseEvictionPolicy + { + = + @Override + public void evict(Fqn fqn) throws Exception + { + throw new Exception("Unable to evict"); + } + + @Override + public void setCache(CacheSPI cache) + { + /* no op */ + } + + public EvictionAlgorithm getEvictionAlgorithm() + { + return null; + } + + public Class getEvictionConfiguratio= nClass() + { + return MockEvictionPolicyConfig.class; + } + } + = + public static class MockEvictionPolicyConfig implements EvictionPolicyC= onfig + { + + public String getEvictionPolicyClass() + { + return MockEvictionPolicy.class.getName(); + } + + public void reset() + { + /* no op */ + } + + public void validate() throws ConfigurationException + { + /* no op */ + } = + } + = + public class ProcessEvictionRegion implements Callable + { + private Region region; + = + private EvictionAlgorithm algorithm; + = + public ProcessEvictionRegion(Region region, EvictionAlgorithm algori= thm) + { + this.region =3D region; + this.algorithm =3D algorithm; + } + + public Void call() throws Exception + { + try + { + algorithm.process(region); + } + catch(EvictionException e) + { + log.error("Eviction exception reported", e); + fail("Eviction exception reported" + e); + } + = + return null; + } + } +} --===============7168841619583791257==--