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