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