Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 153   Methods: 7
NCLOC: 92   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VersioningOnReadTest.java - 93.3% 100% 94.2%
coverage coverage
 1    package org.jboss.cache.optimistic;
 2   
 3    import org.jboss.cache.CacheImpl;
 4    import org.jboss.cache.Fqn;
 5   
 6    import javax.transaction.Transaction;
 7    import javax.transaction.TransactionManager;
 8   
 9    /**
 10    * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
 11    */
 12    public class VersioningOnReadTest extends AbstractOptimisticTestCase
 13    {
 14    CacheImpl cache;
 15    Fqn fqn = Fqn.fromString("/a");
 16    TransactionManager tm;
 17   
 18  4 public VersioningOnReadTest(String name)
 19    {
 20  4 super(name);
 21    }
 22   
 23  4 protected void setUp() throws Exception
 24    {
 25  4 super.setUp();
 26  4 cache = createCache();
 27  4 tm = cache.getTransactionManager();
 28    }
 29   
 30  4 protected void tearDown()
 31    {
 32  4 super.tearDown();
 33  4 destroyCache(cache);
 34    }
 35   
 36  1 public void testUpdateOnWrite() throws Exception
 37    {
 38  1 cache.put(fqn, "k", "v");
 39   
 40  1 assertEquals("v", cache.get(fqn, "k"));
 41   
 42    // now start a tx to mod the node
 43  1 tm.begin();
 44  1 cache.put(fqn, "k", "v2");
 45   
 46    // suspend the tx
 47  1 Transaction tx = tm.suspend();
 48   
 49    // now modify the node
 50  1 cache.put(fqn, "k", "v3");
 51   
 52    // resume the tx
 53  1 tm.resume(tx);
 54   
 55  1 try
 56    {
 57  1 tm.commit();
 58  0 fail("Should have failed with a data version mismatch");
 59    }
 60    catch (Exception e)
 61    {
 62    // do nothing
 63    }
 64    }
 65   
 66  1 public void testUpdateOnRemove() throws Exception
 67    {
 68  1 cache.put(fqn, "k", "v");
 69   
 70  1 assertEquals("v", cache.get(fqn, "k"));
 71   
 72    // now start a tx to mod the node
 73  1 tm.begin();
 74  1 cache.remove(fqn, "k");
 75   
 76    // suspend the tx
 77  1 Transaction tx = tm.suspend();
 78   
 79    // now modify the node
 80  1 cache.put(fqn, "k", "v3");
 81   
 82    // resume the tx
 83  1 tm.resume(tx);
 84   
 85  1 try
 86    {
 87  1 tm.commit();
 88  0 fail("Should have failed with a data version mismatch");
 89    }
 90    catch (Exception e)
 91    {
 92    // do nothing
 93    }
 94    }
 95   
 96  1 public void testUpdateOnRemoveNode() throws Exception
 97    {
 98  1 cache.put(fqn, "k", "v");
 99   
 100  1 assertEquals("v", cache.get(fqn, "k"));
 101   
 102    // now start a tx to mod the node
 103  1 tm.begin();
 104  1 cache.remove(fqn);
 105   
 106    // suspend the tx
 107  1 Transaction tx = tm.suspend();
 108   
 109    // now modify the node
 110  1 cache.put(fqn, "k", "v3");
 111   
 112    // resume the tx
 113  1 tm.resume(tx);
 114   
 115  1 try
 116    {
 117  1 tm.commit();
 118  0 fail("Should have failed with a data version mismatch");
 119    }
 120    catch (Exception e)
 121    {
 122    // do nothing
 123    }
 124    }
 125   
 126   
 127  1 public void testUpdateOnRead() throws Exception
 128    {
 129  1 cache.put(fqn, "k", "v");
 130   
 131  1 assertEquals("v", cache.get(fqn, "k"));
 132   
 133    // now start a tx to mod the node
 134  1 tm.begin();
 135  1 cache.get(fqn, "k");
 136   
 137    // suspend the tx
 138  1 Transaction tx = tm.suspend();
 139   
 140    // now modify the node
 141  1 cache.put(fqn, "k", "v3");
 142   
 143    // resume the tx
 144  1 tm.resume(tx);
 145   
 146    // now put some other stuff elsewhere
 147  1 cache.put(Fqn.fromString("/b"), "k", "v");
 148   
 149    // this should succeed since there is no contention on writing to /a
 150  1 tm.commit();
 151    }
 152   
 153    }