1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| package org.jboss.cache.notifications; |
24 |
| |
25 |
| import junit.framework.TestCase; |
26 |
| import org.jboss.cache.Cache; |
27 |
| import org.jboss.cache.DefaultCacheFactory; |
28 |
| import org.jboss.cache.Fqn; |
29 |
| import org.jboss.cache.Node; |
30 |
| import org.jboss.cache.config.Configuration; |
31 |
| import org.jboss.cache.lock.IsolationLevel; |
32 |
| import org.jboss.cache.notifications.event.Event; |
33 |
| import static org.jboss.cache.notifications.event.Event.Type.*; |
34 |
| import org.jboss.cache.notifications.event.EventImpl; |
35 |
| import static org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType.*; |
36 |
| |
37 |
| import javax.transaction.Transaction; |
38 |
| import javax.transaction.TransactionManager; |
39 |
| import java.util.ArrayList; |
40 |
| import java.util.Collections; |
41 |
| import java.util.HashMap; |
42 |
| import java.util.LinkedList; |
43 |
| import java.util.List; |
44 |
| import java.util.Map; |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| public class RemoteCacheListenerTest extends TestCase |
52 |
| { |
53 |
| |
54 |
| protected boolean optLocking = false; |
55 |
| |
56 |
| private Cache cache1, cache2; |
57 |
| private TransactionManager tm1, tm2; |
58 |
| private EventLog eventLog1 = new EventLog(), eventLog2 = new EventLog(); |
59 |
| private Fqn fqn = Fqn.fromString("/test"); |
60 |
| |
61 |
24
| protected void setUp() throws Exception
|
62 |
| { |
63 |
24
| super.setUp();
|
64 |
24
| Configuration c = new Configuration();
|
65 |
24
| c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
|
66 |
24
| c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
|
67 |
12
| if (optLocking) c.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
|
68 |
24
| c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
|
69 |
24
| c.setFetchInMemoryState(false);
|
70 |
| |
71 |
| |
72 |
| |
73 |
24
| c.setSyncCommitPhase(true);
|
74 |
| |
75 |
| |
76 |
24
| c.setSyncReplTimeout(60000);
|
77 |
| |
78 |
24
| cache1 = DefaultCacheFactory.getInstance().createCache(c);
|
79 |
24
| cache2 = DefaultCacheFactory.getInstance().createCache(c.clone());
|
80 |
| |
81 |
24
| eventLog1.events.clear();
|
82 |
24
| eventLog2.events.clear();
|
83 |
| |
84 |
24
| cache1.addCacheListener(eventLog1);
|
85 |
24
| cache2.addCacheListener(eventLog2);
|
86 |
| |
87 |
24
| tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
|
88 |
24
| tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
|
89 |
| } |
90 |
| |
91 |
24
| protected void tearDown() throws Exception
|
92 |
| { |
93 |
24
| super.tearDown();
|
94 |
24
| TransactionManager tm;
|
95 |
?
| if ((tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
|
96 |
| { |
97 |
24
| if (tm.getTransaction() != null)
|
98 |
| { |
99 |
0
| try
|
100 |
| { |
101 |
0
| tm.rollback();
|
102 |
| } |
103 |
| catch (Exception e) |
104 |
| { |
105 |
| |
106 |
| } |
107 |
| } |
108 |
| } |
109 |
?
| if ((tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
|
110 |
| { |
111 |
24
| if (tm.getTransaction() != null)
|
112 |
| { |
113 |
0
| try
|
114 |
| { |
115 |
0
| tm.rollback();
|
116 |
| } |
117 |
| catch (Exception e) |
118 |
| { |
119 |
| |
120 |
| } |
121 |
| } |
122 |
| } |
123 |
| |
124 |
24
| cache1.stop();
|
125 |
24
| cache1.destroy();
|
126 |
24
| cache2.stop();
|
127 |
24
| cache2.destroy();
|
128 |
| } |
129 |
| |
130 |
| |
131 |
| |
132 |
2
| public void testCreation() throws Exception
|
133 |
| { |
134 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
135 |
2
| cache1.put(fqn, "key", "value");
|
136 |
2
| Map data = new HashMap();
|
137 |
2
| data.put("key", "value");
|
138 |
| |
139 |
| |
140 |
2
| List<Event> expected = new ArrayList<Event>();
|
141 |
| |
142 |
2
| if (optLocking)
|
143 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
|
144 |
2
| expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
|
145 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
|
146 |
2
| expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
|
147 |
2
| expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, null, true, null, false, null, NODE_MODIFIED));
|
148 |
2
| if (optLocking)
|
149 |
| { |
150 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
|
151 |
1
| eventLog1.scrubImplicitTransactions();
|
152 |
1
| eventLog2.scrubImplicitTransactions();
|
153 |
| } |
154 |
| |
155 |
2
| assertEquals("Local events not as expected", expected, eventLog1.events);
|
156 |
| |
157 |
| |
158 |
2
| setCache(cache2, expected);
|
159 |
2
| markOriginRemote(expected);
|
160 |
| |
161 |
2
| assertEquals("Remote events not as expected", expected, eventLog2.events);
|
162 |
2
| assertEquals("value", cache1.get(fqn, "key"));
|
163 |
| } |
164 |
| |
165 |
2
| public void testOnlyModification() throws Exception
|
166 |
| { |
167 |
2
| assertNull(cache1.get(fqn, "key"));
|
168 |
2
| assertNull(cache2.get(fqn, "key"));
|
169 |
| |
170 |
2
| cache1.put(fqn, "key", "value");
|
171 |
2
| Map oldData = new HashMap();
|
172 |
2
| oldData.put("key", "value");
|
173 |
| |
174 |
2
| assertEquals("value", cache1.get(fqn, "key"));
|
175 |
2
| assertEquals("value", cache2.get(fqn, "key"));
|
176 |
| |
177 |
| |
178 |
2
| eventLog1.events.clear();
|
179 |
2
| eventLog2.events.clear();
|
180 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
181 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
182 |
| |
183 |
| |
184 |
2
| cache1.put(fqn, "key", "value2");
|
185 |
2
| Map newData = new HashMap();
|
186 |
2
| newData.put("key", "value2");
|
187 |
| |
188 |
| |
189 |
2
| List<Event> expected = new ArrayList<Event>();
|
190 |
2
| if (optLocking)
|
191 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
|
192 |
2
| expected.add(new EventImpl(true, cache1, PUT_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
|
193 |
2
| expected.add(new EventImpl(false, cache1, PUT_DATA, newData, fqn, null, true, null, false, null, NODE_MODIFIED));
|
194 |
2
| if (optLocking)
|
195 |
| { |
196 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
|
197 |
1
| eventLog1.scrubImplicitTransactions();
|
198 |
1
| eventLog2.scrubImplicitTransactions();
|
199 |
| } |
200 |
| |
201 |
2
| assertEquals("Local events not as expected", expected, eventLog1.events);
|
202 |
| |
203 |
| |
204 |
2
| setCache(cache2, expected);
|
205 |
2
| markOriginRemote(expected);
|
206 |
| |
207 |
2
| assertEquals("Remote events not as expected", expected, eventLog2.events);
|
208 |
| } |
209 |
| |
210 |
| |
211 |
2
| public void testOnlyRemoval() throws Exception
|
212 |
| { |
213 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
214 |
2
| cache1.put(fqn, "key", "value");
|
215 |
2
| Map oldData = new HashMap();
|
216 |
2
| oldData.put("key", "value");
|
217 |
| |
218 |
2
| assertEquals("value", cache1.get(fqn, "key"));
|
219 |
2
| assertEquals("value", cache2.get(fqn, "key"));
|
220 |
| |
221 |
| |
222 |
2
| eventLog1.events.clear();
|
223 |
2
| eventLog2.events.clear();
|
224 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
225 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
226 |
| |
227 |
| |
228 |
2
| cache1.removeNode(fqn);
|
229 |
| |
230 |
2
| List<Event> expected = new ArrayList<Event>();
|
231 |
2
| if (optLocking)
|
232 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
|
233 |
2
| expected.add(new EventImpl(true, cache1, null, oldData, fqn, null, true, null, false, null, NODE_REMOVED));
|
234 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_REMOVED));
|
235 |
2
| if (optLocking)
|
236 |
| { |
237 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
|
238 |
1
| eventLog1.scrubImplicitTransactions();
|
239 |
1
| eventLog2.scrubImplicitTransactions();
|
240 |
| } |
241 |
| |
242 |
2
| assertEquals("Local events not as expected", expected, eventLog1.events);
|
243 |
| |
244 |
| |
245 |
2
| setCache(cache2, expected);
|
246 |
2
| markOriginRemote(expected);
|
247 |
| |
248 |
2
| assertEquals("Remote events not as expected", expected, eventLog2.events);
|
249 |
| |
250 |
| |
251 |
2
| assertNull("Should be null", cache1.getRoot().getChild(fqn));
|
252 |
2
| assertNull("Should be null", cache2.getRoot().getChild(fqn));
|
253 |
| } |
254 |
| |
255 |
| |
256 |
2
| public void testRemoveData() throws Exception
|
257 |
| { |
258 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
259 |
2
| cache1.put(fqn, "key", "value");
|
260 |
2
| cache1.put(fqn, "key2", "value2");
|
261 |
2
| Map oldData = new HashMap();
|
262 |
2
| oldData.put("key", "value");
|
263 |
2
| oldData.put("key2", "value2");
|
264 |
| |
265 |
| |
266 |
2
| eventLog1.events.clear();
|
267 |
2
| eventLog2.events.clear();
|
268 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
269 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
270 |
| |
271 |
| |
272 |
2
| cache1.remove(fqn, "key2");
|
273 |
2
| Map removed = new HashMap();
|
274 |
2
| removed.put("key2", "value2");
|
275 |
| |
276 |
2
| List<Event> expected = new ArrayList<Event>();
|
277 |
2
| if (optLocking)
|
278 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
|
279 |
2
| expected.add(new EventImpl(true, cache1, REMOVE_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
|
280 |
2
| expected.add(new EventImpl(false, cache1, REMOVE_DATA, removed, fqn, null, true, null, false, null, NODE_MODIFIED));
|
281 |
2
| if (optLocking)
|
282 |
| { |
283 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
|
284 |
1
| eventLog1.scrubImplicitTransactions();
|
285 |
1
| eventLog2.scrubImplicitTransactions();
|
286 |
| } |
287 |
| |
288 |
2
| assertEquals("Local events not as expected", expected, eventLog1.events);
|
289 |
| |
290 |
| |
291 |
2
| setCache(cache2, expected);
|
292 |
2
| markOriginRemote(expected);
|
293 |
| |
294 |
2
| assertEquals("Remote events not as expected", expected, eventLog2.events);
|
295 |
| } |
296 |
| |
297 |
2
| public void testPutMap() throws Exception
|
298 |
| { |
299 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
300 |
2
| Map oldData = new HashMap();
|
301 |
2
| oldData.put("key", "value");
|
302 |
2
| oldData.put("key2", "value2");
|
303 |
| |
304 |
2
| assertNull(cache1.getRoot().getChild(fqn));
|
305 |
2
| assertNull(cache2.getRoot().getChild(fqn));
|
306 |
| |
307 |
| |
308 |
2
| eventLog1.events.clear();
|
309 |
2
| eventLog2.events.clear();
|
310 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
311 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
312 |
| |
313 |
2
| cache1.put(fqn, oldData);
|
314 |
| |
315 |
2
| List<Event> expected = new ArrayList<Event>();
|
316 |
2
| if (optLocking)
|
317 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
|
318 |
2
| expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
|
319 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
|
320 |
2
| expected.add(new EventImpl(true, cache1, PUT_MAP, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
|
321 |
2
| expected.add(new EventImpl(false, cache1, PUT_MAP, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
|
322 |
2
| if (optLocking)
|
323 |
| { |
324 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
|
325 |
1
| eventLog1.scrubImplicitTransactions();
|
326 |
1
| eventLog2.scrubImplicitTransactions();
|
327 |
| } |
328 |
| |
329 |
2
| assertEquals("Local events not as expected", expected, eventLog1.events);
|
330 |
| |
331 |
| |
332 |
2
| setCache(cache2, expected);
|
333 |
2
| markOriginRemote(expected);
|
334 |
| |
335 |
2
| assertEquals("Remote events not as expected", expected, eventLog2.events);
|
336 |
| } |
337 |
| |
338 |
2
| public void testMove()
|
339 |
| { |
340 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
341 |
2
| Fqn newParent = Fqn.fromString("/a");
|
342 |
2
| cache1.put(fqn, "key", "value");
|
343 |
2
| cache1.put(newParent, "key", "value");
|
344 |
| |
345 |
2
| Node n1 = cache1.getRoot().getChild(fqn);
|
346 |
2
| Node n2 = cache1.getRoot().getChild(newParent);
|
347 |
| |
348 |
2
| eventLog1.events.clear();
|
349 |
2
| eventLog2.events.clear();
|
350 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
351 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
352 |
| |
353 |
2
| cache1.move(n1.getFqn(), n2.getFqn());
|
354 |
2
| Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
|
355 |
| |
356 |
| |
357 |
2
| List<Event> expected = new ArrayList<Event>();
|
358 |
2
| if (optLocking)
|
359 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
|
360 |
2
| expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
|
361 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
|
362 |
2
| if (optLocking)
|
363 |
| { |
364 |
1
| expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
|
365 |
1
| eventLog1.scrubImplicitTransactions();
|
366 |
1
| eventLog2.scrubImplicitTransactions();
|
367 |
| } |
368 |
| |
369 |
2
| assertEquals("Local events not as expected", expected, eventLog1.events);
|
370 |
| |
371 |
| |
372 |
2
| setCache(cache2, expected);
|
373 |
2
| markOriginRemote(expected);
|
374 |
| |
375 |
2
| assertEquals("Remote events not as expected", expected, eventLog2.events);
|
376 |
| } |
377 |
| |
378 |
| |
379 |
| |
380 |
2
| public void testTxCreationCommit() throws Exception
|
381 |
| { |
382 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
383 |
2
| tm1.begin();
|
384 |
2
| Transaction tx = tm1.getTransaction();
|
385 |
2
| cache1.put(fqn, "key", "value");
|
386 |
2
| Map data = new HashMap();
|
387 |
2
| data.put("key", "value");
|
388 |
| |
389 |
2
| List<Event> expected = new ArrayList<Event>();
|
390 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
|
391 |
2
| expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
|
392 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
|
393 |
2
| expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
|
394 |
2
| expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
|
395 |
| |
396 |
2
| assertEquals(expected, eventLog1.events);
|
397 |
2
| assertTrue(eventLog2.events.isEmpty());
|
398 |
| |
399 |
2
| tm1.commit();
|
400 |
| |
401 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
|
402 |
2
| assertEquals(expected, eventLog1.events);
|
403 |
| |
404 |
2
| setCache(cache2, expected);
|
405 |
2
| markOriginRemote(expected);
|
406 |
2
| scrubTransactions(expected);
|
407 |
2
| eventLog2.scrubImplicitTransactions();
|
408 |
2
| assertEquals(expected, eventLog2.events);
|
409 |
| |
410 |
2
| assertEquals("value", cache1.get(fqn, "key"));
|
411 |
2
| assertEquals("value", cache2.get(fqn, "key"));
|
412 |
| } |
413 |
| |
414 |
2
| public void testTxCreationRollback() throws Exception
|
415 |
| { |
416 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
417 |
2
| tm1.begin();
|
418 |
2
| Transaction tx = tm1.getTransaction();
|
419 |
2
| cache1.put(fqn, "key", "value");
|
420 |
2
| Map data = new HashMap();
|
421 |
2
| data.put("key", "value");
|
422 |
2
| List<Event> expected = new ArrayList<Event>();
|
423 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
|
424 |
2
| expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
|
425 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
|
426 |
2
| expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
|
427 |
2
| expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
|
428 |
| |
429 |
2
| assertEquals(expected, eventLog1.events);
|
430 |
2
| assertTrue(eventLog2.events.isEmpty());
|
431 |
2
| tm1.rollback();
|
432 |
| |
433 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_COMPLETED));
|
434 |
2
| assertEquals(expected, eventLog1.events);
|
435 |
2
| assertTrue(eventLog2.events.isEmpty());
|
436 |
| |
437 |
2
| assertNull(cache1.get(fqn, "key"));
|
438 |
2
| assertNull(cache2.get(fqn, "key"));
|
439 |
| } |
440 |
| |
441 |
| |
442 |
2
| public void testTxOnlyModification() throws Exception
|
443 |
| { |
444 |
2
| assertNull(cache1.get(fqn, "key"));
|
445 |
2
| assertNull(cache2.get(fqn, "key"));
|
446 |
| |
447 |
2
| cache1.put(fqn, "key", "value");
|
448 |
2
| Map oldData = new HashMap();
|
449 |
2
| oldData.put("key", "value");
|
450 |
| |
451 |
2
| assertEquals("value", cache1.get(fqn, "key"));
|
452 |
2
| assertEquals("value", cache2.get(fqn, "key"));
|
453 |
| |
454 |
| |
455 |
2
| eventLog1.events.clear();
|
456 |
2
| eventLog2.events.clear();
|
457 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
458 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
459 |
| |
460 |
| |
461 |
2
| tm1.begin();
|
462 |
2
| Transaction tx = tm1.getTransaction();
|
463 |
2
| Map newData = new HashMap();
|
464 |
2
| newData.put("key", "value2");
|
465 |
2
| cache1.put(fqn, "key", "value2");
|
466 |
2
| List<Event> expected = new ArrayList<Event>();
|
467 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
|
468 |
2
| expected.add(new EventImpl(true, cache1, PUT_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
|
469 |
2
| expected.add(new EventImpl(false, cache1, PUT_DATA, newData, fqn, tx, true, null, false, null, NODE_MODIFIED));
|
470 |
2
| assertEquals(expected, eventLog1.events);
|
471 |
| |
472 |
2
| assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
|
473 |
2
| tm1.commit();
|
474 |
| |
475 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
|
476 |
2
| assertEquals(expected, eventLog1.events);
|
477 |
| |
478 |
2
| setCache(cache2, expected);
|
479 |
2
| markOriginRemote(expected);
|
480 |
2
| scrubTransactions(expected);
|
481 |
2
| eventLog2.scrubImplicitTransactions();
|
482 |
2
| assertEquals(expected, eventLog2.events);
|
483 |
| } |
484 |
| |
485 |
| |
486 |
2
| public void testTxOnlyRemoval() throws Exception
|
487 |
| { |
488 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
489 |
2
| cache1.put(fqn, "key", "value");
|
490 |
2
| Map oldData = new HashMap();
|
491 |
2
| oldData.put("key", "value");
|
492 |
| |
493 |
2
| assertEquals("value", cache1.get(fqn, "key"));
|
494 |
2
| assertEquals("value", cache2.get(fqn, "key"));
|
495 |
| |
496 |
| |
497 |
2
| eventLog1.events.clear();
|
498 |
2
| eventLog2.events.clear();
|
499 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
500 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
501 |
| |
502 |
| |
503 |
2
| tm1.begin();
|
504 |
2
| Transaction tx = tm1.getTransaction();
|
505 |
2
| cache1.removeNode(fqn);
|
506 |
2
| List<Event> expected = new ArrayList<Event>();
|
507 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
|
508 |
2
| expected.add(new EventImpl(true, cache1, null, oldData, fqn, tx, true, null, false, null, NODE_REMOVED));
|
509 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_REMOVED));
|
510 |
2
| assertEquals(expected, eventLog1.events);
|
511 |
2
| assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
|
512 |
2
| tm1.commit();
|
513 |
| |
514 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
|
515 |
2
| assertEquals(expected, eventLog1.events);
|
516 |
| |
517 |
2
| setCache(cache2, expected);
|
518 |
2
| markOriginRemote(expected);
|
519 |
2
| scrubTransactions(expected);
|
520 |
2
| eventLog2.scrubImplicitTransactions();
|
521 |
2
| assertEquals(expected, eventLog2.events);
|
522 |
| |
523 |
| |
524 |
2
| assertNull("Should be null", cache1.getRoot().getChild(fqn));
|
525 |
2
| assertNull("Should be null", cache2.getRoot().getChild(fqn));
|
526 |
| } |
527 |
| |
528 |
| |
529 |
2
| public void testTxRemoveData() throws Exception
|
530 |
| { |
531 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
532 |
2
| cache1.put(fqn, "key", "value");
|
533 |
2
| cache1.put(fqn, "key2", "value2");
|
534 |
2
| Map oldData = new HashMap();
|
535 |
2
| oldData.put("key", "value");
|
536 |
2
| oldData.put("key2", "value2");
|
537 |
| |
538 |
| |
539 |
2
| eventLog1.events.clear();
|
540 |
2
| eventLog2.events.clear();
|
541 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
542 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
543 |
| |
544 |
| |
545 |
2
| tm1.begin();
|
546 |
2
| Transaction tx = tm1.getTransaction();
|
547 |
2
| Map removed = new HashMap();
|
548 |
2
| removed.put("key2", "value2");
|
549 |
2
| cache1.remove(fqn, "key2");
|
550 |
2
| List<Event> expected = new LinkedList<Event>();
|
551 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
|
552 |
2
| expected.add(new EventImpl(true, cache1, REMOVE_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
|
553 |
2
| expected.add(new EventImpl(false, cache1, REMOVE_DATA, removed, fqn, tx, true, null, false, null, NODE_MODIFIED));
|
554 |
2
| assertEquals(expected, eventLog1.events);
|
555 |
2
| assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
|
556 |
2
| tm1.commit();
|
557 |
| |
558 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
|
559 |
2
| assertEquals(expected, eventLog1.events);
|
560 |
| |
561 |
2
| setCache(cache2, expected);
|
562 |
2
| markOriginRemote(expected);
|
563 |
2
| scrubTransactions(expected);
|
564 |
2
| eventLog2.scrubImplicitTransactions();
|
565 |
2
| assertEquals(expected, eventLog2.events);
|
566 |
| |
567 |
| } |
568 |
| |
569 |
2
| public void testTxMove() throws Exception
|
570 |
| { |
571 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
572 |
2
| Fqn newParent = Fqn.fromString("/a");
|
573 |
2
| cache1.put(fqn, "key", "value");
|
574 |
2
| cache1.put(newParent, "key", "value");
|
575 |
| |
576 |
2
| Node n1 = cache1.getRoot().getChild(fqn);
|
577 |
2
| Node n2 = cache1.getRoot().getChild(newParent);
|
578 |
| |
579 |
2
| eventLog1.events.clear();
|
580 |
2
| eventLog2.events.clear();
|
581 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
|
582 |
2
| assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
|
583 |
| |
584 |
2
| tm1.begin();
|
585 |
2
| Transaction tx = tm1.getTransaction();
|
586 |
2
| Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
|
587 |
2
| cache1.move(n1.getFqn(), n2.getFqn());
|
588 |
2
| List<Event> expected = new ArrayList<Event>();
|
589 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
|
590 |
2
| expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
|
591 |
2
| expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
|
592 |
2
| assertEquals(expected, eventLog1.events);
|
593 |
2
| assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
|
594 |
2
| tm1.commit();
|
595 |
| |
596 |
2
| expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
|
597 |
2
| assertEquals(expected, eventLog1.events);
|
598 |
| |
599 |
2
| setCache(cache2, expected);
|
600 |
2
| markOriginRemote(expected);
|
601 |
2
| scrubTransactions(expected);
|
602 |
2
| eventLog2.scrubImplicitTransactions();
|
603 |
2
| assertEquals(expected, eventLog2.events);
|
604 |
| } |
605 |
| |
606 |
22
| private void setCache(Cache c, List<Event> l)
|
607 |
| { |
608 |
88
| for (Event e : l) ((EventImpl) e).setCache(c);
|
609 |
| } |
610 |
| |
611 |
22
| private void markOriginRemote(List<Event> l)
|
612 |
| { |
613 |
88
| for (Event e : l) ((EventImpl) e).setOriginLocal(false);
|
614 |
| } |
615 |
| |
616 |
10
| private void scrubTransactions(List<Event> l)
|
617 |
| { |
618 |
44
| for (Event e : l) ((EventImpl) e).setTransaction(null);
|
619 |
| } |
620 |
| } |