Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 128   Methods: 6
NCLOC: 89   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
OptimisticEvictionTest.java 83.3% 97.1% 100% 94.3%
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.Fqn;
 7    import org.jboss.cache.interceptors.EvictionInterceptor;
 8    import org.jboss.cache.misc.TestingUtil;
 9    import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 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    // shut down any existing txs
 48  4 try
 49    {
 50  4 if (cache.getTransactionManager().getTransaction() != null)
 51    {
 52  0 cache.getTransactionManager().rollback();
 53    }
 54    }
 55    catch (Exception e)
 56    {
 57    // ignore
 58    }
 59  4 cache.stop();
 60  4 cache = null;
 61    }
 62  4 super.tearDown();
 63    }
 64   
 65   
 66  1 public void testEvictionError() throws Exception
 67    {
 68    //Initialize the cache via a map
 69  1 for (int i = 0; i < NUMBER_NODES; i++)
 70    {
 71  256 cache.put(new Fqn(region, i), i, i);
 72    }
 73   
 74  1 for (int i = 0; i < NUMBER_OF_RUNS; i++)
 75    {
 76  1048576 txManager.begin();
 77  1048576 cache.get(region, i % NUMBER_NODES);
 78  1048576 txManager.commit();
 79    }
 80    }
 81   
 82   
 83  1 public void testEvictionOccurence() throws Exception
 84    {
 85  1 cache.put("/timeBased/test", "key", "value");
 86  1 assertTrue(cache.exists("/timeBased/test"));
 87   
 88    // wait for it to be evicted.
 89  1 TestingUtil.sleepThread(3000);
 90  1 assertTrue(!cache.exists("/timeBased/test"));
 91    }
 92   
 93  1 public void testInterceptorChain() throws Exception
 94    {
 95  1 List interceptors = cache.getInterceptors();
 96  1 System.out.println(interceptors);
 97  1 Iterator i = interceptors.iterator();
 98  1 boolean found = false;
 99   
 100  1 while (i.hasNext())
 101    {
 102  10 Object o = i.next();
 103  10 if (o instanceof EvictionInterceptor)
 104    {
 105  1 found = true;
 106    }
 107    }
 108   
 109  1 assertTrue("Eviction interceptor should be in interceptor chain.", found);
 110    }
 111   
 112  1 public void testCompleteRemoval() throws Exception
 113    {
 114  1 String rootStr = "/timeBased/";
 115   
 116    // Add a parent, then a child. LRU will evict the parent,
 117    // then the child, leaving behind an empty parent
 118  1 Fqn parent = Fqn.fromString(rootStr + "parent");
 119  1 cache.put(parent, "key", "value");
 120  1 cache.put(new Fqn(parent, "child"), "key", "value");
 121   
 122    // Give eviction time to run a few times, then confirm parent
 123    // is completely gone
 124  1 TestingUtil.sleepThread(5500);
 125  1 assertFalse("Parent completely removed", cache.getRoot().hasChild(parent));
 126    }
 127   
 128    }