Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 145   Methods: 11
NCLOC: 119   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ReplicatedLRUPolicyTest.java 87.5% 98.4% 100% 97.5%
coverage coverage
 1    package org.jboss.cache.eviction;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.AbstractCacheListener;
 5    import org.jboss.cache.CacheImpl;
 6    import org.jboss.cache.DefaultCacheFactory;
 7    import org.jboss.cache.Fqn;
 8    import org.jboss.cache.config.Configuration.CacheMode;
 9    import org.jboss.cache.factories.UnitTestCacheFactory;
 10    import org.jboss.cache.misc.TestingUtil;
 11   
 12    /**
 13    * @author Ben Wang, Feb 11, 2004
 14    */
 15    public class ReplicatedLRUPolicyTest extends TestCase
 16    {
 17    CacheImpl cache_, cache1_, cache2_;
 18    int wakeupIntervalMillis_ = 0;
 19    EvictionListener listener_;
 20   
 21  3 public ReplicatedLRUPolicyTest(String s)
 22    {
 23  3 super(s);
 24  3 listener_ = new EvictionListener();
 25    }
 26   
 27  3 public void setUp() throws Exception
 28    {
 29  3 super.setUp();
 30  3 cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 31  3 initCaches(cache_);
 32  3 cache_.getConfiguration().setUseRegionBasedMarshalling(true);
 33  3 cache_.start();
 34  3 cache_.getNotifier().addCacheListener(listener_);
 35  3 listener_.resetCounter();
 36   
 37  3 cache2_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 38  3 cache2_.setConfiguration(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC));// read in generic local xml
 39  3 cache2_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 40  3 cache2_.getConfiguration().setUseRegionBasedMarshalling(true);
 41  3 cache2_.start();
 42   
 43  3 wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
 44  3 log("wakeupInterval is " + wakeupIntervalMillis_);
 45  3 if (wakeupIntervalMillis_ <= 0)
 46    {
 47  0 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
 48    }
 49    }
 50   
 51  3 void initCaches(CacheImpl cache) throws Exception
 52    {
 53  3 cache.setConfiguration(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC, true));
 54  3 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 55    }
 56   
 57  3 public void tearDown() throws Exception
 58    {
 59  3 super.tearDown();
 60  3 cache_.stop();
 61  3 cache2_.stop();
 62    }
 63   
 64    /**
 65    * Test local eviction policy that failed for eviction event.
 66    */
 67  1 public void testBasic() throws Exception
 68    {
 69  1 String rootStr = "/org/jboss/test/data/";
 70  1 String str = rootStr + "0";
 71  1 cache_.put(str, str, str);
 72   
 73  1 TestingUtil.sleepThread(30000);
 74  1 String val = (String) cache_.get(str, str);
 75  1 assertNull("DataNode should be evicted already ", val);
 76  1 assertEquals("Eviction counter ", 1, listener_.getCounter());
 77  1 val = (String) cache2_.get(str, str);
 78  1 assertNotNull("DataNode should not be evicted here ", val);
 79  1 assertEquals("Eviction counter ", 1, listener_.getCounter());
 80    }
 81   
 82  1 public void testEviction() throws Exception
 83    {
 84  1 String rootStr = "/org/jboss/test/data/";
 85  1 for (int i = 0; i < 10; i++)
 86    {
 87  10 String str = rootStr + i;
 88  10 Fqn fqn = Fqn.fromString(str);
 89  10 cache_.put(fqn, str, str);
 90    }
 91   
 92  1 TestingUtil.sleepThread(2 * wakeupIntervalMillis_);
 93  1 String val = (String) cache_.get(rootStr + "3", rootStr + "3");
 94  1 assertNull("DataNode should be evicted already ", val);
 95  1 val = (String) cache2_.get(rootStr + "3", rootStr + "3");
 96  1 assertNotNull("DataNode should not be evicted here ", val);
 97    }
 98   
 99  1 public void testEvictionReplication() throws Exception
 100    {
 101  1 String rootStr = "/org/jboss/test/data/";
 102  1 for (int i = 0; i < 10; i++)
 103    {
 104  10 String str = rootStr + i;
 105  10 Fqn fqn = Fqn.fromString(str);
 106  10 cache_.put(fqn, str, str);
 107    }
 108   
 109  1 TestingUtil.sleepThread(wakeupIntervalMillis_ - 1000);
 110  1 String str = rootStr + "7";
 111  1 Fqn fqn = Fqn.fromString(str);
 112  1 cache_.get(fqn, str);
 113  1 TestingUtil.sleepThread(wakeupIntervalMillis_);
 114   
 115  1 String val = (String) cache_.get(rootStr + "3", rootStr + "3");
 116  1 assertNull("DataNode should be empty ", val);
 117  1 val = (String) cache2_.get(rootStr + "7", rootStr + "7");
 118  1 assertNotNull("DataNode should not be null", val);
 119    }
 120   
 121  3 void log(String msg)
 122    {
 123  3 System.out.println("-- " + msg);
 124    }
 125   
 126    class EvictionListener extends AbstractCacheListener
 127    {
 128    int counter = 0;
 129   
 130  2 public int getCounter()
 131    {
 132  2 return counter;
 133    }
 134   
 135  3 public void resetCounter()
 136    {
 137  3 counter = 0;
 138    }
 139   
 140  40 public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
 141    {
 142  20 if (pre) counter++;
 143    }
 144    }
 145    }