Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 87   Methods: 4
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SharedCacheLoaderTest.java 60% 97% 100% 89.4%
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 org.jboss.cache.CacheImpl;
 10    import org.jboss.cache.DefaultCacheFactory;
 11    import org.jboss.cache.interceptors.CacheStoreInterceptor;
 12    import org.jboss.cache.interceptors.Interceptor;
 13   
 14    import java.util.Iterator;
 15   
 16    /**
 17    * See http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3919374#3919374
 18    *
 19    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 20    */
 21    public class SharedCacheLoaderTest extends AbstractCacheLoaderTestBase
 22    {
 23    private CacheImpl cache1, cache2;
 24    private DummyCacheLoader dummyCacheLoader;
 25   
 26  1 protected void setUp() throws Exception
 27    {
 28  0 if (cache1 != null || cache2 != null) tearDown();
 29   
 30    // set up 2 instances of CacheImpl with shared CacheLoaders.
 31  1 cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 32  1 cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 33   
 34  1 cache1.getConfiguration().setCacheMode("REPL_SYNC");
 35  1 cache2.getConfiguration().setCacheMode("REPL_SYNC");
 36   
 37  1 cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
 38  1 cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
 39   
 40  1 cache1.start();
 41  1 cache2.start();
 42   
 43    // force setting up the same cache loader class
 44  1 dummyCacheLoader = new DummyCacheLoader();
 45   
 46  1 cache1.setCacheLoader(dummyCacheLoader);
 47  1 cache2.setCacheLoader(dummyCacheLoader);
 48  1 findCacheStoreInterceptor(cache1).setCache(cache1);
 49  1 findCacheStoreInterceptor(cache2).setCache(cache2);
 50    }
 51   
 52  2 protected CacheStoreInterceptor findCacheStoreInterceptor(CacheImpl cache)
 53    {
 54  2 Iterator ints = cache.getInterceptors().iterator();
 55  2 CacheStoreInterceptor csi = null;
 56  10 while (ints.hasNext())
 57    {
 58  10 Interceptor i = (Interceptor) ints.next();
 59  10 if (i instanceof CacheStoreInterceptor)
 60    {
 61  2 csi = (CacheStoreInterceptor) i;
 62  2 break;
 63    }
 64    }
 65  2 return csi;
 66    }
 67   
 68  1 protected void tearDown()
 69    {
 70  1 if (cache1 != null) cache1.stop();
 71  1 if (cache2 != null) cache2.stop();
 72  1 cache1 = null;
 73  1 cache2 = null;
 74    }
 75   
 76  1 public void testReplicationWithSharedCL() throws Exception
 77    {
 78  1 cache1.put("/test", "one", "two");
 79   
 80    // should have replicated
 81  1 assertEquals("two", cache1.get("/test", "one"));
 82  1 assertEquals("two", cache2.get("/test", "one"));
 83   
 84    // only a single put() should have happened on the cache loader though.
 85  1 assertEquals(1, dummyCacheLoader.getPutCount());
 86    }
 87    }