Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 71   Methods: 3
NCLOC: 51   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ChannelInjectionTest.java - 95.5% 100% 96%
coverage coverage
 1    package org.jboss.cache.config;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.Cache;
 5    import org.jboss.cache.DefaultCacheFactory;
 6    import org.jboss.cache.Fqn;
 7    import org.jboss.cache.misc.TestingUtil;
 8    import org.jgroups.JChannel;
 9   
 10    import java.util.HashSet;
 11    import java.util.Set;
 12   
 13    /**
 14    * Tests that JBC prefers an injected Channel to creating one via
 15    * a configured JChannelFactory and stack name.
 16    *
 17    * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
 18    * @version $Revision: 1.2 $
 19    */
 20    public class ChannelInjectionTest extends TestCase
 21    {
 22    private Set<Cache> caches = new HashSet();
 23   
 24  1 public void tearDown() throws Exception
 25    {
 26  1 super.tearDown();
 27   
 28  1 for (Cache cache : caches)
 29    {
 30  2 try
 31    {
 32  2 cache.stop();
 33    }
 34    catch (Exception e)
 35    {
 36  0 e.printStackTrace(System.out);
 37    }
 38    }
 39    }
 40   
 41  1 public void testChannelInjectionPreference() throws Exception
 42    {
 43  1 Cache cache1 = createCache();
 44  1 Cache cache2 = createCache();
 45   
 46  1 JChannel ch1 = new JChannel(JChannel.DEFAULT_PROTOCOL_STACK);
 47  1 cache1.getConfiguration().getRuntimeConfig().setChannel(ch1);
 48   
 49  1 JChannel ch2 = new JChannel(JChannel.DEFAULT_PROTOCOL_STACK);
 50  1 cache2.getConfiguration().getRuntimeConfig().setChannel(ch2);
 51   
 52  1 cache1.start();
 53  1 cache2.start();
 54   
 55  1 TestingUtil.blockUntilViewsReceived(new Cache[]{cache1, cache2}, 10000);
 56   
 57  1 Fqn fqn = Fqn.fromString("/a");
 58  1 cache1.put(fqn, "key", "value");
 59  1 assertEquals("Value replicated", "value", cache2.get(fqn, "key"));
 60    }
 61   
 62  2 private Cache createCache() throws Exception
 63    {
 64  2 Configuration config = new Configuration();
 65  2 config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
 66  2 Cache cache = DefaultCacheFactory.getInstance().createCache(config, false);
 67  2 caches.add(cache);
 68   
 69  2 return cache;
 70    }
 71    }