Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 182   Methods: 4
NCLOC: 79   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BuddyAssignmentStateTransferTest.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.jboss.cache.CacheImpl;
 10    import org.jboss.cache.Fqn;
 11    import org.jboss.cache.misc.TestingUtil;
 12   
 13    import java.io.File;
 14   
 15    /**
 16    * Tests how groups are formed and disbanded
 17    *
 18    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 19    */
 20    public class BuddyAssignmentStateTransferTest extends BuddyReplicationTestsBase
 21    {
 22   
 23    protected int timeout = 10000; // !!!
 24   
 25  8 protected int getSleepTimeout()
 26    {
 27  8 return timeout;
 28    }
 29   
 30  2 public void testNonRegionBasedStateTransfer() throws Exception
 31    {
 32  2 CacheImpl[] caches = new CacheImpl[2];
 33  2 try
 34    {
 35  2 caches[0] = createCache(1, "TEST", false, true);
 36   
 37  2 Fqn main = Fqn.fromString("/a/b/c");
 38  2 caches[0].put(main, "name", "Joe");
 39   
 40  2 caches[1] = createCache(1, "TEST", false, true);
 41   
 42  2 TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
 43  2 TestingUtil.sleepThread(getSleepTimeout());
 44   
 45  2 Fqn test = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
 46    BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()));
 47  2 test = new Fqn(test, main);
 48   
 49  2 assertEquals("State transferred", "Joe", caches[1].get(test, "name"));
 50   
 51  2 CacheImpl[] old = caches;
 52  2 caches = new CacheImpl[3];
 53  2 System.arraycopy(old, 0, caches, 0, old.length);
 54  2 caches[2] = createCache(1, "TEST", false, true);
 55   
 56  2 TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
 57  2 TestingUtil.sleepThread(getSleepTimeout());
 58   
 59  2 assertNull("State not transferred", caches[2].get(test, "name"));
 60   
 61    // Make 2 the buddy of 0
 62  2 caches[1].stop();
 63  2 caches[1] = null;
 64   
 65  2 TestingUtil.sleepThread(getSleepTimeout());
 66   
 67  2 assertEquals("State transferred", "Joe", caches[2].get(test, "name"));
 68    }
 69    finally
 70    {
 71  2 cleanup(caches);
 72    }
 73    }
 74   
 75  2 public void testRegionBasedStateTransfer() throws Exception
 76    {
 77   
 78    // TODO: Reinstate once we have proper FLUSH working.
 79    // This test relies on calls to inactive regions being queued and re-run
 80    // when the region is activated. After discussions with Brian, the queueing
 81    // was removed, presuming FLUSH will fix this. Need to test with FLUSH.
 82    // - Manik Surtani (16 Oct 2006)
 83    /*
 84    CacheImpl[] caches = new CacheImpl[3];
 85   
 86    try
 87    {
 88    caches[0] = createCache(1, "TEST", false, false);
 89    caches[1] = createCache(1, "TEST", false, false);
 90    caches[2] = createCache(1, "TEST", false, false);
 91    caches[0].getConfiguration().setInactiveOnStartup(true);
 92    caches[1].getConfiguration().setInactiveOnStartup(true);
 93    caches[2].getConfiguration().setInactiveOnStartup(true);
 94    caches[0].getConfiguration().setUseRegionBasedMarshalling(true);
 95    caches[1].getConfiguration().setUseRegionBasedMarshalling(true);
 96    caches[2].getConfiguration().setUseRegionBasedMarshalling(true);
 97    caches[0].start();
 98    caches[1].start();
 99    caches[2].start();
 100   
 101    TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
 102    TestingUtil.sleepThread(getSleepTimeout());
 103   
 104    caches[0].activateRegion("/a");
 105    caches[1].activateRegion("/a");
 106    caches[2].activateRegion("/a");
 107   
 108    caches[0].activateRegion("/d");
 109    caches[1].activateRegion("/d");
 110   
 111    Fqn mainA = Fqn.fromString("/a/b/c");
 112    caches[0].put(mainA, "name", "Joe");
 113   
 114    Fqn mainD = Fqn.fromString("/d/e/f");
 115    caches[0].put(mainD, "name", "Joe");
 116   
 117    Fqn group = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
 118    BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()));
 119    Fqn testA = new Fqn(group, mainA);
 120    assertEquals("/a replicated", "Joe", caches[1].get(testA, "name"));
 121    assertNull("No backup of /a", caches[2].get(testA, "name"));
 122   
 123    Fqn testD = new Fqn(group, mainD);
 124    assertEquals("/d replicated", "Joe", caches[1].get(testD, "name"));
 125    assertNull("No backup of /d", caches[2].get(testD, "name"));
 126   
 127    // Make 2 the buddy of 0
 128    caches[1].stop();
 129    caches[1] = null;
 130   
 131    TestingUtil.sleepThread(getSleepTimeout());
 132   
 133    assertEquals("/a state transferred", "Joe", caches[2].get(testA, "name"));
 134    assertNull("/d state not transferred", caches[2].get(testD, "name"));
 135    }
 136    finally
 137    {
 138    cleanup(caches);
 139    }
 140    */
 141    }
 142   
 143  2 public void testPersistentStateTransfer() throws Exception
 144    {
 145  2 String tmpLoc = System.getProperty("java.io.tmpdir", "/tmp");
 146  2 tmpLoc += File.separator + "BuddyReplicationTestsBase-";
 147  2 String tmpLoc0 = tmpLoc + 0;
 148  2 String tmpLoc1 = tmpLoc + 1;
 149  2 CacheImpl[] caches = new CacheImpl[2];
 150   
 151  2 try
 152    {
 153  2 caches[0] = createCacheWithCacheLoader(tmpLoc0, false, false, false, true, false);
 154  2 caches[0].getConfiguration().setFetchInMemoryState(false);
 155   
 156  2 caches[0].start();
 157   
 158  2 Fqn main = Fqn.fromString("/a/b/c");
 159  2 caches[0].put(main, "name", "Joe");
 160   
 161  2 caches[1] = createCacheWithCacheLoader(tmpLoc1, false, false, false, true, false);
 162  2 caches[1].getConfiguration().setFetchInMemoryState(false);
 163   
 164  2 caches[1].start();
 165   
 166  2 TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT);
 167  2 TestingUtil.sleepThread(getSleepTimeout());
 168   
 169  2 Fqn group = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
 170    BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()));
 171  2 Fqn test = new Fqn(group, main);
 172   
 173  2 assertFalse("/a/b/c shld not be bin memory", caches[1].exists(test));
 174  2 assertNotNull("/a/b/c shld be in CL", caches[1].getCacheLoader().get(test));
 175  2 assertEquals("/a/b/c shld in cache loader", "Joe", caches[1].get(test, "name"));
 176    }
 177    finally
 178    {
 179  2 cleanup(caches);
 180    }
 181    }
 182    }