Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 192   Methods: 7
NCLOC: 133   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeReplicatedMoveTest.java 66.7% 98.9% 100% 95.4%
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    package org.jboss.cache.api;
 8   
 9    import junit.framework.TestCase;
 10    import org.jboss.cache.CacheSPI;
 11    import org.jboss.cache.DefaultCacheFactory;
 12    import org.jboss.cache.Fqn;
 13    import org.jboss.cache.Node;
 14    import org.jboss.cache.config.Configuration;
 15    import org.jboss.cache.config.Configuration.CacheMode;
 16    import org.jboss.cache.factories.UnitTestCacheFactory;
 17   
 18    import javax.transaction.TransactionManager;
 19   
 20    public class NodeReplicatedMoveTest extends TestCase
 21    {
 22    protected Node rootNode, nodeA, nodeB, nodeC, nodeD, nodeE;
 23    protected CacheSPI[] cache;
 24    protected TransactionManager tm;
 25    protected static final Fqn A = Fqn.fromString("/a"), B = Fqn.fromString("/b"), C = Fqn.fromString("/c"), D = Fqn.fromString("/d"), E = Fqn.fromString("/e");
 26    protected Object k = "key", vA = "valueA", vB = "valueB", vC = "valueC", vD = "valueD", vE = "valueE";
 27   
 28    protected boolean optimistic = false;
 29   
 30   
 31  10 protected void setUp() throws Exception
 32    {
 33  10 cache = new CacheSPI[2];
 34   
 35    // start a single cache instance
 36  10 cache[0] = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), false);
 37  10 cache[0].getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
 38  10 cache[0].start();
 39  10 rootNode = cache[0].getRoot();
 40  10 tm = cache[0].getTransactionManager();
 41   
 42    // start second instance
 43  10 cache[1] = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), false);
 44  10 cache[1].getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
 45  10 cache[1].start();
 46    }
 47   
 48  10 protected void tearDown()
 49    {
 50  10 if (cache != null)
 51    {
 52  10 if (cache[0] != null) cache[0].stop();
 53  10 if (cache[1] != null) cache[1].stop();
 54  10 cache = null;
 55    }
 56  10 if (rootNode != null) rootNode = null;
 57    }
 58   
 59  2 public void testReplicatability()
 60    {
 61  2 nodeA = rootNode.addChild(A);
 62  2 nodeB = nodeA.addChild(B);
 63   
 64  2 nodeA.put(k, vA);
 65  2 nodeB.put(k, vB);
 66   
 67  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 68  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 69   
 70  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 71  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 72   
 73    // now move...
 74  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 75   
 76  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 77  2 assertEquals(vB, cache[0].getRoot().getChild(B).get(k));
 78   
 79  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 80  2 assertEquals(vB, cache[1].getRoot().getChild(B).get(k));
 81    }
 82   
 83  2 public void testInvalidations() throws Exception
 84    {
 85  2 cache[0].stop();
 86  2 cache[1].stop();
 87  2 cache[0].getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
 88  2 cache[1].getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
 89  2 cache[0].start();
 90  2 cache[1].start();
 91   
 92  2 nodeA = rootNode.addChild(A);
 93  2 nodeB = nodeA.addChild(B);
 94   
 95  2 nodeA.put(k, vA);
 96  2 nodeB.put(k, vB);
 97   
 98  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 99  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 100   
 101  2 assertNull(cache[1].getRoot().getChild(A));
 102  2 assertNull(cache[1].getRoot().getChild(B));
 103   
 104    // now move...
 105  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 106   
 107  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 108  2 assertEquals(vB, cache[0].getRoot().getChild(B).get(k));
 109   
 110  2 assertNull(cache[1].getRoot().getChild(A));
 111  2 assertNull(cache[1].getRoot().getChild(B));
 112   
 113    // now make sure a node exists on cache 2
 114  2 cache[1].getRoot().addChild(A);
 115   
 116  2 try
 117    {
 118  2 cache[0].move(cache[0].getRoot().getChild(B).getFqn(), cache[0].getRoot().getChild(A).getFqn());// should throw an NPE
 119  0 fail("Expecting an exception");
 120    }
 121    catch (Exception e)
 122    {
 123    // expected
 124    }
 125    }
 126   
 127  2 public void testReplTxCommit() throws Exception
 128    {
 129  2 Fqn A_B = new Fqn(A, B);
 130  2 nodeA = rootNode.addChild(A);
 131  2 nodeB = nodeA.addChild(B);
 132   
 133  2 nodeA.put(k, vA);
 134  2 nodeB.put(k, vB);
 135   
 136  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 137  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 138   
 139  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 140  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 141   
 142    // now move...
 143  2 tm.begin();
 144  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 145   
 146  2 assertEquals(vA, cache[0].get(A, k));
 147  2 assertNull(cache[0].get(A_B, k));
 148  2 assertEquals(vB, cache[0].get(B, k));
 149  2 tm.commit();
 150   
 151  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 152  2 assertEquals(vB, cache[0].getRoot().getChild(B).get(k));
 153  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 154  2 assertEquals(vB, cache[1].getRoot().getChild(B).get(k));
 155   
 156    }
 157   
 158  2 public void testReplTxRollback() throws Exception
 159    {
 160  2 nodeA = rootNode.addChild(A);
 161  2 nodeB = nodeA.addChild(B);
 162   
 163  2 nodeA.put(k, vA);
 164  2 nodeB.put(k, vB);
 165   
 166  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 167  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 168  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 169  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 170   
 171    // now move...
 172  1 tm.begin();
 173  1 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 174   
 175  1 assertEquals(vA, cache[0].get(A, k));
 176  1 assertEquals(vB, cache[0].get(B, k));
 177   
 178  1 tm.rollback();
 179   
 180  1 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 181  1 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 182  1 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 183  1 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 184    }
 185   
 186  2 public void testReplConcurrency()
 187    {
 188    //fail("Implement me");
 189    // TODO: Implement this test
 190    }
 191   
 192    }