Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 151   Methods: 11
NCLOC: 111   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LifeCycleTest.java - 98.4% 90.9% 97.3%
coverage coverage
 1    package org.jboss.cache;
 2   
 3    import junit.framework.Test;
 4    import junit.framework.TestCase;
 5    import junit.framework.TestSuite;
 6    import org.apache.commons.logging.Log;
 7    import org.apache.commons.logging.LogFactory;
 8    import org.jboss.cache.config.Configuration;
 9    import org.jboss.cache.transaction.DummyTransactionManager;
 10   
 11    import javax.transaction.NotSupportedException;
 12    import javax.transaction.SystemException;
 13    import javax.transaction.Transaction;
 14   
 15    /**
 16    * Tests restart (stop-destroy-create-start) of CacheImpl
 17    *
 18    * @author Bela Ban
 19    * @version $Id: LifeCycleTest.java,v 1.7 2007/01/11 13:49:06 msurtani Exp $
 20    */
 21    public class LifeCycleTest extends TestCase
 22    {
 23   
 24    private static Log log = LogFactory.getLog(LifeCycleTest.class);
 25   
 26  1 public void testLocalRestartNoTransactions() throws Exception
 27    {
 28  1 CacheImpl cache = createCache(Configuration.CacheMode.LOCAL);
 29  1 cache.create();
 30  1 cache.start();
 31   
 32  1 cache.put("/a/b/c", null);
 33  1 assertTrue(cache.getNumberOfNodes() > 0);
 34  1 assertEquals(0, cache.getNumberOfLocksHeld());
 35   
 36  1 System.out.println("cache locks before restart:\n" + cache.printLockInfo());
 37  1 restartCache(cache);
 38  1 System.out.println("cache locks after restart:\n" + cache.printLockInfo());
 39   
 40  1 assertTrue(cache.getNumberOfNodes() > 0);
 41  1 assertEquals(0, cache.getNumberOfLocksHeld());
 42    }
 43   
 44   
 45  1 public void testLocalRestartWithTransactions() throws Exception
 46    {
 47  1 CacheImpl cache = createCache(Configuration.CacheMode.LOCAL);
 48  1 cache.create();
 49  1 cache.start();
 50   
 51  1 Transaction tx = beginTransaction();
 52   
 53  1 cache.put("/a/b/c", null);
 54  1 log.debug("cache locks before restart:\n" + cache.printLockInfo());
 55  1 assertTrue(cache.getNumberOfNodes() > 0);
 56  1 assertEquals(4, cache.getNumberOfLocksHeld());
 57   
 58  1 restartCache(cache);
 59  1 log.debug("cache locks after restart:\n" + cache.printLockInfo());
 60   
 61  1 assertEquals(4, cache.getNumberOfLocksHeld());
 62  1 assertTrue(cache.getNumberOfNodes() > 0);
 63   
 64  1 tx.rollback();
 65  1 assertEquals(0, cache.getNumberOfLocksHeld());
 66    }
 67   
 68  1 public void testStartNoCreate() throws Exception
 69    {
 70  1 CacheImpl cache = createCache(Configuration.CacheMode.LOCAL);
 71  1 cache.start();
 72   
 73  1 cache.put("/a/b/c", null);
 74  1 assertTrue(cache.getNumberOfNodes() > 0);
 75  1 assertEquals(0, cache.getNumberOfLocksHeld());
 76   
 77  1 System.out.println("cache locks before restart:\n" + cache.printLockInfo());
 78  1 restartCache(cache);
 79  1 System.out.println("cache locks after restart:\n" + cache.printLockInfo());
 80   
 81  1 assertTrue(cache.getNumberOfNodes() > 0);
 82  1 assertEquals(0, cache.getNumberOfLocksHeld());
 83    }
 84   
 85  1 public void testReStartNoCreate() throws Exception
 86    {
 87  1 CacheImpl cache = createCache(Configuration.CacheMode.LOCAL);
 88  1 cache.start();
 89  1 cache.stop();
 90  1 cache.start();
 91   
 92  1 cache.put("/a/b/c", null);
 93  1 assertTrue(cache.getNumberOfNodes() > 0);
 94  1 assertEquals(0, cache.getNumberOfLocksHeld());
 95   
 96  1 System.out.println("cache locks before restart:\n" + cache.printLockInfo());
 97  1 restartCache(cache);
 98  1 System.out.println("cache locks after restart:\n" + cache.printLockInfo());
 99   
 100  1 assertTrue(cache.getNumberOfNodes() > 0);
 101  1 assertEquals(0, cache.getNumberOfLocksHeld());
 102    }
 103   
 104  4 CacheImpl createCache(Configuration.CacheMode cache_mode) throws Exception
 105    {
 106  4 CacheImpl retval = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 107  4 retval.getConfiguration().setCacheMode(cache_mode);
 108  4 retval.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 109  4 return retval;
 110    }
 111   
 112   
 113  1 Transaction beginTransaction() throws SystemException, NotSupportedException
 114    {
 115  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 116  1 mgr.begin();
 117  1 Transaction tx = mgr.getTransaction();
 118  1 return tx;
 119    }
 120   
 121   
 122  4 void startCache(CacheImpl c) throws Exception
 123    {
 124  4 c.create();
 125  4 c.start();
 126    }
 127   
 128  4 void stopCache(CacheImpl c)
 129    {
 130  4 c.stop();
 131  4 c.destroy();
 132    }
 133   
 134  4 void restartCache(CacheImpl c) throws Exception
 135    {
 136  4 stopCache(c);
 137  4 startCache(c);
 138    }
 139   
 140   
 141  1 public static Test suite()
 142    {
 143  1 return new TestSuite(LifeCycleTest.class);
 144    }
 145   
 146  0 public static void main(String[] args)
 147    {
 148  0 junit.textui.TestRunner.run(suite());
 149    }
 150   
 151    }