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