1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.invalidation; |
8 |
| |
9 |
| import junit.framework.Assert; |
10 |
| import junit.framework.TestCase; |
11 |
| import org.apache.commons.logging.Log; |
12 |
| import org.apache.commons.logging.LogFactory; |
13 |
| import org.jboss.cache.CacheImpl; |
14 |
| import org.jboss.cache.DefaultCacheFactory; |
15 |
| import org.jboss.cache.Fqn; |
16 |
| import org.jboss.cache.config.CacheLoaderConfig; |
17 |
| import org.jboss.cache.config.Configuration; |
18 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
19 |
| import org.jboss.cache.misc.TestingUtil; |
20 |
| import org.jboss.cache.xml.XmlHelper; |
21 |
| import org.w3c.dom.Element; |
22 |
| |
23 |
| import javax.transaction.RollbackException; |
24 |
| import javax.transaction.Transaction; |
25 |
| import javax.transaction.TransactionManager; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class InvalidationInterceptorTest extends TestCase |
33 |
| { |
34 |
| |
35 |
| private static Log log = LogFactory.getLog(InvalidationInterceptorTest.class); |
36 |
| |
37 |
1
| public void testPessimisticNonTransactional() throws Exception
|
38 |
| { |
39 |
1
| CacheImpl cache1 = createCache(false);
|
40 |
1
| CacheImpl cache2 = createCache(false);
|
41 |
| |
42 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
43 |
1
| cache1.put(fqn, "key", "value");
|
44 |
| |
45 |
| |
46 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
47 |
1
| Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
|
48 |
| |
49 |
1
| log.info("***** Node not replicated, as expected.");
|
50 |
| |
51 |
| |
52 |
1
| cache2.put(fqn, "key", "value");
|
53 |
1
| Assert.assertNull("Should be null", cache1.get(fqn));
|
54 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
55 |
| |
56 |
| |
57 |
1
| cache1.put(fqn, "key2", "value2");
|
58 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
59 |
1
| Assert.assertNull("Should have been invalidated!", cache2.get(fqn));
|
60 |
| |
61 |
| |
62 |
1
| cache1.stop();
|
63 |
1
| cache2.stop();
|
64 |
1
| cache1 = null;
|
65 |
1
| cache2 = null;
|
66 |
| } |
67 |
| |
68 |
1
| public void testUnnecessaryEvictions() throws Exception
|
69 |
| { |
70 |
1
| CacheImpl cache1 = createCache(false);
|
71 |
1
| CacheImpl cache2 = createCache(false);
|
72 |
| |
73 |
1
| Fqn fqn1 = Fqn.fromString("/a/b/c");
|
74 |
1
| Fqn fqn2 = Fqn.fromString("/a/b/d");
|
75 |
| |
76 |
1
| cache1.put(fqn1, "hello", "world");
|
77 |
| |
78 |
1
| assertEquals("world", cache1.get(fqn1, "hello"));
|
79 |
1
| assertNull(cache2.get(fqn1, "hello"));
|
80 |
| |
81 |
1
| cache2.put(fqn2, "hello", "world");
|
82 |
1
| assertEquals("world", cache1.get(fqn1, "hello"));
|
83 |
1
| assertNull(cache2.get(fqn1, "hello"));
|
84 |
1
| assertEquals("world", cache2.get(fqn2, "hello"));
|
85 |
1
| assertNull(cache1.get(fqn2, "hello"));
|
86 |
| |
87 |
1
| cache2.put(fqn1, "hello", "world");
|
88 |
1
| assertEquals("world", cache2.get(fqn1, "hello"));
|
89 |
1
| assertEquals("world", cache2.get(fqn2, "hello"));
|
90 |
1
| assertNull(cache1.get(fqn1, "hello"));
|
91 |
1
| assertNull(cache1.get(fqn2, "hello"));
|
92 |
| |
93 |
1
| cache1.stop();
|
94 |
1
| cache2.stop();
|
95 |
1
| cache1 = null;
|
96 |
1
| cache2 = null;
|
97 |
| |
98 |
| } |
99 |
| |
100 |
| |
101 |
1
| public void testPessimisticNonTransactionalAsync() throws Exception
|
102 |
| { |
103 |
1
| CacheImpl cache1 = createUnstartedCache(false);
|
104 |
1
| CacheImpl cache2 = createUnstartedCache(false);
|
105 |
1
| cache1.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
|
106 |
1
| cache2.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
|
107 |
1
| cache1.start();
|
108 |
1
| cache2.start();
|
109 |
| |
110 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
111 |
1
| cache1.put(fqn, "key", "value");
|
112 |
1
| TestingUtil.sleepThread(500);
|
113 |
| |
114 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
115 |
1
| Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
|
116 |
| |
117 |
1
| log.info("***** Node not replicated, as expected.");
|
118 |
| |
119 |
| |
120 |
1
| cache2.put(fqn, "key", "value");
|
121 |
1
| TestingUtil.sleepThread(500);
|
122 |
1
| Assert.assertNull("Should be null", cache1.get(fqn));
|
123 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
124 |
| |
125 |
| |
126 |
1
| cache1.put(fqn, "key2", "value2");
|
127 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
128 |
1
| TestingUtil.sleepThread(500);
|
129 |
1
| Assert.assertNull("Should have been invalidated!", cache2.get(fqn));
|
130 |
| |
131 |
| |
132 |
1
| cache1.stop();
|
133 |
1
| cache2.stop();
|
134 |
1
| cache1 = null;
|
135 |
1
| cache2 = null;
|
136 |
| } |
137 |
| |
138 |
| |
139 |
1
| public void testPessimisticTransactional() throws Exception
|
140 |
| { |
141 |
1
| CacheImpl cache1 = createCache(false);
|
142 |
1
| CacheImpl cache2 = createCache(false);
|
143 |
| |
144 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
145 |
1
| cache1.put(fqn, "key", "value");
|
146 |
| |
147 |
| |
148 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
149 |
1
| Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
|
150 |
| |
151 |
1
| log.info("***** Node not replicated, as expected.");
|
152 |
| |
153 |
| |
154 |
| |
155 |
1
| TransactionManager txm = cache2.getTransactionManager();
|
156 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
157 |
| |
158 |
1
| txm.begin();
|
159 |
1
| cache2.put(fqn, "key", "value");
|
160 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
161 |
1
| txm.commit();
|
162 |
| |
163 |
1
| Assert.assertNull("Should be null", cache1.get(fqn));
|
164 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
165 |
| |
166 |
| |
167 |
1
| txm = cache1.getTransactionManager();
|
168 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
169 |
| |
170 |
1
| txm.begin();
|
171 |
1
| cache1.put(fqn, "key2", "value2");
|
172 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
173 |
1
| txm.commit();
|
174 |
| |
175 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
176 |
1
| Assert.assertNull("Should have been invalidated!", cache2.get(fqn));
|
177 |
| |
178 |
| |
179 |
1
| txm = cache2.getTransactionManager();
|
180 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
181 |
| |
182 |
1
| txm.begin();
|
183 |
1
| cache2.put(fqn, "key", "value");
|
184 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
185 |
1
| txm.rollback();
|
186 |
| |
187 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
188 |
1
| Assert.assertNull("Should not have committed", cache2.get(fqn));
|
189 |
| |
190 |
| |
191 |
1
| cache1.stop();
|
192 |
1
| cache2.stop();
|
193 |
1
| cache1 = null;
|
194 |
1
| cache2 = null;
|
195 |
| |
196 |
| } |
197 |
| |
198 |
| |
199 |
1
| public void testOptSyncUnableToEvict() throws Exception
|
200 |
| { |
201 |
1
| CacheImpl cache1 = createCache(true);
|
202 |
1
| CacheImpl cache2 = createCache(true);
|
203 |
| |
204 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
205 |
| |
206 |
1
| cache2.put(fqn, "key", "value");
|
207 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
208 |
1
| Assert.assertNull(cache1.get(fqn));
|
209 |
| |
210 |
| |
211 |
1
| TransactionManager mgr1 = cache1.getTransactionManager();
|
212 |
1
| TransactionManager mgr2 = cache2.getTransactionManager();
|
213 |
| |
214 |
1
| mgr1.begin();
|
215 |
1
| cache1.put(fqn, "key2", "value2");
|
216 |
1
| Transaction tx1 = mgr1.suspend();
|
217 |
1
| mgr2.begin();
|
218 |
1
| cache2.put(fqn, "key3", "value3");
|
219 |
1
| Transaction tx2 = mgr2.suspend();
|
220 |
1
| mgr1.resume(tx1);
|
221 |
| |
222 |
1
| try
|
223 |
| { |
224 |
1
| mgr1.commit();
|
225 |
1
| Assert.assertTrue("Ought to have succeeded!", true);
|
226 |
| } |
227 |
| catch (RollbackException roll) |
228 |
| { |
229 |
0
| Assert.assertTrue("Ought to have succeeded!", false);
|
230 |
| } |
231 |
| |
232 |
1
| mgr2.resume(tx2);
|
233 |
1
| try
|
234 |
| { |
235 |
1
| mgr2.commit();
|
236 |
0
| Assert.assertTrue("Ought to have failed!", false);
|
237 |
| } |
238 |
| catch (RollbackException roll) |
239 |
| { |
240 |
1
| Assert.assertTrue("Ought to have failed!", true);
|
241 |
| } |
242 |
| |
243 |
1
| cache1.stop();
|
244 |
1
| cache2.stop();
|
245 |
1
| cache1 = null;
|
246 |
1
| cache2 = null;
|
247 |
| } |
248 |
| |
249 |
1
| public void testPessTxSyncUnableToEvict() throws Exception
|
250 |
| { |
251 |
1
| CacheImpl cache1 = createCache(false);
|
252 |
1
| CacheImpl cache2 = createCache(false);
|
253 |
| |
254 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
255 |
| |
256 |
1
| cache1.put("/a/b", "key", "value");
|
257 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
258 |
1
| Assert.assertNull(cache2.get(fqn));
|
259 |
| |
260 |
| |
261 |
1
| TransactionManager mgr1 = cache1.getTransactionManager();
|
262 |
1
| TransactionManager mgr2 = cache2.getTransactionManager();
|
263 |
| |
264 |
1
| mgr1.begin();
|
265 |
1
| cache1.put(fqn, "key2", "value2");
|
266 |
1
| Transaction tx1 = mgr1.suspend();
|
267 |
1
| mgr2.begin();
|
268 |
1
| cache2.put(fqn, "key3", "value3");
|
269 |
1
| Transaction tx2 = mgr2.suspend();
|
270 |
1
| mgr1.resume(tx1);
|
271 |
| |
272 |
1
| try
|
273 |
| { |
274 |
1
| mgr1.commit();
|
275 |
0
| Assert.assertTrue("Ought to have failed!", false);
|
276 |
| } |
277 |
| catch (RollbackException roll) |
278 |
| { |
279 |
1
| Assert.assertTrue("Ought to have failed!", true);
|
280 |
| } |
281 |
| |
282 |
1
| mgr2.resume(tx2);
|
283 |
1
| try
|
284 |
| { |
285 |
1
| mgr2.commit();
|
286 |
1
| Assert.assertTrue("Ought to have succeeded!", true);
|
287 |
| } |
288 |
| catch (RollbackException roll) |
289 |
| { |
290 |
0
| Assert.assertTrue("Ought to have succeeded!", false);
|
291 |
| } |
292 |
| |
293 |
1
| cache1.stop();
|
294 |
1
| cache2.stop();
|
295 |
1
| cache1 = null;
|
296 |
1
| cache2 = null;
|
297 |
| } |
298 |
| |
299 |
1
| public void testPessTxAsyncUnableToEvict() throws Exception
|
300 |
| { |
301 |
1
| CacheImpl cache1 = createUnstartedCache(false);
|
302 |
1
| CacheImpl cache2 = createUnstartedCache(false);
|
303 |
1
| cache1.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
|
304 |
1
| cache2.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
|
305 |
1
| cache1.start();
|
306 |
1
| cache2.start();
|
307 |
| |
308 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
309 |
| |
310 |
1
| cache1.put("/a/b", "key", "value");
|
311 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
312 |
1
| Assert.assertNull(cache2.get(fqn));
|
313 |
| |
314 |
| |
315 |
1
| TransactionManager mgr1 = cache1.getTransactionManager();
|
316 |
1
| TransactionManager mgr2 = cache2.getTransactionManager();
|
317 |
| |
318 |
1
| mgr1.begin();
|
319 |
1
| cache1.put(fqn, "key2", "value2");
|
320 |
1
| Transaction tx1 = mgr1.suspend();
|
321 |
1
| mgr2.begin();
|
322 |
1
| cache2.put(fqn, "key3", "value3");
|
323 |
1
| Transaction tx2 = mgr2.suspend();
|
324 |
1
| mgr1.resume(tx1);
|
325 |
| |
326 |
1
| try
|
327 |
| { |
328 |
1
| mgr1.commit();
|
329 |
1
| Assert.assertTrue("Ought to have succeeded!", true);
|
330 |
| } |
331 |
| catch (RollbackException roll) |
332 |
| { |
333 |
0
| Assert.assertTrue("Ought to have succeeded!", false);
|
334 |
| } |
335 |
| |
336 |
1
| mgr2.resume(tx2);
|
337 |
1
| try
|
338 |
| { |
339 |
1
| mgr2.commit();
|
340 |
1
| Assert.assertTrue("Ought to have succeeded!", true);
|
341 |
| } |
342 |
| catch (RollbackException roll) |
343 |
| { |
344 |
0
| Assert.assertTrue("Ought to have succeeded!", false);
|
345 |
| } |
346 |
| |
347 |
1
| cache1.stop();
|
348 |
1
| cache2.stop();
|
349 |
1
| cache1 = null;
|
350 |
1
| cache2 = null;
|
351 |
| } |
352 |
| |
353 |
| |
354 |
1
| public void testOptimistic() throws Exception
|
355 |
| { |
356 |
1
| CacheImpl cache1 = createCache(true);
|
357 |
1
| CacheImpl cache2 = createCache(true);
|
358 |
| |
359 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
360 |
1
| cache1.put(fqn, "key", "value");
|
361 |
| |
362 |
| |
363 |
1
| Assert.assertEquals("value", cache1.get(fqn, "key"));
|
364 |
1
| Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
|
365 |
| |
366 |
1
| log.info("***** Node not replicated, as expected.");
|
367 |
| |
368 |
| |
369 |
1
| cache2.put(fqn, "key", "value");
|
370 |
1
| Assert.assertNull("Should be null", cache1.get(fqn));
|
371 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
372 |
| |
373 |
| |
374 |
1
| cache1.put(fqn, "key2", "value2");
|
375 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
376 |
1
| Assert.assertNull("Should have been invalidated!", cache2.get(fqn));
|
377 |
| |
378 |
| |
379 |
1
| TransactionManager txm = cache2.getTransactionManager();
|
380 |
| |
381 |
1
| txm.begin();
|
382 |
1
| cache2.put(fqn, "key", "value");
|
383 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
384 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
385 |
1
| txm.commit();
|
386 |
| |
387 |
1
| Assert.assertNull("Should be null", cache1.get(fqn));
|
388 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
389 |
| |
390 |
| |
391 |
1
| txm = cache1.getTransactionManager();
|
392 |
| |
393 |
1
| txm.begin();
|
394 |
1
| cache1.put(fqn, "key2", "value2");
|
395 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
396 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
397 |
1
| txm.commit();
|
398 |
| |
399 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
400 |
1
| Assert.assertNull("Should have been invalidated!", cache2.get(fqn));
|
401 |
| |
402 |
| |
403 |
1
| txm = cache2.getTransactionManager();
|
404 |
| |
405 |
1
| txm.begin();
|
406 |
1
| cache2.put(fqn, "key", "value");
|
407 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
408 |
1
| Assert.assertEquals("value", cache2.get(fqn, "key"));
|
409 |
1
| txm.rollback();
|
410 |
| |
411 |
1
| Assert.assertEquals("value2", cache1.get(fqn, "key2"));
|
412 |
1
| Assert.assertNull("Should not have committed", cache2.get(fqn));
|
413 |
| |
414 |
| |
415 |
1
| cache1.stop();
|
416 |
1
| cache2.stop();
|
417 |
1
| cache1 = null;
|
418 |
1
| cache2 = null;
|
419 |
| |
420 |
| } |
421 |
| |
422 |
1
| public void testPessimisticNonTransactionalWithCacheLoader() throws Exception
|
423 |
| { |
424 |
1
| CacheImpl[] caches = createCachesWithSharedCL(false);
|
425 |
| |
426 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
427 |
1
| caches[0].put(fqn, "key", "value");
|
428 |
| |
429 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
430 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
431 |
| |
432 |
| |
433 |
1
| caches[1].put(fqn, "key", "value");
|
434 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
435 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
436 |
| |
437 |
| |
438 |
1
| caches[0].put(fqn, "key2", "value2");
|
439 |
1
| Assert.assertEquals("value2", caches[0].get(fqn, "key2"));
|
440 |
1
| Assert.assertEquals("value2", caches[1].get(fqn, "key2"));
|
441 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
442 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
443 |
| |
444 |
| |
445 |
1
| caches[0].remove(fqn);
|
446 |
1
| caches[1].remove(fqn);
|
447 |
1
| caches[0].stop();
|
448 |
1
| caches[1].stop();
|
449 |
1
| caches[0] = null;
|
450 |
1
| caches[1] = null;
|
451 |
| } |
452 |
| |
453 |
1
| public void testPessimisticTransactionalWithCacheLoader() throws Exception
|
454 |
| { |
455 |
1
| CacheImpl[] caches = createCachesWithSharedCL(false);
|
456 |
| |
457 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
458 |
1
| TransactionManager mgr = caches[0].getTransactionManager();
|
459 |
1
| Assert.assertNull("Should be null", caches[0].get(fqn, "key"));
|
460 |
1
| Assert.assertNull("Should be null", caches[1].get(fqn, "key"));
|
461 |
1
| mgr.begin();
|
462 |
1
| caches[0].put(fqn, "key", "value");
|
463 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
464 |
1
| mgr.commit();
|
465 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
466 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
467 |
| |
468 |
1
| mgr.begin();
|
469 |
1
| caches[0].put(fqn, "key2", "value2");
|
470 |
1
| Assert.assertEquals("value2", caches[0].get(fqn, "key2"));
|
471 |
1
| mgr.rollback();
|
472 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
473 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
474 |
1
| Assert.assertNull("Should be null", caches[0].get(fqn, "key2"));
|
475 |
1
| Assert.assertNull("Should be null", caches[1].get(fqn, "key2"));
|
476 |
| |
477 |
| |
478 |
1
| caches[0].remove(fqn);
|
479 |
1
| caches[1].remove(fqn);
|
480 |
1
| caches[0].stop();
|
481 |
1
| caches[1].stop();
|
482 |
1
| caches[0] = null;
|
483 |
1
| caches[1] = null;
|
484 |
| } |
485 |
| |
486 |
1
| public void testOptimisticWithCacheLoader() throws Exception
|
487 |
| { |
488 |
1
| CacheImpl[] caches = createCachesWithSharedCL(true);
|
489 |
| |
490 |
1
| Fqn fqn = Fqn.fromString("/a/b");
|
491 |
1
| TransactionManager mgr = caches[0].getTransactionManager();
|
492 |
1
| Assert.assertNull("Should be null", caches[0].get(fqn, "key"));
|
493 |
1
| Assert.assertNull("Should be null", caches[1].get(fqn, "key"));
|
494 |
1
| mgr.begin();
|
495 |
1
| caches[0].put(fqn, "key", "value");
|
496 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
497 |
1
| Assert.assertNull("Should be null", caches[1].get(fqn, "key"));
|
498 |
1
| mgr.commit();
|
499 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
500 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
501 |
| |
502 |
1
| mgr.begin();
|
503 |
1
| caches[0].put(fqn, "key2", "value2");
|
504 |
1
| Assert.assertEquals("value2", caches[0].get(fqn, "key2"));
|
505 |
1
| Assert.assertNull("Should be null", caches[1].get(fqn, "key2"));
|
506 |
1
| mgr.rollback();
|
507 |
1
| Assert.assertEquals("value", caches[1].get(fqn, "key"));
|
508 |
1
| Assert.assertEquals("value", caches[0].get(fqn, "key"));
|
509 |
1
| Assert.assertNull("Should be null", caches[0].get(fqn, "key2"));
|
510 |
1
| Assert.assertNull("Should be null", caches[1].get(fqn, "key2"));
|
511 |
| |
512 |
| |
513 |
1
| caches[0].remove(fqn);
|
514 |
1
| caches[1].remove(fqn);
|
515 |
1
| caches[0].stop();
|
516 |
1
| caches[1].stop();
|
517 |
1
| caches[0] = null;
|
518 |
1
| caches[1] = null;
|
519 |
| } |
520 |
| |
521 |
1
| public void testInvalidationWithRegionBasedMarshalling() throws Exception
|
522 |
| { |
523 |
1
| doRegionBasedTest(false);
|
524 |
| } |
525 |
| |
526 |
1
| public void testInvalidationWithRegionBasedMarshallingOptimistic() throws Exception
|
527 |
| { |
528 |
1
| doRegionBasedTest(true);
|
529 |
| } |
530 |
| |
531 |
2
| protected void doRegionBasedTest(boolean optimistic) throws Exception
|
532 |
| { |
533 |
2
| CacheImpl[] caches = new CacheImpl[2];
|
534 |
2
| caches[0] = createUnstartedCache(false);
|
535 |
2
| caches[1] = createUnstartedCache(false);
|
536 |
| |
537 |
2
| caches[0].getConfiguration().setUseRegionBasedMarshalling(true);
|
538 |
2
| caches[1].getConfiguration().setUseRegionBasedMarshalling(true);
|
539 |
| |
540 |
2
| if (optimistic)
|
541 |
| { |
542 |
1
| caches[0].getConfiguration().setNodeLockingScheme("OPTIMISTIC");
|
543 |
1
| caches[1].getConfiguration().setNodeLockingScheme("OPTIMISTIC");
|
544 |
| } |
545 |
| |
546 |
2
| caches[0].start();
|
547 |
2
| caches[1].start();
|
548 |
| |
549 |
2
| TestingUtil.blockUntilViewsReceived(caches, 5000);
|
550 |
| |
551 |
2
| Fqn fqn = Fqn.fromString("/a/b");
|
552 |
| |
553 |
2
| assertNull("Should be null", caches[0].get(fqn));
|
554 |
2
| assertNull("Should be null", caches[1].get(fqn));
|
555 |
| |
556 |
2
| caches[0].put(fqn, "key", "value");
|
557 |
2
| assertEquals("expecting value", "value", caches[0].get(fqn, "key"));
|
558 |
2
| assertNull("Should be null", caches[1].get(fqn));
|
559 |
| |
560 |
| |
561 |
2
| caches[1].put(fqn, "key", "value2");
|
562 |
2
| assertEquals("expecting value2", "value2", caches[1].get(fqn, "key"));
|
563 |
2
| assertNull("Should be null", caches[0].get(fqn));
|
564 |
| |
565 |
| |
566 |
2
| caches[0].remove(fqn);
|
567 |
2
| caches[1].remove(fqn);
|
568 |
2
| caches[0].stop();
|
569 |
2
| caches[1].stop();
|
570 |
2
| caches[0] = null;
|
571 |
2
| caches[1] = null;
|
572 |
| } |
573 |
| |
574 |
26
| protected CacheImpl createUnstartedCache(boolean optimistic) throws Exception
|
575 |
| { |
576 |
26
| CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
577 |
26
| cache.getConfiguration().setClusterName("MyCluster");
|
578 |
26
| cache.getConfiguration().setStateRetrievalTimeout(3000);
|
579 |
26
| cache.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
|
580 |
6
| if (optimistic) cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
|
581 |
26
| cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
|
582 |
26
| return cache;
|
583 |
| } |
584 |
| |
585 |
12
| protected CacheImpl createCache(boolean optimistic) throws Exception
|
586 |
| { |
587 |
12
| CacheImpl cache = createUnstartedCache(optimistic);
|
588 |
12
| cache.start();
|
589 |
12
| return cache;
|
590 |
| } |
591 |
| |
592 |
3
| protected CacheImpl[] createCachesWithSharedCL(boolean optimistic) throws Exception
|
593 |
| { |
594 |
3
| CacheImpl[] caches = new CacheImpl[2];
|
595 |
3
| caches[0] = createUnstartedCache(optimistic);
|
596 |
3
| caches[1] = createUnstartedCache(optimistic);
|
597 |
| |
598 |
3
| caches[0].getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
|
599 |
3
| caches[1].getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
|
600 |
| |
601 |
3
| caches[0].start();
|
602 |
3
| caches[1].start();
|
603 |
3
| return caches;
|
604 |
| } |
605 |
| |
606 |
| |
607 |
6
| protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
|
608 |
| { |
609 |
6
| String xml = " <config>\n" +
|
610 |
| " <shared>shared</shared>\n" + |
611 |
| " <passivation>false</passivation>\n" + |
612 |
| " <preload></preload>\n" + |
613 |
| " <cacheloader>\n" + |
614 |
| " <class>org.jboss.cache.loader.DummySharedInMemoryCacheLoader</class>\n" + |
615 |
| " <async>false</async>\n" + |
616 |
| " <fetchPersistentState>false</fetchPersistentState>\n" + |
617 |
| " <ignoreModifications>false</ignoreModifications>\n" + |
618 |
| " </cacheloader>\n" + |
619 |
| " \n" + |
620 |
| " </config>"; |
621 |
6
| Element element = XmlHelper.stringToElement(xml);
|
622 |
6
| return XmlConfigurationParser.parseCacheLoaderConfig(element);
|
623 |
| } |
624 |
| } |