11 |
|
|
12 |
|
public class ConcurrentSkipListMapTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ConcurrentSkipListMapTest.class); |
427 |
|
map.remove(four, "A"); |
428 |
|
assertEquals(4, map.size()); |
429 |
|
assertTrue(map.containsKey(four)); |
430 |
– |
|
430 |
|
} |
431 |
|
|
432 |
|
/** |
445 |
|
|
446 |
|
Map.Entry e4 = map.lowerEntry(zero); |
447 |
|
assertNull(e4); |
449 |
– |
|
448 |
|
} |
449 |
|
|
450 |
|
/** |
463 |
|
|
464 |
|
Map.Entry e4 = map.higherEntry(six); |
465 |
|
assertNull(e4); |
468 |
– |
|
466 |
|
} |
467 |
|
|
468 |
|
/** |
481 |
|
|
482 |
|
Map.Entry e4 = map.floorEntry(zero); |
483 |
|
assertNull(e4); |
487 |
– |
|
484 |
|
} |
485 |
|
|
486 |
|
/** |
499 |
|
|
500 |
|
Map.Entry e4 = map.ceilingEntry(six); |
501 |
|
assertNull(e4); |
506 |
– |
|
502 |
|
} |
503 |
|
|
504 |
|
/** |
505 |
|
* lowerEntry, higherEntry, ceilingEntry, and floorEntry return |
506 |
< |
* imutable entries |
506 |
> |
* immutable entries |
507 |
|
*/ |
508 |
|
public void testEntryImmutablity() { |
509 |
|
ConcurrentSkipListMap map = map5(); |
511 |
|
assertEquals(two, e.getKey()); |
512 |
|
try { |
513 |
|
e.setValue("X"); |
514 |
< |
fail(); |
514 |
> |
shouldThrow(); |
515 |
|
} catch (UnsupportedOperationException success) {} |
516 |
|
e = map.higherEntry(zero); |
517 |
|
assertEquals(one, e.getKey()); |
518 |
|
try { |
519 |
|
e.setValue("X"); |
520 |
< |
fail(); |
520 |
> |
shouldThrow(); |
521 |
|
} catch (UnsupportedOperationException success) {} |
522 |
|
e = map.floorEntry(one); |
523 |
|
assertEquals(one, e.getKey()); |
524 |
|
try { |
525 |
|
e.setValue("X"); |
526 |
< |
fail(); |
526 |
> |
shouldThrow(); |
527 |
|
} catch (UnsupportedOperationException success) {} |
528 |
|
e = map.ceilingEntry(five); |
529 |
|
assertEquals(five, e.getKey()); |
530 |
|
try { |
531 |
|
e.setValue("X"); |
532 |
< |
fail(); |
532 |
> |
shouldThrow(); |
533 |
|
} catch (UnsupportedOperationException success) {} |
534 |
|
} |
535 |
|
|
551 |
|
|
552 |
|
Object e4 = q.lowerKey(zero); |
553 |
|
assertNull(e4); |
559 |
– |
|
554 |
|
} |
555 |
|
|
556 |
|
/** |
569 |
|
|
570 |
|
Object e4 = q.higherKey(six); |
571 |
|
assertNull(e4); |
578 |
– |
|
572 |
|
} |
573 |
|
|
574 |
|
/** |
587 |
|
|
588 |
|
Object e4 = q.floorKey(zero); |
589 |
|
assertNull(e4); |
597 |
– |
|
590 |
|
} |
591 |
|
|
592 |
|
/** |
605 |
|
|
606 |
|
Object e4 = q.ceilingKey(six); |
607 |
|
assertNull(e4); |
616 |
– |
|
608 |
|
} |
609 |
|
|
610 |
|
/** |
629 |
|
try { |
630 |
|
e.setValue("A"); |
631 |
|
shouldThrow(); |
632 |
< |
} catch (Exception ok) { |
642 |
< |
} |
632 |
> |
} catch (UnsupportedOperationException success) {} |
633 |
|
e = map.pollFirstEntry(); |
634 |
|
assertNull(e); |
635 |
|
} |
656 |
|
try { |
657 |
|
e.setValue("E"); |
658 |
|
shouldThrow(); |
659 |
< |
} catch (Exception ok) { |
670 |
< |
} |
659 |
> |
} catch (UnsupportedOperationException success) {} |
660 |
|
e = map.pollLastEntry(); |
661 |
|
assertNull(e); |
662 |
|
} |
692 |
|
ConcurrentSkipListMap c = map5(); |
693 |
|
c.get(null); |
694 |
|
shouldThrow(); |
695 |
< |
} catch (NullPointerException e) {} |
695 |
> |
} catch (NullPointerException success) {} |
696 |
|
} |
697 |
|
|
698 |
|
/** |
703 |
|
ConcurrentSkipListMap c = map5(); |
704 |
|
c.containsKey(null); |
705 |
|
shouldThrow(); |
706 |
< |
} catch (NullPointerException e) {} |
706 |
> |
} catch (NullPointerException success) {} |
707 |
|
} |
708 |
|
|
709 |
|
/** |
714 |
|
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
715 |
|
c.containsValue(null); |
716 |
|
shouldThrow(); |
717 |
< |
} catch (NullPointerException e) {} |
717 |
> |
} catch (NullPointerException success) {} |
718 |
|
} |
719 |
|
|
720 |
|
|
726 |
|
ConcurrentSkipListMap c = map5(); |
727 |
|
c.put(null, "whatever"); |
728 |
|
shouldThrow(); |
729 |
< |
} catch (NullPointerException e) {} |
729 |
> |
} catch (NullPointerException success) {} |
730 |
|
} |
731 |
|
|
732 |
|
/** |
737 |
|
ConcurrentSkipListMap c = map5(); |
738 |
|
c.putIfAbsent(null, "whatever"); |
739 |
|
shouldThrow(); |
740 |
< |
} catch (NullPointerException e) {} |
740 |
> |
} catch (NullPointerException success) {} |
741 |
|
} |
742 |
|
|
743 |
|
/** |
748 |
|
ConcurrentSkipListMap c = map5(); |
749 |
|
c.replace(null, "whatever"); |
750 |
|
shouldThrow(); |
751 |
< |
} catch (NullPointerException e) {} |
751 |
> |
} catch (NullPointerException success) {} |
752 |
|
} |
753 |
|
|
754 |
|
/** |
759 |
|
ConcurrentSkipListMap c = map5(); |
760 |
|
c.replace(null, one, "whatever"); |
761 |
|
shouldThrow(); |
762 |
< |
} catch (NullPointerException e) {} |
762 |
> |
} catch (NullPointerException success) {} |
763 |
|
} |
764 |
|
|
765 |
|
/** |
771 |
|
c.put("sadsdf", "asdads"); |
772 |
|
c.remove(null); |
773 |
|
shouldThrow(); |
774 |
< |
} catch (NullPointerException e) {} |
774 |
> |
} catch (NullPointerException success) {} |
775 |
|
} |
776 |
|
|
777 |
|
/** |
783 |
|
c.put("sadsdf", "asdads"); |
784 |
|
c.remove(null, "whatever"); |
785 |
|
shouldThrow(); |
786 |
< |
} catch (NullPointerException e) {} |
786 |
> |
} catch (NullPointerException success) {} |
787 |
|
} |
788 |
|
|
789 |
|
/** |
790 |
|
* remove(x, null) returns false |
791 |
|
*/ |
792 |
|
public void testRemove3() { |
793 |
< |
try { |
794 |
< |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
795 |
< |
c.put("sadsdf", "asdads"); |
807 |
< |
assertFalse(c.remove("sadsdf", null)); |
808 |
< |
} catch (NullPointerException e) { |
809 |
< |
fail(); |
810 |
< |
} |
793 |
> |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
794 |
> |
c.put("sadsdf", "asdads"); |
795 |
> |
assertFalse(c.remove("sadsdf", null)); |
796 |
|
} |
797 |
|
|
798 |
|
/** |
799 |
|
* A deserialized map equals original |
800 |
|
*/ |
801 |
< |
public void testSerialization() { |
801 |
> |
public void testSerialization() throws Exception { |
802 |
|
ConcurrentSkipListMap q = map5(); |
803 |
|
|
804 |
< |
try { |
805 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
806 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
807 |
< |
out.writeObject(q); |
808 |
< |
out.close(); |
809 |
< |
|
810 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
811 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
812 |
< |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
813 |
< |
assertEquals(q.size(), r.size()); |
814 |
< |
assertTrue(q.equals(r)); |
830 |
< |
assertTrue(r.equals(q)); |
831 |
< |
} catch (Exception e) { |
832 |
< |
e.printStackTrace(); |
833 |
< |
unexpectedException(); |
834 |
< |
} |
804 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
805 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
806 |
> |
out.writeObject(q); |
807 |
> |
out.close(); |
808 |
> |
|
809 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
810 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
811 |
> |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
812 |
> |
assertEquals(q.size(), r.size()); |
813 |
> |
assertTrue(q.equals(r)); |
814 |
> |
assertTrue(r.equals(q)); |
815 |
|
} |
816 |
|
|
817 |
|
|
852 |
|
assertEquals(1, sm.size()); |
853 |
|
assertEquals(three, sm.firstKey()); |
854 |
|
assertEquals(three, sm.lastKey()); |
855 |
< |
assertTrue(sm.remove(three) != null); |
855 |
> |
assertEquals("C", sm.remove(three)); |
856 |
|
assertTrue(sm.isEmpty()); |
857 |
|
assertEquals(3, map.size()); |
858 |
|
} |
885 |
|
assertEquals(4, map.size()); |
886 |
|
assertEquals(0, sm.size()); |
887 |
|
assertTrue(sm.isEmpty()); |
888 |
< |
assertTrue(sm.remove(three) == null); |
888 |
> |
assertSame(sm.remove(three), null); |
889 |
|
assertEquals(4, map.size()); |
890 |
|
} |
891 |
|
|
967 |
|
NavigableMap ssm = sm.tailMap(four, true); |
968 |
|
assertEquals(four, ssm.firstKey()); |
969 |
|
assertEquals(five, ssm.lastKey()); |
970 |
< |
assertTrue(ssm.remove(four) != null); |
970 |
> |
assertEquals("D", ssm.remove(four)); |
971 |
|
assertEquals(1, ssm.size()); |
972 |
|
assertEquals(3, sm.size()); |
973 |
|
assertEquals(4, map.size()); |
979 |
|
/** |
980 |
|
* Submaps of submaps subdivide correctly |
981 |
|
*/ |
982 |
< |
public void testRecursiveSubMaps() { |
982 |
> |
public void testRecursiveSubMaps() throws Exception { |
983 |
|
int mapSize = 1000; |
984 |
|
Class cl = ConcurrentSkipListMap.class; |
985 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
997 |
|
0, mapSize - 1, true); |
998 |
|
} |
999 |
|
|
1000 |
< |
static NavigableMap<Integer, Integer> newMap(Class cl) { |
1001 |
< |
NavigableMap<Integer, Integer> result = null; |
1002 |
< |
try { |
1023 |
< |
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
1024 |
< |
} catch (Exception e) { |
1025 |
< |
fail(); |
1026 |
< |
} |
1000 |
> |
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
1001 |
> |
NavigableMap<Integer, Integer> result = |
1002 |
> |
(NavigableMap<Integer, Integer>) cl.newInstance(); |
1003 |
|
assertEquals(result.size(), 0); |
1004 |
|
assertFalse(result.keySet().iterator().hasNext()); |
1005 |
|
return result; |
1062 |
|
} else { |
1063 |
|
try { |
1064 |
|
map.put(key, 2 * key); |
1065 |
< |
fail(); |
1066 |
< |
} catch (IllegalArgumentException e) { |
1091 |
< |
// expected |
1092 |
< |
} |
1065 |
> |
shouldThrow(); |
1066 |
> |
} catch (IllegalArgumentException success) {} |
1067 |
|
} |
1068 |
|
} |
1069 |
|
} |
1192 |
|
// BitSet should support this! Test would run much faster |
1193 |
|
while (key >= min) { |
1194 |
|
if (bs.get(key)) |
1195 |
< |
return(key); |
1195 |
> |
return key; |
1196 |
|
key--; |
1197 |
|
} |
1198 |
|
return -1; |
1258 |
|
assertEq(rs.last(), -1); |
1259 |
|
try { |
1260 |
|
map.firstKey(); |
1261 |
< |
fail(); |
1262 |
< |
} catch (NoSuchElementException e) { |
1289 |
< |
// expected |
1290 |
< |
} |
1261 |
> |
shouldThrow(); |
1262 |
> |
} catch (NoSuchElementException success) {} |
1263 |
|
try { |
1264 |
|
map.lastKey(); |
1265 |
< |
fail(); |
1266 |
< |
} catch (NoSuchElementException e) { |
1295 |
< |
// expected |
1296 |
< |
} |
1265 |
> |
shouldThrow(); |
1266 |
> |
} catch (NoSuchElementException success) {} |
1267 |
|
} |
1268 |
|
} |
1269 |
|
|