Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 100   Methods: 4
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CacheSPITest.java 50% 100% 100% 92.2%
coverage coverage
 1    package org.jboss.cache.api;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.CacheSPI;
 5    import org.jboss.cache.DefaultCacheFactory;
 6    import org.jboss.cache.config.Configuration;
 7    import org.jboss.cache.config.Configuration.CacheMode;
 8    import org.jboss.cache.factories.UnitTestCacheFactory;
 9    import org.jboss.cache.factories.XmlConfigurationParser;
 10   
 11    import java.util.List;
 12   
 13    public class CacheSPITest extends TestCase
 14    {
 15    private CacheSPI cache1;
 16    private CacheSPI cache2;
 17   
 18    protected boolean optimistic = false;
 19   
 20  2 protected void setUp() throws Exception
 21    {
 22  2 super.setUp();
 23   
 24  2 Configuration conf1 = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC);
 25   
 26  2 Configuration conf2 = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC);
 27   
 28  2 conf1.setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
 29  2 conf2.setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
 30   
 31  2 cache1 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(conf1, false);
 32  2 cache2 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(conf2, false);
 33    }
 34   
 35  2 protected void tearDown() throws Exception
 36    {
 37  2 super.tearDown();
 38   
 39  2 if (cache1 != null)
 40    {
 41  2 try
 42    {
 43  2 cache1.stop();
 44    }
 45    catch (Exception e) {}
 46    }
 47   
 48  2 if (cache2 != null)
 49    {
 50  2 try
 51    {
 52  2 cache2.stop();
 53    }
 54    catch (Exception e) {}
 55    }
 56    }
 57   
 58  1 public void testGetMembers() throws Exception
 59    {
 60   
 61  1 cache1.start();
 62  1 List memb1 = cache1.getMembers();
 63  1 assertEquals("View has one member", 1, memb1.size());
 64   
 65  1 Object coord = memb1.get(0);
 66   
 67  1 cache2.start();
 68  1 memb1 = cache1.getMembers();
 69  1 List memb2 = cache2.getMembers();
 70  1 assertEquals("View has two members", 2, memb1.size());
 71  1 assertEquals("Both caches have same view", memb1, memb2);
 72   
 73  1 cache1.stop();
 74  1 memb2 = cache2.getMembers();
 75  1 assertEquals("View has one member", 1, memb2.size());
 76  1 assertFalse("Coordinator changed", coord.equals(memb2.get(0)));
 77    }
 78   
 79  1 public void testIsCoordinator() throws Exception
 80    {
 81  1 XmlConfigurationParser parser = new XmlConfigurationParser();
 82  1 Configuration conf1 = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC);
 83   
 84  1 Configuration conf2 = UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC);
 85   
 86  1 cache1 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(conf1, false);
 87  1 cache2 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(conf2, false);
 88   
 89  1 cache1.start();
 90  1 assertTrue("Cache1 is coordinator", cache1.getRPCManager().isCoordinator());
 91   
 92  1 cache2.start();
 93  1 assertTrue("Cache1 is still coordinator", cache1.getRPCManager().isCoordinator());
 94  1 assertFalse("Cache2 is not coordinator", cache2.getRPCManager().isCoordinator());
 95   
 96  1 cache1.stop();
 97  1 assertTrue("Cache2 is coordinator", cache2.getRPCManager().isCoordinator());
 98   
 99    }
 100    }