1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.optimistic; |
8 |
| |
9 |
| import org.jboss.cache.CacheImpl; |
10 |
| import org.jboss.cache.GlobalTransaction; |
11 |
| import org.jboss.cache.OptimisticTransactionEntry; |
12 |
| import org.jboss.cache.TransactionTable; |
13 |
| import org.jboss.cache.config.Configuration; |
14 |
| import org.jboss.cache.loader.SamplePojo; |
15 |
| import org.jboss.cache.marshall.MethodCall; |
16 |
| import org.jboss.cache.marshall.MethodCallFactory; |
17 |
| import org.jboss.cache.marshall.MethodDeclarations; |
18 |
| import org.jboss.cache.transaction.DummyTransactionManager; |
19 |
| import org.jgroups.Address; |
20 |
| |
21 |
| import javax.transaction.RollbackException; |
22 |
| import javax.transaction.Transaction; |
23 |
| import java.io.DataInputStream; |
24 |
| import java.io.DataOutputStream; |
25 |
| import java.io.ObjectInput; |
26 |
| import java.io.ObjectOutput; |
27 |
| import java.util.ArrayList; |
28 |
| import java.util.List; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class OptimisticReplicationInterceptorTest extends AbstractOptimisticTestCase |
34 |
| { |
35 |
| private CacheImpl cache; |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
10
| public OptimisticReplicationInterceptorTest(String name)
|
41 |
| { |
42 |
10
| super(name);
|
43 |
| } |
44 |
| |
45 |
10
| protected void setUp() throws Exception
|
46 |
| { |
47 |
10
| super.setUp();
|
48 |
10
| cache = createCache();
|
49 |
| } |
50 |
| |
51 |
10
| protected void tearDown()
|
52 |
| { |
53 |
10
| super.tearDown();
|
54 |
10
| destroyCache(cache);
|
55 |
| } |
56 |
| |
57 |
1
| public void testLocalTransaction() throws Exception
|
58 |
| { |
59 |
1
| MockInterceptor dummy = new MockInterceptor();
|
60 |
1
| dummy.setCache(cache);
|
61 |
| |
62 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
63 |
| |
64 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
65 |
1
| assertNull(mgr.getTransaction());
|
66 |
| |
67 |
1
| mgr.begin();
|
68 |
| |
69 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
70 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
71 |
| |
72 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
73 |
| |
74 |
1
| cache.put("/one/two", "key1", pojo);
|
75 |
| |
76 |
1
| mgr.commit();
|
77 |
| |
78 |
1
| assertNull(mgr.getTransaction());
|
79 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
80 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
81 |
| |
82 |
| |
83 |
| |
84 |
1
| List calls = dummy.getAllCalled();
|
85 |
| |
86 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
|
87 |
1
| assertEquals(MethodDeclarations.commitMethod, calls.get(1));
|
88 |
| } |
89 |
| |
90 |
1
| public void testRollbackTransaction() throws Exception
|
91 |
| { |
92 |
1
| MockInterceptor dummy = new MockInterceptor();
|
93 |
1
| dummy.setCache(cache);
|
94 |
| |
95 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
96 |
| |
97 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
98 |
1
| assertNull(mgr.getTransaction());
|
99 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
100 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
101 |
| |
102 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
103 |
1
| mgr.begin();
|
104 |
1
| cache.put("/one/two", "key1", pojo);
|
105 |
1
| mgr.rollback();
|
106 |
1
| assertNull(mgr.getTransaction());
|
107 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
108 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
109 |
| |
110 |
| |
111 |
| |
112 |
1
| List calls = dummy.getAllCalled();
|
113 |
| |
114 |
1
| assertEquals(1, calls.size());
|
115 |
1
| assertEquals(MethodDeclarations.rollbackMethod, calls.get(0));
|
116 |
| } |
117 |
| |
118 |
1
| public void testRemotePrepareTransaction() throws Exception
|
119 |
| { |
120 |
1
| MockInterceptor dummy = new MockInterceptor();
|
121 |
1
| dummy.setCache(cache);
|
122 |
| |
123 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
124 |
| |
125 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
126 |
| |
127 |
| |
128 |
1
| mgr.begin();
|
129 |
1
| Transaction tx = mgr.getTransaction();
|
130 |
| |
131 |
| |
132 |
1
| cache.getCurrentTransaction(tx);
|
133 |
| |
134 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
135 |
| |
136 |
1
| cache.put("/one/two", "key1", pojo);
|
137 |
| |
138 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
139 |
1
| TransactionTable table = cache.getTransactionTable();
|
140 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
141 |
1
| assertNotNull(mgr.getTransaction());
|
142 |
1
| mgr.commit();
|
143 |
| |
144 |
| |
145 |
1
| GlobalTransaction remoteGtx = new GlobalTransaction();
|
146 |
| |
147 |
1
| remoteGtx.setAddress(new TestAddress());
|
148 |
| |
149 |
1
| MethodCall meth = entry.getModifications().get(0);
|
150 |
| |
151 |
1
| meth.getArgs()[0] = remoteGtx;
|
152 |
| |
153 |
1
| MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
|
154 |
1
| try
|
155 |
| { |
156 |
1
| cache._replicate(prepareMethod);
|
157 |
| } |
158 |
| catch (Throwable t) |
159 |
| { |
160 |
0
| fail();
|
161 |
| } |
162 |
| |
163 |
| |
164 |
1
| assertNull(mgr.getTransaction());
|
165 |
| |
166 |
| |
167 |
1
| assertNotNull(table.get(remoteGtx));
|
168 |
1
| assertNotNull(table.getLocalTransaction(remoteGtx));
|
169 |
| |
170 |
1
| assertEquals(1, table.get(remoteGtx).getModifications().size());
|
171 |
| |
172 |
| |
173 |
1
| OptimisticTransactionEntry opEntry = (OptimisticTransactionEntry) table.get(gtx);
|
174 |
| |
175 |
1
| assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
|
176 |
1
| assertEquals(1, entry.getModifications().size());
|
177 |
1
| List calls = dummy.getAllCalled();
|
178 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));
|
179 |
| |
180 |
| |
181 |
1
| assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
|
182 |
1
| assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
|
183 |
| |
184 |
| } |
185 |
| |
186 |
| |
187 |
1
| public void testRemoteRollbackTransaction() throws Exception
|
188 |
| { |
189 |
1
| MockInterceptor dummy = new MockInterceptor();
|
190 |
1
| dummy.setCache(cache);
|
191 |
| |
192 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
193 |
| |
194 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
195 |
| |
196 |
| |
197 |
1
| mgr.begin();
|
198 |
1
| Transaction tx = mgr.getTransaction();
|
199 |
| |
200 |
| |
201 |
1
| cache.getCurrentTransaction(tx);
|
202 |
| |
203 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
204 |
| |
205 |
1
| cache.put("/one/two", "key1", pojo);
|
206 |
| |
207 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
208 |
1
| TransactionTable table = cache.getTransactionTable();
|
209 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
210 |
1
| assertNotNull(mgr.getTransaction());
|
211 |
1
| mgr.commit();
|
212 |
| |
213 |
| |
214 |
1
| GlobalTransaction remoteGtx = new GlobalTransaction();
|
215 |
| |
216 |
1
| remoteGtx.setAddress(new TestAddress());
|
217 |
| |
218 |
1
| MethodCall meth = entry.getModifications().get(0);
|
219 |
| |
220 |
1
| meth.getArgs()[0] = remoteGtx;
|
221 |
| |
222 |
1
| MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
|
223 |
1
| try
|
224 |
| { |
225 |
1
| cache._replicate(prepareMethod);
|
226 |
| } |
227 |
| catch (Throwable t) |
228 |
| { |
229 |
0
| fail();
|
230 |
| } |
231 |
| |
232 |
| |
233 |
1
| assertNull(mgr.getTransaction());
|
234 |
| |
235 |
| |
236 |
1
| assertNotNull(table.get(remoteGtx));
|
237 |
1
| assertNotNull(table.getLocalTransaction(remoteGtx));
|
238 |
| |
239 |
1
| assertEquals(1, table.get(remoteGtx).getModifications().size());
|
240 |
| |
241 |
| |
242 |
1
| OptimisticTransactionEntry opEntry = (OptimisticTransactionEntry) table.get(gtx);
|
243 |
| |
244 |
1
| assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
|
245 |
1
| assertEquals(1, entry.getModifications().size());
|
246 |
1
| List calls = dummy.getAllCalled();
|
247 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));
|
248 |
| |
249 |
| |
250 |
1
| assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
|
251 |
1
| assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
|
252 |
| |
253 |
| |
254 |
1
| MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, remoteGtx);
|
255 |
1
| try
|
256 |
| { |
257 |
1
| cache._replicate(rollbackMethod);
|
258 |
| } |
259 |
| catch (Throwable t) |
260 |
| { |
261 |
0
| fail();
|
262 |
| } |
263 |
| |
264 |
1
| assertNull(mgr.getTransaction());
|
265 |
1
| assertEquals(MethodDeclarations.rollbackMethod, calls.get(3));
|
266 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
267 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
268 |
| } |
269 |
| |
270 |
| |
271 |
1
| public void testRemoteCommitNoPrepareTransaction() throws Exception
|
272 |
| { |
273 |
1
| MockInterceptor dummy = new MockInterceptor();
|
274 |
1
| dummy.setCache(cache);
|
275 |
| |
276 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
277 |
| |
278 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
279 |
| |
280 |
| |
281 |
1
| mgr.begin();
|
282 |
1
| Transaction tx = mgr.getTransaction();
|
283 |
| |
284 |
| |
285 |
1
| cache.getCurrentTransaction(tx);
|
286 |
| |
287 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
288 |
| |
289 |
1
| cache.put("/one/two", "key1", pojo);
|
290 |
| |
291 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
292 |
1
| TransactionTable table = cache.getTransactionTable();
|
293 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
294 |
1
| assertNotNull(mgr.getTransaction());
|
295 |
1
| mgr.commit();
|
296 |
| |
297 |
| |
298 |
1
| GlobalTransaction remoteGtx = new GlobalTransaction();
|
299 |
| |
300 |
1
| remoteGtx.setAddress(new TestAddress());
|
301 |
| |
302 |
1
| MethodCall meth = entry.getModifications().get(0);
|
303 |
| |
304 |
1
| meth.getArgs()[0] = remoteGtx;
|
305 |
| |
306 |
| |
307 |
1
| List calls = dummy.getAllCalled();
|
308 |
1
| assertEquals(2, calls.size());
|
309 |
| |
310 |
| |
311 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
312 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
313 |
| |
314 |
| |
315 |
1
| MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, remoteGtx);
|
316 |
1
| try
|
317 |
| { |
318 |
1
| cache._replicate(commitMethod);
|
319 |
0
| fail();
|
320 |
| } |
321 |
| catch (Throwable t) |
322 |
| { |
323 |
1
| assertTrue(t instanceof RuntimeException);
|
324 |
| |
325 |
| } |
326 |
| |
327 |
1
| assertNull(mgr.getTransaction());
|
328 |
1
| assertEquals(2, calls.size());
|
329 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
330 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
331 |
| } |
332 |
| |
333 |
| |
334 |
1
| public void testRemoteRollbackNoPrepareTransaction() throws Throwable
|
335 |
| { |
336 |
1
| MockInterceptor dummy = new MockInterceptor();
|
337 |
1
| dummy.setCache(cache);
|
338 |
| |
339 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
340 |
| |
341 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
342 |
| |
343 |
| |
344 |
1
| mgr.begin();
|
345 |
1
| Transaction tx = mgr.getTransaction();
|
346 |
| |
347 |
| |
348 |
1
| cache.getCurrentTransaction(tx);
|
349 |
| |
350 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
351 |
| |
352 |
1
| cache.put("/one/two", "key1", pojo);
|
353 |
| |
354 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
355 |
1
| TransactionTable table = cache.getTransactionTable();
|
356 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
357 |
1
| assertNotNull(mgr.getTransaction());
|
358 |
1
| mgr.commit();
|
359 |
| |
360 |
| |
361 |
1
| GlobalTransaction remoteGtx = new GlobalTransaction();
|
362 |
| |
363 |
1
| remoteGtx.setAddress(new TestAddress());
|
364 |
| |
365 |
1
| MethodCall meth = entry.getModifications().get(0);
|
366 |
| |
367 |
1
| meth.getArgs()[0] = remoteGtx;
|
368 |
| |
369 |
| |
370 |
1
| List calls = dummy.getAllCalled();
|
371 |
1
| assertEquals(2, calls.size());
|
372 |
| |
373 |
| |
374 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
375 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
376 |
| |
377 |
| |
378 |
1
| MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, remoteGtx);
|
379 |
| |
380 |
1
| cache._replicate(rollbackMethod);
|
381 |
1
| assertTrue("Should be handled on the remote end without barfing, in the event of a rollback without a prepare", true);
|
382 |
| |
383 |
| |
384 |
1
| assertNull(mgr.getTransaction());
|
385 |
1
| assertEquals(2, calls.size());
|
386 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
387 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
388 |
| } |
389 |
| |
390 |
| |
391 |
1
| public void testRemoteCommitTransaction() throws Exception
|
392 |
| { |
393 |
1
| MockInterceptor dummy = new MockInterceptor();
|
394 |
1
| dummy.setCache(cache);
|
395 |
| |
396 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
397 |
| |
398 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
399 |
| |
400 |
| |
401 |
1
| mgr.begin();
|
402 |
1
| Transaction tx = mgr.getTransaction();
|
403 |
| |
404 |
| |
405 |
1
| cache.getCurrentTransaction(tx);
|
406 |
| |
407 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
408 |
| |
409 |
1
| cache.put("/one/two", "key1", pojo);
|
410 |
| |
411 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
412 |
1
| TransactionTable table = cache.getTransactionTable();
|
413 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
414 |
1
| assertNotNull(mgr.getTransaction());
|
415 |
1
| mgr.commit();
|
416 |
| |
417 |
| |
418 |
1
| GlobalTransaction remoteGtx = new GlobalTransaction();
|
419 |
| |
420 |
1
| remoteGtx.setAddress(new TestAddress());
|
421 |
| |
422 |
1
| MethodCall meth = entry.getModifications().get(0);
|
423 |
| |
424 |
1
| meth.getArgs()[0] = remoteGtx;
|
425 |
| |
426 |
1
| MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
|
427 |
1
| try
|
428 |
| { |
429 |
1
| cache._replicate(prepareMethod);
|
430 |
| } |
431 |
| catch (Throwable t) |
432 |
| { |
433 |
0
| fail();
|
434 |
| } |
435 |
| |
436 |
| |
437 |
1
| assertNull(mgr.getTransaction());
|
438 |
| |
439 |
| |
440 |
1
| assertNotNull(table.get(remoteGtx));
|
441 |
1
| assertNotNull(table.getLocalTransaction(remoteGtx));
|
442 |
| |
443 |
1
| assertEquals(1, table.get(remoteGtx).getModifications().size());
|
444 |
| |
445 |
| |
446 |
1
| OptimisticTransactionEntry opEntry = (OptimisticTransactionEntry) table.get(gtx);
|
447 |
| |
448 |
1
| assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
|
449 |
1
| assertEquals(1, entry.getModifications().size());
|
450 |
1
| List calls = dummy.getAllCalled();
|
451 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(2));
|
452 |
| |
453 |
| |
454 |
1
| assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
|
455 |
1
| assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
|
456 |
| |
457 |
| |
458 |
1
| MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, remoteGtx);
|
459 |
1
| try
|
460 |
| { |
461 |
1
| cache._replicate(commitMethod);
|
462 |
| } |
463 |
| catch (Throwable t) |
464 |
| { |
465 |
0
| fail();
|
466 |
| } |
467 |
| |
468 |
1
| assertNull(mgr.getTransaction());
|
469 |
1
| assertEquals(MethodDeclarations.commitMethod, calls.get(3));
|
470 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
471 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
472 |
| } |
473 |
| |
474 |
| |
475 |
1
| public void testTwoWayRemoteCacheBroadcast() throws Exception
|
476 |
| { |
477 |
1
| destroyCache(cache);
|
478 |
1
| cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
|
479 |
| |
480 |
1
| MockInterceptor dummy = new MockInterceptor();
|
481 |
1
| dummy.setCache(cache);
|
482 |
| |
483 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
484 |
| |
485 |
1
| CacheImpl cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
|
486 |
1
| MockInterceptor dummy2 = new MockInterceptor();
|
487 |
1
| dummy.setCache(cache2);
|
488 |
| |
489 |
1
| cache2.setInterceptorChain(getAlteredInterceptorChain(dummy2, cache2, true));
|
490 |
| |
491 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
492 |
| |
493 |
| |
494 |
1
| mgr.begin();
|
495 |
1
| Transaction tx = mgr.getTransaction();
|
496 |
| |
497 |
| |
498 |
1
| cache.getCurrentTransaction(tx);
|
499 |
| |
500 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
501 |
| |
502 |
1
| cache.put("/one/two", "key1", pojo);
|
503 |
| |
504 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
505 |
1
| TransactionTable table = cache.getTransactionTable();
|
506 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
507 |
1
| assertNotNull(mgr.getTransaction());
|
508 |
1
| mgr.commit();
|
509 |
| |
510 |
| |
511 |
1
| assertNull(mgr.getTransaction());
|
512 |
| |
513 |
| |
514 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
515 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
516 |
| |
517 |
| |
518 |
1
| assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
|
519 |
1
| assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
|
520 |
| |
521 |
| |
522 |
1
| List calls = dummy.getAllCalled();
|
523 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
|
524 |
1
| assertEquals(MethodDeclarations.commitMethod, calls.get(1));
|
525 |
| |
526 |
1
| List calls2 = dummy2.getAllCalled();
|
527 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls2.get(0));
|
528 |
1
| assertEquals(MethodDeclarations.commitMethod, calls2.get(1));
|
529 |
| |
530 |
1
| destroyCache(cache2);
|
531 |
| } |
532 |
| |
533 |
| |
534 |
1
| public void testFailurePrepareRemoteCacheBroadcast() throws Exception
|
535 |
| { |
536 |
1
| destroyCache(cache);
|
537 |
1
| cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
|
538 |
| |
539 |
1
| MockInterceptor dummy = new MockInterceptor();
|
540 |
1
| dummy.setCache(cache);
|
541 |
| |
542 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
543 |
| |
544 |
1
| CacheImpl cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
|
545 |
1
| MockFailureInterceptor dummy2 = new MockFailureInterceptor();
|
546 |
1
| List failures = new ArrayList();
|
547 |
1
| failures.add(MethodDeclarations.optimisticPrepareMethod);
|
548 |
1
| dummy2.setFailurelist(failures);
|
549 |
1
| dummy.setCache(cache2);
|
550 |
| |
551 |
1
| cache2.setInterceptorChain(getAlteredInterceptorChain(dummy2, cache2, true));
|
552 |
| |
553 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
554 |
| |
555 |
| |
556 |
1
| mgr.begin();
|
557 |
1
| Transaction tx = mgr.getTransaction();
|
558 |
| |
559 |
| |
560 |
1
| cache.getCurrentTransaction(tx);
|
561 |
| |
562 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
563 |
| |
564 |
1
| cache.put("/one/two", "key1", pojo);
|
565 |
| |
566 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
567 |
1
| TransactionTable table = cache.getTransactionTable();
|
568 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
569 |
1
| assertNotNull(mgr.getTransaction());
|
570 |
1
| try
|
571 |
| { |
572 |
1
| mgr.commit();
|
573 |
| } |
574 |
| catch (Exception e) |
575 |
| { |
576 |
1
| assertTrue(e instanceof RollbackException);
|
577 |
| } |
578 |
| |
579 |
| |
580 |
1
| assertNull(mgr.getTransaction());
|
581 |
| |
582 |
| |
583 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
584 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
585 |
| |
586 |
| |
587 |
1
| assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
|
588 |
1
| assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
|
589 |
| |
590 |
| |
591 |
1
| List calls = dummy.getAllCalled();
|
592 |
1
| assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
|
593 |
1
| assertEquals(MethodDeclarations.rollbackMethod, calls.get(1));
|
594 |
| |
595 |
| |
596 |
1
| List calls2 = dummy2.getAllCalled();
|
597 |
1
| assertEquals(MethodDeclarations.rollbackMethod, calls2.get(0));
|
598 |
| |
599 |
1
| destroyCache(cache2);
|
600 |
| } |
601 |
| |
602 |
| |
603 |
1
| public void testFailurePrepareLocalCacheBroadcast() throws Exception
|
604 |
| { |
605 |
| |
606 |
1
| destroyCache(cache);
|
607 |
1
| cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
|
608 |
| |
609 |
1
| MockFailureInterceptor dummy = new MockFailureInterceptor();
|
610 |
1
| dummy.setCache(cache);
|
611 |
| |
612 |
1
| cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
|
613 |
| |
614 |
1
| CacheImpl cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
|
615 |
1
| MockInterceptor dummy2 = new MockInterceptor();
|
616 |
1
| dummy.setCache(cache2);
|
617 |
| |
618 |
1
| cache2.setInterceptorChain(getAlteredInterceptorChain(dummy2, cache2, true));
|
619 |
| |
620 |
1
| List failures = new ArrayList();
|
621 |
1
| failures.add(MethodDeclarations.optimisticPrepareMethod);
|
622 |
1
| dummy.setFailurelist(failures);
|
623 |
| |
624 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
625 |
| |
626 |
| |
627 |
1
| mgr.begin();
|
628 |
1
| Transaction tx = mgr.getTransaction();
|
629 |
| |
630 |
| |
631 |
1
| cache.getCurrentTransaction(tx);
|
632 |
| |
633 |
1
| SamplePojo pojo = new SamplePojo(21, "test");
|
634 |
| |
635 |
1
| cache.put("/one/two", "key1", pojo);
|
636 |
| |
637 |
1
| GlobalTransaction gtx = cache.getCurrentTransaction(tx);
|
638 |
1
| TransactionTable table = cache.getTransactionTable();
|
639 |
1
| OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
|
640 |
1
| assertNotNull(mgr.getTransaction());
|
641 |
1
| try
|
642 |
| { |
643 |
1
| mgr.commit();
|
644 |
| } |
645 |
| catch (Exception e) |
646 |
| { |
647 |
1
| assertTrue(e instanceof RollbackException);
|
648 |
| } |
649 |
| |
650 |
| |
651 |
1
| assertNull(mgr.getTransaction());
|
652 |
| |
653 |
| |
654 |
1
| assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
|
655 |
1
| assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
|
656 |
| |
657 |
| |
658 |
1
| assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
|
659 |
1
| assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
|
660 |
| |
661 |
| |
662 |
1
| List calls = dummy.getAllCalled();
|
663 |
1
| assertEquals(MethodDeclarations.rollbackMethod, calls.get(0));
|
664 |
| |
665 |
| |
666 |
1
| List calls2 = dummy2.getAllCalled();
|
667 |
1
| assertEquals(0, calls2.size());
|
668 |
| |
669 |
1
| destroyCache(cache2);
|
670 |
| } |
671 |
| |
672 |
| static class TestAddress implements Address |
673 |
| { |
674 |
0
| public boolean isMulticastAddress()
|
675 |
| { |
676 |
0
| return false;
|
677 |
| } |
678 |
| |
679 |
0
| public void readExternal(ObjectInput arg0)
|
680 |
| { |
681 |
| } |
682 |
| |
683 |
0
| public int size()
|
684 |
| { |
685 |
0
| return 0;
|
686 |
| } |
687 |
| |
688 |
0
| public void writeExternal(ObjectOutput arg0)
|
689 |
| { |
690 |
| } |
691 |
| |
692 |
0
| public void writeTo(DataOutputStream arg0)
|
693 |
| { |
694 |
| } |
695 |
| |
696 |
0
| public void readFrom(DataInputStream arg0)
|
697 |
| { |
698 |
| } |
699 |
| |
700 |
0
| public int compareTo(Object arg0)
|
701 |
| { |
702 |
0
| return 0;
|
703 |
| } |
704 |
| } |
705 |
| |
706 |
| } |