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.misc.TestingUtil; 12 13 import java.io.File ; 14 15 20 public class BuddyAssignmentStateTransferTest extends BuddyReplicationTestsBase 21 { 22 23 protected int timeout = 10000; 25 protected int getSleepTimeout() 26 { 27 return timeout; 28 } 29 30 public void testNonRegionBasedStateTransfer() throws Exception 31 { 32 CacheImpl[] caches = new CacheImpl[2]; 33 try 34 { 35 caches[0] = createCache(1, "TEST", false, true); 36 37 Fqn main = Fqn.fromString("/a/b/c"); 38 caches[0].put(main, "name", "Joe"); 39 40 caches[1] = createCache(1, "TEST", false, true); 41 42 TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT); 43 TestingUtil.sleepThread(getSleepTimeout()); 44 45 Fqn test = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, 46 BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())); 47 test = new Fqn(test, main); 48 49 assertEquals("State transferred", "Joe", caches[1].get(test, "name")); 50 51 CacheImpl[] old = caches; 52 caches = new CacheImpl[3]; 53 System.arraycopy(old, 0, caches, 0, old.length); 54 caches[2] = createCache(1, "TEST", false, true); 55 56 TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT); 57 TestingUtil.sleepThread(getSleepTimeout()); 58 59 assertNull("State not transferred", caches[2].get(test, "name")); 60 61 caches[1].stop(); 63 caches[1] = null; 64 65 TestingUtil.sleepThread(getSleepTimeout()); 66 67 assertEquals("State transferred", "Joe", caches[2].get(test, "name")); 68 } 69 finally 70 { 71 cleanup(caches); 72 } 73 } 74 75 public void testRegionBasedStateTransfer() throws Exception 76 { 77 78 141 } 142 143 public void testPersistentStateTransfer() throws Exception 144 { 145 String tmpLoc = System.getProperty("java.io.tmpdir", "/tmp"); 146 tmpLoc += File.separator + "BuddyReplicationTestsBase-"; 147 String tmpLoc0 = tmpLoc + 0; 148 String tmpLoc1 = tmpLoc + 1; 149 CacheImpl[] caches = new CacheImpl[2]; 150 151 try 152 { 153 caches[0] = createCacheWithCacheLoader(tmpLoc0, false, false, false, true, false); 154 caches[0].getConfiguration().setFetchInMemoryState(false); 155 156 caches[0].start(); 157 158 Fqn main = Fqn.fromString("/a/b/c"); 159 caches[0].put(main, "name", "Joe"); 160 161 caches[1] = createCacheWithCacheLoader(tmpLoc1, false, false, false, true, false); 162 caches[1].getConfiguration().setFetchInMemoryState(false); 163 164 caches[1].start(); 165 166 TestingUtil.blockUntilViewsReceived(caches, VIEW_BLOCK_TIMEOUT); 167 TestingUtil.sleepThread(getSleepTimeout()); 168 169 Fqn group = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, 170 BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress())); 171 Fqn test = new Fqn(group, main); 172 173 assertFalse("/a/b/c not in memory", caches[1].exists(test)); 174 assertEquals("/a/b/c in cache loader", "Joe", caches[1].get(test, "name")); 175 } 176 finally 177 { 178 cleanup(caches); 179 } 180 } 181 } 182 | Popular Tags |