Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 206   Methods: 7
NCLOC: 110   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BuddyReplicationWithCacheLoaderTest.java 100% 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.loader.CacheLoader;
 12    import org.jboss.cache.misc.TestingUtil;
 13   
 14    import java.util.Map;
 15   
 16    /**
 17    * Tests use of the data gravitator alongside other cache loaders as well as data gravitator options such as removeOnFind.
 18    *
 19    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 20    */
 21    public class BuddyReplicationWithCacheLoaderTest extends BuddyReplicationTestsBase
 22    {
 23   
 24    protected Fqn fqn = Fqn.fromString("/test/br/four/level");
 25    protected String key = "key";
 26    protected String value = "value";
 27    protected boolean passivation = false;
 28   
 29   
 30  8 private CacheLoader[] getLoaders(CacheImpl[] caches)
 31    {
 32  8 CacheLoader[] retVal = new CacheLoader[caches.length];
 33   
 34  8 for (int i = 0; i < retVal.length; i++)
 35    {
 36  24 retVal[i] = caches[i].getCacheLoaderManager().getCacheLoader();
 37    }
 38   
 39  8 return retVal;
 40    }
 41   
 42  2 public void testWithDataGravitationDefault() throws Exception
 43    {
 44  2 dataGravitationDefaultTest(true);
 45    }
 46   
 47  2 public void testWithDataGravitationDefaultNoAuto() throws Exception
 48    {
 49  2 dataGravitationDefaultTest(false);
 50    }
 51   
 52  4 private void dataGravitationDefaultTest(boolean autoGravitate)
 53    throws Exception
 54    {
 55   
 56    // create 3 caches
 57  4 caches = createCachesWithCacheLoader(3, autoGravitate, true, passivation);
 58   
 59  4 TestingUtil.sleepThread(1000);
 60   
 61  4 CacheLoader[] loaders = getLoaders(caches);
 62   
 63    // cleanup
 64  12 for (int i = 0; i < 3; i++) loaders[i].remove(Fqn.ROOT);
 65   
 66  12 for (int i = 0; i < 3; i++) System.out.println(i + ": " + loaders[i].get(fqn));
 67   
 68    // put stuff in cache0
 69  4 caches[0].put(fqn, key, value);
 70   
 71    // make sure there are no locks.
 72  4 assertNoLocks(caches);
 73  12 for (int i = 0; i < 3; i++) System.out.println(i + ": " + loaders[i].get(fqn));
 74   
 75  4 dumpCacheContents(caches);
 76   
 77    // request data from cache2
 78  4 if (!autoGravitate)
 79  2 caches[2].getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
 80  4 assertEquals(value, caches[2].get(fqn, key));
 81  4 assertNoLocks(caches);
 82   
 83  12 for (int i = 0; i < 3; i++) System.out.println(i + ": " + loaders[i].get(fqn));
 84   
 85  4 dumpCacheContents(caches);
 86   
 87    // test that data does not exist in cache0
 88  4 assertTrue("should not exist in cache0", !caches[0].exists(fqn));
 89   
 90    // test that data does not exist in cache1
 91  4 assertTrue("should not exist in cache1", !caches[1].exists(fqn));
 92   
 93    // test that data does exist in cache2
 94  4 assertTrue("should exist in cache2", caches[2].exists(fqn));
 95   
 96    // test that data does not exist in loader0
 97  4 assertTrue("should not exist in loader0", !loaders[0].exists(fqn));
 98   
 99    // test that data does not exist in loader1
 100  4 assertTrue("should not exist in loader1", !loaders[1].exists(fqn));
 101   
 102    // test that data does exist in loader2
 103  4 assertTrue("should exist in loader2", passivation ? !loaders[2].exists(fqn) : loaders[2].exists(fqn));
 104   
 105  4 Fqn b1 = new Fqn(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())), fqn.peekElements());
 106  4 Fqn b2 = new Fqn(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(caches[2].getLocalAddress())), fqn.peekElements());
 107   
 108    // test that bkup does exist in cache0
 109  4 assertTrue("should not exist in cache0", !caches[0].exists(b1));
 110  4 assertTrue("should exist in cache0", caches[0].exists(b2));
 111   
 112    // test that bkup does not exist in cache1
 113  4 assertTrue("should not exist in cache1", !caches[1].exists(b1));
 114  4 assertTrue("should not exist in cache1", !caches[1].exists(b2));
 115   
 116    // test that bkup does not exist in cache2
 117  4 assertTrue("should not exist in cache2", !caches[2].exists(b1));
 118  4 assertTrue("should not exist in cache2", !caches[2].exists(b2));
 119   
 120    // test that bkup does exist in loader0
 121  4 assertTrue("should not exist in loader0", !loaders[0].exists(b1));
 122  4 assertTrue("should exist in loader0", passivation ? !loaders[0].exists(b2) : loaders[0].exists(b2));
 123   
 124    // test that bkup does not exist in loader1
 125  4 assertTrue("should not exist in loaders1", !loaders[1].exists(b1));
 126  4 assertTrue("should not exist in loaders1", !loaders[1].exists(b2));
 127   
 128    // test that bkup does not exist in loader2
 129  4 assertTrue("should not exist in loaders2", !loaders[2].exists(b1));
 130  4 assertTrue("should not exist in loaders2", !loaders[2].exists(b2));
 131    }
 132   
 133  2 public void testWithDataGravitationEviction() throws Exception
 134    {
 135  2 dataGravitationEvictionTest(true);
 136    }
 137   
 138  2 public void testWithDataGravitationEvictionNoAuto() throws Exception
 139    {
 140  2 dataGravitationEvictionTest(false);
 141    }
 142   
 143  4 private void dataGravitationEvictionTest(boolean autoGravitate)
 144    throws Exception
 145    {
 146    // create 3 caches
 147  4 caches = createCachesWithCacheLoader(3, autoGravitate, false, passivation);
 148  4 CacheLoader[] loaders = getLoaders(caches);
 149  4 Fqn b1 = BuddyManager.getBackupFqn(caches[0].getLocalAddress(), fqn);
 150  4 Fqn b2 = BuddyManager.getBackupFqn(caches[2].getLocalAddress(), fqn);
 151    // put stuff in cache0
 152  4 caches[0].put(fqn, key, value);
 153   
 154  4 Map m = loaders[1].get(b1);
 155  4 System.out.println("From loader: " + m);
 156   
 157  4 System.out.println("*** About do cause a gravitation event ... ");
 158    // request data from cache2
 159  4 if (!autoGravitate)
 160  2 caches[2].getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
 161  4 assertEquals(value, caches[2].get(fqn, key));
 162   
 163    // test that data does not exist in cache0
 164  4 assertTrue("should not exist in cache0", !caches[0].exists(fqn));
 165   
 166    // test that data does not exist in cache1
 167  4 assertTrue("should not exist in cache1", !caches[1].exists(fqn));
 168   
 169    // test that data does exist in cache2
 170  4 assertTrue("should exist in cache2", caches[2].exists(fqn));
 171   
 172    // test that data does exist in loader0
 173  4 assertTrue("should exist in loader0", loaders[0].exists(fqn));
 174   
 175    // test that data does not exist in loader1
 176  4 assertTrue("should not exist in loader1", !loaders[1].exists(fqn));
 177   
 178    // test that data does exist in loader2
 179  4 assertTrue("should exist in loader2", passivation ? !loaders[2].exists(fqn) : loaders[2].exists(fqn));
 180   
 181    // test that bkup does exist in cache0
 182  4 assertTrue("should not exist in cache0", !caches[0].exists(b1));
 183  4 assertTrue("should exist in cache0", caches[0].exists(b2));
 184   
 185    // test that bkup does not exist in cache1
 186  4 assertTrue("should not exist in cache1", !caches[1].exists(b1));
 187  4 assertTrue("should not exist in cache1", !caches[1].exists(b2));
 188   
 189    // test that bkup does not exist in cache2
 190  4 assertTrue("should not exist in cache2", !caches[2].exists(b1));
 191  4 assertTrue("should not exist in cache2", !caches[2].exists(b2));
 192   
 193    // test that bkup does exist in loader0
 194  4 assertTrue("should not exist in loader0", !loaders[0].exists(b1));
 195  4 assertTrue("should exist in loader0", passivation ? !loaders[0].exists(b2) : loaders[0].exists(b2));
 196   
 197    // test that bkup does not exist in loader1
 198  4 assertTrue("should exist in loaders1", loaders[1].exists(b1));
 199  4 assertTrue("should not exist in loaders1", !loaders[1].exists(b2));
 200   
 201    // test that bkup does not exist in loader2
 202  4 assertTrue("should not exist in loaders2", !loaders[2].exists(b1));
 203  4 assertTrue("should not exist in loaders2", !loaders[2].exists(b2));
 204    }
 205   
 206    }