Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 207   Methods: 4
NCLOC: 140   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeInterceptorPutMapTest.java - 100% 100% 100%
coverage
 1    package org.jboss.cache.optimistic;
 2   
 3    import org.jboss.cache.CacheImpl;
 4    import org.jboss.cache.Fqn;
 5    import org.jboss.cache.interceptors.Interceptor;
 6    import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
 7    import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
 8    import org.jboss.cache.loader.SamplePojo;
 9    import org.jboss.cache.transaction.DummyTransactionManager;
 10    import org.jboss.cache.transaction.GlobalTransaction;
 11    import org.jboss.cache.transaction.OptimisticTransactionEntry;
 12    import org.jboss.cache.transaction.TransactionTable;
 13   
 14    import javax.transaction.Transaction;
 15    import java.util.HashMap;
 16    import java.util.Map;
 17   
 18    /**
 19    * @author xenephon
 20    */
 21    public class NodeInterceptorPutMapTest extends AbstractOptimisticTestCase
 22    {
 23   
 24   
 25    /**
 26    * @param name
 27    */
 28  3 public NodeInterceptorPutMapTest(String name)
 29    {
 30  3 super(name);
 31    }
 32   
 33  1 public void testTransactionPutDataMethod() throws Exception
 34    {
 35   
 36  1 TestListener listener = new TestListener();
 37  1 final CacheImpl cache = createCacheWithListener(listener);
 38   
 39  1 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
 40  1 interceptor.setCache(cache);
 41  1 Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
 42  1 nodeInterceptor.setCache(cache);
 43  1 MockInterceptor dummy = new MockInterceptor();
 44  1 dummy.setCache(cache);
 45   
 46   
 47  1 interceptor.setNext(nodeInterceptor);
 48  1 nodeInterceptor.setNext(dummy);
 49   
 50  1 cache.setInterceptorChain(interceptor);
 51   
 52    // first set up a node with a pojo
 53  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 54  1 mgr.begin();
 55  1 Transaction tx = mgr.getTransaction();
 56   
 57    // inject InvocationContext
 58  1 cache.getInvocationContext().setTransaction(tx);
 59  1 cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
 60   
 61  1 SamplePojo pojo = new SamplePojo(21, "test");
 62  1 Map temp = new HashMap();
 63  1 temp.put("key1", pojo);
 64  1 cache.put("/one/two", temp);
 65   
 66  1 assertEquals(null, dummy.getCalled());
 67  1 TransactionTable table = cache.getTransactionTable();
 68   
 69  1 GlobalTransaction gtx = table.get(tx);
 70   
 71  1 OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
 72   
 73  1 TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 74   
 75   
 76  1 mgr.commit();
 77   
 78    //assert what should be the results of our call
 79  1 assertEquals(3, workspace.getNodes().size());
 80  1 assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
 81  1 assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
 82  1 assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
 83  1 assertTrue(entry.getLocks().isEmpty());
 84  1 assertEquals(1, entry.getModifications().size());
 85  1 assertTrue(!cache.exists("/one/two"));
 86  1 assertEquals(null, dummy.getCalled());
 87  1 cache.stop();
 88    }
 89   
 90  1 public void testTransactionPutLocalOverwriteDataMethod() throws Exception
 91    {
 92   
 93  1 TestListener listener = new TestListener();
 94  1 final CacheImpl cache = createCacheWithListener(listener);
 95   
 96  1 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
 97  1 interceptor.setCache(cache);
 98  1 Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
 99  1 nodeInterceptor.setCache(cache);
 100  1 MockInterceptor dummy = new MockInterceptor();
 101  1 dummy.setCache(cache);
 102   
 103  1 interceptor.setNext(nodeInterceptor);
 104  1 nodeInterceptor.setNext(dummy);
 105   
 106  1 cache.setInterceptorChain(interceptor);
 107   
 108    // first set up a node with a pojo
 109  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 110  1 mgr.begin();
 111  1 Transaction tx = mgr.getTransaction();
 112   
 113    // inject InvocationContext
 114  1 cache.getInvocationContext().setTransaction(tx);
 115  1 cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
 116   
 117  1 SamplePojo pojo = new SamplePojo(21, "test");
 118  1 Map temp = new HashMap();
 119  1 temp.put("key1", pojo);
 120  1 cache.put("/one/two", temp);
 121   
 122    //overwrite the map we just put in
 123  1 SamplePojo pojo2 = new SamplePojo(22, "test");
 124  1 Map temp2 = new HashMap();
 125  1 temp2.put("key1", pojo2);
 126  1 cache.put("/one/two", temp2);
 127   
 128  1 assertEquals(null, dummy.getCalled());
 129  1 TransactionTable table = cache.getTransactionTable();
 130   
 131  1 GlobalTransaction gtx = table.get(tx);
 132   
 133  1 OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
 134   
 135  1 TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 136   
 137  1 mgr.commit();
 138    //assert what should be the results of our call
 139  1 assertEquals(3, workspace.getNodes().size());
 140  1 assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
 141  1 assertEquals(pojo2, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
 142  1 assertTrue(entry.getLocks().isEmpty());
 143  1 assertEquals(2, entry.getModifications().size());
 144  1 assertTrue(!cache.exists("/one/two"));
 145  1 assertEquals(null, dummy.getCalled());
 146  1 cache.stop();
 147    }
 148   
 149  1 public void testTransactionPutLocalEmptyMethod() throws Exception
 150    {
 151   
 152  1 TestListener listener = new TestListener();
 153  1 final CacheImpl cache = createCacheWithListener(listener);
 154  1 Fqn f = Fqn.fromString("/one/two");
 155   
 156  1 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
 157  1 interceptor.setCache(cache);
 158  1 Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
 159  1 nodeInterceptor.setCache(cache);
 160  1 MockInterceptor dummy = new MockInterceptor();
 161  1 dummy.setCache(cache);
 162   
 163  1 interceptor.setNext(nodeInterceptor);
 164  1 nodeInterceptor.setNext(dummy);
 165   
 166  1 cache.setInterceptorChain(interceptor);
 167   
 168    // first set up a node with a pojo
 169  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 170  1 mgr.begin();
 171  1 Transaction tx = mgr.getTransaction();
 172   
 173    // inject InvocationContext
 174  1 cache.getInvocationContext().setTransaction(tx);
 175  1 cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
 176   
 177  1 SamplePojo pojo = new SamplePojo(21, "test");
 178  1 Map temp = new HashMap();
 179  1 temp.put("key1", pojo);
 180  1 cache.put(f, temp);
 181   
 182   
 183  1 Map temp2 = new HashMap();
 184   
 185  1 cache.put(f, temp2, true);
 186   
 187  1 assertEquals(null, dummy.getCalled());
 188  1 TransactionTable table = cache.getTransactionTable();
 189   
 190  1 GlobalTransaction gtx = table.get(tx);
 191   
 192  1 OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
 193   
 194  1 TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 195   
 196  1 mgr.commit();
 197    //assert what should be the results of our call
 198  1 assertEquals(3, workspace.getNodes().size());
 199  1 assertNotNull(workspace.getNode(f));
 200  1 assertEquals(null, workspace.getNode(f).get("key1"));
 201  1 assertTrue(entry.getLocks().isEmpty());
 202  1 assertEquals(2, entry.getModifications().size());
 203  1 assertTrue(!cache.exists(f));
 204  1 assertEquals(null, dummy.getCalled());
 205  1 cache.stop();
 206    }
 207    }