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