| 1 package org.jboss.cache.tests.loader; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.jboss.cache.*; 7 import org.jboss.cache.loader.CacheLoader; 8 import org.jboss.cache.transaction.DummyTransactionManager; 9 10 import javax.transaction.NotSupportedException ; 11 import javax.transaction.Transaction ; 12 import java.io.Serializable ; 13 import java.util.*; 14 15 20 abstract public class CacheLoaderTestsBase extends TestCase { 21 TreeCache cache; 22 CacheLoader loader=null; 23 Transaction tx=null; 24 static final Fqn FQN = new Fqn("key"); 25 26 27 protected void setUp() throws Exception { 28 super.setUp(); 29 cache=new TreeCache(); 30 cache.setCacheMode("local"); 31 configureCache(); 32 cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 34 cache.createService(); 35 cache.startService(); 36 loader=cache.getCacheLoader(); 37 } 38 39 abstract protected void configureCache() throws Exception ; 40 41 42 protected void tearDown() throws Exception { 43 super.tearDown(); 44 if(tx != null) { 45 try { 46 tx.commit(); 47 } 48 catch(Throwable e) { 49 e.printStackTrace(); 50 } 51 } 52 cache.remove("/"); 53 loader.remove(Fqn.fromString("/")); 54 cache.stopService(); 55 cache.destroyService(); 56 } 57 58 59 60 public void testPrint() throws CacheException { 61 final Fqn NODE=Fqn.fromString("/test"); 62 final String KEY="key"; 63 cache.put(NODE, KEY, new Integer (10)); 64 cache.evict(NODE); 65 String ret=cache.print(NODE); 66 assertNotNull(ret); 67 } 68 69 public void testPut() throws CacheException { 70 final String NODE="/test"; 71 final String KEY="key"; 72 Object retval=null; 73 cache.remove(NODE); 74 retval=cache.put(NODE, KEY, new Integer (10)); 75 assertNull(retval); 76 retval=cache.put(NODE, KEY, new Integer (20)); 77 assertEquals(new Integer (10), retval); 78 cache.evict(Fqn.fromString(NODE)); 80 retval=cache.put(NODE, KEY, new Integer (30)); 81 assertEquals(new Integer (20), retval); 82 } 83 84 public void testPut2() throws CacheException { 85 final String NODE="/a/b/c"; 86 final String KEY="key"; 87 Object retval=null; 88 cache.remove(NODE); 89 retval=cache.put(NODE, KEY, new Integer (10)); 90 assertNull(retval); 91 retval=cache.put(NODE, KEY, new Integer (20)); 92 assertEquals(new Integer (10), retval); 93 cache.evict(Fqn.fromString(NODE)); cache.evict(Fqn.fromString("/a/b")); 95 cache.evict(Fqn.fromString("/a")); 96 retval=cache.put(NODE, KEY, new Integer (30)); 97 assertEquals(new Integer (20), retval); 98 } 99 100 101 public void testSerialization() throws CacheException { 102 SamplePojo pojo=new SamplePojo(39, "Bela"); 103 pojo.getHobbies().add("Running"); 104 pojo.getHobbies().add("Beerathlon"); 105 pojo.getHobbies().add("Triathlon"); 106 cache.put("/mypojo", new Integer (322649), pojo); 107 assertNotNull(cache.get("/mypojo", new Integer (322649))); 108 cache.evict(Fqn.fromString("/mypojo")); 109 assertFalse(cache.exists("/mypojo")); 110 SamplePojo pojo2=(SamplePojo)cache.get("/mypojo", new Integer (322649)); assertNotNull(pojo2); 112 assertEquals(39, pojo2.getAge()); 113 assertEquals("Bela", pojo2.getName()); 114 assertEquals(3, pojo2.getHobbies().size()); 115 } 116 117 118 public void testPopulate() { 119 try { 120 Map m=new HashMap(); 121 for(int i=0; i < 10; i++) 122 m.put("key" + i, "val" + i); 123 cache.put("/a/b/c", m); 124 cache.load("/1/2/3/4/5"); 125 cache.put("/1/2/3/4/5", null); 126 cache.put("/1/2/3/4/5/a", null); 127 cache.put("/1/2/3/4/5/b", null); 128 cache.put("/1/2/3/4/5/c", null); 129 cache.put("/1/2/3/4/5/d", null); 130 cache.put("/1/2/3/4/5/e", null); 131 cache.put("/1/2/3/4/5/d/one", null); 132 cache.put("/1/2/3/4/5/d/two", null); 133 cache.put("/1/2/3/4/5/d/three", null); 134 System.out.println("cache: " + cache); 136 137 assertTrue(cache.exists("/1/2/3/4")); 138 assertTrue(cache.exists("/a/b/c")); 139 assertFalse(cache.exists("/a/b/c/d")); 140 } 141 catch(Exception e) { 142 fail(e.toString()); 143 } 144 } 145 146 147 public void testPreloading() throws CacheException { 148 cache.remove("/"); 149 cache.put("1/2/3/4/5/d", "key", "val"); 150 cache.evict(Fqn.fromString("1/2/3/4/5/d")); 151 System.out.println("-- checking for 1/2/3/4/5/d"); 152 assertFalse(cache.exists("1/2/3/4/5/d")); cache.get("1/2/3/4/5/d"); assertTrue(cache.exists("1/2/3/4/5/d")); 155 System.out.println("-- 1/2/3/4/5/d exists"); 156 } 157 158 159 160 public void testCacheLoading2() throws CacheException { 161 Set keys=null; 162 cache.put("/a/b/c", "key", "val"); 163 try { 164 keys=cache.getKeys("/a/b/c"); 165 assertNotNull(keys); 166 assertEquals(1, keys.size()); 167 } 168 catch(Exception e) { 169 fail(e.toString()); 170 } 171 172 try { 173 keys.add("myKey"); 174 } 175 catch(UnsupportedOperationException ex) { 176 fail("unsupported operation: " + ex); 177 } 178 } 179 180 181 public void testExists() throws Exception { 182 cache.put("/eins/zwei/drei", "key1", "val1"); 183 assertTrue(cache.exists("/eins/zwei/drei")); 184 assertTrue(cache.exists("/eins/zwei/drei", "key1")); 185 assertFalse(cache.exists("/eins/zwei/drei", "key2")); 186 assertFalse(cache.exists("/uno/due/tre")); 187 assertFalse(cache.exists("/une/due/tre", "key1")); 188 } 189 190 public void testGetChildren() { 191 try { 192 cache.put("/1/2/3/4/5/d/one", null); 193 cache.put("/1/2/3/4/5/d/two", null); 194 cache.put("/1/2/3/4/5/d/three", null); 195 Set children=cache.getChildrenNames("/1/2/3/4/5/d"); 196 assertNotNull(children); 197 assertEquals(3, children.size()); 198 assertTrue(children.contains("one")); 199 assertTrue(children.contains("two")); 200 assertTrue(children.contains("three")); 201 } 202 catch(Exception e) { 203 fail(e.toString()); 204 } 205 } 206 207 208 public void testGetChildrenWithEviction() throws CacheException { 209 cache.put("/a/b/c/1", null); 210 cache.put("/a/b/c/2", null); 211 cache.put("/a/b/c/3", null); 212 cache.evict(Fqn.fromString("/a/b/c/1")); 213 cache.evict(Fqn.fromString("/a/b/c/2")); 214 cache.evict(Fqn.fromString("/a/b/c/3")); 215 cache.evict(Fqn.fromString("/a/b/c")); 216 cache.evict(Fqn.fromString("/a/b")); 217 cache.evict(Fqn.fromString("/a")); 218 cache.evict(Fqn.fromString("/")); 219 Set children=cache.getChildrenNames("/a/b/c"); 220 assertNotNull(children); 221 assertEquals(3, children.size()); 222 assertTrue(children.contains("1")); 223 assertTrue(children.contains("2")); 224 assertTrue(children.contains("3")); 225 } 226 227 public void testGetChildren2() { 228 try { 229 cache.put("/1", null); 230 cache.put("a", null); 231 Set children=cache.getChildrenNames("/"); 232 assertNotNull(children); 233 assertEquals(2, children.size()); 234 assertTrue(children.contains("1")); 235 assertTrue(children.contains("a")); 236 } 237 catch(Exception e) { 238 fail(e.toString()); 239 } 240 } 241 242 public void testGetChildren3() { 243 try { 244 cache.put("/1", null); 245 cache.put("a", null); 246 Set children=cache.getChildrenNames(""); 247 assertNotNull(children); 248 assertEquals(2, children.size()); 249 assertTrue(children.contains("1")); 250 assertTrue(children.contains("a")); 251 } 252 catch(Exception e) { 253 fail(e.toString()); 254 } 255 } 256 257 public void testGetChildren4() { 258 try { 259 if(!cache.exists("/a/b/c")) 260 cache.put("/a/b/c", null); 261 Set children=cache.getChildrenNames((Fqn)null); 262 assertNull(children); 263 } 264 catch(Exception e) { 265 fail(e.toString()); 266 } 267 } 268 269 270 public void testGetChildren5() { 271 try { 272 cache.put("/a/1", null); 273 cache.put("/a/2", null); 274 cache.put("/a/3", null); 275 System.out.println("cache is " + cache.printLockInfo()); 276 277 Node n=cache.get("/a"); 278 assertNotNull(n); 279 280 Set children=cache.getChildrenNames("/a"); 281 assertNotNull(children); 282 assertEquals(3, children.size()); 283 } 284 catch(Exception e) { 285 fail(e.toString()); 286 } 287 } 288 289 290 public void testGetChildren6() { 291 try { 292 cache.put("/a/1", null); 293 cache.put("/a/2", null); 294 cache.put("/a/3", null); 295 System.out.println("cache is " + cache.printLockInfo()); 296 cache.evict(Fqn.fromString("/a/1")); 297 cache.evict(Fqn.fromString("/a/2")); 298 cache.evict(Fqn.fromString("/a/3")); 299 cache.evict(Fqn.fromString("/a")); 300 System.out.println("cache is " + cache.printLockInfo()); 301 302 assertNotNull(cache.get("/a")); 303 304 Set children=cache.getChildrenNames("/a"); 305 assertNotNull("No children were loaded", children); 306 System.out.println("children: " + children); 307 assertEquals("3 children weren't loaded", 3, children.size()); 308 } 309 catch(Exception e) { 310 fail(e.toString()); 311 } 312 } 313 314 public void testGetChildren7() { 315 try { 316 cache.put("/a/1", null); 317 cache.put("/a/2", null); 318 cache.put("/a/3", null); 319 cache.put("/a", "test", "test"); 320 System.out.println("cache is " + cache.printLockInfo()); 321 cache.evict(Fqn.fromString("/a/1")); 322 cache.evict(Fqn.fromString("/a/2")); 323 cache.evict(Fqn.fromString("/a/3")); 324 cache.evict(Fqn.fromString("/a")); 325 System.out.println("cache is " + cache.printLockInfo()); 326 327 Object val=cache.get("/a", "test"); 328 assertEquals("attributes weren't loaded", "test", val); 329 330 Set children=cache.getChildrenNames("/a"); 331 assertNotNull("No children were loaded", children); 332 System.out.println("children: " + children); 333 assertEquals("3 children weren't loaded", 3, children.size()); 334 } 335 catch(Exception e) { 336 fail(e.toString()); 337 } 338 } 339 340 public void testGetChildren8() { 341 try { 342 cache.put("/a/1", null); 343 cache.put("/a/2", null); 344 cache.put("/a/3", null); 345 System.out.println("cache is " + cache.printLockInfo()); 346 cache.evict(Fqn.fromString("/a/1")); 347 cache.evict(Fqn.fromString("/a/2")); 348 cache.evict(Fqn.fromString("/a/3")); 349 cache.evict(Fqn.fromString("/a")); 350 System.out.println("cache is " + cache.printLockInfo()); 351 352 assertNull(cache.get("/a", "test")); 353 354 cache.get("/a/1"); 355 Set children=cache.getChildrenNames("/a"); 356 assertNotNull("No children were loaded", children); 357 System.out.println("children: " + children); 358 assertEquals("3 children weren't loaded", 3, children.size()); 359 } 360 catch(Exception e) { 361 fail(e.toString()); 362 } 363 } 364 365 public void testGetChildren9() { 366 try { 367 cache.put("/a/1", null); 368 cache.put("/a/2", null); 369 cache.put("/a/3", null); 370 System.out.println("cache is " + cache.printLockInfo()); 371 cache.evict(Fqn.fromString("/a/1")); 372 cache.evict(Fqn.fromString("/a/2")); 373 cache.evict(Fqn.fromString("/a/3")); 374 cache.evict(Fqn.fromString("/a")); 375 System.out.println("cache is " + cache.printLockInfo()); 376 377 assertNull(cache.get("/a", "test")); 378 379 cache.get("/a/1"); 380 Set children=cache.getChildrenNames("/a"); 381 assertNotNull("No children were loaded", children); 382 System.out.println("children: " + children); 383 assertEquals("3 children weren't loaded", 3, children.size()); 384 385 cache.evict(Fqn.fromString("/a/1")); 386 cache.evict(Fqn.fromString("/a/2")); 387 cache.evict(Fqn.fromString("/a/3")); 388 cache.evict(Fqn.fromString("/a")); 389 System.out.println("cache is " + cache.printLockInfo()); 390 391 assertNull(cache.get("/a", "test")); 392 393 cache.get("/a/1"); 394 children=cache.getChildrenNames("/a"); 395 assertNotNull("No children were loaded", children); 396 System.out.println("children: " + children); 397 assertEquals("3 children weren't loaded", 3, children.size()); 398 } 399 catch(Exception e) { 400 fail(e.toString()); 401 } 402 } 403 404 405 public void testGetChildren10() { 406 try { 407 cache.put("/a/1", null); 408 cache.put("/a/2", null); 409 cache.put("/a/3", null); 410 System.out.println("cache is " + cache.printLockInfo()); 411 cache.evict(Fqn.fromString("/a/1")); 412 cache.evict(Fqn.fromString("/a/2")); 413 cache.evict(Fqn.fromString("/a/3")); 414 cache.evict(Fqn.fromString("/a")); 415 System.out.println("cache is " + cache.printLockInfo()); 416 417 assertNull(cache.get("/a", "test")); 418 419 cache.get("/a/1"); 420 Set children=cache.getChildrenNames("/a"); 421 assertNotNull("No children were loaded", children); 422 System.out.println("children: " + children); 423 assertEquals("3 children weren't loaded", 3, children.size()); 424 425 children=cache.getChildrenNames("/a"); 426 assertNotNull("No children were loaded", children); 427 System.out.println("children: " + children); 428 assertEquals("3 children weren't loaded", 3, children.size()); 429 } 430 catch(Exception e) { 431 fail(e.toString()); 432 } 433 } 434 435 public void testRemoveData() throws Exception { 436 String key="/x/y/z/"; 437 cache.put(key, "keyA", "valA"); 438 cache.put(key, "keyB", "valB"); 439 cache.put(key, "keyC", "valC"); 440 assertEquals(3, cache.getKeys(key).size()); 441 cache.removeData(key); 442 Set keys=cache.getKeys(key); 443 assertNull(keys); 444 cache.remove("/x"); 445 Object val=cache.get(key, "keyA"); 446 assertNull(val); 447 } 448 449 450 public void testRemoveData2() throws Exception { 451 Set keys; 452 Fqn key=Fqn.fromString("/x/y/z/"); 453 cache.put(key, "keyA", "valA"); 454 cache.put(key, "keyB", "valB"); 455 cache.put(key, "keyC", "valC"); 456 keys=cache.getKeys(key); 457 assertEquals(3, keys.size()); 458 cache.removeData(key); 459 cache.evict(key); 460 keys=cache.getKeys(key); 461 assertEquals(0, keys.size()); 462 } 463 464 public void testRemoveData3() throws Exception { 465 Set keys; 466 Fqn key=Fqn.fromString("/x/y/z/"); 467 cache.put(key, "keyA", "valA"); 468 cache.put(key, "keyB", "valB"); 469 cache.put(key, "keyC", "valC"); 470 keys=cache.getKeys(key); 471 assertEquals(3, keys.size()); 472 cache.evict(key); 473 cache.removeData(key); 474 keys=cache.getKeys(key); 475 assertNull(keys); 476 } 477 478 public void testRemoveKey() throws Exception { 479 String key="/x/y/z/"; 480 cache.put(key, "keyA", "valA"); 481 cache.put(key, "keyB", "valB"); 482 cache.put(key, "keyC", "valC"); 483 cache.remove(key, "keyA"); 484 assertEquals(2, cache.getKeys(key).size()); 485 cache.remove("/x"); 486 } 487 488 489 public void testRemoveKey2() throws CacheException { 490 final String NODE="/test"; 491 final String KEY="key"; 492 Object retval=null; 493 cache.remove(NODE); 494 retval=cache.put(NODE, KEY, new Integer (10)); 495 assertNull(retval); 496 retval=cache.remove(NODE, KEY); 497 assertEquals(new Integer (10), retval); 498 retval=cache.remove(NODE, KEY); 499 assertNull(retval); 500 } 501 502 public void testRemoveKey3() throws CacheException { 503 final String NODE="/test"; 504 final String KEY="key"; 505 Object retval=null; 506 cache.remove(NODE); 507 retval=cache.put(NODE, KEY, new Integer (10)); 508 assertNull(retval); 509 510 cache.evict(Fqn.fromString(NODE)); retval=cache.remove(NODE, KEY); 512 assertEquals(new Integer (10), retval); 513 514 cache.evict(Fqn.fromString(NODE)); retval=cache.remove(NODE, KEY); 516 assertNull(retval); 517 } 518 519 520 public void testRemove() throws Exception { 521 String key="/x/y/z/"; 522 cache.put(key, "keyA", "valA"); 523 cache.put(key, "keyB", "valB"); 524 cache.put(key, "keyC", "valC"); 525 cache.remove("/x"); 526 assertNull(cache.get(key, "keyA")); 527 Set keys=cache.getKeys(key); 528 assertNull(keys); 529 cache.remove("/x"); 530 } 531 532 533 public void testRemoveRoot() throws Exception { 534 assertNull(cache.getKeys("/")); 535 cache.put("/1/2/3/4/5", null); 536 cache.put("uno/due/tre", null); 537 cache.put("1/2/3/a", null); 538 cache.put("/eins/zwei/drei", null); 539 cache.put("/one/two/three", null); 540 cache.remove("/"); 541 assertEquals(null, cache.getKeys("/")); 542 } 543 544 545 public void testEvictionWithCacheLoader() throws Exception { 546 cache.put("/first/second", "key1", "val1"); cache.put("/first/second/third", "key2", "val2"); cache.evict(Fqn.fromString("/first/second")); assertTrue(cache.exists("/first/second/third")); 550 assertTrue(cache.exists("/first/second")); 551 assertTrue(cache.exists("/first")); 552 String val=(String )cache.get("/first/second", "key1"); assertEquals("val1", val); 554 assertTrue(cache.exists("/first/second/third")); 555 assertTrue(cache.exists("/first/second")); 556 assertTrue(cache.exists("/first")); 557 } 558 559 560 public void testEvictionWithCacheLoader2() throws Exception { 561 cache.put("/first/second/third", "key1", "val1"); cache.evict(Fqn.fromString("/first/second/third")); assertFalse(cache.exists("/first/second/third")); 564 assertTrue(cache.exists("/first/second")); 565 assertTrue(cache.exists("/first")); 566 String val=(String )cache.get("/first/second/third", "key1"); assertEquals("val1", val); 568 assertTrue(cache.exists("/first/second/third")); 569 assertTrue(cache.exists("/first/second")); 570 assertTrue(cache.exists("/first")); 571 } 572 573 574 575 public void testEvictionWithGetChildrenNames() throws Exception { 576 cache.put("/a/1", null); 577 cache.put("/a/2", null); 578 cache.put("/a/3", null); 579 cache.evict(Fqn.fromString("/a/1")); 581 cache.evict(Fqn.fromString("/a/2")); 582 cache.evict(Fqn.fromString("/a/3")); 583 cache.evict(Fqn.fromString("/a")); 584 585 DummyTransactionManager mgr=DummyTransactionManager.getInstance(); 586 mgr.begin(); 587 tx=mgr.getTransaction(); 588 Set children=cache.getChildrenNames("/a"); 589 assertEquals(3, children.size()); 590 assertTrue(children.contains("1")); 591 assertTrue(children.contains("2")); 592 assertTrue(children.contains("3")); 593 assertEquals(4, cache.getNumberOfLocksHeld()); 594 tx.commit(); 595 } 596 597 598 public void testTxPutCommit() throws Exception , NotSupportedException { 599 DummyTransactionManager mgr=DummyTransactionManager.getInstance(); 600 mgr.begin(); 601 tx=mgr.getTransaction(); 602 603 cache.put("/one/two/three", "key1", "val1"); 604 cache.put("/one/two/three/four", "key2", "val2"); 605 tx.commit(); 606 assertNotNull(cache.getKeys("/one/two/three")); 607 Set children=cache.getChildrenNames("/one"); 608 assertEquals(1, children.size()); 609 cache.remove("/"); 610 } 611 612 613 public void testTxPutRollback() throws Exception , NotSupportedException { 614 DummyTransactionManager mgr=DummyTransactionManager.getInstance(); 615 616 cache.remove("/one"); 617 618 mgr.begin(); 619 tx=mgr.getTransaction(); 620 621 cache.put("/one/two/three", "key1", "val1"); 622 cache.put("/one/two/three/four", "key2", "val2"); 623 tx.rollback(); 624 assertNull(cache.getKeys("/one/two/three")); 625 Set children=cache.getChildrenNames("/one"); 626 assertNull(children); 627 } 628 629 630 631 632 633 634 635 636 639 public void testBasicOperations() 640 throws Exception { 641 642 doTestBasicOperations(); 643 } 644 645 648 public void testBasicOperationsTransactional() 649 throws Exception { 650 651 DummyTransactionManager mgr=DummyTransactionManager.getInstance(); 652 mgr.begin(); 653 tx=mgr.getTransaction(); 654 doTestBasicOperations(); 655 tx.commit(); 656 } 657 658 661 private void doTestBasicOperations() throws Exception { 662 663 664 doPutTests(new Fqn("key")); 665 doRemoveTests(new Fqn("key")); 666 668 669 doPutTests(new Fqn("key1")); 670 doPutTests(new Fqn("key3")); 671 doPutTests(new Fqn("key2")); 672 assertEquals(4, loader.get(new Fqn("key1")).size()); 673 assertEquals(4, loader.get(new Fqn("key2")).size()); 674 assertEquals(4, loader.get(new Fqn("key3")).size()); 675 676 677 doRemoveTests(new Fqn("key2")); 678 doRemoveTests(new Fqn("key3")); 679 doRemoveTests(new Fqn("key1")); 680 assertEquals(null, loader.get(new Fqn("key1"))); 681 assertEquals(null, loader.get(new Fqn("key2"))); 682 assertEquals(null, loader.get(new Fqn("key3"))); 683 } 685 686 689 private void doPutTests(Fqn fqn) 690 throws Exception { 691 692 assertTrue(!loader.exists(fqn)); 693 694 695 Object oldVal; 696 oldVal = loader.put(fqn, "one", "two"); 697 assertNull(oldVal); 698 oldVal = loader.put(fqn, "three", "four"); 699 assertNull(oldVal); 700 assertEquals("two", loader.get(fqn, "one")); 701 assertEquals("four", loader.get(fqn, "three")); 702 oldVal = loader.put(fqn, "one", "xxx"); 703 assertEquals("two", oldVal); 704 oldVal = loader.put(fqn, "one", "two"); 705 assertEquals("xxx", oldVal); 706 707 708 Map map = loader.get(fqn); 709 assertEquals(2, map.size()); 710 assertEquals("two", map.get("one")); 711 assertEquals("four", map.get("three")); 712 713 714 map.put("five", "six"); 715 map.put("seven", "eight"); 716 loader.put(fqn, map); 717 assertEquals("six", loader.get(fqn, "five")); 718 assertEquals("eight", loader.get(fqn, "seven")); 719 assertEquals(map, loader.get(fqn)); 720 assertEquals(4, map.size()); 721 722 assertTrue(loader.exists(fqn)); 723 } 724 725 728 private void doRemoveTests(Fqn fqn) 729 throws Exception { 730 731 732 Object oldVal; 733 oldVal = loader.remove(fqn, "one"); 734 assertEquals("two", oldVal); 735 oldVal = loader.remove(fqn, "five"); 736 assertEquals("six", oldVal); 737 assertEquals(null, loader.get(fqn, "one")); 738 assertEquals(null, loader.get(fqn, "five")); 739 assertEquals("four", loader.get(fqn, "three")); 740 assertEquals("eight", loader.get(fqn, "seven")); 741 Map map = loader.get(fqn); 742 assertEquals(2, map.size()); 743 assertEquals("four", map.get("three")); 744 assertEquals("eight", map.get("seven")); 745 746 747 assertTrue(loader.exists(fqn)); 748 loader.remove(fqn); 749 assertEquals(null, loader.get(fqn, "three")); 750 assertEquals(null, loader.get(fqn, "seven")); 751 map = loader.get(fqn); 752 assertEquals(null, map); 753 assertTrue(!loader.exists(fqn)); 754 } 755 756 760 public void testMultiLevelTree() 761 throws Exception { 762 763 764 assertTrue(!loader.exists(new Fqn("key0"))); 765 loader.put(Fqn.fromString("/key0/level1/level2"), null); 766 assertTrue(loader.exists(Fqn.fromString("/key0/level1/level2"))); 767 assertTrue(loader.exists(Fqn.fromString("/key0/level1"))); 768 assertTrue(loader.exists(new Fqn("key0"))); 769 770 771 loader.put(Fqn.fromString("/key0/x/y"), null); 772 assertTrue(loader.exists(Fqn.fromString("/key0/x/y"))); 773 assertTrue(loader.exists(Fqn.fromString("/key0/x"))); 774 loader.remove(Fqn.fromString("/key0/x/y")); 775 assertTrue(!loader.exists(Fqn.fromString("/key0/x/y"))); 776 assertTrue(loader.exists(Fqn.fromString("/key0/x"))); 777 778 779 loader.remove(new Fqn("key0")); 780 assertTrue(!loader.exists(new Fqn("key0"))); 781 assertTrue(!loader.exists(Fqn.fromString("/key0/level1/level2"))); 782 assertTrue(!loader.exists(Fqn.fromString("/key0/level1"))); 783 assertTrue(!loader.exists(Fqn.fromString("/key0/x"))); 784 785 786 loader.put(new Fqn("key1"), null); 787 loader.put(new Fqn("key2"), null); 788 loader.put(new Fqn("key3"), null); 789 assertTrue(loader.exists(new Fqn("key1"))); 790 assertTrue(loader.exists(new Fqn("key2"))); 791 assertTrue(loader.exists(new Fqn("key3"))); 792 793 794 assertTrue(!loader.exists(Fqn.fromString("/key3/level1"))); 795 assertTrue(!loader.exists(Fqn.fromString("/key3/level1/level2"))); 796 loader.put(Fqn.fromString("/key3/level1/level2"), null); 797 assertTrue(loader.exists(Fqn.fromString("/key3/level1/level2"))); 798 assertTrue(loader.exists(Fqn.fromString("/key3/level1"))); 799 800 801 assertTrue(loader.exists(new Fqn("key1"))); 802 assertTrue(loader.exists(new Fqn("key2"))); 803 assertTrue(loader.exists(new Fqn("key3"))); 804 805 806 loader.remove(Fqn.fromString("/key3/level1")); 807 assertTrue(!loader.exists(Fqn.fromString("/key3/level1/level2"))); 808 assertTrue(!loader.exists(Fqn.fromString("/key3/level1"))); 809 810 811 assertTrue(loader.exists(new Fqn("key1"))); 812 assertTrue(loader.exists(new Fqn("key2"))); 813 assertTrue(loader.exists(new Fqn("key3"))); 814 815 816 loader.remove(new Fqn("key1")); 817 assertTrue(!loader.exists(new Fqn("key1"))); 818 assertTrue(loader.exists(new Fqn("key2"))); 819 assertTrue(loader.exists(new Fqn("key3"))); 820 821 822 loader.remove(new Fqn("key3")); 823 assertTrue(loader.exists(new Fqn("key2"))); 824 assertTrue(!loader.exists(new Fqn("key3"))); 825 826 827 loader.remove(new Fqn("key2")); 828 assertTrue(!loader.exists(new Fqn("key0"))); 829 assertTrue(!loader.exists(new Fqn("key1"))); 830 assertTrue(!loader.exists(new Fqn("key2"))); 831 assertTrue(!loader.exists(new Fqn("key3"))); 832 833 834 835 assertNull(loader.get(new Fqn("key0"))); 836 loader.put(Fqn.fromString("/key0/level1/level2"), "a", "b"); 837 assertNotNull(loader.get(Fqn.fromString("/key0/level1/level2"))); 838 assertNull(loader.get(Fqn.fromString("/key0/level1
|