Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 135   Methods: 5
NCLOC: 84   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AsyncCacheTest.java - 100% 100% 100%
coverage
 1    /*
 2    * Created on 17-Feb-2005
 3    *
 4    */
 5    package org.jboss.cache.optimistic;
 6   
 7    import org.jboss.cache.CacheImpl;
 8    import org.jboss.cache.Fqn;
 9    import org.jboss.cache.GlobalTransaction;
 10    import org.jboss.cache.TransactionTable;
 11    import org.jboss.cache.config.Configuration;
 12    import org.jboss.cache.loader.SamplePojo;
 13    import org.jboss.cache.misc.TestingUtil;
 14    import org.jboss.cache.transaction.DummyTransactionManager;
 15   
 16    import javax.transaction.Transaction;
 17   
 18    public class AsyncCacheTest extends AbstractOptimisticTestCase
 19    {
 20   
 21    CacheImpl cache, cache2;
 22   
 23  2 protected void setUp() throws Exception
 24    {
 25  2 cache = createReplicatedCache(Configuration.CacheMode.REPL_ASYNC);
 26  2 cache2 = createReplicatedCache(Configuration.CacheMode.REPL_ASYNC);
 27    }
 28   
 29  2 protected void tearDown()
 30    {
 31  2 super.tearDown();
 32  2 destroyCache(cache);
 33  2 destroyCache(cache2);
 34  2 cache = null;
 35  2 cache2 = null;
 36    }
 37   
 38  2 public AsyncCacheTest(String s)
 39    {
 40  2 super(s);
 41    }
 42   
 43  1 public void testRemoteCacheBroadcast() throws Exception
 44    {
 45   
 46  1 assertEquals(2, cache.getMembers().size());
 47  1 assertEquals(2, cache2.getMembers().size());
 48   
 49  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 50   
 51    //start local transaction
 52  1 mgr.begin();
 53  1 Transaction tx = mgr.getTransaction();
 54   
 55    //this sets
 56  1 GlobalTransaction gtx = cache.getCurrentTransaction(tx);
 57   
 58  1 SamplePojo pojo = new SamplePojo(21, "test");
 59   
 60  1 cache.put("/one/two", "key1", pojo);
 61   
 62    //GlobalTransaction gtx = cache.getCurrentTransaction(tx);
 63  1 TransactionTable table = cache.getTransactionTable();
 64  1 assertNotNull(mgr.getTransaction());
 65  1 mgr.commit();
 66   
 67   
 68  1 assertNull(mgr.getTransaction());
 69   
 70    //assert that the local cache is in the right state
 71  1 assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
 72  1 assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
 73   
 74  1 assertTrue(cache.exists(Fqn.fromString("/one/two")));
 75  1 assertTrue(cache.exists(Fqn.fromString("/one")));
 76  1 assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));
 77   
 78    // allow changes to replicate since this is async
 79  1 TestingUtil.sleepThread((long) 1000);
 80   
 81  1 assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
 82  1 assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
 83   
 84  1 assertTrue(cache2.exists(Fqn.fromString("/one/two")));
 85  1 assertTrue(cache2.exists(Fqn.fromString("/one")));
 86  1 assertEquals(pojo, cache2.get(Fqn.fromString("/one/two"), "key1"));
 87    }
 88   
 89   
 90  1 public void testTwoWayRemoteCacheBroadcast() throws Exception
 91    {
 92  1 assertEquals(2, cache.getMembers().size());
 93  1 assertEquals(2, cache2.getMembers().size());
 94   
 95  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 96   
 97    //start local transaction
 98  1 mgr.begin();
 99  1 Transaction tx = mgr.getTransaction();
 100   
 101    //this sets
 102  1 cache.getCurrentTransaction(tx);
 103   
 104  1 SamplePojo pojo = new SamplePojo(21, "test");
 105   
 106  1 cache.put("/one/two", "key1", pojo);
 107   
 108  1 GlobalTransaction gtx = cache.getCurrentTransaction(tx);
 109  1 TransactionTable table = cache.getTransactionTable();
 110  1 assertNotNull(mgr.getTransaction());
 111  1 mgr.commit();
 112   
 113   
 114  1 assertNull(mgr.getTransaction());
 115   
 116    //assert that the local cache is in the right state
 117  1 assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
 118  1 assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
 119   
 120  1 assertTrue(cache.exists(Fqn.fromString("/one/two")));
 121  1 assertTrue(cache.exists(Fqn.fromString("/one")));
 122  1 assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));
 123   
 124    // let the async calls complete
 125  1 TestingUtil.sleepThread((long) 1000);
 126   
 127  1 assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
 128  1 assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
 129   
 130  1 assertTrue(cache2.exists(Fqn.fromString("/one/two")));
 131  1 assertTrue(cache2.exists(Fqn.fromString("/one")));
 132   
 133  1 assertEquals(pojo, cache2.get(Fqn.fromString("/one/two"), "key1"));
 134    }
 135    }