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