Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 116   Methods: 6
NCLOC: 79   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
OptimisticEvictionTest.java 90% 100% 100% 97.9%
coverage coverage
 1    package org.jboss.cache.eviction;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.CacheImpl;
 5    import org.jboss.cache.DefaultCacheFactory;
 6    import org.jboss.cache.DummyTransactionManagerLookup;
 7    import org.jboss.cache.Fqn;
 8    import org.jboss.cache.interceptors.EvictionInterceptor;
 9    import org.jboss.cache.misc.TestingUtil;
 10   
 11    import javax.transaction.TransactionManager;
 12    import java.util.Iterator;
 13    import java.util.List;
 14   
 15    /**
 16    * Tests the eviction and the possible lack of locking nodes.
 17    * The configuration is with an aggressive eviction policy, 100 objects 2 seconds interval.
 18    * <p/>
 19    * It is possible that the number needs to be changed a little, depending on the machine speed.
 20    *
 21    * @author fhenning
 22    */
 23    public class OptimisticEvictionTest extends TestCase
 24    {
 25   
 26    //Maximum number of runs 2^20
 27    private static final int NUMBER_OF_RUNS = 1 << 20;
 28    //Initial number of nodes
 29    private static final int NUMBER_NODES = 256;
 30   
 31    private Fqn region = Fqn.fromString("testingRegion");
 32    private TransactionManager txManager;
 33    private CacheImpl cache;
 34   
 35  4 protected void setUp() throws Exception
 36    {
 37  4 super.setUp();
 38   
 39  4 txManager = new DummyTransactionManagerLookup().getTransactionManager();
 40  4 cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/optimistic-eviction.xml");
 41    }
 42   
 43  4 protected void tearDown() throws Exception
 44    {
 45  4 if (cache != null)
 46    {
 47  4 cache.stop();
 48  4 cache = null;
 49    }
 50  4 super.tearDown();
 51    }
 52   
 53   
 54  1 public void testEvictionError() throws Exception
 55    {
 56    //Initialize the cache via a map
 57  1 for (int i = 0; i < NUMBER_NODES; i++)
 58    {
 59  256 cache.put(new Fqn(region, i), i, i);
 60    }
 61   
 62  1 for (int i = 0; i < NUMBER_OF_RUNS; i++)
 63    {
 64  1048576 txManager.begin();
 65  1048576 cache.get(region, i % NUMBER_NODES);
 66  1048576 txManager.commit();
 67    }
 68    }
 69   
 70   
 71  1 public void testEvictionOccurence() throws Exception
 72    {
 73  1 cache.put("/timeBased/test", "key", "value");
 74  1 assertTrue(cache.exists("/timeBased/test"));
 75   
 76    // wait for it to be evicted.
 77  1 TestingUtil.sleepThread(3000);
 78  1 assertTrue(!cache.exists("/timeBased/test"));
 79    }
 80   
 81  1 public void testInterceptorChain() throws Exception
 82    {
 83  1 List interceptors = cache.getInterceptors();
 84  1 System.out.println(interceptors);
 85  1 Iterator i = interceptors.iterator();
 86  1 boolean found = false;
 87   
 88  1 while (i.hasNext())
 89    {
 90  10 Object o = i.next();
 91  10 if (o instanceof EvictionInterceptor)
 92    {
 93  1 found = true;
 94    }
 95    }
 96   
 97  1 assertTrue("Eviction interceptor should be in interceptor chain.", found);
 98    }
 99   
 100  1 public void testCompleteRemoval() throws Exception
 101    {
 102  1 String rootStr = "/timeBased/";
 103   
 104    // Add a parent, then a child. LRU will evict the parent,
 105    // then the child, leaving behind an empty parent
 106  1 Fqn parent = Fqn.fromString(rootStr + "parent");
 107  1 cache.put(parent, "key", "value");
 108  1 cache.put(new Fqn(parent, "child"), "key", "value");
 109   
 110    // Give eviction time to run a few times, then confirm parent
 111    // is completely gone
 112  1 TestingUtil.sleepThread(5500);
 113  1 assertFalse("Parent completely removed", cache.getRoot().hasChild(parent));
 114    }
 115   
 116    }