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