Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 159   Methods: 10
NCLOC: 121   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FailSilentlyTest.java 50% 98.5% 100% 95.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    package org.jboss.cache.options;
 8   
 9    import junit.framework.TestCase;
 10    import org.jboss.cache.CacheImpl;
 11    import org.jboss.cache.DefaultCacheFactory;
 12    import org.jboss.cache.Fqn;
 13    import org.jboss.cache.config.Configuration;
 14   
 15    import javax.transaction.Transaction;
 16    import javax.transaction.TransactionManager;
 17    import java.util.HashMap;
 18    import java.util.Map;
 19   
 20    /**
 21    * Tests passing in the failSilently option in various scenarios.
 22    *
 23    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 24    */
 25    public class FailSilentlyTest extends TestCase
 26    {
 27    private CacheImpl cache;
 28    private TransactionManager manager;
 29    private Transaction tx;
 30    private Fqn fqn = Fqn.fromString("/a");
 31    private String key = "key";
 32   
 33  8 protected void setUp() throws Exception
 34    {
 35  0 if (cache != null) tearDown();
 36  8 cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 37    // very short acquisition timeout
 38  8 cache.getConfiguration().setLockAcquisitionTimeout(100);
 39  8 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 40  8 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
 41  8 cache.start();
 42  8 manager = cache.getTransactionManager();
 43    }
 44   
 45  8 protected void tearDown()
 46    {
 47  8 if (tx != null)
 48    {
 49  8 try
 50    {
 51  8 manager.resume(tx);
 52  8 manager.rollback();
 53    }
 54    catch (Exception e)
 55    {
 56    // who cares
 57    }
 58    }
 59  8 if (cache != null)
 60    {
 61  8 cache.stop();
 62  8 cache = null;
 63    }
 64    }
 65   
 66  1 public void testPutKeyValue() throws Exception
 67    {
 68  1 manager.begin();
 69  1 cache.put(fqn, key, "value");
 70  1 tx = manager.suspend();
 71  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 72  1 cache.put(fqn, key, "value2");
 73    }
 74   
 75  1 public void testPutData() throws Exception
 76    {
 77  1 Map<String, String> data = new HashMap<String, String>();
 78  1 data.put(key, "value");
 79  1 manager.begin();
 80  1 cache.put(fqn, data);
 81  1 tx = manager.suspend();
 82  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 83  1 cache.put(fqn, data);
 84    }
 85   
 86   
 87  1 public void testRemoveNode() throws Exception
 88    {
 89  1 cache.put(fqn, key, "value");
 90  1 manager.begin();
 91    // get a read lock
 92  1 cache.get(fqn, key);
 93  1 tx = manager.suspend();
 94  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 95  1 cache.remove(fqn);
 96    }
 97   
 98  1 public void testRemoveKey() throws Exception
 99    {
 100  1 cache.put(fqn, key, "value");
 101  1 manager.begin();
 102    // get a read lock
 103  1 cache.get(fqn, key);
 104  1 tx = manager.suspend();
 105  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 106  1 cache.remove(fqn, key);
 107    }
 108   
 109  1 public void testGetNode() throws Exception
 110    {
 111  1 cache.put(fqn, key, "value");
 112  1 manager.begin();
 113    // get a WL
 114  1 cache.put(fqn, key, "value2");
 115  1 tx = manager.suspend();
 116  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 117  1 cache.get(fqn);
 118    }
 119   
 120  1 public void testGetKey() throws Exception
 121    {
 122  1 cache.put(fqn, key, "value");
 123  1 manager.begin();
 124    // get a WL
 125  1 cache.put(fqn, key, "value2");
 126  1 tx = manager.suspend();
 127  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 128  1 cache.get(fqn, key);
 129    }
 130   
 131  1 public void testGetChildrenNames() throws Exception
 132    {
 133  1 cache.put(fqn, key, "value");
 134  1 manager.begin();
 135    // get a WL
 136  1 cache.put(fqn, key, "value2");
 137  1 tx = manager.suspend();
 138  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 139  1 cache.getChildrenNames(fqn);
 140   
 141    }
 142   
 143  1 public void testPutThatWillFail() throws Exception
 144    {
 145  1 manager.begin();
 146  1 cache.put(fqn, "k", "v");// this will get WLs on / and /a
 147  1 tx = manager.suspend();
 148   
 149  1 assertEquals(2, cache.getNumberOfLocksHeld());
 150   
 151    // now this call WILL fail, but should fail silently - i.e., not roll back.
 152  1 manager.begin();
 153  1 cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
 154  1 cache.put(fqn, "x", "y");
 155   
 156    // should not roll back, despite the cache put call failing/timing out.
 157  1 manager.commit();
 158    }
 159    }