1 |
| package org.jboss.cache.passivation; |
2 |
| |
3 |
| import junit.framework.Test; |
4 |
| import junit.framework.TestCase; |
5 |
| import junit.framework.TestSuite; |
6 |
| import org.apache.commons.logging.Log; |
7 |
| import org.apache.commons.logging.LogFactory; |
8 |
| import org.jboss.cache.CacheException; |
9 |
| import org.jboss.cache.CacheImpl; |
10 |
| import org.jboss.cache.DefaultCacheFactory; |
11 |
| import org.jboss.cache.Fqn; |
12 |
| import org.jboss.cache.Modification; |
13 |
| import org.jboss.cache.Node; |
14 |
| import org.jboss.cache.config.CacheLoaderConfig; |
15 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
16 |
| import org.jboss.cache.loader.CacheLoader; |
17 |
| import org.jboss.cache.loader.SamplePojo; |
18 |
| import org.jboss.cache.lock.IsolationLevel; |
19 |
| import org.jboss.cache.statetransfer.StateTransferManager; |
20 |
| import org.jboss.cache.transaction.DummyTransactionManager; |
21 |
| import org.jboss.cache.xml.XmlHelper; |
22 |
| import org.jboss.util.stream.MarshalledValueInputStream; |
23 |
| import org.jboss.util.stream.MarshalledValueOutputStream; |
24 |
| import org.w3c.dom.Element; |
25 |
| |
26 |
| import javax.transaction.NotSupportedException; |
27 |
| import javax.transaction.Transaction; |
28 |
| import java.io.ByteArrayInputStream; |
29 |
| import java.io.ByteArrayOutputStream; |
30 |
| import java.io.Serializable; |
31 |
| import java.util.ArrayList; |
32 |
| import java.util.HashMap; |
33 |
| import java.util.Iterator; |
34 |
| import java.util.List; |
35 |
| import java.util.Map; |
36 |
| import java.util.Set; |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| abstract public class PassivationTestsBase extends TestCase |
45 |
| { |
46 |
| |
47 |
| Log log = LogFactory.getLog(getClass()); |
48 |
| |
49 |
| |
50 |
| CacheImpl cache; |
51 |
| CacheLoader loader = null; |
52 |
| Transaction tx = null; |
53 |
| static final Fqn FQN = new Fqn("key"); |
54 |
| |
55 |
| |
56 |
45
| protected CacheLoaderConfig getCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState) throws Exception
|
57 |
| { |
58 |
45
| String xml = "<config>\n" +
|
59 |
| "<passivation>true</passivation>\n" + |
60 |
| "<preload>" + preload + "</preload>\n" + |
61 |
| "<cacheloader>\n" + |
62 |
| "<class>" + cacheloaderClass + "</class>\n" + |
63 |
| "<properties>" + properties + "</properties>\n" + |
64 |
| "<async>" + async + "</async>\n" + |
65 |
| "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" + |
66 |
| "</cacheloader>\n" + |
67 |
| "</config>"; |
68 |
45
| Element element = XmlHelper.stringToElement(xml);
|
69 |
45
| return XmlConfigurationParser.parseCacheLoaderConfig(element);
|
70 |
| } |
71 |
| |
72 |
180
| protected void setUp() throws Exception
|
73 |
| { |
74 |
180
| super.setUp();
|
75 |
180
| log.debug("Testing " + getName());
|
76 |
180
| log.debug("");
|
77 |
180
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
78 |
180
| cache.getConfiguration().setCacheMode("local");
|
79 |
180
| configureCache();
|
80 |
| |
81 |
180
| cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
|
82 |
180
| cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
|
83 |
180
| cache.create();
|
84 |
180
| cache.start();
|
85 |
180
| loader = cache.getCacheLoader();
|
86 |
| } |
87 |
| |
88 |
| abstract protected void configureCache() throws Exception; |
89 |
| |
90 |
| |
91 |
180
| protected void tearDown() throws Exception
|
92 |
| { |
93 |
180
| super.tearDown();
|
94 |
180
| if (tx != null)
|
95 |
| { |
96 |
20
| try
|
97 |
| { |
98 |
20
| tx.commit();
|
99 |
| } |
100 |
| catch (Throwable e) |
101 |
| { |
102 |
0
| e.printStackTrace();
|
103 |
| } |
104 |
| } |
105 |
180
| cache.remove("/");
|
106 |
180
| loader.remove(Fqn.fromString("/"));
|
107 |
180
| cache.stop();
|
108 |
180
| cache.destroy();
|
109 |
| } |
110 |
| |
111 |
| |
112 |
578
| protected void addDelay()
|
113 |
| { |
114 |
| ; |
115 |
| } |
116 |
| |
117 |
4
| public void testPrintPassivation() throws Exception
|
118 |
| { |
119 |
4
| final Fqn NODE = Fqn.fromString("/test");
|
120 |
4
| final String KEY = "key";
|
121 |
4
| loader.remove(NODE);
|
122 |
4
| cache.put(NODE, KEY, 10);
|
123 |
4
| cache.evict(NODE);
|
124 |
4
| assertTrue(loader.exists(NODE));
|
125 |
4
| addDelay();
|
126 |
4
| log.info("print node " + NODE);
|
127 |
4
| String ret = cache.print(NODE);
|
128 |
4
| assertNotNull(ret);
|
129 |
4
| log.info("loader exists " + NODE);
|
130 |
4
| assertTrue(!loader.exists(NODE));
|
131 |
4
| cache.get(NODE, KEY);
|
132 |
4
| assertFalse(loader.exists(NODE));
|
133 |
| } |
134 |
| |
135 |
4
| public void testPutPassivation() throws Exception
|
136 |
| { |
137 |
4
| final String NODE = "/test";
|
138 |
4
| final String KEY = "key";
|
139 |
4
| Object retval = null;
|
140 |
4
| cache.remove(NODE);
|
141 |
4
| addDelay();
|
142 |
4
| retval = cache.put(NODE, KEY, 10);
|
143 |
4
| assertNull(retval);
|
144 |
4
| retval = cache.put(NODE, KEY, 20);
|
145 |
4
| addDelay();
|
146 |
4
| assertEquals(10, retval);
|
147 |
4
| cache.evict(Fqn.fromString(NODE));
|
148 |
4
| addDelay();
|
149 |
4
| log.debug("______________");
|
150 |
4
| retval = cache.put(NODE, KEY, 30);
|
151 |
4
| assertFalse(loader.exists(Fqn.fromString(NODE)));
|
152 |
4
| assertEquals(20, retval);
|
153 |
| } |
154 |
| |
155 |
4
| public void testPut2Passivation() throws CacheException
|
156 |
| { |
157 |
4
| final String NODE = "/a/b/c";
|
158 |
4
| final String KEY = "key";
|
159 |
4
| Object retval = null;
|
160 |
4
| cache.remove(NODE);
|
161 |
4
| addDelay();
|
162 |
4
| retval = cache.put(NODE, KEY, 10);
|
163 |
4
| assertNull(retval);
|
164 |
4
| addDelay();
|
165 |
4
| retval = cache.put(NODE, KEY, 20);
|
166 |
4
| assertEquals(10, retval);
|
167 |
4
| cache.evict(Fqn.fromString(NODE));
|
168 |
4
| cache.evict(Fqn.fromString("/a/b"));
|
169 |
4
| cache.evict(Fqn.fromString("/a"));
|
170 |
4
| addDelay();
|
171 |
4
| try
|
172 |
| { |
173 |
4
| assertTrue(loader.exists(Fqn.fromString("/a/b/c")));
|
174 |
| } |
175 |
| catch (Exception e) |
176 |
| { |
177 |
0
| fail(e.toString());
|
178 |
| } |
179 |
4
| retval = cache.put(NODE, KEY, 30);
|
180 |
4
| try
|
181 |
| { |
182 |
4
| assertFalse(loader.exists(Fqn.fromString(NODE)));
|
183 |
| } |
184 |
| catch (Exception e) |
185 |
| { |
186 |
0
| fail(e.toString());
|
187 |
| } |
188 |
4
| assertEquals(20, retval);
|
189 |
| } |
190 |
| |
191 |
| |
192 |
4
| public void testSerializationPassivation() throws CacheException
|
193 |
| { |
194 |
4
| SamplePojo pojo = new SamplePojo(39, "Hany");
|
195 |
4
| pojo.getHobbies().add("Running");
|
196 |
4
| pojo.getHobbies().add("Beerathlon");
|
197 |
4
| pojo.getHobbies().add("Triathlon");
|
198 |
4
| cache.put("/mypojo", 322649, pojo);
|
199 |
4
| addDelay();
|
200 |
4
| assertNotNull(cache.get("/mypojo", 322649));
|
201 |
4
| cache.evict(Fqn.fromString("/mypojo"));
|
202 |
4
| try
|
203 |
| { |
204 |
4
| assertTrue(loader.exists(Fqn.fromString("/mypojo")));
|
205 |
| } |
206 |
| catch (Exception e) |
207 |
| { |
208 |
0
| fail(e.toString());
|
209 |
| } |
210 |
4
| SamplePojo pojo2 = (SamplePojo) cache.get("/mypojo", 322649);
|
211 |
4
| try
|
212 |
| { |
213 |
4
| assertFalse(loader.exists(Fqn.fromString("/mypojo")));
|
214 |
| } |
215 |
| catch (Exception e) |
216 |
| { |
217 |
0
| fail(e.toString());
|
218 |
| } |
219 |
4
| assertNotNull(pojo2);
|
220 |
4
| assertEquals(39, pojo2.getAge());
|
221 |
4
| assertEquals("Hany", pojo2.getName());
|
222 |
4
| assertEquals(3, pojo2.getHobbies().size());
|
223 |
| } |
224 |
| |
225 |
| |
226 |
| |
227 |
| |
228 |
4
| public void testPopulate()
|
229 |
| { |
230 |
4
| try
|
231 |
| { |
232 |
4
| Map m = new HashMap();
|
233 |
4
| for (int i = 0; i < 10; i++)
|
234 |
| { |
235 |
40
| m.put("key" + i, "val" + i);
|
236 |
| } |
237 |
4
| cache.put("/a/b/c", m);
|
238 |
4
| cache.load("/1/2/3/4/5");
|
239 |
4
| cache.put("/1/2/3/4/5", null);
|
240 |
4
| cache.put("/1/2/3/4/5/a", null);
|
241 |
4
| cache.put("/1/2/3/4/5/b", null);
|
242 |
4
| cache.put("/1/2/3/4/5/c", null);
|
243 |
4
| cache.put("/1/2/3/4/5/d", null);
|
244 |
4
| cache.put("/1/2/3/4/5/e", null);
|
245 |
4
| cache.put("/1/2/3/4/5/d/one", null);
|
246 |
4
| cache.put("/1/2/3/4/5/d/two", null);
|
247 |
4
| cache.put("/1/2/3/4/5/d/three", null);
|
248 |
| |
249 |
4
| System.out.println("cache: " + cache);
|
250 |
| |
251 |
4
| assertTrue(cache.exists("/1/2/3/4"));
|
252 |
4
| assertTrue(cache.exists("/a/b/c"));
|
253 |
4
| assertFalse(cache.exists("/a/b/c/d"));
|
254 |
| } |
255 |
| catch (Exception e) |
256 |
| { |
257 |
0
| fail(e.toString());
|
258 |
| } |
259 |
| } |
260 |
| |
261 |
| |
262 |
4
| public void testPreloadingPassivation() throws Exception
|
263 |
| { |
264 |
4
| cache.remove("/");
|
265 |
4
| cache.put("1/2/3/4/5/d", "key", "val");
|
266 |
4
| cache.evict(Fqn.fromString("1/2/3/4/5/d"));
|
267 |
4
| System.out.println("-- checking for 1/2/3/4/5/d");
|
268 |
4
| addDelay();
|
269 |
4
| try
|
270 |
| { |
271 |
4
| assertTrue(loader.exists(Fqn.fromString("1/2/3/4/5/d")));
|
272 |
| } |
273 |
| catch (Exception e) |
274 |
| { |
275 |
0
| fail(e.toString());
|
276 |
| } |
277 |
4
| cache.get("1/2/3/4/5/d");
|
278 |
4
| assertEquals(false, loader.exists(Fqn.fromString("1/2/3/4/5/d")));
|
279 |
4
| assertTrue(cache.exists("1/2/3/4/5/d"));
|
280 |
4
| System.out.println("-- 1/2/3/4/5/d exists");
|
281 |
4
| cache.get("1/2/3/4/5/d", "key");
|
282 |
4
| assertEquals(false, loader.exists(Fqn.fromString("1/2/3/4/5/d")));
|
283 |
| } |
284 |
| |
285 |
| |
286 |
4
| public void testCacheLoading2() throws CacheException
|
287 |
| { |
288 |
4
| Set keys = null;
|
289 |
4
| cache.put("/a/b/c", "key", "val");
|
290 |
4
| try
|
291 |
| { |
292 |
4
| keys = cache.getKeys("/a/b/c");
|
293 |
4
| assertNotNull(keys);
|
294 |
4
| assertEquals(1, keys.size());
|
295 |
| } |
296 |
| catch (Exception e) |
297 |
| { |
298 |
0
| fail(e.toString());
|
299 |
| } |
300 |
| |
301 |
4
| try
|
302 |
| { |
303 |
4
| keys.add("myKey");
|
304 |
| } |
305 |
| catch (UnsupportedOperationException ex) |
306 |
| { |
307 |
0
| fail("unsupported operation: " + ex);
|
308 |
| } |
309 |
| } |
310 |
| |
311 |
| |
312 |
4
| public void testExists() throws Exception
|
313 |
| { |
314 |
4
| cache.put("/eins/zwei/drei", "key1", "val1");
|
315 |
4
| assertTrue(cache.exists("/eins/zwei/drei"));
|
316 |
4
| assertTrue(cache.exists("/eins/zwei/drei", "key1"));
|
317 |
4
| assertFalse(cache.exists("/eins/zwei/drei", "key2"));
|
318 |
4
| assertFalse(cache.exists("/uno/due/tre"));
|
319 |
4
| assertFalse(cache.exists("/une/due/tre", "key1"));
|
320 |
| } |
321 |
| |
322 |
4
| public void testGetChildren() throws Exception
|
323 |
| { |
324 |
4
| cache.put("/d/one", null);
|
325 |
4
| cache.put("/d/two", null);
|
326 |
4
| cache.put("/d/three", null);
|
327 |
4
| cache.get("/d");
|
328 |
4
| Set children = cache.getChildrenNames("/d");
|
329 |
4
| assertNotNull(children);
|
330 |
4
| assertEquals(3, children.size());
|
331 |
4
| assertTrue(children.contains("one"));
|
332 |
4
| assertTrue(children.contains("two"));
|
333 |
4
| assertTrue(children.contains("three"));
|
334 |
| } |
335 |
| |
336 |
| |
337 |
4
| public void testGetChildrenWithEvictionPassivation() throws Exception
|
338 |
| { |
339 |
4
| cache.put("/a/b/c/1", null);
|
340 |
4
| cache.put("/a/b/c/2", null);
|
341 |
4
| cache.put("/a/b/c/3", null);
|
342 |
4
| cache.evict(Fqn.fromString("/a/b/c/1"));
|
343 |
4
| cache.evict(Fqn.fromString("/a/b/c/2"));
|
344 |
4
| cache.evict(Fqn.fromString("/a/b/c/3"));
|
345 |
4
| cache.evict(Fqn.fromString("/a/b/c"));
|
346 |
4
| cache.evict(Fqn.fromString("/a/b"));
|
347 |
4
| cache.evict(Fqn.fromString("/a"));
|
348 |
4
| cache.evict(Fqn.fromString("/"));
|
349 |
4
| addDelay();
|
350 |
4
| Set children = cache.getChildrenNames("/a/b/c");
|
351 |
4
| assertNotNull(children);
|
352 |
4
| assertEquals(3, children.size());
|
353 |
4
| assertTrue(children.contains("1"));
|
354 |
4
| assertTrue(children.contains("2"));
|
355 |
4
| assertTrue(children.contains("3"));
|
356 |
| |
357 |
4
| assertTrue(loader.exists(Fqn.fromString("/a/b/c")));
|
358 |
| |
359 |
4
| cache.get("/a/b/c/1", "test");
|
360 |
4
| cache.get("/a/b/c/2", "test");
|
361 |
4
| cache.get("/a/b/c/3", "test");
|
362 |
4
| cache.get("/a/b/c", "test");
|
363 |
| |
364 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/b/c/1")));
|
365 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/b/c/2")));
|
366 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/b/c/3")));
|
367 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/b/c")));
|
368 |
| } |
369 |
| |
370 |
4
| public void testGetChildren2()
|
371 |
| { |
372 |
4
| try
|
373 |
| { |
374 |
4
| cache.put("/1", null);
|
375 |
4
| cache.put("a", null);
|
376 |
4
| Set children = cache.getChildrenNames("/");
|
377 |
4
| assertNotNull(children);
|
378 |
4
| assertEquals(2, children.size());
|
379 |
4
| assertTrue(children.contains("1"));
|
380 |
4
| assertTrue(children.contains("a"));
|
381 |
| } |
382 |
| catch (Exception e) |
383 |
| { |
384 |
0
| fail(e.toString());
|
385 |
| } |
386 |
| } |
387 |
| |
388 |
4
| public void testGetChildren3()
|
389 |
| { |
390 |
4
| try
|
391 |
| { |
392 |
4
| cache.put("/1", null);
|
393 |
4
| cache.put("a", null);
|
394 |
4
| Set children = cache.getChildrenNames("");
|
395 |
4
| assertNotNull(children);
|
396 |
4
| assertEquals(2, children.size());
|
397 |
4
| assertTrue(children.contains("1"));
|
398 |
4
| assertTrue(children.contains("a"));
|
399 |
| } |
400 |
| catch (Exception e) |
401 |
| { |
402 |
0
| fail(e.toString());
|
403 |
| } |
404 |
| } |
405 |
| |
406 |
4
| public void testGetChildren4()
|
407 |
| { |
408 |
4
| try
|
409 |
| { |
410 |
4
| if (!cache.exists("/a/b/c"))
|
411 |
| { |
412 |
4
| cache.put("/a/b/c", null);
|
413 |
| } |
414 |
4
| Set children = cache.getChildrenNames((Fqn) null);
|
415 |
4
| assertTrue(children.isEmpty());
|
416 |
| } |
417 |
| catch (Exception e) |
418 |
| { |
419 |
0
| fail(e.toString());
|
420 |
| } |
421 |
| } |
422 |
| |
423 |
| |
424 |
4
| public void testGetChildren5()
|
425 |
| { |
426 |
4
| try
|
427 |
| { |
428 |
4
| cache.put("/a/1", null);
|
429 |
4
| cache.put("/a/2", null);
|
430 |
4
| cache.put("/a/3", null);
|
431 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
432 |
| |
433 |
4
| Node n = cache.get("/a");
|
434 |
4
| assertNotNull(n);
|
435 |
| |
436 |
4
| Set children = cache.getChildrenNames("/a");
|
437 |
4
| assertNotNull(children);
|
438 |
4
| assertEquals(3, children.size());
|
439 |
| } |
440 |
| catch (Exception e) |
441 |
| { |
442 |
0
| fail(e.toString());
|
443 |
| } |
444 |
| } |
445 |
| |
446 |
| |
447 |
4
| public void testGetChildren6Passivation() throws Exception
|
448 |
| { |
449 |
4
| cache.put("/a/1", null);
|
450 |
4
| cache.put("/a/2", null);
|
451 |
4
| cache.put("/a/3", null);
|
452 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
453 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
454 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
455 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
456 |
4
| cache.evict(Fqn.fromString("/a"));
|
457 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
458 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
459 |
4
| addDelay();
|
460 |
4
| assertNotNull(cache.get("/a"));
|
461 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
462 |
4
| Set children = cache.getChildrenNames("/a");
|
463 |
4
| assertNotNull("No children were loaded", children);
|
464 |
4
| System.out.println("children: " + children);
|
465 |
4
| assertEquals("3 children weren't loaded", 3, children.size());
|
466 |
4
| cache.get("/a/1", "test");
|
467 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/1")));
|
468 |
4
| cache.get("/a/2", "test");
|
469 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/2")));
|
470 |
4
| cache.get("/a/3", "test");
|
471 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/3")));
|
472 |
4
| cache.get("/a", "test");
|
473 |
4
| assertFalse(loader.exists(Fqn.fromString("/a")));
|
474 |
| } |
475 |
| |
476 |
4
| public void testGetChildren7Passivation() throws Exception
|
477 |
| { |
478 |
4
| cache.put("/a/1", null);
|
479 |
4
| cache.put("/a/2", null);
|
480 |
4
| cache.put("/a/3", null);
|
481 |
4
| cache.put("/a", "test", "test");
|
482 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
483 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
484 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
485 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
486 |
4
| cache.evict(Fqn.fromString("/a"));
|
487 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
488 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
489 |
4
| addDelay();
|
490 |
4
| Object val = cache.get("/a", "test");
|
491 |
4
| assertEquals("attributes weren't loaded", "test", val);
|
492 |
| |
493 |
4
| Set children = cache.getChildrenNames("/a");
|
494 |
4
| assertNotNull("No children were loaded", children);
|
495 |
4
| System.out.println("children: " + children);
|
496 |
4
| assertEquals("3 children weren't loaded", 3, children.size());
|
497 |
4
| cache.get("/a/1", "test");
|
498 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/1")));
|
499 |
4
| cache.get("/a/2", "test");
|
500 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/2")));
|
501 |
4
| cache.get("/a/3", "test");
|
502 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/3")));
|
503 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
504 |
| } |
505 |
| |
506 |
4
| public void testGetChildren8Passivation() throws Exception
|
507 |
| { |
508 |
4
| cache.put("/a/1", null);
|
509 |
4
| cache.put("/a/2", null);
|
510 |
4
| cache.put("/a/3", null);
|
511 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
512 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
513 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
514 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
515 |
4
| cache.evict(Fqn.fromString("/a"));
|
516 |
| |
517 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
518 |
4
| addDelay();
|
519 |
4
| assertNull(cache.get("/a", "test"));
|
520 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
521 |
| |
522 |
4
| assertNull(cache.get("/a/1", "test"));
|
523 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/1")));
|
524 |
4
| Set children = cache.getChildrenNames("/a");
|
525 |
4
| assertNotNull("No children were loaded", children);
|
526 |
4
| System.out.println("children: " + children);
|
527 |
4
| assertEquals("3 children weren't loaded", 3, children.size());
|
528 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
529 |
| } |
530 |
| |
531 |
4
| public void testGetChildren9Passivation() throws Exception
|
532 |
| { |
533 |
4
| cache.put("/a/1", null);
|
534 |
4
| cache.put("/a/2", null);
|
535 |
4
| cache.put("/a/3", null);
|
536 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
537 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
538 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
539 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
540 |
4
| cache.evict(Fqn.fromString("/a"));
|
541 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
542 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
543 |
4
| addDelay();
|
544 |
| |
545 |
4
| cache.get("/a/1", "test");
|
546 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/1")));
|
547 |
4
| cache.get("/a/2", "test");
|
548 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/2")));
|
549 |
4
| cache.get("/a/3", "test");
|
550 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/3")));
|
551 |
4
| Set children = cache.getChildrenNames("/a");
|
552 |
4
| assertNotNull("No children were loaded", children);
|
553 |
4
| System.out.println("children: " + children);
|
554 |
4
| assertEquals("3 children weren't loaded", 3, children.size());
|
555 |
4
| assertNull(cache.get("/a", "test"));
|
556 |
4
| assertFalse(loader.exists(Fqn.fromString("/a")));
|
557 |
| |
558 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
559 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
560 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
561 |
4
| cache.evict(Fqn.fromString("/a"));
|
562 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
563 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
564 |
| |
565 |
4
| cache.get("/a/1", "test");
|
566 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/1")));
|
567 |
4
| cache.get("/a/2", "test");
|
568 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/2")));
|
569 |
4
| cache.get("/a/3", "test");
|
570 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/3")));
|
571 |
4
| children = cache.getChildrenNames("/a");
|
572 |
4
| assertNotNull("No children were loaded", children);
|
573 |
4
| System.out.println("children: " + children);
|
574 |
4
| assertEquals("3 children weren't loaded", 3, children.size());
|
575 |
4
| assertNull(cache.get("/a", "test"));
|
576 |
4
| assertFalse(loader.exists(Fqn.fromString("/a")));
|
577 |
| } |
578 |
| |
579 |
| |
580 |
4
| public void testGetChildren10Passivation() throws Exception
|
581 |
| { |
582 |
4
| cache.put("/a/1", null);
|
583 |
4
| cache.put("/a/2", null);
|
584 |
4
| cache.put("/a/3", null);
|
585 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
586 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
587 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
588 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
589 |
4
| cache.evict(Fqn.fromString("/a"));
|
590 |
4
| System.out.println("cache is " + cache.printLockInfo());
|
591 |
4
| addDelay();
|
592 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
593 |
4
| assertNull(cache.get("/a", "test"));
|
594 |
| |
595 |
4
| cache.get("/a/1", "test");
|
596 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/1")));
|
597 |
4
| cache.get("/a/2", "test");
|
598 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/2")));
|
599 |
4
| cache.get("/a/3", "test");
|
600 |
4
| assertFalse(loader.exists(Fqn.fromString("/a/3")));
|
601 |
4
| Set children = cache.getChildrenNames("/a");
|
602 |
4
| assertNotNull("No children were loaded", children);
|
603 |
4
| System.out.println("children: " + children);
|
604 |
4
| assertEquals("3 children weren't loaded", 3, children.size());
|
605 |
| |
606 |
4
| assertNull(cache.get("/a", "test"));
|
607 |
4
| assertFalse(loader.exists(Fqn.fromString("/a")));
|
608 |
| } |
609 |
| |
610 |
4
| public void testRemoveData() throws Exception
|
611 |
| { |
612 |
4
| String key = "/x/y/z/";
|
613 |
4
| cache.put(key, "keyA", "valA");
|
614 |
4
| cache.put(key, "keyB", "valB");
|
615 |
4
| cache.put(key, "keyC", "valC");
|
616 |
4
| assertEquals(3, cache.getKeys(key).size());
|
617 |
4
| cache.removeData(key);
|
618 |
4
| Set keys = cache.getKeys(key);
|
619 |
4
| assertEquals(0, keys.size());
|
620 |
4
| cache.remove("/x");
|
621 |
4
| Object val = cache.get(key, "keyA");
|
622 |
4
| assertNull(val);
|
623 |
| } |
624 |
| |
625 |
| |
626 |
4
| public void testRemoveData2Passivation() throws Exception
|
627 |
| { |
628 |
4
| Set keys;
|
629 |
4
| Fqn key = Fqn.fromString("/x/y/z/");
|
630 |
4
| cache.put(key, "keyA", "valA");
|
631 |
4
| cache.put(key, "keyB", "valB");
|
632 |
4
| cache.put(key, "keyC", "valC");
|
633 |
4
| addDelay();
|
634 |
4
| keys = cache.getKeys(key);
|
635 |
4
| assertEquals(3, keys.size());
|
636 |
4
| cache.removeData(key);
|
637 |
4
| cache.evict(key);
|
638 |
| |
639 |
4
| addDelay();
|
640 |
4
| keys = cache.getKeys(key);
|
641 |
4
| assertFalse(loader.exists(key));
|
642 |
4
| assertEquals(0, keys.size());
|
643 |
| } |
644 |
| |
645 |
4
| public void testRemoveData3Passivation() throws Exception
|
646 |
| { |
647 |
4
| Set keys;
|
648 |
4
| Fqn key = Fqn.fromString("/x/y/z/");
|
649 |
4
| cache.put(key, "keyA", "valA");
|
650 |
4
| cache.put(key, "keyB", "valB");
|
651 |
4
| cache.put(key, "keyC", "valC");
|
652 |
4
| keys = cache.getKeys(key);
|
653 |
4
| assertEquals(3, keys.size());
|
654 |
4
| cache.evict(key);
|
655 |
4
| assertTrue(loader.exists(key));
|
656 |
4
| cache.removeData(key);
|
657 |
4
| keys = cache.getKeys(key);
|
658 |
4
| assertFalse(loader.exists(key));
|
659 |
4
| assertEquals(0, keys.size());
|
660 |
| } |
661 |
| |
662 |
4
| public void testRemoveKey() throws Exception
|
663 |
| { |
664 |
4
| String key = "/x/y/z/";
|
665 |
4
| cache.put(key, "keyA", "valA");
|
666 |
4
| cache.put(key, "keyB", "valB");
|
667 |
4
| cache.put(key, "keyC", "valC");
|
668 |
4
| cache.remove(key, "keyA");
|
669 |
4
| assertEquals(2, cache.getKeys(key).size());
|
670 |
4
| cache.remove("/x");
|
671 |
| } |
672 |
| |
673 |
| |
674 |
4
| public void testRemoveKey2() throws CacheException
|
675 |
| { |
676 |
4
| final String NODE = "/test";
|
677 |
4
| final String KEY = "key";
|
678 |
4
| Object retval = null;
|
679 |
4
| cache.remove(NODE);
|
680 |
4
| retval = cache.put(NODE, KEY, 10);
|
681 |
4
| assertNull(retval);
|
682 |
4
| addDelay();
|
683 |
4
| retval = cache.remove(NODE, KEY);
|
684 |
4
| assertEquals(10, retval);
|
685 |
4
| addDelay();
|
686 |
4
| retval = cache.remove(NODE, KEY);
|
687 |
4
| assertNull(retval);
|
688 |
| } |
689 |
| |
690 |
4
| public void testRemoveKey3Passivation() throws Exception
|
691 |
| { |
692 |
4
| final String NODE = "/test";
|
693 |
4
| final String KEY = "key";
|
694 |
4
| Object retval = null;
|
695 |
4
| cache.remove(NODE);
|
696 |
4
| retval = cache.put(NODE, KEY, 10);
|
697 |
4
| assertNull(retval);
|
698 |
| |
699 |
4
| cache.evict(Fqn.fromString(NODE));
|
700 |
4
| addDelay();
|
701 |
4
| assertTrue(loader.exists(Fqn.fromString(NODE)));
|
702 |
4
| assertEquals(10, loader.get(Fqn.fromString(NODE)).get(KEY));
|
703 |
4
| retval = cache.remove(NODE, KEY);
|
704 |
4
| assertEquals(10, retval);
|
705 |
4
| assertFalse(loader.exists(Fqn.fromString(NODE)));
|
706 |
| |
707 |
4
| cache.evict(Fqn.fromString(NODE));
|
708 |
4
| addDelay();
|
709 |
4
| retval = cache.remove(NODE, KEY);
|
710 |
4
| assertFalse(loader.exists(Fqn.fromString(NODE)));
|
711 |
4
| assertNull(retval);
|
712 |
| } |
713 |
| |
714 |
| |
715 |
4
| public void testRemove() throws Exception
|
716 |
| { |
717 |
4
| String key = "/x/y/z/";
|
718 |
4
| cache.put(key, "keyA", "valA");
|
719 |
4
| cache.put(key, "keyB", "valB");
|
720 |
4
| cache.put(key, "keyC", "valC");
|
721 |
4
| cache.remove("/x");
|
722 |
4
| assertNull(cache.get(key, "keyA"));
|
723 |
4
| addDelay();
|
724 |
4
| Set keys = cache.getKeys(key);
|
725 |
4
| assertNull(keys);
|
726 |
4
| cache.remove("/x");
|
727 |
| } |
728 |
| |
729 |
| |
730 |
4
| public void testRemoveRoot() throws Exception
|
731 |
| { |
732 |
4
| assertEquals(0, cache.getKeys("/").size());
|
733 |
4
| cache.put("/1/2/3/4/5", null);
|
734 |
4
| cache.put("uno/due/tre", null);
|
735 |
4
| cache.put("1/2/3/a", null);
|
736 |
4
| cache.put("/eins/zwei/drei", null);
|
737 |
4
| cache.put("/one/two/three", null);
|
738 |
4
| cache.remove("/");
|
739 |
4
| assertEquals(0, cache.getKeys("/").size());
|
740 |
| } |
741 |
| |
742 |
| |
743 |
4
| public void testEvictionWithCacheLoaderPassivation() throws Exception
|
744 |
| { |
745 |
4
| cache.put("/first/second", "key1", "val1");
|
746 |
4
| cache.put("/first/second/third", "key2", "val2");
|
747 |
4
| cache.evict(Fqn.fromString("/first/second"));
|
748 |
4
| addDelay();
|
749 |
4
| assertTrue(loader.exists(Fqn.fromString("/first/second")));
|
750 |
4
| assertTrue(cache.exists("/first"));
|
751 |
4
| String val = (String) cache.get("/first/second", "key1");
|
752 |
4
| assertTrue(loader.exists(Fqn.fromString("/first/second")));
|
753 |
4
| assertEquals("val1", val);
|
754 |
4
| String val2 = (String) cache.get("/first/second/third", "key2");
|
755 |
4
| assertFalse(loader.exists(Fqn.fromString("/first/second/third")));
|
756 |
4
| assertEquals("val2", val2);
|
757 |
4
| assertTrue(cache.exists("/first/second/third"));
|
758 |
4
| assertTrue(cache.exists("/first/second"));
|
759 |
4
| assertTrue(cache.exists("/first"));
|
760 |
| } |
761 |
| |
762 |
| |
763 |
4
| public void testEvictionWithCacheLoaderPassivation2() throws Exception
|
764 |
| { |
765 |
4
| cache.put("/first/second/third", "key1", "val1");
|
766 |
4
| cache.evict(Fqn.fromString("/first/second/third"));
|
767 |
4
| addDelay();
|
768 |
4
| assertTrue(loader.exists(Fqn.fromString("/first/second/third")));
|
769 |
4
| assertTrue(cache.exists("/first/second"));
|
770 |
4
| assertTrue(cache.exists("/first"));
|
771 |
4
| String val = (String) cache.get("/first/second/third", "key1");
|
772 |
4
| assertFalse(loader.exists(Fqn.fromString("/first/second/third")));
|
773 |
4
| assertEquals("val1", val);
|
774 |
4
| assertTrue(cache.exists("/first/second/third"));
|
775 |
4
| assertTrue(cache.exists("/first/second"));
|
776 |
4
| assertTrue(cache.exists("/first"));
|
777 |
| } |
778 |
| |
779 |
| |
780 |
4
| public void testEvictionWithGetChildrenNamesPassivation() throws Exception
|
781 |
| { |
782 |
4
| cache.put("/a/1", null);
|
783 |
4
| cache.put("/a/2", null);
|
784 |
4
| cache.put("/a/3", null);
|
785 |
4
| cache.evict(Fqn.fromString("/a/1"));
|
786 |
4
| assertTrue(loader.exists(Fqn.fromString("/a/1")));
|
787 |
4
| cache.evict(Fqn.fromString("/a/2"));
|
788 |
4
| assertTrue(loader.exists(Fqn.fromString("/a/2")));
|
789 |
4
| cache.evict(Fqn.fromString("/a/3"));
|
790 |
4
| assertTrue(loader.exists(Fqn.fromString("/a/3")));
|
791 |
4
| cache.evict(Fqn.fromString("/a"));
|
792 |
4
| assertTrue(loader.exists(Fqn.fromString("/a")));
|
793 |
4
| addDelay();
|
794 |
4
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
795 |
4
| mgr.begin();
|
796 |
4
| tx = mgr.getTransaction();
|
797 |
4
| Set children = cache.getChildrenNames("/a");
|
798 |
4
| assertEquals(3, children.size());
|
799 |
4
| assertTrue(children.contains("1"));
|
800 |
4
| assertTrue(children.contains("2"));
|
801 |
4
| assertTrue(children.contains("3"));
|
802 |
4
| assertEquals(5, cache.getNumberOfLocksHeld());
|
803 |
4
| tx.commit();
|
804 |
| } |
805 |
| |
806 |
| |
807 |
4
| public void testTxPutCommit() throws Exception, NotSupportedException
|
808 |
| { |
809 |
| |
810 |
4
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
811 |
4
| mgr.begin();
|
812 |
4
| tx = mgr.getTransaction();
|
813 |
| |
814 |
4
| cache.put("/one/two/three", "key1", "val1");
|
815 |
4
| cache.put("/one/two/three/four", "key2", "val2");
|
816 |
| |
817 |
4
| tx.commit();
|
818 |
| |
819 |
4
| assertNotNull(cache.getKeys("/one/two/three"));
|
820 |
4
| assertEquals("val1", cache.get(Fqn.fromString("/one/two/three"), "key1"));
|
821 |
4
| mgr.begin();
|
822 |
4
| tx = mgr.getTransaction();
|
823 |
| |
824 |
4
| cache.evict(Fqn.fromString("/one/two/three"));
|
825 |
4
| cache.evict(Fqn.fromString("/one/two/three/four"));
|
826 |
| |
827 |
4
| tx.commit();
|
828 |
4
| assertTrue(loader.exists(Fqn.fromString("/one/two/three")));
|
829 |
4
| assertTrue(loader.exists(Fqn.fromString("/one/two/three/four")));
|
830 |
4
| assertNotNull(cache.getKeys("/one/two/three"));
|
831 |
4
| Set children = cache.getChildrenNames("/one");
|
832 |
4
| assertEquals(1, children.size());
|
833 |
4
| cache.remove("/");
|
834 |
| } |
835 |
| |
836 |
| |
837 |
4
| public void testTxPutRollback() throws Exception
|
838 |
| { |
839 |
4
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
840 |
| |
841 |
4
| cache.remove("/one");
|
842 |
4
| addDelay();
|
843 |
4
| mgr.begin();
|
844 |
4
| tx = mgr.getTransaction();
|
845 |
| |
846 |
4
| cache.put("/one/two/three", "key1", "val1");
|
847 |
4
| cache.put("/one/two/three/four", "key2", "val2");
|
848 |
4
| tx.rollback();
|
849 |
4
| addDelay();
|
850 |
4
| assertNull(cache.getKeys("/one/two/three"));
|
851 |
4
| Set children = cache.getChildrenNames("/one");
|
852 |
4
| assertTrue(children.isEmpty());
|
853 |
4
| assertFalse(loader.exists(Fqn.fromString("/one/two/three")));
|
854 |
4
| assertFalse(loader.exists(Fqn.fromString("/one/two/three/four")));
|
855 |
| } |
856 |
| |
857 |
| |
858 |
4
| public void testPassivationAndActivation() throws Exception
|
859 |
| { |
860 |
4
| Object val, val2;
|
861 |
4
| Fqn NODE = Fqn.fromString("/test");
|
862 |
4
| loader.remove(Fqn.fromString("/"));
|
863 |
4
| cache.put(NODE, "key", "val");
|
864 |
| |
865 |
4
| assertNull("value cannot be passivated yet (only on eviction)", loader.get(NODE));
|
866 |
4
| cache.evict(NODE);
|
867 |
4
| assertEquals(0, cache.getNumberOfNodes());
|
868 |
4
| assertEquals(0, cache.getNumberOfAttributes());
|
869 |
4
| val = loader.get(NODE).get("key");
|
870 |
4
| assertNotNull("value must have been passivated on evict()", val);
|
871 |
4
| assertEquals(val, "val");
|
872 |
4
| val2 = cache.get(NODE, "key");
|
873 |
4
| assertNotNull(val2);
|
874 |
4
| assertEquals(val, val2);
|
875 |
| |
876 |
4
| assertNull("value should have been deleted from store on activation", loader.get(NODE));
|
877 |
| } |
878 |
| |
879 |
| |
880 |
| |
881 |
| |
882 |
| |
883 |
4
| public void testBasicOperations()
|
884 |
| throws Exception |
885 |
| { |
886 |
| |
887 |
4
| doTestBasicOperations();
|
888 |
| } |
889 |
| |
890 |
| |
891 |
| |
892 |
| |
893 |
4
| public void testBasicOperationsTransactional()
|
894 |
| throws Exception |
895 |
| { |
896 |
| |
897 |
4
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
898 |
4
| mgr.begin();
|
899 |
4
| tx = mgr.getTransaction();
|
900 |
4
| doTestBasicOperations();
|
901 |
4
| tx.commit();
|
902 |
| } |
903 |
| |
904 |
| |
905 |
| |
906 |
| |
907 |
8
| private void doTestBasicOperations() throws Exception
|
908 |
| { |
909 |
| |
910 |
| |
911 |
8
| doPutTests(new Fqn("key"));
|
912 |
8
| doRemoveTests(new Fqn("key"));
|
913 |
| |
914 |
| |
915 |
| |
916 |
8
| doPutTests(new Fqn("key1"));
|
917 |
8
| doPutTests(new Fqn("key3"));
|
918 |
8
| doPutTests(new Fqn("key2"));
|
919 |
8
| assertEquals(4, loader.get(new Fqn("key1")).size());
|
920 |
8
| assertEquals(4, loader.get(new Fqn("key2")).size());
|
921 |
8
| assertEquals(4, loader.get(new Fqn("key3")).size());
|
922 |
| |
923 |
| |
924 |
8
| doRemoveTests(new Fqn("key2"));
|
925 |
8
| doRemoveTests(new Fqn("key3"));
|
926 |
8
| doRemoveTests(new Fqn("key1"));
|
927 |
8
| assertEquals(null, loader.get(new Fqn("key1")));
|
928 |
8
| assertEquals(null, loader.get(new Fqn("key2")));
|
929 |
8
| assertEquals(null, loader.get(new Fqn("key3")));
|
930 |
| |
931 |
| } |
932 |
| |
933 |
| |
934 |
| |
935 |
| |
936 |
32
| private void doPutTests(Fqn fqn)
|
937 |
| throws Exception |
938 |
| { |
939 |
| |
940 |
32
| assertTrue(!loader.exists(fqn));
|
941 |
| |
942 |
| |
943 |
32
| Object oldVal;
|
944 |
32
| oldVal = loader.put(fqn, "one", "two");
|
945 |
32
| assertNull(oldVal);
|
946 |
32
| addDelay();
|
947 |
32
| oldVal = loader.put(fqn, "three", "four");
|
948 |
32
| assertNull(oldVal);
|
949 |
32
| addDelay();
|
950 |
32
| assertEquals("two", loader.get(fqn).get("one"));
|
951 |
32
| assertEquals("four", loader.get(fqn).get("three"));
|
952 |
32
| addDelay();
|
953 |
32
| oldVal = loader.put(fqn, "one", "xxx");
|
954 |
32
| assertEquals("two", oldVal);
|
955 |
32
| addDelay();
|
956 |
32
| oldVal = loader.put(fqn, "one", "two");
|
957 |
32
| assertEquals("xxx", oldVal);
|
958 |
| |
959 |
| |
960 |
32
| addDelay();
|
961 |
32
| Map map = loader.get(fqn);
|
962 |
32
| assertEquals(2, map.size());
|
963 |
32
| assertEquals("two", map.get("one"));
|
964 |
32
| assertEquals("four", map.get("three"));
|
965 |
| |
966 |
32
| Map map2 = new HashMap(map);
|
967 |
| |
968 |
32
| map2.put("five", "six");
|
969 |
32
| map2.put("seven", "eight");
|
970 |
32
| loader.put(fqn, map2);
|
971 |
32
| addDelay();
|
972 |
32
| assertEquals("six", loader.get(fqn).get("five"));
|
973 |
32
| assertEquals("eight", loader.get(fqn).get("seven"));
|
974 |
32
| assertEquals(map2, loader.get(fqn));
|
975 |
32
| assertEquals(4, map2.size());
|
976 |
| |
977 |
32
| assertTrue(loader.exists(fqn));
|
978 |
| } |
979 |
| |
980 |
| |
981 |
| |
982 |
| |
983 |
32
| private void doRemoveTests(Fqn fqn)
|
984 |
| throws Exception |
985 |
| { |
986 |
| |
987 |
| |
988 |
32
| Object oldVal;
|
989 |
32
| oldVal = loader.remove(fqn, "one");
|
990 |
32
| assertEquals("two", oldVal);
|
991 |
32
| addDelay();
|
992 |
32
| oldVal = loader.remove(fqn, "five");
|
993 |
32
| assertEquals("six", oldVal);
|
994 |
32
| addDelay();
|
995 |
32
| assertEquals(null, loader.get(fqn).get("one"));
|
996 |
32
| assertEquals(null, loader.get(fqn).get("five"));
|
997 |
32
| assertEquals("four", loader.get(fqn).get("three"));
|
998 |
32
| assertEquals("eight", loader.get(fqn).get("seven"));
|
999 |
32
| Map map = loader.get(fqn);
|
1000 |
32
| assertEquals(2, map.size());
|
1001 |
32
| assertEquals("four", map.get("three"));
|
1002 |
32
| assertEquals("eight", map.get("seven"));
|
1003 |
| |
1004 |
| |
1005 |
32
| assertTrue(loader.exists(fqn));
|
1006 |
32
| loader.remove(fqn);
|
1007 |
32
| addDelay();
|
1008 |
32
| assertNull(loader.get(fqn));
|
1009 |
32
| assertTrue(!loader.exists(fqn));
|
1010 |
| } |
1011 |
| |
1012 |
| |
1013 |
| |
1014 |
| |
1015 |
| |
1016 |
4
| public void testMultiLevelTree()
|
1017 |
| throws Exception |
1018 |
| { |
1019 |
| |
1020 |
| |
1021 |
4
| assertTrue(!loader.exists(new Fqn("key0")));
|
1022 |
4
| loader.put(Fqn.fromString("/key0/level1/level2"), null);
|
1023 |
4
| addDelay();
|
1024 |
4
| assertTrue(loader.exists(Fqn.fromString("/key0/level1/level2")));
|
1025 |
4
| assertTrue(loader.exists(Fqn.fromString("/key0/level1")));
|
1026 |
4
| assertTrue(loader.exists(new Fqn("key0")));
|
1027 |
| |
1028 |
| |
1029 |
4
| loader.put(Fqn.fromString("/key0/x/y"), null);
|
1030 |
4
| addDelay();
|
1031 |
4
| assertTrue(loader.exists(Fqn.fromString("/key0/x/y")));
|
1032 |
4
| assertTrue(loader.exists(Fqn.fromString("/key0/x")));
|
1033 |
4
| loader.remove(Fqn.fromString("/key0/x/y"));
|
1034 |
4
| addDelay();
|
1035 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key0/x/y")));
|
1036 |
4
| assertTrue(loader.exists(Fqn.fromString("/key0/x")));
|
1037 |
| |
1038 |
| |
1039 |
4
| loader.remove(new Fqn("key0"));
|
1040 |
4
| addDelay();
|
1041 |
4
| assertTrue(!loader.exists(new Fqn("key0")));
|
1042 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key0/level1/level2")));
|
1043 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key0/level1")));
|
1044 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key0/x")));
|
1045 |
| |
1046 |
| |
1047 |
4
| loader.put(new Fqn("key1"), null);
|
1048 |
4
| loader.put(new Fqn("key2"), null);
|
1049 |
4
| loader.put(new Fqn("key3"), null);
|
1050 |
4
| addDelay();
|
1051 |
4
| assertTrue(loader.exists(new Fqn("key1")));
|
1052 |
4
| assertTrue(loader.exists(new Fqn("key2")));
|
1053 |
4
| assertTrue(loader.exists(new Fqn("key3")));
|
1054 |
| |
1055 |
| |
1056 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key3/level1")));
|
1057 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key3/level1/level2")));
|
1058 |
4
| loader.put(Fqn.fromString("/key3/level1/level2"), null);
|
1059 |
4
| addDelay();
|
1060 |
4
| assertTrue(loader.exists(Fqn.fromString("/key3/level1/level2")));
|
1061 |
4
| assertTrue(loader.exists(Fqn.fromString("/key3/level1")));
|
1062 |
| |
1063 |
| |
1064 |
4
| assertTrue(loader.exists(new Fqn("key1")));
|
1065 |
4
| assertTrue(loader.exists(new Fqn("key2")));
|
1066 |
4
| assertTrue(loader.exists(new Fqn("key3")));
|
1067 |
| |
1068 |
| |
1069 |
4
| loader.remove(Fqn.fromString("/key3/level1"));
|
1070 |
4
| addDelay();
|
1071 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key3/level1/level2")));
|
1072 |
4
| assertTrue(!loader.exists(Fqn.fromString("/key3/level1")));
|
1073 |
| |
1074 |
| |
1075 |
4
| assertTrue(loader.exists(new Fqn("key1")));
|
1076 |
4
| assertTrue(loader.exists(new Fqn("key2")));
|
1077 |
4
| assertTrue(loader.exists(new Fqn("key3")));
|
1078 |
| |
1079 |
| |
1080 |
4
| loader.remove(new Fqn("key1"));
|
1081 |
4
| addDelay();
|
1082 |
4
| assertTrue(!loader.exists(new Fqn("key1")));
|
1083 |
4
| assertTrue(loader.exists(new Fqn("key2")));
|
1084 |
4
| assertTrue(loader.exists(new Fqn("key3")));
|
1085 |
| |
1086 |
| |
1087 |
4
| loader.remove(new Fqn("key3"));
|
1088 |
4
| addDelay();
|
1089 |
4
| assertTrue(loader.exists(new Fqn("key2")));
|
1090 |
4
| assertTrue(!loader.exists(new Fqn("key3")));
|
1091 |
| |
1092 |
| |
1093 |
4
| loader.remove(new Fqn("key2"));
|
1094 |
4
| addDelay();
|
1095 |
4
| assertTrue(!loader.exists(new Fqn("key0")));
|
1096 |
4
| assertTrue(!loader.exists(new Fqn("key1")));
|
1097 |
4
| assertTrue(!loader.exists(new Fqn("key2")));
|
1098 |
4
| assertTrue(!loader.exists(new Fqn("key3")));
|
1099 |
| |
1100 |
| |
1101 |
| |
1102 |
4
| assertNull(loader.get(new Fqn("key0")));
|
1103 |
4
| loader.put(Fqn.fromString("/key0/level1/level2"), "a", "b");
|
1104 |
4
| addDelay();
|
1105 |
4
| assertNotNull(loader.get(Fqn.fromString("/key0/level1/level2")));
|
1106 |
4
| assertNotNull(loader.get(Fqn.fromString("/key0/level1")));
|
1107 |
4
| assertTrue(loader.get(Fqn.fromString("/key0/level1")).isEmpty());
|
1108 |
4
| assertNotNull(loader.get(new Fqn("key0")));
|
1109 |
4
| assertTrue(loader.get(Fqn.fromString("/key0")).isEmpty());
|
1110 |
| |
1111 |
4
| loader.put(Fqn.fromString("/key0/x/y"), "a", "b");
|
1112 |
4
| addDelay();
|
1113 |
4
| assertNotNull(loader.get(Fqn.fromString("/key0/x/y")));
|
1114 |
4
| assertNotNull(loader.get(Fqn.fromString("/key0/x")));
|
1115 |
4
| assertTrue(loader.get(Fqn.fromString("/key0/x")).isEmpty());
|
1116 |
4
| loader.remove(Fqn.fromString("/key0/x/y"));
|
1117 |
4
| addDelay();
|
1118 |
4
| assertNull(loader.get(Fqn.fromString("/key0/x/y")));
|
1119 |
4
| assertNotNull(loader.get(Fqn.fromString("/key0/x")));
|
1120 |
4
| assertTrue(loader.get(Fqn.fromString("/key0/x")).isEmpty());
|
1121 |
| |
1122 |
4
| loader.remove(new Fqn("key0"));
|
1123 |
4
| addDelay();
|
1124 |
4
| assertNull(loader.get(new Fqn("key0")));
|
1125 |
4
| assertNull(loader.get(Fqn.fromString("/key0/level1/level2")));
|
1126 |
4
| assertNull(loader.get(Fqn.fromString("/key0/level1")));
|
1127 |
4
| assertNull(loader.get(Fqn.fromString("/key0/x")));
|
1128 |
| |
1129 |
4
| loader.put(new Fqn("key1"), "a", "b");
|
1130 |
4
| loader.put(new Fqn("key2"), "a", "b");
|
1131 |
4
| loader.put(new Fqn("key3"), "a", "b");
|
1132 |
4
| addDelay();
|
1133 |
4
| assertNotNull(loader.get(new Fqn("key1")));
|
1134 |
4
| assertNotNull(loader.get(new Fqn("key2")));
|
1135 |
4
| assertNotNull(loader.get(new Fqn("key3")));
|
1136 |
| |
1137 |
4
| assertNull(loader.get(Fqn.fromString("/key3/level1")));
|
1138 |
4
| assertNull(loader.get(Fqn.fromString("/key3/level1/level2")));
|
1139 |
4
| loader.put(Fqn.fromString("/key3/level1/level2"), "a", "b");
|
1140 |
4
| addDelay();
|
1141 |
4
| assertNotNull(loader.get(Fqn.fromString("/key3/level1/level2")));
|
1142 |
4
| assertNotNull(loader.get(Fqn.fromString("/key3/level1")));
|
1143 |
4
| assertTrue(loader.get(Fqn.fromString("/key3/level1")).isEmpty());
|
1144 |
| |
1145 |
4
| assertNotNull(loader.get(new Fqn("key1")));
|
1146 |
4
| assertNotNull(loader.get(new Fqn("key2")));
|
1147 |
4
| assertNotNull(loader.get(new Fqn("key3")));
|
1148 |
| |
1149 |
4
| loader.remove(Fqn.fromString("/key3/level1"));
|
1150 |
4
| addDelay();
|
1151 |
4
| assertNull(loader.get(Fqn.fromString("/key3/level1/level2")));
|
1152 |
4
| assertNull(loader.get(Fqn.fromString("/key3/level1")));
|
1153 |
| |
1154 |
4
| assertNotNull(loader.get(new Fqn("key1")));
|
1155 |
4
| assertNotNull(loader.get(new Fqn("key2")));
|
1156 |
4
| assertNotNull(loader.get(new Fqn("key3")));
|
1157 |
| |
1158 |
4
| loader.remove(new Fqn("key1"));
|
1159 |
4
| addDelay();
|
1160 |
4
| assertNull(loader.get(new Fqn("key1")));
|
1161 |
4
| assertNotNull(loader.get(new Fqn("key2")));
|
1162 |
4
| assertNotNull(loader.get(new Fqn("key3")));
|
1163 |
| |
1164 |
4
| loader.remove(new Fqn("key3"));
|
1165 |
4
| addDelay();
|
1166 |
4
| assertNotNull(loader.get(new Fqn("key2")));
|
1167 |
4
| assertNull(loader.get(new Fqn("key3")));
|
1168 |
| |
1169 |
4
| loader.remove(new Fqn("key2"));
|
1170 |
4
| addDelay();
|
1171 |
4
| assertNull(loader.get(new Fqn("key0")));
|
1172 |
4
| assertNull(loader.get(new Fqn("key1")));
|
1173 |
4
| assertNull(loader.get(new Fqn("key2")));
|
1174 |
4
| assertNull(loader.get(new Fqn("key3")));
|
1175 |
| } |
1176 |
| |
1177 |
| |
1178 |
| |
1179 |
| |
1180 |
4
| public void testGetChildrenNames()
|
1181 |
| throws Exception |
1182 |
| { |
1183 |
| |
1184 |
4
| checkChildren(new Fqn(), null);
|
1185 |
4
| checkChildren(Fqn.fromString("/key0"), null);
|
1186 |
| |
1187 |
4
| loader.put(Fqn.fromString("/key0"), null);
|
1188 |
4
| addDelay();
|
1189 |
4
| checkChildren(new Fqn(), new String[]{"key0"});
|
1190 |
| |
1191 |
4
| loader.put(Fqn.fromString("/key1/x"), null);
|
1192 |
4
| addDelay();
|
1193 |
4
| checkChildren(new Fqn(), new String[]{"key0", "key1"});
|
1194 |
4
| checkChildren(Fqn.fromString("/key1"), new String[]{"x"});
|
1195 |
| |
1196 |
4
| loader.remove(Fqn.fromString("/key1/x"));
|
1197 |
4
| addDelay();
|
1198 |
4
| checkChildren(new Fqn(), new String[]{"key0", "key1"});
|
1199 |
4
| checkChildren(Fqn.fromString("/key0"), null);
|
1200 |
4
| checkChildren(Fqn.fromString("/key1"), null);
|
1201 |
| |
1202 |
4
| loader.put(Fqn.fromString("/key0/a"), null);
|
1203 |
4
| loader.put(Fqn.fromString("/key0/ab"), null);
|
1204 |
4
| loader.put(Fqn.fromString("/key0/abc"), null);
|
1205 |
4
| addDelay();
|
1206 |
4
| checkChildren(Fqn.fromString("/key0"),
|
1207 |
| new String[]{"a", "ab", "abc"}); |
1208 |
| |
1209 |
4
| loader.put(Fqn.fromString("/key0/xxx"), null);
|
1210 |
4
| loader.put(Fqn.fromString("/key0/xx"), null);
|
1211 |
4
| loader.put(Fqn.fromString("/key0/x"), null);
|
1212 |
4
| addDelay();
|
1213 |
4
| checkChildren(Fqn.fromString("/key0"),
|
1214 |
| new String[]{"a", "ab", "abc", "x", "xx", "xxx"}); |
1215 |
| |
1216 |
4
| loader.put(Fqn.fromString("/key0/a/1"), null);
|
1217 |
4
| loader.put(Fqn.fromString("/key0/a/2"), null);
|
1218 |
4
| loader.put(Fqn.fromString("/key0/a/2/1"), null);
|
1219 |
4
| addDelay();
|
1220 |
4
| checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
|
1221 |
4
| checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
|
1222 |
4
| checkChildren(Fqn.fromString("/key0"),
|
1223 |
| new String[]{"a", "ab", "abc", "x", "xx", "xxx"}); |
1224 |
| |
1225 |
| |
1226 |
| |
1227 |
| |
1228 |
| |
1229 |
| |
1230 |
| |
1231 |
| |
1232 |
| |
1233 |
| |
1234 |
| |
1235 |
| |
1236 |
| |
1237 |
| |
1238 |
| |
1239 |
| |
1240 |
| |
1241 |
| |
1242 |
| |
1243 |
| |
1244 |
| } |
1245 |
| |
1246 |
| |
1247 |
| |
1248 |
| |
1249 |
52
| private void checkChildren(Fqn fqn, String[] names)
|
1250 |
| throws Exception |
1251 |
| { |
1252 |
| |
1253 |
52
| Set set = loader.getChildrenNames(fqn);
|
1254 |
52
| if (names != null)
|
1255 |
| { |
1256 |
36
| assertEquals(names.length, set.size());
|
1257 |
36
| for (int i = 0; i < names.length; i += 1)
|
1258 |
| { |
1259 |
96
| assertTrue(set.contains(names[i]));
|
1260 |
| } |
1261 |
| } |
1262 |
| else |
1263 |
| { |
1264 |
16
| assertNull(set);
|
1265 |
| } |
1266 |
| } |
1267 |
| |
1268 |
| |
1269 |
| |
1270 |
| |
1271 |
4
| public void testModifications()
|
1272 |
| throws Exception |
1273 |
| { |
1274 |
| |
1275 |
4
| doTestModifications();
|
1276 |
| } |
1277 |
| |
1278 |
| |
1279 |
| |
1280 |
| |
1281 |
4
| public void testModificationsTransactional()
|
1282 |
| throws Exception |
1283 |
| { |
1284 |
4
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
1285 |
4
| mgr.begin();
|
1286 |
4
| tx = mgr.getTransaction();
|
1287 |
4
| doTestModifications();
|
1288 |
4
| tx.commit();
|
1289 |
| } |
1290 |
| |
1291 |
| |
1292 |
| |
1293 |
| |
1294 |
8
| private void doTestModifications()
|
1295 |
| throws Exception |
1296 |
| { |
1297 |
| |
1298 |
| |
1299 |
8
| List list = createUpdates();
|
1300 |
8
| loader.put(list);
|
1301 |
8
| addDelay();
|
1302 |
8
| checkModifications(list);
|
1303 |
| |
1304 |
| |
1305 |
8
| list = new ArrayList();
|
1306 |
8
| Modification mod = new Modification();
|
1307 |
8
| mod.setType(Modification.ModificationType.REMOVE_KEY_VALUE);
|
1308 |
8
| mod.setFqn(FQN);
|
1309 |
8
| mod.setKey("one");
|
1310 |
8
| list.add(mod);
|
1311 |
8
| loader.put(list);
|
1312 |
8
| addDelay();
|
1313 |
8
| checkModifications(list);
|
1314 |
| |
1315 |
| |
1316 |
8
| list = new ArrayList();
|
1317 |
8
| mod = new Modification();
|
1318 |
8
| mod.setType(Modification.ModificationType.REMOVE_NODE);
|
1319 |
8
| mod.setFqn(FQN);
|
1320 |
8
| list.add(mod);
|
1321 |
8
| loader.put(list);
|
1322 |
8
| addDelay();
|
1323 |
8
| checkModifications(list);
|
1324 |
8
| assertEquals(null, loader.get(FQN));
|
1325 |
| |
1326 |
| |
1327 |
8
| loader.put(FQN, "one", "two");
|
1328 |
8
| list = new ArrayList();
|
1329 |
8
| mod = new Modification();
|
1330 |
8
| mod.setType(Modification.ModificationType.REMOVE_DATA);
|
1331 |
8
| mod.setFqn(FQN);
|
1332 |
8
| list.add(mod);
|
1333 |
8
| loader.put(list);
|
1334 |
8
| addDelay();
|
1335 |
8
| checkModifications(list);
|
1336 |
| } |
1337 |
| |
1338 |
| |
1339 |
| |
1340 |
| |
1341 |
4
| public void testOnePhaseTransaction()
|
1342 |
| throws Exception |
1343 |
| { |
1344 |
4
| List mods = createUpdates();
|
1345 |
4
| loader.prepare(null, mods, true);
|
1346 |
4
| checkModifications(mods);
|
1347 |
| } |
1348 |
| |
1349 |
| |
1350 |
| |
1351 |
| |
1352 |
4
| public void testTwoPhaseTransactionPassivation()
|
1353 |
| throws Exception |
1354 |
| { |
1355 |
| |
1356 |
4
| Object txnKey = new Object();
|
1357 |
4
| List mods = createUpdates();
|
1358 |
4
| loader.prepare(txnKey, mods, false);
|
1359 |
| |
1360 |
| |
1361 |
| |
1362 |
| |
1363 |
4
| loader.commit(txnKey);
|
1364 |
4
| addDelay();
|
1365 |
4
| checkModifications(mods);
|
1366 |
| } |
1367 |
| |
1368 |
| |
1369 |
| |
1370 |
| |
1371 |
4
| public void testTransactionRollbackPassivation()
|
1372 |
| throws Exception |
1373 |
| { |
1374 |
| |
1375 |
4
| loader.remove(Fqn.fromString("/"));
|
1376 |
| |
1377 |
4
| ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
1378 |
4
| MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
|
1379 |
4
| loader.loadEntireState(os);
|
1380 |
4
| os.close();
|
1381 |
4
| int num = baos.size();
|
1382 |
| |
1383 |
4
| Object txnKey = new Object();
|
1384 |
4
| List mods = createUpdates();
|
1385 |
4
| loader.prepare(txnKey, mods, false);
|
1386 |
4
| loader.rollback(txnKey);
|
1387 |
| |
1388 |
4
| baos = new ByteArrayOutputStream(1024);
|
1389 |
4
| os = new MarshalledValueOutputStream(baos);
|
1390 |
4
| loader.loadEntireState(os);
|
1391 |
4
| os.close();
|
1392 |
| |
1393 |
4
| assertEquals(num, baos.size());
|
1394 |
| } |
1395 |
| |
1396 |
| |
1397 |
| |
1398 |
| |
1399 |
20
| private List createUpdates()
|
1400 |
| { |
1401 |
| |
1402 |
20
| List list = new ArrayList();
|
1403 |
| |
1404 |
20
| Modification mod = new Modification();
|
1405 |
20
| mod.setType(Modification.ModificationType.PUT_KEY_VALUE);
|
1406 |
20
| mod.setFqn(FQN);
|
1407 |
20
| mod.setKey("one");
|
1408 |
20
| mod.setValue("two");
|
1409 |
20
| list.add(mod);
|
1410 |
| |
1411 |
20
| mod = new Modification();
|
1412 |
20
| mod.setType(Modification.ModificationType.PUT_KEY_VALUE);
|
1413 |
20
| mod.setFqn(FQN);
|
1414 |
20
| mod.setKey("three");
|
1415 |
20
| mod.setValue("four");
|
1416 |
20
| list.add(mod);
|
1417 |
| |
1418 |
20
| Map map = new HashMap();
|
1419 |
20
| map.put("five", "six");
|
1420 |
20
| map.put("seven", "eight");
|
1421 |
20
| mod = new Modification();
|
1422 |
20
| mod.setType(Modification.ModificationType.PUT_DATA);
|
1423 |
20
| mod.setFqn(FQN);
|
1424 |
20
| mod.setData(map);
|
1425 |
20
| list.add(mod);
|
1426 |
| |
1427 |
20
| return list;
|
1428 |
| } |
1429 |
| |
1430 |
| |
1431 |
| |
1432 |
| |
1433 |
40
| private void checkModifications(List list)
|
1434 |
| throws Exception |
1435 |
| { |
1436 |
| |
1437 |
40
| for (int i = 0; i < list.size(); i += 1)
|
1438 |
| { |
1439 |
72
| Modification mod = (Modification) list.get(i);
|
1440 |
72
| Fqn fqn = mod.getFqn();
|
1441 |
72
| switch (mod.getType())
|
1442 |
| { |
1443 |
32
| case PUT_KEY_VALUE:
|
1444 |
32
| assertEquals(mod.getValue(), loader.get(fqn).get(mod.getKey()));
|
1445 |
32
| break;
|
1446 |
16
| case PUT_DATA:
|
1447 |
16
| Map map = mod.getData();
|
1448 |
16
| for (Iterator iter = map.keySet().iterator(); iter.hasNext();)
|
1449 |
| { |
1450 |
32
| Object key = iter.next();
|
1451 |
32
| assertEquals(map.get(key), loader.get(fqn).get(key));
|
1452 |
| } |
1453 |
16
| break;
|
1454 |
8
| case REMOVE_KEY_VALUE:
|
1455 |
8
| assertEquals(null, loader.get(fqn).get(mod.getKey()));
|
1456 |
8
| break;
|
1457 |
8
| case REMOVE_DATA:
|
1458 |
8
| map = loader.get(fqn);
|
1459 |
8
| assertNotNull(map);
|
1460 |
8
| assertTrue(map.isEmpty());
|
1461 |
8
| break;
|
1462 |
8
| case REMOVE_NODE:
|
1463 |
8
| assertEquals(null, loader.get(fqn));
|
1464 |
8
| break;
|
1465 |
0
| default:
|
1466 |
0
| fail("unknown type: " + mod);
|
1467 |
0
| break;
|
1468 |
| } |
1469 |
| } |
1470 |
| } |
1471 |
| |
1472 |
| |
1473 |
| |
1474 |
| |
1475 |
| |
1476 |
4
| public void testNullKeysAndValues()
|
1477 |
| throws Exception |
1478 |
| { |
1479 |
| |
1480 |
4
| loader.put(FQN, null, "x");
|
1481 |
4
| addDelay();
|
1482 |
4
| assertEquals("x", loader.get(FQN).get(null));
|
1483 |
4
| Map map = loader.get(FQN);
|
1484 |
4
| assertEquals(1, map.size());
|
1485 |
4
| assertEquals("x", map.get(null));
|
1486 |
| |
1487 |
4
| loader.put(FQN, "y", null);
|
1488 |
4
| addDelay();
|
1489 |
4
| assertEquals(null, loader.get(FQN).get("y"));
|
1490 |
4
| map = loader.get(FQN);
|
1491 |
4
| assertEquals(2, map.size());
|
1492 |
4
| assertEquals("x", map.get(null));
|
1493 |
4
| assertEquals(null, map.get("y"));
|
1494 |
| |
1495 |
4
| loader.remove(FQN, null);
|
1496 |
4
| addDelay();
|
1497 |
4
| assertEquals(null, loader.get(FQN).get(null));
|
1498 |
4
| assertEquals(1, loader.get(FQN).size());
|
1499 |
| |
1500 |
4
| loader.remove(FQN, "y");
|
1501 |
4
| addDelay();
|
1502 |
4
| assertNotNull(loader.get(FQN));
|
1503 |
4
| assertNull(loader.get(FQN).get("y"));
|
1504 |
4
| assertEquals(0, loader.get(FQN).size());
|
1505 |
| |
1506 |
4
| map = new HashMap();
|
1507 |
4
| map.put(null, null);
|
1508 |
4
| loader.put(FQN, map);
|
1509 |
4
| addDelay();
|
1510 |
4
| assertEquals(map, loader.get(FQN));
|
1511 |
| |
1512 |
4
| loader.remove(FQN);
|
1513 |
4
| addDelay();
|
1514 |
4
| assertNull(loader.get(FQN));
|
1515 |
| |
1516 |
4
| map = new HashMap();
|
1517 |
4
| map.put("xyz", null);
|
1518 |
4
| map.put(null, "abc");
|
1519 |
4
| loader.put(FQN, map);
|
1520 |
4
| addDelay();
|
1521 |
4
| assertEquals(map, loader.get(FQN));
|
1522 |
| |
1523 |
4
| loader.remove(FQN);
|
1524 |
4
| addDelay();
|
1525 |
4
| assertNull(loader.get(FQN));
|
1526 |
| } |
1527 |
| |
1528 |
| |
1529 |
| |
1530 |
| |
1531 |
4
| public void testDatabaseNamePassivation()
|
1532 |
| throws Exception |
1533 |
| { |
1534 |
| |
1535 |
4
| loader.put(FQN, "one", "two");
|
1536 |
4
| addDelay();
|
1537 |
4
| assertEquals("two", loader.get(FQN).get("one"));
|
1538 |
| } |
1539 |
| |
1540 |
| |
1541 |
| |
1542 |
| |
1543 |
3
| public void testLoadAndStore()
|
1544 |
| throws Exception |
1545 |
| { |
1546 |
| |
1547 |
| |
1548 |
3
| loader.remove(Fqn.fromString("/"));
|
1549 |
| |
1550 |
| |
1551 |
| |
1552 |
| |
1553 |
| |
1554 |
| |
1555 |
| |
1556 |
| |
1557 |
3
| Complex c1 = new Complex();
|
1558 |
3
| Complex c2 = new Complex(c1);
|
1559 |
| |
1560 |
| |
1561 |
3
| loader.put(FQN, 1, c1);
|
1562 |
3
| loader.put(FQN, 2, c2);
|
1563 |
3
| addDelay();
|
1564 |
3
| assertEquals(c1, loader.get(FQN).get(1));
|
1565 |
3
| assertEquals(c2, loader.get(FQN).get(2));
|
1566 |
3
| assertEquals(2, loader.get(FQN).size());
|
1567 |
| |
1568 |
| |
1569 |
3
| ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
1570 |
3
| MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
|
1571 |
3
| loader.loadEntireState(os);
|
1572 |
3
| cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE, os);
|
1573 |
3
| os.close();
|
1574 |
3
| assertTrue(baos.size() > 0);
|
1575 |
| |
1576 |
3
| byte[] savedState = baos.toByteArray();
|
1577 |
| |
1578 |
| |
1579 |
3
| ByteArrayInputStream bais = new ByteArrayInputStream(savedState);
|
1580 |
3
| MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
|
1581 |
3
| loader.storeEntireState(is);
|
1582 |
3
| is.close();
|
1583 |
| |
1584 |
3
| addDelay();
|
1585 |
3
| assertEquals(c1, loader.get(FQN).get(1));
|
1586 |
3
| assertEquals(c2, loader.get(FQN).get(2));
|
1587 |
3
| assertEquals(2, loader.get(FQN).size());
|
1588 |
| } |
1589 |
| |
1590 |
| |
1591 |
| |
1592 |
| |
1593 |
| |
1594 |
| private static class Complex implements Serializable |
1595 |
| { |
1596 |
| |
1597 |
| |
1598 |
| |
1599 |
| private static final long serialVersionUID = 8950692199236424832L; |
1600 |
| |
1601 |
| Complex nested; |
1602 |
| |
1603 |
3
| Complex()
|
1604 |
| { |
1605 |
3
| this(null);
|
1606 |
| } |
1607 |
| |
1608 |
6
| Complex(Complex nested)
|
1609 |
| { |
1610 |
6
| this.nested = nested;
|
1611 |
| } |
1612 |
| |
1613 |
18
| public boolean equals(Object o)
|
1614 |
| { |
1615 |
18
| try
|
1616 |
| { |
1617 |
18
| Complex x = (Complex) o;
|
1618 |
18
| return (nested != null) ? nested.equals(x.nested)
|
1619 |
| : (x.nested == null); |
1620 |
| } |
1621 |
| catch (ClassCastException e) |
1622 |
| { |
1623 |
0
| return false;
|
1624 |
| } |
1625 |
| } |
1626 |
| |
1627 |
60
| public int hashCode()
|
1628 |
| { |
1629 |
60
| if (nested == null)
|
1630 |
| { |
1631 |
42
| return super.hashCode();
|
1632 |
| } |
1633 |
| else |
1634 |
| { |
1635 |
18
| return 13 + nested.hashCode();
|
1636 |
| } |
1637 |
| } |
1638 |
| } |
1639 |
| |
1640 |
| |
1641 |
0
| public static Test suite()
|
1642 |
| { |
1643 |
0
| return new TestSuite(PassivationTestsBase.class);
|
1644 |
| } |
1645 |
| |
1646 |
0
| public static void main(String[] args)
|
1647 |
| { |
1648 |
0
| junit.textui.TestRunner.run(suite());
|
1649 |
| } |
1650 |
| |
1651 |
| } |