1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.buddyreplication; |
8 |
| |
9 |
| import org.apache.commons.logging.Log; |
10 |
| import org.apache.commons.logging.LogFactory; |
11 |
| import org.jboss.cache.CacheImpl; |
12 |
| import org.jboss.cache.misc.TestingUtil; |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| public class BuddyReplicationContentTest extends BuddyReplicationTestsBase |
20 |
| { |
21 |
| private String key = "key"; |
22 |
| private String value = "value"; |
23 |
| private CacheImpl[] caches; |
24 |
| private Log log = LogFactory.getLog(BuddyGroupAssignmentTest.class); |
25 |
| |
26 |
| |
27 |
18
| private void assertNoStaleLocks(CacheImpl[] caches)
|
28 |
| { |
29 |
54
| for (CacheImpl cache : caches) assertNoStaleLocks(cache);
|
30 |
| } |
31 |
| |
32 |
54
| private void assertNoStaleLocks(CacheImpl cache)
|
33 |
| { |
34 |
54
| assertEquals("Number of locks in cache instance " + cache.toString(true) + " should be 0", 0, cache.getNumberOfLocksHeld());
|
35 |
| } |
36 |
| |
37 |
5
| protected void setUp() throws Exception
|
38 |
| { |
39 |
5
| log.debug("Starting setUp()");
|
40 |
5
| super.setUp();
|
41 |
5
| log.debug("Finishing setUp()");
|
42 |
| } |
43 |
| |
44 |
5
| protected void tearDown() throws Exception
|
45 |
| { |
46 |
5
| super.tearDown();
|
47 |
5
| log.debug("Starting tearDown()");
|
48 |
5
| cleanup(caches);
|
49 |
5
| log.debug("Finishing tearDown()");
|
50 |
| } |
51 |
| |
52 |
1
| public void testSimplePut() throws Exception
|
53 |
| { |
54 |
1
| log.debug("Running testSimplePut");
|
55 |
1
| caches = createCaches(3, false);
|
56 |
| |
57 |
1
| String fqn = "/test";
|
58 |
1
| String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()) + fqn;
|
59 |
| |
60 |
1
| assertNoStaleLocks(caches);
|
61 |
| |
62 |
| |
63 |
1
| caches[0].put(fqn, key, value);
|
64 |
| |
65 |
1
| assertNoStaleLocks(caches);
|
66 |
| |
67 |
| |
68 |
1
| assertEquals(value, caches[0].get(fqn, key));
|
69 |
1
| assertNull("Should be null", caches[1].get(fqn, key));
|
70 |
1
| assertNull("Should be null", caches[2].get(fqn, key));
|
71 |
| |
72 |
| |
73 |
| |
74 |
1
| assertEquals("Buddy should have data in backup tree", value, caches[1].get(backupFqn, key));
|
75 |
1
| assertNull("Should be null", caches[2].get(backupFqn, key));
|
76 |
| |
77 |
1
| assertNoStaleLocks(caches);
|
78 |
| } |
79 |
| |
80 |
1
| public void testPutAndRemove() throws Exception
|
81 |
| { |
82 |
1
| log.debug("Running testPutAndRemove");
|
83 |
1
| caches = createCaches(3, false);
|
84 |
| |
85 |
1
| String fqn = "/test";
|
86 |
1
| String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()) + fqn;
|
87 |
| |
88 |
1
| assertNoStaleLocks(caches);
|
89 |
| |
90 |
| |
91 |
1
| caches[0].put(fqn, key, value);
|
92 |
| |
93 |
1
| assertNoStaleLocks(caches);
|
94 |
| |
95 |
| |
96 |
1
| assertEquals(value, caches[0].get(fqn, key));
|
97 |
1
| assertNull("Should be null", caches[1].get(fqn, key));
|
98 |
1
| assertNull("Should be null", caches[2].get(fqn, key));
|
99 |
| |
100 |
| |
101 |
| |
102 |
1
| assertEquals("Buddy should have data in backup tree", value, caches[1].get(backupFqn, key));
|
103 |
1
| assertNull("Should be null", caches[2].get(backupFqn, key));
|
104 |
| |
105 |
1
| assertNoStaleLocks(caches);
|
106 |
| |
107 |
| |
108 |
1
| caches[0].remove(fqn);
|
109 |
1
| assertNoStaleLocks(caches);
|
110 |
| |
111 |
| |
112 |
1
| assertNull("Should be null", caches[0].get(fqn, key));
|
113 |
1
| assertNull("Should be null", caches[1].get(fqn, key));
|
114 |
1
| assertNull("Should be null", caches[2].get(fqn, key));
|
115 |
| |
116 |
| |
117 |
1
| assertNull("Should be null", caches[0].get(backupFqn, key));
|
118 |
1
| assertNull("Should be null", caches[1].get(backupFqn, key));
|
119 |
1
| assertNull("Should be null", caches[2].get(backupFqn, key));
|
120 |
| |
121 |
1
| assertNoStaleLocks(caches);
|
122 |
| } |
123 |
| |
124 |
1
| public void testPutAndRemove2() throws Exception
|
125 |
| { |
126 |
1
| log.debug("Running testPutAndRemove2");
|
127 |
1
| caches = createCaches(2, 4, false);
|
128 |
| |
129 |
1
| String fqn = "/test";
|
130 |
1
| String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches[0].getLocalAddress()) + fqn;
|
131 |
| |
132 |
| |
133 |
1
| assertNoStaleLocks(caches);
|
134 |
| |
135 |
1
| caches[0].put(fqn, key, value);
|
136 |
| |
137 |
1
| assertNoStaleLocks(caches);
|
138 |
| |
139 |
| |
140 |
1
| assertEquals(value, caches[0].get(fqn, key));
|
141 |
1
| assertNull("Should be null", caches[1].get(fqn, key));
|
142 |
1
| assertNull("Should be null", caches[2].get(fqn, key));
|
143 |
1
| assertNull("Should be null", caches[3].get(fqn, key));
|
144 |
| |
145 |
| |
146 |
1
| assertEquals("Buddy should have data in backup tree", value, caches[1].get(backupFqn, key));
|
147 |
1
| assertEquals("Buddy should have data in backup tree", value, caches[2].get(backupFqn, key));
|
148 |
1
| assertNull("Should be null", caches[3].get(backupFqn, key));
|
149 |
| |
150 |
1
| assertNoStaleLocks(caches);
|
151 |
| |
152 |
| |
153 |
1
| caches[0].remove(fqn);
|
154 |
1
| assertNoStaleLocks(caches);
|
155 |
| |
156 |
1
| assertNull("Should be null", caches[0].get(fqn, key));
|
157 |
1
| assertNull("Should be null", caches[1].get(fqn, key));
|
158 |
1
| assertNull("Should be null", caches[2].get(fqn, key));
|
159 |
1
| assertNull("Should be null", caches[3].get(fqn, key));
|
160 |
| |
161 |
| |
162 |
1
| assertNull("Should be null", caches[0].get(backupFqn, key));
|
163 |
1
| assertNull("Should be null", caches[1].get(backupFqn, key));
|
164 |
1
| assertNull("Should be null", caches[2].get(backupFqn, key));
|
165 |
1
| assertNull("Should be null", caches[3].get(backupFqn, key));
|
166 |
| |
167 |
1
| assertNoStaleLocks(caches);
|
168 |
| } |
169 |
| |
170 |
1
| public void testBuddyJoin() throws Exception
|
171 |
| { |
172 |
1
| log.debug("Running testBuddyJoin");
|
173 |
1
| caches = createCaches(2, false);
|
174 |
1
| CacheImpl cache2 = null;
|
175 |
| |
176 |
1
| try
|
177 |
| { |
178 |
1
| String fqn = "/test";
|
179 |
1
| String backupFqn = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches[1].getLocalAddress()) + fqn;
|
180 |
| |
181 |
1
| assertNoStaleLocks(caches);
|
182 |
| |
183 |
| |
184 |
1
| caches[1].put(fqn, key, value);
|
185 |
| |
186 |
1
| assertNoStaleLocks(caches);
|
187 |
| |
188 |
| |
189 |
1
| assertEquals(value, caches[1].get(fqn, key));
|
190 |
1
| assertNull("Should be null", caches[0].get(fqn, key));
|
191 |
| |
192 |
| |
193 |
1
| assertEquals("Buddy should have data in backup tree", value, caches[0].get(backupFqn, key));
|
194 |
| |
195 |
1
| assertNoStaleLocks(caches);
|
196 |
| |
197 |
| |
198 |
1
| cache2 = createCache(1, null);
|
199 |
| |
200 |
| |
201 |
1
| TestingUtil.sleepThread(500);
|
202 |
| |
203 |
| |
204 |
1
| assertIsBuddy(caches[1], cache2, true);
|
205 |
| |
206 |
1
| assertIsBuddy(caches[0], caches[1], true);
|
207 |
| |
208 |
1
| assertIsBuddy(cache2, caches[0], true);
|
209 |
| |
210 |
| |
211 |
1
| assertNull("This backup data should have been removed", caches[0].get(backupFqn, key));
|
212 |
| |
213 |
| |
214 |
1
| assertEquals("Backup state should have been transferred to this new cache instance", value, cache2.get(backupFqn, key));
|
215 |
| |
216 |
1
| caches[1].remove(fqn);
|
217 |
1
| assertNoStaleLocks(caches);
|
218 |
| |
219 |
| |
220 |
1
| assertNull("Should be null", caches[0].get(fqn, key));
|
221 |
1
| assertNull("Should be null", caches[1].get(fqn, key));
|
222 |
1
| assertNull("Should be null", cache2.get(fqn, key));
|
223 |
| |
224 |
| |
225 |
1
| assertNull("Should be null", caches[0].get(backupFqn, key));
|
226 |
1
| assertNull("Should be null", caches[1].get(backupFqn, key));
|
227 |
1
| assertNull("Should be null", cache2.get(backupFqn, key));
|
228 |
| |
229 |
1
| assertNoStaleLocks(caches);
|
230 |
| |
231 |
| } |
232 |
| finally |
233 |
| { |
234 |
1
| if (cache2 != null) cache2.stop();
|
235 |
| } |
236 |
| } |
237 |
| |
238 |
1
| public void testCompleteStateSurvival() throws Exception
|
239 |
| { |
240 |
1
| log.debug("Running testCompleteStateSurvival");
|
241 |
1
| caches = null;
|
242 |
| |
243 |
1
| caches = createCaches(3, false, true);
|
244 |
1
| caches[0].put("/0", "key", "value");
|
245 |
1
| caches[1].put("/1", "key", "value");
|
246 |
1
| caches[2].put("/2", "key", "value");
|
247 |
| |
248 |
1
| TestingUtil.sleepThread(getSleepTimeout());
|
249 |
| |
250 |
1
| caches[2].stop();
|
251 |
| |
252 |
1
| System.out.println("*** " + caches[0].printLockInfo());
|
253 |
1
| System.out.println("*** " + caches[1].printLockInfo());
|
254 |
1
| System.out.println("*** " + caches[2].printLockInfo());
|
255 |
| |
256 |
| |
257 |
1
| TestingUtil.sleepThread(getSleepTimeout());
|
258 |
| |
259 |
1
| assertEquals("value", caches[0].get("/2", "key"));
|
260 |
| |
261 |
1
| TestingUtil.sleepThread(getSleepTimeout());
|
262 |
| |
263 |
1
| caches[1].stop();
|
264 |
| |
265 |
| |
266 |
| |
267 |
| |
268 |
1
| assertEquals("value", caches[0].get("/0", "key"));
|
269 |
1
| assertEquals("value", caches[1].get("/1", "key"));
|
270 |
1
| assertEquals("value", caches[2].get("/2", "key"));
|
271 |
| } |
272 |
| } |