Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 95   Methods: 6
NCLOC: 62   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SuspendTxTest.java 50% 96.4% 83.3% 91.7%
coverage coverage
 1    package org.jboss.cache.transaction;
 2   
 3    import junit.framework.Test;
 4    import junit.framework.TestCase;
 5    import junit.framework.TestSuite;
 6    import org.jboss.cache.CacheImpl;
 7    import org.jboss.cache.DefaultCacheFactory;
 8    import org.jboss.cache.Fqn;
 9   
 10    import javax.transaction.Transaction;
 11    import javax.transaction.TransactionManager;
 12   
 13    /**
 14    * Based on a contribution by Owen Taylor
 15    *
 16    * @author otaylor@redhat.com
 17    * @author Manik Surtani (manik@jboss.org)
 18    */
 19    public class SuspendTxTest extends TestCase
 20    {
 21    CacheImpl cache;
 22    TransactionManager mgr;
 23   
 24  2 protected void setUp() throws Exception
 25    {
 26  2 super.setUp();
 27  2 cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 28  2 cache.getConfiguration().setCacheMode("local");
 29  2 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 30  2 cache.start();
 31  2 mgr = cache.getTransactionManager();
 32    }
 33   
 34  2 protected void tearDown() throws Exception
 35    {
 36  2 super.tearDown();
 37  2 cache.stop();
 38  2 if (mgr.getTransaction() != null)
 39    {
 40  2 mgr.rollback();
 41    }
 42  2 mgr = null;
 43    }
 44   
 45    /**
 46    * Tests that locks created when a transaction is suspended are independent
 47    * from the transaction.
 48    */
 49  1 public void testSuspendedLocks() throws Exception
 50    {
 51    // create /one first
 52  1 cache.put("/one", null);
 53  1 cache.put("/a", null);
 54  1 mgr.begin();
 55   
 56  1 cache.put("/one/two", "key1", "val1");
 57  1 int numLocksBefore = cache.getNumberOfLocksHeld();
 58   
 59  1 Transaction tx = mgr.suspend();
 60   
 61  1 cache.put("/a/b", "key1", "val1");
 62  1 mgr.resume(tx);
 63   
 64  1 assertEquals(numLocksBefore, cache.getNumberOfLocksHeld());
 65    }
 66   
 67    /**
 68    * Tests that locks created when a transaction is suspended are independent
 69    * from the transaction.
 70    */
 71  1 public void testSuspendedUsingOptionsLocks() throws Exception
 72    {
 73  1 mgr.begin();
 74   
 75  1 cache.put("/one/two", "key1", "val1");
 76  1 int numLocksBefore = cache.getNumberOfLocksHeld();
 77   
 78  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);// will cause any current txs to be suspended for the duration of this call.
 79  1 cache.put(Fqn.fromString("/a/b"), "key1", "val1");
 80   
 81  1 assertEquals(numLocksBefore, cache.getNumberOfLocksHeld());
 82    }
 83   
 84   
 85  1 public static Test suite()
 86    {
 87  1 return new TestSuite(SuspendTxTest.class);
 88    }
 89   
 90  0 public static void main(String[] args)
 91    {
 92  0 junit.textui.TestRunner.run(suite());
 93    }
 94   
 95    }