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