Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 101   Methods: 5
NCLOC: 79   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BuddyReplicationConfigTest.java - 100% 100% 100%
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.buddyreplication;
 8   
 9    import junit.framework.TestCase;
 10    import org.jboss.cache.CacheImpl;
 11    import org.jboss.cache.CacheSPI;
 12    import org.jboss.cache.DefaultCacheFactory;
 13    import org.jboss.cache.config.BuddyReplicationConfig;
 14    import org.jboss.cache.config.Configuration;
 15    import org.jboss.cache.factories.XmlConfigurationParser;
 16    import org.jboss.cache.interceptors.DataGravitatorInterceptor;
 17    import org.jboss.cache.interceptors.Interceptor;
 18    import org.jboss.cache.xml.XmlHelper;
 19    import org.w3c.dom.Element;
 20   
 21    /**
 22    * Tests basic configuration options by passing stuff into the CacheImpl.
 23    *
 24    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 25    */
 26    public class BuddyReplicationConfigTest extends TestCase
 27    {
 28    private CacheSPI<?, ?> cache;
 29   
 30  4 protected void tearDown()
 31    {
 32  4 cache.stop();
 33  4 cache = null;
 34    }
 35   
 36  1 public void testNullConfig() throws Exception
 37    {
 38  1 cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
 39  1 cache.getConfiguration().setBuddyReplicationConfig(null);
 40  1 assertNull(cache.getBuddyManager());
 41    }
 42   
 43  1 public void testDisabledConfig() throws Exception
 44    {
 45  1 String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
 46  1 Element element = XmlHelper.stringToElement(xmlConfig);
 47  1 BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
 48  1 cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
 49  1 cache.getConfiguration().setBuddyReplicationConfig(config);
 50  1 assertNull(cache.getBuddyManager());
 51    }
 52   
 53  1 public void testBasicConfig() throws Exception
 54    {
 55  1 String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
 56  1 Element element = XmlHelper.stringToElement(xmlConfig);
 57  1 BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
 58  1 cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
 59  1 cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
 60  1 cache.getConfiguration().setBuddyReplicationConfig(config);
 61  1 cache.create();
 62  1 cache.start();
 63  1 assertNotNull(cache.getBuddyManager());
 64  1 BuddyManager mgr = cache.getBuddyManager();
 65  1 assertTrue(mgr.isEnabled());
 66  1 assertNull(mgr.getBuddyPoolName());
 67  1 assertEquals(NextMemberBuddyLocator.class, mgr.buddyLocator.getClass());
 68  1 NextMemberBuddyLocatorConfig blc = (NextMemberBuddyLocatorConfig) mgr.buddyLocator.getConfig();
 69  1 assertEquals(1, blc.getNumBuddies());
 70  1 assertTrue(blc.isIgnoreColocatedBuddies());
 71    }
 72   
 73  1 public void testXmlConfig() throws Exception
 74    {
 75  1 cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
 76  1 ((CacheImpl) cache).setConfiguration(new XmlConfigurationParser().parseFile("META-INF/buddyreplication-service.xml"));
 77  1 cache.create();
 78  1 cache.start();
 79  1 BuddyManager bm = cache.getBuddyManager();
 80  1 assertNotNull(bm);
 81  1 assertTrue(bm.isEnabled());
 82  1 assertTrue(bm.buddyLocator instanceof NextMemberBuddyLocator);
 83  1 NextMemberBuddyLocator bl = (NextMemberBuddyLocator) bm.buddyLocator;
 84  1 NextMemberBuddyLocatorConfig blc = (NextMemberBuddyLocatorConfig) bl.getConfig();
 85  1 assertTrue(blc.isIgnoreColocatedBuddies());
 86  1 assertEquals(1, blc.getNumBuddies());
 87  1 assertEquals("myBuddyPoolReplicationGroup", bm.getConfig().getBuddyPoolName());
 88  1 assertEquals(2000, bm.getConfig().getBuddyCommunicationTimeout());
 89   
 90    // test Data Gravitator
 91  1 boolean hasDG = false;
 92  1 for (Interceptor interceptor : cache.getInterceptorChain())
 93    {
 94  9 hasDG = hasDG || (interceptor instanceof DataGravitatorInterceptor);
 95    }
 96   
 97  1 System.out.println(cache.getInterceptorChain());
 98   
 99  1 assertTrue("Should have a data gravitator!!", hasDG);
 100    }
 101    }