1 7 8 package org.jboss.cache.statetransfer; 9 10 import org.jboss.cache.CacheSPI; 11 import org.jboss.cache.Fqn; 12 import org.jboss.cache.Node; 13 import org.jboss.cache.buddyreplication.BuddyManager; 14 import org.jboss.cache.config.BuddyReplicationConfig; 15 import org.jboss.cache.factories.XmlConfigurationParser; 16 import org.jboss.cache.misc.TestingUtil; 17 import org.w3c.dom.Document ; 18 import org.w3c.dom.Element ; 19 20 import javax.xml.parsers.DocumentBuilder ; 21 import javax.xml.parsers.DocumentBuilderFactory ; 22 23 29 public class StateTransfer200Test extends VersionedTestBase 30 { 31 32 protected String getReplicationVersion() 33 { 34 return "2.0.0.GA"; 35 } 36 37 public void testBuddyBackupExclusion() throws Exception 38 { 39 CacheSPI cache1 = createCache("cache1", false, false, false, false, false); 40 41 42 cache1.getConfiguration().setBuddyReplicationConfig(getBuddyConfig()); 43 44 cache1.start(); 45 46 Fqn backup = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, "test"); 47 cache1.put(backup, "name", JOE); 48 cache1.put(A_B, "age", TWENTY); 49 50 CacheSPI cache2 = createCache("cache2", false, false, false); 51 52 TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000); 54 55 assertNull("_buddy_backup_ not transferred", cache2.get(backup, "test")); 56 assertEquals("Correct age for /a/b", TWENTY, cache2.get(A_B, "age")); 57 } 58 59 public void testBuddyIntegration() throws Exception 60 { 61 CacheSPI cache1 = createCache("cache1", false, false, false, false, false); 62 63 cache1.getConfiguration().setBuddyReplicationConfig(getBuddyConfig()); 64 65 cache1.start(); 66 67 CacheSPI cache2 = createCache("cache2", false, false, false); 68 69 TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000); 71 72 Fqn backup = Fqn.fromString(BuddyManager.BUDDY_BACKUP_SUBTREE); 73 backup = new Fqn(backup, "a"); 74 cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); 75 cache1.put(backup, null); 76 77 Node target = cache1.peek(backup); 78 79 assertNotNull("Data Node should not be null", target); 80 81 Fqn abc = Fqn.fromString("/a/b/c"); 82 cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); 83 cache2.put(abc, "name", JOE); 84 cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); 85 cache2.put(A_D, "name", JANE); 86 87 Object [] sources = cache1.getMembers().toArray(); 88 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 89 Fqn a = Fqn.fromString("/a"); 90 cache1.getStateTransferManager().loadState(a, target, sources, cl); 91 92 Fqn test = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, abc); 93 assertEquals("/a/b/c state integrated in backup region", JOE, cache1.get(test, "name")); 94 95 test = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, A_D); 96 assertEquals("/a/d state integrated in backup region", JANE, cache1.get(test, "name")); 97 } 98 99 public void testCacheLoaderFailure() throws Exception 100 { 101 CacheSPI cache1 = createCache("cache1", false, false, "org.jboss.cache.statetransfer.CorruptedFileCacheLoader", false, true); 102 103 cache1.put(A_B, "name", JOE); 104 cache1.put(A_B, "age", TWENTY); 105 cache1.put(A_C, "name", BOB); 106 cache1.put(A_C, "age", FORTY); 107 108 CacheSPI cache2 = null; 109 try 110 { 111 cache2 = createCache("cache2", false, false, true, false, false); 112 cache2.create(); 113 cache2.start(); 114 fail("Should have caused an exception"); 115 } 116 catch (Exception e) 117 { 118 assertNotNull(e); 119 } 120 121 assertFalse("/a/b is not in cache loader ", cache2.getCacheLoaderManager().getCacheLoader().exists(A_B)); 123 } 124 125 126 private BuddyReplicationConfig getBuddyConfig() throws Exception 127 { 128 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 130 DocumentBuilder db = dbf.newDocumentBuilder(); 131 Document doc = db.newDocument(); 132 Element config = doc.createElement("config"); 133 doc.appendChild(config); 134 Element enabled = doc.createElement("buddyReplicationEnabled"); 135 enabled.appendChild(doc.createTextNode("true")); 136 config.appendChild(enabled); 137 Element pool = doc.createElement("buddyPoolName"); 138 pool.appendChild(doc.createTextNode("TEST")); 139 config.appendChild(pool); 140 return XmlConfigurationParser.parseBuddyReplicationConfig(config); 141 } 142 } 143 | Popular Tags |