Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 159   Methods: 8
NCLOC: 124   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SyncReplTxTest.java 33.3% 94% 100% 89.1%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.api;
 9   
 10    import junit.framework.TestCase;
 11    import org.jboss.cache.Cache;
 12    import org.jboss.cache.CacheSPI;
 13    import org.jboss.cache.DefaultCacheFactory;
 14    import org.jboss.cache.Fqn;
 15    import org.jboss.cache.InvocationContext;
 16    import org.jboss.cache.Node;
 17    import org.jboss.cache.config.Configuration.CacheMode;
 18    import org.jboss.cache.config.Option;
 19    import org.jboss.cache.factories.UnitTestCacheFactory;
 20    import org.jboss.cache.misc.TestingUtil;
 21    import org.jboss.cache.transaction.DummyTransactionManager;
 22   
 23    import javax.transaction.HeuristicMixedException;
 24    import javax.transaction.HeuristicRollbackException;
 25    import javax.transaction.NotSupportedException;
 26    import javax.transaction.RollbackException;
 27    import javax.transaction.SystemException;
 28    import javax.transaction.Transaction;
 29   
 30    /**
 31    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 32    */
 33    public class SyncReplTxTest extends TestCase
 34    {
 35    private CacheSPI[] caches;
 36   
 37  1 protected void setUp()
 38    {
 39  1 System.out.println("*** In setUp()");
 40  1 caches = new CacheSPI[2];
 41  1 caches[0] = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC));
 42  1 caches[1] = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC));
 43   
 44  1 TestingUtil.blockUntilViewsReceived(caches, 5000);
 45  1 System.out.println("*** Finished setUp()");
 46    }
 47   
 48  1 protected void tearDown()
 49    {
 50  1 System.out.println("*** In tearDown()");
 51  1 if (caches != null)
 52    {
 53  1 for (CacheSPI c : caches)
 54    {
 55  2 if (c != null)
 56    {
 57  2 Transaction t;
 58   
 59  2 try
 60    {
 61  ? if ((t = c.getTransactionManager().getTransaction()) != null)
 62    {
 63  0 try
 64    {
 65  0 t.rollback();
 66    }
 67    catch (SystemException e)
 68    {
 69    // do nothing
 70    }
 71    }
 72    }
 73    catch (SystemException e)
 74    {
 75    // do nothing
 76    }
 77  2 c.stop();
 78    }
 79    }
 80  1 caches = null;
 81    }
 82  1 System.out.println("*** Finished tearDown()");
 83    }
 84   
 85  1 Transaction beginTransaction() throws SystemException, NotSupportedException
 86    {
 87  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 88  1 mgr.begin();
 89  1 return mgr.getTransaction();
 90    }
 91   
 92  1 public void testBasicOperation() throws SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException
 93    {
 94  1 assertClusterSize("Should only be 2 caches in the cluster!!!", 2);
 95  1 assertInvocationContextInitState();
 96   
 97  1 Fqn f = Fqn.fromString("/test/data");
 98  1 String k = "key", v = "value";
 99   
 100  1 assertNull("Should be null", caches[0].getRoot().getChild(f));
 101  1 assertNull("Should be null", caches[1].getRoot().getChild(f));
 102   
 103  1 Node node = caches[0].getRoot().addChild(f);
 104   
 105  1 assertNotNull("Should not be null", node);
 106   
 107  1 Transaction tx = beginTransaction();
 108  1 node.put(k, v);
 109  1 Transaction tx1 = caches[0].getInvocationContext().getTransaction();
 110  1 assertNotNull("Transaction can't be null ", tx1);
 111  1 tx.commit();
 112   
 113  1 assertEquals(v, node.get(k));
 114  1 assertEquals(v, caches[0].get(f, k));
 115  1 assertEquals("Should have replicated", v, caches[1].get(f, k));
 116    }
 117   
 118  1 private void assertClusterSize(String message, int size)
 119    {
 120  1 for (Cache c : caches)
 121    {
 122  2 assertClusterSize(message, size, c);
 123    }
 124    }
 125   
 126  2 private void assertClusterSize(String message, int size, Cache c)
 127    {
 128  2 assertEquals(message, size, c.getMembers().size());
 129    }
 130   
 131  1 private void assertInvocationContextInitState()
 132    {
 133  1 for (Cache c : caches)
 134    {
 135  2 assertInvocationContextInitState(c);
 136    }
 137    }
 138   
 139  2 private void assertInvocationContextInitState(Cache c)
 140    {
 141  2 InvocationContext ctx = c.getInvocationContext();
 142  2 InvocationContext control = null;
 143  2 try
 144    {
 145  2 control = ctx.clone();
 146    }
 147    catch (CloneNotSupportedException e)
 148    {
 149  0 fail("Unable to clone InvocationCOntext");
 150    }
 151   
 152  2 control.reset();
 153  2 control.setOptionOverrides(new Option());
 154   
 155  2 assertEquals("Should be equal", control, ctx);
 156    }
 157   
 158   
 159    }