Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 189   Methods: 6
NCLOC: 126   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClusteredCacheLoaderTest.java 50% 98.9% 100% 96%
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.loader;
 8   
 9    import junit.framework.Assert;
 10    import org.apache.commons.logging.Log;
 11    import org.apache.commons.logging.LogFactory;
 12    import org.jboss.cache.CacheImpl;
 13    import org.jboss.cache.DefaultCacheFactory;
 14    import org.jboss.cache.Fqn;
 15    import org.jboss.cache.config.Configuration;
 16   
 17    import java.util.Map;
 18    import java.util.Set;
 19   
 20    /**
 21    * Tests ClusteredCacheLoader
 22    *
 23    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 24    */
 25    public class ClusteredCacheLoaderTest extends AbstractCacheLoaderTestBase
 26    {
 27    private static Log log = LogFactory.getLog(ClusteredCacheLoaderTest.class);
 28    private CacheImpl cache1, cache2;
 29    private CacheLoader loader1, loader2;
 30    private Fqn fqn = Fqn.fromString("/a");
 31    private String key = "key";
 32   
 33  4 protected void setUp() throws Exception
 34    {
 35  0 if (cache1 != null || cache2 != null) tearDown();
 36  4 cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 37  4 cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 38   
 39  4 cache1.getConfiguration().setClusterName("CCL-Test");
 40  4 cache1.getConfiguration().setInitialStateRetrievalTimeout(2000);
 41  4 cache2.getConfiguration().setClusterName("CCL-Test");
 42  4 cache2.getConfiguration().setInitialStateRetrievalTimeout(2000);
 43  4 cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
 44  4 cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
 45   
 46  4 cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.ClusteredCacheLoader", "timeout=500", false, false, false));
 47  4 cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.ClusteredCacheLoader", "timeout=500", false, false, false));
 48   
 49  4 cache1.start();
 50  4 cache2.start();
 51   
 52  4 loader1 = cache1.getCacheLoaderManager().getCacheLoader();
 53  4 loader2 = cache2.getCacheLoaderManager().getCacheLoader();
 54    }
 55   
 56  4 protected void tearDown()
 57    {
 58  4 if (cache1 != null)
 59    {
 60  4 cache1.stop();
 61  4 cache1 = null;
 62  4 loader1 = null;
 63    }
 64   
 65  4 if (cache2 != null)
 66    {
 67  4 cache2.stop();
 68  4 cache2 = null;
 69  4 loader2 = null;
 70    }
 71    }
 72   
 73  1 public void testGetKeyValue() throws Exception
 74    {
 75  1 cache1.put(fqn, key, "value");
 76   
 77  1 log.info("Finished put");
 78    // test that this has propagated.
 79  1 Assert.assertEquals("value", loader1.get(fqn).get(key));
 80  1 Assert.assertEquals("value", loader2.get(fqn).get(key));
 81   
 82  1 cache1.evict(fqn);
 83   
 84    // now cache 1 should not have this but cache 2 should.
 85    // loader1 looks at cache2 while loader2 looks at cache1
 86  1 Assert.assertEquals("value", loader1.get(fqn).get(key));
 87  1 Assert.assertNull("Expecting null", loader2.get(fqn));
 88    // // calling a get on cache1 should cause the loader to retrieve the node from cache2
 89  1 Assert.assertEquals("value", cache1.get(fqn, key));
 90    // // and now loader2 should see it
 91    // Assert.assertEquals("value", loader2.get(fqn).get(key));
 92    }
 93   
 94  1 public void testGet() throws Exception
 95    {
 96  1 cache1.put(fqn, key, "value");
 97   
 98    // test that this has propagated.
 99  1 Map map = loader1.get(fqn);
 100  1 Assert.assertTrue("Should contain key", map.containsKey(key));
 101  1 Assert.assertEquals("value", map.get(key));
 102  1 Assert.assertEquals(1, map.size());
 103   
 104  1 map = loader2.get(fqn);
 105  1 Assert.assertTrue("Should contain key", map.containsKey(key));
 106  1 Assert.assertEquals("value", map.get(key));
 107  1 Assert.assertEquals(1, map.size());
 108   
 109  1 cache1.evict(fqn);
 110   
 111    // now cache 1 should not have this but cache 2 should.
 112    // loader1 looks at cache2 while loader2 looks at cache1
 113  1 map = loader1.get(fqn);
 114  1 Assert.assertTrue(map.containsKey(key));
 115  1 Assert.assertEquals("value", map.get(key));
 116  1 Assert.assertEquals(1, map.size());
 117   
 118  1 Assert.assertNull("Expecting null", loader2.get(fqn));
 119  1 map = loader2.get(fqn);
 120  1 Assert.assertNull("Should be null", map);
 121   
 122    // calling a get on cache1 should cause the loader to retrieve the node from cache2
 123  1 Assert.assertEquals("value", cache1.get(fqn, key));
 124    // and now loader2 should see it
 125  1 map = loader2.get(fqn);
 126  1 Assert.assertTrue(map.containsKey(key));
 127  1 Assert.assertEquals("value", map.get(key));
 128  1 Assert.assertEquals(1, map.size());
 129    }
 130   
 131  1 public void testGetChildrenNames() throws Exception
 132    {
 133  1 cache1.put(fqn, key, "value");
 134  1 Fqn child1 = new Fqn(fqn, "child1");
 135  1 Fqn child2 = new Fqn(fqn, "child2");
 136  1 Fqn child3 = new Fqn(fqn, "child3");
 137  1 cache1.put(child1, key, "value");
 138  1 cache1.put(child2, key, "value");
 139  1 cache1.put(child3, key, "value");
 140   
 141    // test that this has propagated.
 142  1 Set childNames = loader1.getChildrenNames(fqn);
 143  1 Assert.assertEquals(3, childNames.size());
 144  1 childNames = loader2.getChildrenNames(fqn);
 145  1 Assert.assertEquals(3, childNames.size());
 146   
 147  1 cache1.evict(child1);
 148  1 cache1.evict(child2);
 149  1 cache1.evict(child3);
 150  1 cache1.evict(fqn);
 151   
 152    // now cache 1 should not have this but cache 2 should.
 153    // loader1 looks at cache2 while loader2 looks at cache1
 154  1 childNames = loader1.getChildrenNames(fqn);
 155  1 Assert.assertEquals(3, childNames.size());
 156   
 157  1 childNames = loader2.getChildrenNames(fqn);
 158  1 Assert.assertNull("should be null", childNames);
 159    // calling a get on cache1 should cause the loader to retrieve the node from cache2
 160  1 Assert.assertEquals("value", cache1.get(fqn, key));
 161    // load up children
 162  1 Assert.assertEquals("value", cache1.get(child1, key));
 163  1 Assert.assertEquals("value", cache1.get(child2, key));
 164  1 Assert.assertEquals("value", cache1.get(child3, key));
 165    // and now loader2 should see it
 166  1 childNames = loader2.getChildrenNames(fqn);
 167  1 Assert.assertEquals(3, childNames.size());
 168    }
 169   
 170  1 public void testExists() throws Exception
 171    {
 172  1 cache1.put(fqn, key, "value");
 173   
 174    // test that this has propagated.
 175  1 Assert.assertTrue("should exist", loader1.exists(fqn));
 176  1 Assert.assertTrue("should exist", loader2.exists(fqn));
 177   
 178  1 cache1.evict(fqn);
 179   
 180    // now cache 1 should not have this but cache 2 should.
 181    // loader1 looks at cache2 while loader2 looks at cache1
 182  1 Assert.assertTrue("should exist", loader1.exists(fqn));
 183  1 Assert.assertTrue("should not exist", !loader2.exists(fqn));
 184    // calling a get on cache1 should cause the loader to retrieve the node from cache2
 185  1 Assert.assertEquals("value", cache1.get(fqn, key));
 186    // and now loader2 should see it
 187  1 Assert.assertTrue("should exist", loader2.exists(fqn));
 188    }
 189    }