4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.*; |
7 |
> |
import java.util.ArrayList; |
8 |
> |
import java.util.Arrays; |
9 |
> |
import java.util.BitSet; |
10 |
> |
import java.util.Collection; |
11 |
> |
import java.util.Iterator; |
12 |
> |
import java.util.Map; |
13 |
> |
import java.util.NavigableMap; |
14 |
> |
import java.util.NavigableSet; |
15 |
> |
import java.util.NoSuchElementException; |
16 |
> |
import java.util.Random; |
17 |
> |
import java.util.Set; |
18 |
|
import java.util.concurrent.ConcurrentSkipListMap; |
19 |
|
|
20 |
+ |
import junit.framework.Test; |
21 |
+ |
|
22 |
|
public class ConcurrentSkipListMapTest extends JSR166TestCase { |
23 |
|
public static void main(String[] args) { |
24 |
< |
junit.textui.TestRunner.run(suite()); |
24 |
> |
main(suite(), args); |
25 |
|
} |
26 |
|
public static Test suite() { |
27 |
< |
return new TestSuite(ConcurrentSkipListMapTest.class); |
27 |
> |
class Implementation implements MapImplementation { |
28 |
> |
public Class<?> klazz() { return ConcurrentSkipListMap.class; } |
29 |
> |
public Map emptyMap() { return new ConcurrentSkipListMap(); } |
30 |
> |
public boolean isConcurrent() { return true; } |
31 |
> |
public boolean remappingFunctionCalledAtMostOnce() { return false; }; |
32 |
> |
public boolean permitsNullKeys() { return false; } |
33 |
> |
public boolean permitsNullValues() { return false; } |
34 |
> |
public boolean supportsSetValue() { return false; } |
35 |
> |
} |
36 |
> |
return newTestSuite( |
37 |
> |
ConcurrentSkipListMapTest.class, |
38 |
> |
MapTest.testSuite(new Implementation())); |
39 |
|
} |
40 |
|
|
41 |
|
/** |
704 |
|
* get(null) of nonempty map throws NPE |
705 |
|
*/ |
706 |
|
public void testGet_NullPointerException() { |
707 |
+ |
ConcurrentSkipListMap c = map5(); |
708 |
|
try { |
686 |
– |
ConcurrentSkipListMap c = map5(); |
709 |
|
c.get(null); |
710 |
|
shouldThrow(); |
711 |
|
} catch (NullPointerException success) {} |
715 |
|
* containsKey(null) of nonempty map throws NPE |
716 |
|
*/ |
717 |
|
public void testContainsKey_NullPointerException() { |
718 |
+ |
ConcurrentSkipListMap c = map5(); |
719 |
|
try { |
697 |
– |
ConcurrentSkipListMap c = map5(); |
720 |
|
c.containsKey(null); |
721 |
|
shouldThrow(); |
722 |
|
} catch (NullPointerException success) {} |
726 |
|
* containsValue(null) throws NPE |
727 |
|
*/ |
728 |
|
public void testContainsValue_NullPointerException() { |
729 |
+ |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
730 |
|
try { |
708 |
– |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
731 |
|
c.containsValue(null); |
732 |
|
shouldThrow(); |
733 |
|
} catch (NullPointerException success) {} |
737 |
|
* put(null,x) throws NPE |
738 |
|
*/ |
739 |
|
public void testPut1_NullPointerException() { |
740 |
+ |
ConcurrentSkipListMap c = map5(); |
741 |
|
try { |
719 |
– |
ConcurrentSkipListMap c = map5(); |
742 |
|
c.put(null, "whatever"); |
743 |
|
shouldThrow(); |
744 |
|
} catch (NullPointerException success) {} |
748 |
|
* putIfAbsent(null, x) throws NPE |
749 |
|
*/ |
750 |
|
public void testPutIfAbsent1_NullPointerException() { |
751 |
+ |
ConcurrentSkipListMap c = map5(); |
752 |
|
try { |
730 |
– |
ConcurrentSkipListMap c = map5(); |
753 |
|
c.putIfAbsent(null, "whatever"); |
754 |
|
shouldThrow(); |
755 |
|
} catch (NullPointerException success) {} |
759 |
|
* replace(null, x) throws NPE |
760 |
|
*/ |
761 |
|
public void testReplace_NullPointerException() { |
762 |
+ |
ConcurrentSkipListMap c = map5(); |
763 |
|
try { |
741 |
– |
ConcurrentSkipListMap c = map5(); |
764 |
|
c.replace(null, "whatever"); |
765 |
|
shouldThrow(); |
766 |
|
} catch (NullPointerException success) {} |
770 |
|
* replace(null, x, y) throws NPE |
771 |
|
*/ |
772 |
|
public void testReplaceValue_NullPointerException() { |
773 |
+ |
ConcurrentSkipListMap c = map5(); |
774 |
|
try { |
752 |
– |
ConcurrentSkipListMap c = map5(); |
775 |
|
c.replace(null, one, "whatever"); |
776 |
|
shouldThrow(); |
777 |
|
} catch (NullPointerException success) {} |
781 |
|
* remove(null) throws NPE |
782 |
|
*/ |
783 |
|
public void testRemove1_NullPointerException() { |
784 |
+ |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
785 |
+ |
c.put("sadsdf", "asdads"); |
786 |
|
try { |
763 |
– |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
764 |
– |
c.put("sadsdf", "asdads"); |
787 |
|
c.remove(null); |
788 |
|
shouldThrow(); |
789 |
|
} catch (NullPointerException success) {} |
793 |
|
* remove(null, x) throws NPE |
794 |
|
*/ |
795 |
|
public void testRemove2_NullPointerException() { |
796 |
+ |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
797 |
+ |
c.put("sadsdf", "asdads"); |
798 |
|
try { |
775 |
– |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
776 |
– |
c.put("sadsdf", "asdads"); |
799 |
|
c.remove(null, "whatever"); |
800 |
|
shouldThrow(); |
801 |
|
} catch (NullPointerException success) {} |
811 |
|
} |
812 |
|
|
813 |
|
/** |
814 |
< |
* A deserialized map equals original |
814 |
> |
* A cloned map equals original |
815 |
> |
*/ |
816 |
> |
public void testClone() { |
817 |
> |
ConcurrentSkipListMap x = map5(); |
818 |
> |
ConcurrentSkipListMap y = x.clone(); |
819 |
> |
|
820 |
> |
assertNotSame(x, y); |
821 |
> |
assertEquals(x.size(), y.size()); |
822 |
> |
assertEquals(x.toString(), y.toString()); |
823 |
> |
assertEquals(x, y); |
824 |
> |
assertEquals(y, x); |
825 |
> |
y.clear(); |
826 |
> |
assertTrue(y.isEmpty()); |
827 |
> |
assertFalse(x.equals(y)); |
828 |
> |
} |
829 |
> |
|
830 |
> |
/** |
831 |
> |
* A deserialized/reserialized map equals original |
832 |
|
*/ |
833 |
|
public void testSerialization() throws Exception { |
834 |
|
NavigableMap x = map5(); |
835 |
|
NavigableMap y = serialClone(x); |
836 |
|
|
837 |
< |
assertTrue(x != y); |
837 |
> |
assertNotSame(x, y); |
838 |
|
assertEquals(x.size(), y.size()); |
839 |
|
assertEquals(x.toString(), y.toString()); |
840 |
|
assertEquals(x, y); |
841 |
|
assertEquals(y, x); |
842 |
+ |
y.clear(); |
843 |
+ |
assertTrue(y.isEmpty()); |
844 |
+ |
assertFalse(x.equals(y)); |
845 |
|
} |
846 |
|
|
847 |
|
/** |
1027 |
|
|
1028 |
|
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
1029 |
|
NavigableMap<Integer, Integer> result = |
1030 |
< |
(NavigableMap<Integer, Integer>) cl.newInstance(); |
1030 |
> |
(NavigableMap<Integer, Integer>) cl.getConstructor().newInstance(); |
1031 |
|
assertEquals(0, result.size()); |
1032 |
|
assertFalse(result.keySet().iterator().hasNext()); |
1033 |
|
return result; |
1060 |
|
// Add entries till we're back to original size |
1061 |
|
while (map.size() < size) { |
1062 |
|
int key = min + rnd.nextInt(rangeSize); |
1063 |
< |
assertTrue(key >= min && key<= max); |
1063 |
> |
assertTrue(key >= min && key <= max); |
1064 |
|
put(map, key); |
1065 |
|
} |
1066 |
|
} |
1085 |
|
// Add entries till we're back to original size |
1086 |
|
while (map.size() < size) { |
1087 |
|
int key = min - 5 + rnd.nextInt(rangeSize + 10); |
1088 |
< |
if (key >= min && key<= max) { |
1088 |
> |
if (key >= min && key <= max) { |
1089 |
|
put(map, key); |
1090 |
|
} else { |
1091 |
|
try { |
1303 |
|
} |
1304 |
|
|
1305 |
|
static boolean eq(Integer i, int j) { |
1306 |
< |
return i == null ? j == -1 : i == j; |
1306 |
> |
return (i == null) ? j == -1 : i == j; |
1307 |
|
} |
1308 |
|
|
1309 |
|
} |