Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 130   Methods: 5
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BuddyGroupAssignmentTest.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 org.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.cache.CacheImpl;
 12    import org.jboss.cache.misc.TestingUtil;
 13   
 14    /**
 15    * Tests how groups are formed and disbanded
 16    *
 17    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 18    */
 19    public class BuddyGroupAssignmentTest extends BuddyReplicationTestsBase
 20    {
 21    private Log log = LogFactory.getLog(BuddyGroupAssignmentTest.class);
 22   
 23  8 protected void setUp() throws Exception
 24    {
 25  8 log.debug("Starting setUp()");
 26  8 super.setUp();
 27  8 log.debug("Finishing setUp()");
 28    }
 29   
 30  2 public void testSingleBuddy() throws Exception
 31    {
 32  2 log.debug("Running testSingleBuddy");
 33  2 caches = createCaches(3, false);
 34   
 35  2 for (CacheImpl cache : caches)
 36    {
 37  6 printBuddyGroup(cache);
 38    }
 39   
 40  2 System.out.println("*** Testing cache 0:");
 41  2 assertIsBuddy(caches[0], caches[1], true);
 42  2 System.out.println("*** Testing cache 1:");
 43  2 assertIsBuddy(caches[1], caches[2], true);
 44  2 System.out.println("*** Testing cache 2:");
 45  2 assertIsBuddy(caches[2], caches[0], true);
 46    }
 47   
 48  2 public void test2Buddies() throws Exception
 49    {
 50  2 log.debug("Running test2Buddies");
 51  2 caches = createCaches(2, 3, false);
 52   
 53  2 TestingUtil.sleepThread(2000);
 54   
 55  2 System.out.println("*** Testing cache 0");
 56  2 assertIsBuddy(caches[0], caches[1], false);
 57  2 assertIsBuddy(caches[0], caches[2], false);
 58  2 System.out.println("*** Testing cache 1");
 59  2 assertIsBuddy(caches[1], caches[2], false);
 60  2 assertIsBuddy(caches[1], caches[0], false);
 61  2 System.out.println("*** Testing cache 2");
 62  2 assertIsBuddy(caches[2], caches[1], false);
 63  2 assertIsBuddy(caches[2], caches[0], false);
 64    }
 65   
 66  2 public void testRemovalFromClusterSingleBuddy() throws Exception
 67    {
 68  2 log.debug("Running testRemovalFromClusterSingleBuddy");
 69  2 caches = createCaches(3, false);
 70   
 71  2 System.out.println("*** Testing cache 0");
 72  2 assertIsBuddy(caches[0], caches[1], true);
 73  2 System.out.println("*** Testing cache 1");
 74  2 assertIsBuddy(caches[1], caches[2], true);
 75  2 System.out.println("*** Testing cache 2");
 76  2 assertIsBuddy(caches[2], caches[0], true);
 77   
 78    // now remove a cache from the cluster
 79  2 caches[1].stop();
 80  2 caches[1] = null;
 81   
 82  2 TestingUtil.sleepThread(getSleepTimeout());
 83   
 84    // now test new buddy groups
 85  2 System.out.println("*** Testing cache 0");
 86  2 assertIsBuddy(caches[0], caches[2], true);
 87  2 System.out.println("*** Testing cache 2");
 88  2 assertIsBuddy(caches[2], caches[0], true);
 89  2 System.out.println("*** Completed successfully ***");
 90  2 assertNoLocks(caches);
 91    }
 92   
 93  2 public void testRemovalFromCluster2Buddies() throws Exception
 94    {
 95  2 log.debug("Running testRemovalFromCluster2Buddies");
 96  2 caches = createCaches(2, 4, false);
 97  2 assertNoLocks(caches);
 98   
 99  2 System.out.println("*** Testing cache 0");
 100  2 assertIsBuddy(caches[0], caches[1], false);
 101  2 assertIsBuddy(caches[0], caches[2], false);
 102  2 System.out.println("*** Testing cache 1");
 103  2 assertIsBuddy(caches[1], caches[2], false);
 104  2 assertIsBuddy(caches[1], caches[3], false);
 105  2 System.out.println("*** Testing cache 2");
 106  2 assertIsBuddy(caches[2], caches[3], false);
 107  1 assertIsBuddy(caches[2], caches[0], false);
 108  1 System.out.println("*** Testing cache 3");
 109  1 assertIsBuddy(caches[3], caches[0], false);
 110  1 assertIsBuddy(caches[3], caches[1], false);
 111   
 112    // now remove a cache from the cluster
 113  1 caches[1].stop();
 114  1 caches[1] = null;
 115   
 116  1 TestingUtil.sleepThread(getSleepTimeout());
 117   
 118    // now test new buddy groups
 119  1 System.out.println("*** Testing cache 0");
 120  1 assertIsBuddy(caches[0], caches[2], false);
 121  1 assertIsBuddy(caches[0], caches[3], false);
 122  1 System.out.println("*** Testing cache 2");
 123  1 assertIsBuddy(caches[2], caches[3], false);
 124  1 assertIsBuddy(caches[2], caches[0], false);
 125  1 System.out.println("*** Testing cache 3");
 126  1 assertIsBuddy(caches[3], caches[0], false);
 127  1 assertIsBuddy(caches[3], caches[2], false);
 128  1 assertNoLocks(caches);
 129    }
 130    }