Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 99   Methods: 6
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConcurrentEvictionTest.java 87.5% 96.3% 100% 95.1%
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    import java.util.Properties;
 19   
 20    /**
 21    * Tests cache behavior in the presence of concurrent passivation.
 22    *
 23    * @author Brian Stansberry
 24    * @version $Revision: 1.12 $
 25    */
 26    public class ConcurrentEvictionTest extends TestCase
 27    {
 28    private CacheImpl cache_;
 29    private int wakeupIntervalMillis_ = 0;
 30    private String tmpDir = System.getProperty("java.io.tmpdir", "/tmp");
 31    private String cacheLoaderDir = "/JBossCacheFileCacheLoader";
 32   
 33  1 public ConcurrentEvictionTest(String s)
 34    {
 35  1 super(s);
 36    }
 37   
 38  1 protected void setUp() throws Exception
 39    {
 40  1 super.setUp();
 41  1 initCaches();
 42  1 wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
 43  1 if (wakeupIntervalMillis_ < 0)
 44    {
 45  0 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
 46    }
 47   
 48    }
 49   
 50  1 void initCaches() throws Exception
 51    {
 52  1 TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
 53  1 cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/local-eviction-cacheloader-service.xml", false);// read in generic local xml
 54  1 cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
 55  1 Properties p = new Properties();
 56  1 p.put("location", tmpDir + cacheLoaderDir);
 57  1 cache_.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setProperties(p);
 58  1 cache_.start();
 59    }
 60   
 61  1 public void tearDown() throws Exception
 62    {
 63  1 super.tearDown();
 64  1 TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
 65  1 cache_.stop();
 66  1 cache_ = null;
 67    }
 68   
 69  1 public void testConcurrentEviction() throws Exception
 70    {
 71  1 Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/eviction");
 72   
 73    // Create a bunch of nodes; more than the /org/jboss/test/data
 74    // region's maxNodes so we know eviction will kick in
 75  1 for (int i = 0; i < 1000; i++)
 76    {
 77  1000 cache_.put(new Fqn(base, i / 100), i, "value");
 78    }
 79   
 80    // Loop for long enough to have 5 runs of the eviction thread
 81  1 long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
 82  1 while (System.currentTimeMillis() < loopDone)
 83    {
 84    // If any get returns null, that's a failure
 85  275 for (int i = 0; i < 1000; i++)
 86    {
 87  275000 Fqn fqn = new Fqn(base, i / 100);
 88  275000 Integer key = i;
 89  275000 assertNotNull("found value under Fqn " + fqn + " and key " + key,
 90    cache_.get(fqn, key));
 91    }
 92    }
 93    }
 94   
 95  1 public static Test suite()
 96    {
 97  1 return new TestSuite(ConcurrentEvictionTest.class);
 98    }
 99    }