Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 198   Methods: 7
NCLOC: 139   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeReplicatedMoveTest.java 66.7% 98.9% 100% 95.6%
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.UnitTestCacheConfigurationFactory;
 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(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
 37  10 cache[0].getConfiguration().setSyncCommitPhase(true);
 38  10 cache[0].getConfiguration().setSyncRollbackPhase(true);
 39  10 cache[0].getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
 40  10 cache[0].start();
 41  10 rootNode = cache[0].getRoot();
 42  10 tm = cache[0].getTransactionManager();
 43   
 44    // start second instance
 45  10 cache[1] = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
 46  10 cache[1].getConfiguration().setSyncCommitPhase(true);
 47  10 cache[1].getConfiguration().setSyncRollbackPhase(true);
 48  10 cache[1].getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
 49  10 cache[1].start();
 50    }
 51   
 52  10 protected void tearDown()
 53    {
 54  10 if (cache != null)
 55    {
 56  10 if (cache[0] != null) cache[0].stop();
 57  10 if (cache[1] != null) cache[1].stop();
 58  10 cache = null;
 59    }
 60  10 if (rootNode != null) rootNode = null;
 61    }
 62   
 63  2 public void testReplicatability()
 64    {
 65  2 nodeA = rootNode.addChild(A);
 66  2 nodeB = nodeA.addChild(B);
 67   
 68  2 nodeA.put(k, vA);
 69  2 nodeB.put(k, vB);
 70   
 71  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 72  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 73   
 74  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 75  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 76   
 77    // now move...
 78  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 79   
 80  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 81  2 assertEquals(vB, cache[0].getRoot().getChild(B).get(k));
 82   
 83  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 84  2 assertEquals(vB, cache[1].getRoot().getChild(B).get(k));
 85    }
 86   
 87  2 public void testInvalidations() throws Exception
 88    {
 89  2 cache[0].stop();
 90  2 cache[1].stop();
 91  2 cache[0].destroy();
 92  2 cache[1].destroy();
 93  2 cache[0].getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
 94  2 cache[1].getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
 95  2 cache[0].start();
 96  2 cache[1].start();
 97   
 98  2 nodeA = rootNode.addChild(A);
 99  2 nodeB = nodeA.addChild(B);
 100   
 101  2 nodeA.put(k, vA);
 102  2 nodeB.put(k, vB);
 103   
 104  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 105  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 106   
 107  2 assertNull(cache[1].getRoot().getChild(A));
 108  2 assertNull(cache[1].getRoot().getChild(B));
 109   
 110    // now move...
 111  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 112   
 113  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 114  2 assertEquals(vB, cache[0].getRoot().getChild(B).get(k));
 115   
 116  2 assertNull(cache[1].getRoot().getChild(A));
 117  2 assertNull(cache[1].getRoot().getChild(B));
 118   
 119    // now make sure a node exists on cache 2
 120  2 cache[1].getRoot().addChild(A);
 121   
 122  2 try
 123    {
 124  2 cache[0].move(cache[0].getRoot().getChild(B).getFqn(), cache[0].getRoot().getChild(A).getFqn());// should throw an NPE
 125  0 fail("Expecting an exception");
 126    }
 127    catch (Exception e)
 128    {
 129    // expected
 130    }
 131    }
 132   
 133  2 public void testReplTxCommit() throws Exception
 134    {
 135  2 Fqn A_B = new Fqn(A, B);
 136  2 nodeA = rootNode.addChild(A);
 137  2 nodeB = nodeA.addChild(B);
 138   
 139  2 nodeA.put(k, vA);
 140  2 nodeB.put(k, vB);
 141   
 142  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 143  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 144   
 145  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 146  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 147   
 148    // now move...
 149  2 tm.begin();
 150  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 151   
 152  2 assertEquals(vA, cache[0].get(A, k));
 153  2 assertNull(cache[0].get(A_B, k));
 154  2 assertEquals(vB, cache[0].get(B, k));
 155  2 tm.commit();
 156   
 157  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 158  2 assertEquals(vB, cache[0].getRoot().getChild(B).get(k));
 159  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 160  2 assertEquals(vB, cache[1].getRoot().getChild(B).get(k));
 161   
 162    }
 163   
 164  2 public void testReplTxRollback() throws Exception
 165    {
 166  2 nodeA = rootNode.addChild(A);
 167  2 nodeB = nodeA.addChild(B);
 168   
 169  2 nodeA.put(k, vA);
 170  2 nodeB.put(k, vB);
 171   
 172  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 173  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 174  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 175  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 176   
 177    // now move...
 178  2 tm.begin();
 179  2 cache[0].move(nodeB.getFqn(), Fqn.ROOT);
 180   
 181  2 assertEquals(vA, cache[0].get(A, k));
 182  2 assertEquals(vB, cache[0].get(B, k));
 183   
 184  2 tm.rollback();
 185   
 186  2 assertEquals(vA, cache[0].getRoot().getChild(A).get(k));
 187  2 assertEquals(vB, cache[0].getRoot().getChild(A).getChild(B).get(k));
 188  2 assertEquals(vA, cache[1].getRoot().getChild(A).get(k));
 189  2 assertEquals(vB, cache[1].getRoot().getChild(A).getChild(B).get(k));
 190    }
 191   
 192  2 public void testReplConcurrency()
 193    {
 194    //fail("Implement me");
 195    // TODO: Implement this test
 196    }
 197   
 198    }