5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
+ |
import java.util.concurrent.ConcurrentNavigableMap; |
9 |
+ |
import java.util.concurrent.ConcurrentSkipListMap; |
10 |
|
import java.util.*; |
9 |
– |
import java.util.concurrent.*; |
10 |
– |
import java.io.*; |
11 |
|
|
12 |
|
public class ConcurrentSkipListSubMapTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
18 |
|
} |
19 |
|
|
20 |
|
/** |
21 |
< |
* Create a map from Integers 1-5 to Strings "A"-"E". |
21 |
> |
* Creates a map from Integers 1-5 to Strings "A"-"E". |
22 |
|
*/ |
23 |
|
private static ConcurrentNavigableMap map5() { |
24 |
|
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
36 |
|
} |
37 |
|
|
38 |
|
/** |
39 |
< |
* Create a map from Integers -5 to -1 to Strings "A"-"E". |
39 |
> |
* Creates a map from Integers -5 to -1 to Strings "A"-"E". |
40 |
|
*/ |
41 |
|
private static ConcurrentNavigableMap dmap5() { |
42 |
|
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
69 |
|
public void testClear() { |
70 |
|
ConcurrentNavigableMap map = map5(); |
71 |
|
map.clear(); |
72 |
< |
assertEquals(map.size(), 0); |
72 |
> |
assertEquals(0, map.size()); |
73 |
|
} |
74 |
|
|
75 |
– |
|
75 |
|
/** |
76 |
|
* Maps with same contents are equal |
77 |
|
*/ |
140 |
|
assertEquals(five, map.lastKey()); |
141 |
|
} |
142 |
|
|
144 |
– |
|
143 |
|
/** |
144 |
|
* keySet returns a Set containing all the keys |
145 |
|
*/ |
226 |
|
assertTrue(s.contains("E")); |
227 |
|
} |
228 |
|
|
231 |
– |
|
229 |
|
/** |
230 |
|
* entrySet contains all pairs |
231 |
|
*/ |
295 |
|
assertEquals("Z", map.get(one)); |
296 |
|
} |
297 |
|
|
301 |
– |
|
298 |
|
/** |
299 |
|
* replace value fails when the given key not mapped to expected value |
300 |
|
*/ |
315 |
|
assertEquals("Z", map.get(one)); |
316 |
|
} |
317 |
|
|
322 |
– |
|
318 |
|
/** |
319 |
|
* remove removes the correct key-value pair from the map |
320 |
|
*/ |
483 |
|
ConcurrentNavigableMap map = map5(); |
484 |
|
String s = map.toString(); |
485 |
|
for (int i = 1; i <= 5; ++i) { |
486 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
486 |
> |
assertTrue(s.contains(String.valueOf(i))); |
487 |
|
} |
488 |
|
} |
489 |
|
|
522 |
|
} catch (NullPointerException success) {} |
523 |
|
} |
524 |
|
|
530 |
– |
|
525 |
|
/** |
526 |
|
* put(null,x) throws NPE |
527 |
|
*/ |
592 |
|
* A deserialized map equals original |
593 |
|
*/ |
594 |
|
public void testSerialization() throws Exception { |
595 |
< |
ConcurrentNavigableMap q = map5(); |
595 |
> |
NavigableMap x = map5(); |
596 |
> |
NavigableMap y = serialClone(x); |
597 |
|
|
598 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
599 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
600 |
< |
out.writeObject(q); |
601 |
< |
out.close(); |
602 |
< |
|
608 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
609 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
610 |
< |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
611 |
< |
assertEquals(q.size(), r.size()); |
612 |
< |
assertTrue(q.equals(r)); |
613 |
< |
assertTrue(r.equals(q)); |
598 |
> |
assertTrue(x != y); |
599 |
> |
assertEquals(x.size(), y.size()); |
600 |
> |
assertEquals(x.toString(), y.toString()); |
601 |
> |
assertEquals(x, y); |
602 |
> |
assertEquals(y, x); |
603 |
|
} |
604 |
|
|
616 |
– |
|
617 |
– |
|
605 |
|
/** |
606 |
|
* subMap returns map with keys in requested range |
607 |
|
*/ |
743 |
|
public void testDescendingClear() { |
744 |
|
ConcurrentNavigableMap map = dmap5(); |
745 |
|
map.clear(); |
746 |
< |
assertEquals(map.size(), 0); |
746 |
> |
assertEquals(0, map.size()); |
747 |
|
} |
748 |
|
|
762 |
– |
|
749 |
|
/** |
750 |
|
* Maps with same contents are equal |
751 |
|
*/ |
814 |
|
assertEquals(m5, map.lastKey()); |
815 |
|
} |
816 |
|
|
831 |
– |
|
817 |
|
/** |
818 |
|
* keySet returns a Set containing all the keys |
819 |
|
*/ |
900 |
|
assertTrue(s.contains("E")); |
901 |
|
} |
902 |
|
|
918 |
– |
|
903 |
|
/** |
904 |
|
* entrySet contains all pairs |
905 |
|
*/ |
969 |
|
assertEquals("Z", map.get(m1)); |
970 |
|
} |
971 |
|
|
988 |
– |
|
972 |
|
/** |
973 |
|
* replace value fails when the given key not mapped to expected value |
974 |
|
*/ |
989 |
|
assertEquals("Z", map.get(m1)); |
990 |
|
} |
991 |
|
|
1009 |
– |
|
992 |
|
/** |
993 |
|
* remove removes the correct key-value pair from the map |
994 |
|
*/ |
1157 |
|
ConcurrentNavigableMap map = dmap5(); |
1158 |
|
String s = map.toString(); |
1159 |
|
for (int i = 1; i <= 5; ++i) { |
1160 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
1160 |
> |
assertTrue(s.contains(String.valueOf(i))); |
1161 |
|
} |
1162 |
|
} |
1163 |
|
|
1196 |
|
} catch (NullPointerException success) {} |
1197 |
|
} |
1198 |
|
|
1217 |
– |
|
1199 |
|
/** |
1200 |
|
* put(null,x) throws NPE |
1201 |
|
*/ |
1266 |
|
* A deserialized map equals original |
1267 |
|
*/ |
1268 |
|
public void testDescendingSerialization() throws Exception { |
1269 |
< |
ConcurrentNavigableMap q = dmap5(); |
1269 |
> |
NavigableMap x = dmap5(); |
1270 |
> |
NavigableMap y = serialClone(x); |
1271 |
|
|
1272 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1273 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1274 |
< |
out.writeObject(q); |
1275 |
< |
out.close(); |
1276 |
< |
|
1295 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1296 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1297 |
< |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
1298 |
< |
assertEquals(q.size(), r.size()); |
1299 |
< |
assertTrue(q.equals(r)); |
1300 |
< |
assertTrue(r.equals(q)); |
1272 |
> |
assertTrue(x != y); |
1273 |
> |
assertEquals(x.size(), y.size()); |
1274 |
> |
assertEquals(x.toString(), y.toString()); |
1275 |
> |
assertEquals(x, y); |
1276 |
> |
assertEquals(y, x); |
1277 |
|
} |
1278 |
|
|
1303 |
– |
|
1279 |
|
/** |
1280 |
|
* subMap returns map with keys in requested range |
1281 |
|
*/ |