Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 92   Methods: 6
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConcurrentEvictionTest.java 87.5% 95.8% 100% 94.7%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.eviction;
 9   
 10    import junit.framework.Test;
 11    import junit.framework.TestCase;
 12    import junit.framework.TestSuite;
 13    import org.jboss.cache.CacheImpl;
 14    import org.jboss.cache.DefaultCacheFactory;
 15    import org.jboss.cache.Fqn;
 16    import org.jboss.cache.misc.TestingUtil;
 17   
 18    /**
 19    * Tests cache behavior in the presence of concurrent passivation.
 20    *
 21    * @author Brian Stansberry
 22    * @version $Revision: 1.8 $
 23    */
 24    public class ConcurrentEvictionTest extends TestCase
 25    {
 26    private CacheImpl cache_;
 27    private int wakeupIntervalMillis_ = 0;
 28   
 29  1 public ConcurrentEvictionTest(String s)
 30    {
 31  1 super(s);
 32    }
 33   
 34  1 protected void setUp() throws Exception
 35    {
 36  1 super.setUp();
 37  1 initCaches();
 38  1 wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
 39  1 if (wakeupIntervalMillis_ < 0)
 40    {
 41  0 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
 42    }
 43   
 44    }
 45   
 46  1 void initCaches() throws Exception
 47    {
 48  1 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader");
 49  1 cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/local-eviction-cacheloader-service.xml", false);// read in generic local xml
 50  1 cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 51  1 cache_.start();
 52    }
 53   
 54  1 public void tearDown() throws Exception
 55    {
 56  1 super.tearDown();
 57  1 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader");
 58  1 cache_.stop();
 59  1 cache_ = null;
 60    }
 61   
 62  1 public void testConcurrentEviction() throws Exception
 63    {
 64  1 Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/eviction");
 65   
 66    // Create a bunch of nodes; more than the /org/jboss/test/data
 67    // region's maxNodes so we know eviction will kick in
 68  1 for (int i = 0; i < 1000; i++)
 69    {
 70  1000 cache_.put(new Fqn(base, i / 100), new Integer(i), "value");
 71    }
 72   
 73    // Loop for long enough to have 5 runs of the eviction thread
 74  1 long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
 75  1 while (System.currentTimeMillis() < loopDone)
 76    {
 77    // If any get returns null, that's a failure
 78  359 for (int i = 0; i < 1000; i++)
 79    {
 80  359000 Fqn fqn = new Fqn(base, i / 100);
 81  359000 Integer key = i;
 82  359000 assertNotNull("found value under Fqn " + fqn + " and key " + key,
 83    cache_.get(fqn, key));
 84    }
 85    }
 86    }
 87   
 88  1 public static Test suite()
 89    {
 90  1 return new TestSuite(ConcurrentEvictionTest.class);
 91    }
 92    }