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