1 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 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 private CacheLoader[] getLoaders(CacheImpl[] caches) 28 { 29 CacheLoader[] retVal = new CacheLoader[caches.length]; 30 31 for (int i = 0; i < retVal.length; i++) 32 { 33 retVal[i] = caches[i].getCacheLoaderManager().getCacheLoader(); 34 } 35 36 return retVal; 37 } 38 39 public void testWithDataGravitationDefault() throws Exception 40 { 41 42 CacheImpl[] caches = null; 43 try 44 { 45 caches = createCachesWithCacheLoader(3, true, true, passivation); 47 48 TestingUtil.sleepThread(1000); 49 50 CacheLoader[] loaders = getLoaders(caches); 51 52 for (int i = 0; i < 3; i++) loaders[i].remove(Fqn.ROOT); 54 55 for (int i = 0; i < 3; i++) System.out.println(i + ": " + loaders[i].get(fqn)); 56 57 caches[0].put(fqn, key, value); 59 60 assertNoLocks(caches); 62 for (int i = 0; i < 3; i++) System.out.println(i + ": " + loaders[i].get(fqn)); 63 64 dumpCacheContents(caches); 65 66 assertEquals(value, caches[2].get(fqn, key)); 68 assertNoLocks(caches); 69 70 for (int i = 0; i < 3; i++) System.out.println(i + ": " + loaders[i].get(fqn)); 71 72 dumpCacheContents(caches); 73 74 assertTrue("should not exist in cache0", !caches[0].exists(fqn)); 76 77 assertTrue("should not exist in cache1", !caches[1].exists(fqn)); 79 80 assertTrue("should exist in cache2", caches[2].exists(fqn)); 82 83 assertTrue("should not exist in loader0", !loaders[0].exists(fqn)); 85 86 assertTrue("should not exist in loader1", !loaders[1].exists(fqn)); 88 89 assertTrue("should exist in loader2", passivation ? !loaders[2].exists(fqn) : loaders[2].exists(fqn)); 91 92 Fqn b1 = new Fqn(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())), fqn.peekElements()); 93 Fqn b2 = new Fqn(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(caches[2].getLocalAddress())), fqn.peekElements()); 94 95 assertTrue("should not exist in cache0", !caches[0].exists(b1)); 97 assertTrue("should exist in cache0", caches[0].exists(b2)); 98 99 assertTrue("should not exist in cache1", !caches[1].exists(b1)); 101 assertTrue("should not exist in cache1", !caches[1].exists(b2)); 102 103 assertTrue("should not exist in cache2", !caches[2].exists(b1)); 105 assertTrue("should not exist in cache2", !caches[2].exists(b2)); 106 107 assertTrue("should not exist in loader0", !loaders[0].exists(b1)); 109 assertTrue("should exist in loader0", passivation ? !loaders[0].exists(b2) : loaders[0].exists(b2)); 110 111 assertTrue("should not exist in loaders1", !loaders[1].exists(b1)); 113 assertTrue("should not exist in loaders1", !loaders[1].exists(b2)); 114 115 assertTrue("should not exist in loaders2", !loaders[2].exists(b1)); 117 assertTrue("should not exist in loaders2", !loaders[2].exists(b2)); 118 119 120 } 121 finally 122 { 123 cleanup(caches); 124 } 125 126 } 127 128 public void testWithDataGravitationEviction() throws Exception 129 { 130 CacheImpl[] caches = null; 131 try 132 { 133 caches = createCachesWithCacheLoader(3, true, false, passivation); 135 CacheLoader[] loaders = getLoaders(caches); 136 137 caches[0].put(fqn, key, value); 139 140 assertEquals(value, caches[2].get(fqn, key)); 142 143 assertTrue("should not exist in cache0", !caches[0].exists(fqn)); 145 146 assertTrue("should not exist in cache1", !caches[1].exists(fqn)); 148 149 assertTrue("should exist in cache2", caches[2].exists(fqn)); 151 152 assertTrue("should exist in loader0", loaders[0].exists(fqn)); 154 155 assertTrue("should not exist in loader1", !loaders[1].exists(fqn)); 157 158 assertTrue("should exist in loader2", passivation ? !loaders[2].exists(fqn) : loaders[2].exists(fqn)); 160 161 Fqn b1 = new Fqn(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())), fqn.peekElements()); 162 Fqn b2 = new Fqn(new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(caches[2].getLocalAddress())), fqn.peekElements()); 163 164 assertTrue("should not exist in cache0", !caches[0].exists(b1)); 166 assertTrue("should exist in cache0", caches[0].exists(b2)); 167 168 assertTrue("should not exist in cache1", !caches[1].exists(b1)); 170 assertTrue("should not exist in cache1", !caches[1].exists(b2)); 171 172 assertTrue("should not exist in cache2", !caches[2].exists(b1)); 174 assertTrue("should not exist in cache2", !caches[2].exists(b2)); 175 176 assertTrue("should not exist in loader0", !loaders[0].exists(b1)); 178 assertTrue("should exist in loader0", passivation ? !loaders[0].exists(b2) : loaders[0].exists(b2)); 179 180 assertTrue("should exist in loaders1", loaders[1].exists(b1)); 182 assertTrue("should not exist in loaders1", !loaders[1].exists(b2)); 183 184 assertTrue("should not exist in loaders2", !loaders[2].exists(b1)); 186 assertTrue("should not exist in loaders2", !loaders[2].exists(b2)); 187 } 188 finally 189 { 190 cleanup(caches); 191 } 192 } 193 194 } 195 | Popular Tags |