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); |
17 |
> |
return new TestSuite(ConcurrentSkipListMapTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
/** |
21 |
|
* Create a map from Integers 1-5 to Strings "A"-"E". |
22 |
|
*/ |
23 |
< |
private static ConcurrentSkipListMap map5() { |
24 |
< |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
23 |
> |
private static ConcurrentSkipListMap map5() { |
24 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
25 |
|
assertTrue(map.isEmpty()); |
26 |
< |
map.put(one, "A"); |
27 |
< |
map.put(five, "E"); |
28 |
< |
map.put(three, "C"); |
29 |
< |
map.put(two, "B"); |
30 |
< |
map.put(four, "D"); |
26 |
> |
map.put(one, "A"); |
27 |
> |
map.put(five, "E"); |
28 |
> |
map.put(three, "C"); |
29 |
> |
map.put(two, "B"); |
30 |
> |
map.put(four, "D"); |
31 |
|
assertFalse(map.isEmpty()); |
32 |
|
assertEquals(5, map.size()); |
33 |
< |
return map; |
33 |
> |
return map; |
34 |
|
} |
35 |
|
|
36 |
|
/** |
38 |
|
*/ |
39 |
|
public void testClear() { |
40 |
|
ConcurrentSkipListMap map = map5(); |
41 |
< |
map.clear(); |
42 |
< |
assertEquals(map.size(), 0); |
41 |
> |
map.clear(); |
42 |
> |
assertEquals(map.size(), 0); |
43 |
|
} |
44 |
|
|
45 |
|
/** |
46 |
< |
* |
46 |
> |
* |
47 |
|
*/ |
48 |
|
public void testConstructFromSorted() { |
49 |
|
ConcurrentSkipListMap map = map5(); |
59 |
|
ConcurrentSkipListMap map2 = map5(); |
60 |
|
assertEquals(map1, map2); |
61 |
|
assertEquals(map2, map1); |
62 |
< |
map1.clear(); |
62 |
> |
map1.clear(); |
63 |
|
assertFalse(map1.equals(map2)); |
64 |
|
assertFalse(map2.equals(map1)); |
65 |
|
} |
69 |
|
*/ |
70 |
|
public void testContainsKey() { |
71 |
|
ConcurrentSkipListMap map = map5(); |
72 |
< |
assertTrue(map.containsKey(one)); |
72 |
> |
assertTrue(map.containsKey(one)); |
73 |
|
assertFalse(map.containsKey(zero)); |
74 |
|
} |
75 |
|
|
78 |
|
*/ |
79 |
|
public void testContainsValue() { |
80 |
|
ConcurrentSkipListMap map = map5(); |
81 |
< |
assertTrue(map.containsValue("A")); |
81 |
> |
assertTrue(map.containsValue("A")); |
82 |
|
assertFalse(map.containsValue("Z")); |
83 |
|
} |
84 |
|
|
88 |
|
*/ |
89 |
|
public void testGet() { |
90 |
|
ConcurrentSkipListMap map = map5(); |
91 |
< |
assertEquals("A", (String)map.get(one)); |
91 |
> |
assertEquals("A", (String)map.get(one)); |
92 |
|
ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); |
93 |
|
assertNull(empty.get(one)); |
94 |
|
} |
99 |
|
public void testIsEmpty() { |
100 |
|
ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); |
101 |
|
ConcurrentSkipListMap map = map5(); |
102 |
< |
assertTrue(empty.isEmpty()); |
102 |
> |
assertTrue(empty.isEmpty()); |
103 |
|
assertFalse(map.isEmpty()); |
104 |
|
} |
105 |
|
|
108 |
|
*/ |
109 |
|
public void testFirstKey() { |
110 |
|
ConcurrentSkipListMap map = map5(); |
111 |
< |
assertEquals(one, map.firstKey()); |
111 |
> |
assertEquals(one, map.firstKey()); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
116 |
|
*/ |
117 |
|
public void testLastKey() { |
118 |
|
ConcurrentSkipListMap map = map5(); |
119 |
< |
assertEquals(five, map.lastKey()); |
119 |
> |
assertEquals(five, map.lastKey()); |
120 |
|
} |
121 |
|
|
122 |
|
|
125 |
|
*/ |
126 |
|
public void testKeySetToArray() { |
127 |
|
ConcurrentSkipListMap map = map5(); |
128 |
< |
Set s = map.keySet(); |
128 |
> |
Set s = map.keySet(); |
129 |
|
Object[] ar = s.toArray(); |
130 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
131 |
< |
assertEquals(5, ar.length); |
131 |
> |
assertEquals(5, ar.length); |
132 |
|
ar[0] = m10; |
133 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
134 |
|
} |
138 |
|
*/ |
139 |
|
public void testDescendingKeySetToArray() { |
140 |
|
ConcurrentSkipListMap map = map5(); |
141 |
< |
Set s = map.descendingKeySet(); |
141 |
> |
Set s = map.descendingKeySet(); |
142 |
|
Object[] ar = s.toArray(); |
143 |
< |
assertEquals(5, ar.length); |
143 |
> |
assertEquals(5, ar.length); |
144 |
|
assertTrue(s.containsAll(Arrays.asList(ar))); |
145 |
|
ar[0] = m10; |
146 |
|
assertFalse(s.containsAll(Arrays.asList(ar))); |
151 |
|
*/ |
152 |
|
public void testKeySet() { |
153 |
|
ConcurrentSkipListMap map = map5(); |
154 |
< |
Set s = map.keySet(); |
155 |
< |
assertEquals(5, s.size()); |
156 |
< |
assertTrue(s.contains(one)); |
157 |
< |
assertTrue(s.contains(two)); |
158 |
< |
assertTrue(s.contains(three)); |
159 |
< |
assertTrue(s.contains(four)); |
160 |
< |
assertTrue(s.contains(five)); |
154 |
> |
Set s = map.keySet(); |
155 |
> |
assertEquals(5, s.size()); |
156 |
> |
assertTrue(s.contains(one)); |
157 |
> |
assertTrue(s.contains(two)); |
158 |
> |
assertTrue(s.contains(three)); |
159 |
> |
assertTrue(s.contains(four)); |
160 |
> |
assertTrue(s.contains(five)); |
161 |
|
} |
162 |
|
|
163 |
|
/** |
165 |
|
*/ |
166 |
|
public void testKeySetOrder() { |
167 |
|
ConcurrentSkipListMap map = map5(); |
168 |
< |
Set s = map.keySet(); |
168 |
> |
Set s = map.keySet(); |
169 |
|
Iterator i = s.iterator(); |
170 |
|
Integer last = (Integer)i.next(); |
171 |
|
assertEquals(last, one); |
172 |
+ |
int count = 1; |
173 |
|
while (i.hasNext()) { |
174 |
|
Integer k = (Integer)i.next(); |
175 |
|
assertTrue(last.compareTo(k) < 0); |
176 |
|
last = k; |
177 |
+ |
++count; |
178 |
+ |
} |
179 |
+ |
assertEquals(count ,5); |
180 |
+ |
} |
181 |
+ |
|
182 |
+ |
/** |
183 |
+ |
* descending iterator of key set is inverse ordered |
184 |
+ |
*/ |
185 |
+ |
public void testKeySetDescendingIteratorOrder() { |
186 |
+ |
ConcurrentSkipListMap map = map5(); |
187 |
+ |
NavigableSet s = map.navigableKeySet(); |
188 |
+ |
Iterator i = s.descendingIterator(); |
189 |
+ |
Integer last = (Integer)i.next(); |
190 |
+ |
assertEquals(last, five); |
191 |
+ |
int count = 1; |
192 |
+ |
while (i.hasNext()) { |
193 |
+ |
Integer k = (Integer)i.next(); |
194 |
+ |
assertTrue(last.compareTo(k) > 0); |
195 |
+ |
last = k; |
196 |
+ |
++count; |
197 |
|
} |
198 |
+ |
assertEquals(count ,5); |
199 |
|
} |
200 |
|
|
201 |
|
/** |
203 |
|
*/ |
204 |
|
public void testDescendingKeySetOrder() { |
205 |
|
ConcurrentSkipListMap map = map5(); |
206 |
< |
Set s = map.descendingKeySet(); |
206 |
> |
Set s = map.descendingKeySet(); |
207 |
|
Iterator i = s.iterator(); |
208 |
|
Integer last = (Integer)i.next(); |
209 |
|
assertEquals(last, five); |
210 |
+ |
int count = 1; |
211 |
|
while (i.hasNext()) { |
212 |
|
Integer k = (Integer)i.next(); |
213 |
|
assertTrue(last.compareTo(k) > 0); |
214 |
|
last = k; |
215 |
+ |
++count; |
216 |
|
} |
217 |
+ |
assertEquals(count, 5); |
218 |
|
} |
219 |
|
|
220 |
+ |
/** |
221 |
+ |
* descending iterator of descendingKeySet is ordered |
222 |
+ |
*/ |
223 |
+ |
public void testDescendingKeySetDescendingIteratorOrder() { |
224 |
+ |
ConcurrentSkipListMap map = map5(); |
225 |
+ |
NavigableSet s = map.descendingKeySet(); |
226 |
+ |
Iterator i = s.descendingIterator(); |
227 |
+ |
Integer last = (Integer)i.next(); |
228 |
+ |
assertEquals(last, one); |
229 |
+ |
int count = 1; |
230 |
+ |
while (i.hasNext()) { |
231 |
+ |
Integer k = (Integer)i.next(); |
232 |
+ |
assertTrue(last.compareTo(k) < 0); |
233 |
+ |
last = k; |
234 |
+ |
++count; |
235 |
+ |
} |
236 |
+ |
assertEquals(count, 5); |
237 |
+ |
} |
238 |
|
|
239 |
|
/** |
240 |
|
* Values.toArray contains all values |
241 |
|
*/ |
242 |
|
public void testValuesToArray() { |
243 |
|
ConcurrentSkipListMap map = map5(); |
244 |
< |
Collection v = map.values(); |
244 |
> |
Collection v = map.values(); |
245 |
|
Object[] ar = v.toArray(); |
246 |
|
ArrayList s = new ArrayList(Arrays.asList(ar)); |
247 |
< |
assertEquals(5, ar.length); |
248 |
< |
assertTrue(s.contains("A")); |
249 |
< |
assertTrue(s.contains("B")); |
250 |
< |
assertTrue(s.contains("C")); |
251 |
< |
assertTrue(s.contains("D")); |
252 |
< |
assertTrue(s.contains("E")); |
247 |
> |
assertEquals(5, ar.length); |
248 |
> |
assertTrue(s.contains("A")); |
249 |
> |
assertTrue(s.contains("B")); |
250 |
> |
assertTrue(s.contains("C")); |
251 |
> |
assertTrue(s.contains("D")); |
252 |
> |
assertTrue(s.contains("E")); |
253 |
|
} |
254 |
|
|
255 |
|
/** |
257 |
|
*/ |
258 |
|
public void testValues() { |
259 |
|
ConcurrentSkipListMap map = map5(); |
260 |
< |
Collection s = map.values(); |
261 |
< |
assertEquals(5, s.size()); |
262 |
< |
assertTrue(s.contains("A")); |
263 |
< |
assertTrue(s.contains("B")); |
264 |
< |
assertTrue(s.contains("C")); |
265 |
< |
assertTrue(s.contains("D")); |
266 |
< |
assertTrue(s.contains("E")); |
260 |
> |
Collection s = map.values(); |
261 |
> |
assertEquals(5, s.size()); |
262 |
> |
assertTrue(s.contains("A")); |
263 |
> |
assertTrue(s.contains("B")); |
264 |
> |
assertTrue(s.contains("C")); |
265 |
> |
assertTrue(s.contains("D")); |
266 |
> |
assertTrue(s.contains("E")); |
267 |
|
} |
268 |
|
|
269 |
|
/** |
271 |
|
*/ |
272 |
|
public void testEntrySet() { |
273 |
|
ConcurrentSkipListMap map = map5(); |
274 |
< |
Set s = map.entrySet(); |
275 |
< |
assertEquals(5, s.size()); |
274 |
> |
Set s = map.entrySet(); |
275 |
> |
assertEquals(5, s.size()); |
276 |
|
Iterator it = s.iterator(); |
277 |
|
while (it.hasNext()) { |
278 |
|
Map.Entry e = (Map.Entry) it.next(); |
279 |
< |
assertTrue( |
279 |
> |
assertTrue( |
280 |
|
(e.getKey().equals(one) && e.getValue().equals("A")) || |
281 |
|
(e.getKey().equals(two) && e.getValue().equals("B")) || |
282 |
|
(e.getKey().equals(three) && e.getValue().equals("C")) || |
290 |
|
*/ |
291 |
|
public void testDescendingEntrySet() { |
292 |
|
ConcurrentSkipListMap map = map5(); |
293 |
< |
Set s = map.descendingMap().entrySet(); |
294 |
< |
assertEquals(5, s.size()); |
293 |
> |
Set s = map.descendingMap().entrySet(); |
294 |
> |
assertEquals(5, s.size()); |
295 |
|
Iterator it = s.iterator(); |
296 |
|
while (it.hasNext()) { |
297 |
|
Map.Entry e = (Map.Entry) it.next(); |
298 |
< |
assertTrue( |
298 |
> |
assertTrue( |
299 |
|
(e.getKey().equals(one) && e.getValue().equals("A")) || |
300 |
|
(e.getKey().equals(two) && e.getValue().equals("B")) || |
301 |
|
(e.getKey().equals(three) && e.getValue().equals("C")) || |
309 |
|
*/ |
310 |
|
public void testEntrySetToArray() { |
311 |
|
ConcurrentSkipListMap map = map5(); |
312 |
< |
Set s = map.entrySet(); |
312 |
> |
Set s = map.entrySet(); |
313 |
|
Object[] ar = s.toArray(); |
314 |
|
assertEquals(5, ar.length); |
315 |
|
for (int i = 0; i < 5; ++i) { |
323 |
|
*/ |
324 |
|
public void testDescendingEntrySetToArray() { |
325 |
|
ConcurrentSkipListMap map = map5(); |
326 |
< |
Set s = map.descendingMap().entrySet(); |
326 |
> |
Set s = map.descendingMap().entrySet(); |
327 |
|
Object[] ar = s.toArray(); |
328 |
|
assertEquals(5, ar.length); |
329 |
|
for (int i = 0; i < 5; ++i) { |
338 |
|
public void testPutAll() { |
339 |
|
ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); |
340 |
|
ConcurrentSkipListMap map = map5(); |
341 |
< |
empty.putAll(map); |
342 |
< |
assertEquals(5, empty.size()); |
343 |
< |
assertTrue(empty.containsKey(one)); |
344 |
< |
assertTrue(empty.containsKey(two)); |
345 |
< |
assertTrue(empty.containsKey(three)); |
346 |
< |
assertTrue(empty.containsKey(four)); |
347 |
< |
assertTrue(empty.containsKey(five)); |
341 |
> |
empty.putAll(map); |
342 |
> |
assertEquals(5, empty.size()); |
343 |
> |
assertTrue(empty.containsKey(one)); |
344 |
> |
assertTrue(empty.containsKey(two)); |
345 |
> |
assertTrue(empty.containsKey(three)); |
346 |
> |
assertTrue(empty.containsKey(four)); |
347 |
> |
assertTrue(empty.containsKey(five)); |
348 |
|
} |
349 |
|
|
350 |
|
/** |
352 |
|
*/ |
353 |
|
public void testPutIfAbsent() { |
354 |
|
ConcurrentSkipListMap map = map5(); |
355 |
< |
map.putIfAbsent(six, "Z"); |
355 |
> |
map.putIfAbsent(six, "Z"); |
356 |
|
assertTrue(map.containsKey(six)); |
357 |
|
} |
358 |
|
|
369 |
|
*/ |
370 |
|
public void testReplace() { |
371 |
|
ConcurrentSkipListMap map = map5(); |
372 |
< |
assertNull(map.replace(six, "Z")); |
372 |
> |
assertNull(map.replace(six, "Z")); |
373 |
|
assertFalse(map.containsKey(six)); |
374 |
|
} |
375 |
|
|
389 |
|
public void testReplaceValue() { |
390 |
|
ConcurrentSkipListMap map = map5(); |
391 |
|
assertEquals("A", map.get(one)); |
392 |
< |
assertFalse(map.replace(one, "Z", "Z")); |
392 |
> |
assertFalse(map.replace(one, "Z", "Z")); |
393 |
|
assertEquals("A", map.get(one)); |
394 |
|
} |
395 |
|
|
399 |
|
public void testReplaceValue2() { |
400 |
|
ConcurrentSkipListMap map = map5(); |
401 |
|
assertEquals("A", map.get(one)); |
402 |
< |
assertTrue(map.replace(one, "A", "Z")); |
402 |
> |
assertTrue(map.replace(one, "A", "Z")); |
403 |
|
assertEquals("Z", map.get(one)); |
404 |
|
} |
405 |
|
|
409 |
|
*/ |
410 |
|
public void testRemove() { |
411 |
|
ConcurrentSkipListMap map = map5(); |
412 |
< |
map.remove(five); |
413 |
< |
assertEquals(4, map.size()); |
414 |
< |
assertFalse(map.containsKey(five)); |
412 |
> |
map.remove(five); |
413 |
> |
assertEquals(4, map.size()); |
414 |
> |
assertFalse(map.containsKey(five)); |
415 |
|
} |
416 |
|
|
417 |
|
/** |
419 |
|
*/ |
420 |
|
public void testRemove2() { |
421 |
|
ConcurrentSkipListMap map = map5(); |
422 |
< |
assertTrue(map.containsKey(five)); |
422 |
> |
assertTrue(map.containsKey(five)); |
423 |
|
assertEquals("E", map.get(five)); |
424 |
< |
map.remove(five, "E"); |
425 |
< |
assertEquals(4, map.size()); |
426 |
< |
assertFalse(map.containsKey(five)); |
427 |
< |
map.remove(four, "A"); |
428 |
< |
assertEquals(4, map.size()); |
429 |
< |
assertTrue(map.containsKey(four)); |
424 |
> |
map.remove(five, "E"); |
425 |
> |
assertEquals(4, map.size()); |
426 |
> |
assertFalse(map.containsKey(five)); |
427 |
> |
map.remove(four, "A"); |
428 |
> |
assertEquals(4, map.size()); |
429 |
> |
assertTrue(map.containsKey(four)); |
430 |
|
|
431 |
|
} |
432 |
|
|
516 |
|
assertEquals(two, e.getKey()); |
517 |
|
try { |
518 |
|
e.setValue("X"); |
519 |
< |
fail(); |
520 |
< |
} catch(UnsupportedOperationException success) {} |
519 |
> |
shouldThrow(); |
520 |
> |
} catch (UnsupportedOperationException success) {} |
521 |
|
e = map.higherEntry(zero); |
522 |
|
assertEquals(one, e.getKey()); |
523 |
|
try { |
524 |
|
e.setValue("X"); |
525 |
< |
fail(); |
526 |
< |
} catch(UnsupportedOperationException success) {} |
525 |
> |
shouldThrow(); |
526 |
> |
} catch (UnsupportedOperationException success) {} |
527 |
|
e = map.floorEntry(one); |
528 |
|
assertEquals(one, e.getKey()); |
529 |
|
try { |
530 |
|
e.setValue("X"); |
531 |
< |
fail(); |
532 |
< |
} catch(UnsupportedOperationException success) {} |
531 |
> |
shouldThrow(); |
532 |
> |
} catch (UnsupportedOperationException success) {} |
533 |
|
e = map.ceilingEntry(five); |
534 |
|
assertEquals(five, e.getKey()); |
535 |
|
try { |
536 |
|
e.setValue("X"); |
537 |
< |
fail(); |
538 |
< |
} catch(UnsupportedOperationException success) {} |
537 |
> |
shouldThrow(); |
538 |
> |
} catch (UnsupportedOperationException success) {} |
539 |
|
} |
540 |
|
|
541 |
|
|
638 |
|
try { |
639 |
|
e.setValue("A"); |
640 |
|
shouldThrow(); |
641 |
< |
} catch (Exception ok) { |
599 |
< |
} |
641 |
> |
} catch (UnsupportedOperationException success) {} |
642 |
|
e = map.pollFirstEntry(); |
643 |
|
assertNull(e); |
644 |
|
} |
665 |
|
try { |
666 |
|
e.setValue("E"); |
667 |
|
shouldThrow(); |
668 |
< |
} catch (Exception ok) { |
627 |
< |
} |
668 |
> |
} catch (UnsupportedOperationException success) {} |
669 |
|
e = map.pollLastEntry(); |
670 |
|
assertNull(e); |
671 |
|
} |
676 |
|
public void testSize() { |
677 |
|
ConcurrentSkipListMap map = map5(); |
678 |
|
ConcurrentSkipListMap empty = new ConcurrentSkipListMap(); |
679 |
< |
assertEquals(0, empty.size()); |
680 |
< |
assertEquals(5, map.size()); |
679 |
> |
assertEquals(0, empty.size()); |
680 |
> |
assertEquals(5, map.size()); |
681 |
|
} |
682 |
|
|
683 |
|
/** |
689 |
|
for (int i = 1; i <= 5; ++i) { |
690 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
691 |
|
} |
692 |
< |
} |
692 |
> |
} |
693 |
|
|
694 |
|
// Exception tests |
695 |
|
|
701 |
|
ConcurrentSkipListMap c = map5(); |
702 |
|
c.get(null); |
703 |
|
shouldThrow(); |
704 |
< |
} catch(NullPointerException e){} |
704 |
> |
} catch (NullPointerException success) {} |
705 |
|
} |
706 |
|
|
707 |
|
/** |
712 |
|
ConcurrentSkipListMap c = map5(); |
713 |
|
c.containsKey(null); |
714 |
|
shouldThrow(); |
715 |
< |
} catch(NullPointerException e){} |
715 |
> |
} catch (NullPointerException success) {} |
716 |
|
} |
717 |
|
|
718 |
|
/** |
723 |
|
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
724 |
|
c.containsValue(null); |
725 |
|
shouldThrow(); |
726 |
< |
} catch(NullPointerException e){} |
726 |
> |
} catch (NullPointerException success) {} |
727 |
|
} |
728 |
|
|
729 |
|
|
735 |
|
ConcurrentSkipListMap c = map5(); |
736 |
|
c.put(null, "whatever"); |
737 |
|
shouldThrow(); |
738 |
< |
} catch(NullPointerException e){} |
738 |
> |
} catch (NullPointerException success) {} |
739 |
|
} |
740 |
|
|
741 |
|
/** |
746 |
|
ConcurrentSkipListMap c = map5(); |
747 |
|
c.putIfAbsent(null, "whatever"); |
748 |
|
shouldThrow(); |
749 |
< |
} catch(NullPointerException e){} |
749 |
> |
} catch (NullPointerException success) {} |
750 |
|
} |
751 |
|
|
752 |
|
/** |
757 |
|
ConcurrentSkipListMap c = map5(); |
758 |
|
c.replace(null, "whatever"); |
759 |
|
shouldThrow(); |
760 |
< |
} catch(NullPointerException e){} |
760 |
> |
} catch (NullPointerException success) {} |
761 |
|
} |
762 |
|
|
763 |
|
/** |
768 |
|
ConcurrentSkipListMap c = map5(); |
769 |
|
c.replace(null, one, "whatever"); |
770 |
|
shouldThrow(); |
771 |
< |
} catch(NullPointerException e){} |
771 |
> |
} catch (NullPointerException success) {} |
772 |
|
} |
773 |
|
|
774 |
|
/** |
780 |
|
c.put("sadsdf", "asdads"); |
781 |
|
c.remove(null); |
782 |
|
shouldThrow(); |
783 |
< |
} catch(NullPointerException e){} |
783 |
> |
} catch (NullPointerException success) {} |
784 |
|
} |
785 |
|
|
786 |
|
/** |
792 |
|
c.put("sadsdf", "asdads"); |
793 |
|
c.remove(null, "whatever"); |
794 |
|
shouldThrow(); |
795 |
< |
} catch(NullPointerException e){} |
795 |
> |
} catch (NullPointerException success) {} |
796 |
|
} |
797 |
|
|
798 |
|
/** |
799 |
|
* remove(x, null) returns false |
800 |
|
*/ |
801 |
|
public void testRemove3() { |
802 |
< |
try { |
803 |
< |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
804 |
< |
c.put("sadsdf", "asdads"); |
764 |
< |
assertFalse(c.remove("sadsdf", null)); |
765 |
< |
} catch(NullPointerException e){ |
766 |
< |
fail(); |
767 |
< |
} |
802 |
> |
ConcurrentSkipListMap c = new ConcurrentSkipListMap(); |
803 |
> |
c.put("sadsdf", "asdads"); |
804 |
> |
assertFalse(c.remove("sadsdf", null)); |
805 |
|
} |
806 |
|
|
807 |
|
/** |
808 |
|
* A deserialized map equals original |
809 |
|
*/ |
810 |
< |
public void testSerialization() { |
810 |
> |
public void testSerialization() throws Exception { |
811 |
|
ConcurrentSkipListMap q = map5(); |
812 |
|
|
813 |
< |
try { |
814 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
815 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
816 |
< |
out.writeObject(q); |
817 |
< |
out.close(); |
818 |
< |
|
819 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
820 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
821 |
< |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
822 |
< |
assertEquals(q.size(), r.size()); |
823 |
< |
assertTrue(q.equals(r)); |
787 |
< |
assertTrue(r.equals(q)); |
788 |
< |
} catch(Exception e){ |
789 |
< |
e.printStackTrace(); |
790 |
< |
unexpectedException(); |
791 |
< |
} |
813 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
814 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
815 |
> |
out.writeObject(q); |
816 |
> |
out.close(); |
817 |
> |
|
818 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
819 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
820 |
> |
ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject(); |
821 |
> |
assertEquals(q.size(), r.size()); |
822 |
> |
assertTrue(q.equals(r)); |
823 |
> |
assertTrue(r.equals(q)); |
824 |
|
} |
825 |
|
|
826 |
|
|
852 |
|
k = (Integer)(r.next()); |
853 |
|
assertEquals(two, k); |
854 |
|
assertFalse(r.hasNext()); |
855 |
< |
|
855 |
> |
|
856 |
|
Iterator j = sm.keySet().iterator(); |
857 |
|
j.next(); |
858 |
|
j.remove(); |
861 |
|
assertEquals(1, sm.size()); |
862 |
|
assertEquals(three, sm.firstKey()); |
863 |
|
assertEquals(three, sm.lastKey()); |
864 |
< |
assertTrue(sm.remove(three) != null); |
864 |
> |
assertEquals("C", sm.remove(three)); |
865 |
|
assertTrue(sm.isEmpty()); |
866 |
|
assertEquals(3, map.size()); |
867 |
|
} |
886 |
|
k = (Integer)(r.next()); |
887 |
|
assertEquals(two, k); |
888 |
|
assertFalse(r.hasNext()); |
889 |
< |
|
889 |
> |
|
890 |
|
Iterator j = sm.keySet().iterator(); |
891 |
|
j.next(); |
892 |
|
j.remove(); |
894 |
|
assertEquals(4, map.size()); |
895 |
|
assertEquals(0, sm.size()); |
896 |
|
assertTrue(sm.isEmpty()); |
897 |
< |
assertTrue(sm.remove(three) == null); |
897 |
> |
assertSame(sm.remove(three), null); |
898 |
|
assertEquals(4, map.size()); |
899 |
|
} |
900 |
|
|
976 |
|
NavigableMap ssm = sm.tailMap(four, true); |
977 |
|
assertEquals(four, ssm.firstKey()); |
978 |
|
assertEquals(five, ssm.lastKey()); |
979 |
< |
assertTrue(ssm.remove(four) != null); |
979 |
> |
assertEquals("D", ssm.remove(four)); |
980 |
|
assertEquals(1, ssm.size()); |
981 |
|
assertEquals(3, sm.size()); |
982 |
|
assertEquals(4, map.size()); |
988 |
|
/** |
989 |
|
* Submaps of submaps subdivide correctly |
990 |
|
*/ |
991 |
< |
public void testRecursiveSubMaps() { |
992 |
< |
int mapSize = 1000; |
993 |
< |
Class cl = ConcurrentSkipListMap.class; |
991 |
> |
public void testRecursiveSubMaps() throws Exception { |
992 |
> |
int mapSize = 1000; |
993 |
> |
Class cl = ConcurrentSkipListMap.class; |
994 |
|
NavigableMap<Integer, Integer> map = newMap(cl); |
995 |
|
bs = new BitSet(mapSize); |
996 |
|
|
1006 |
|
0, mapSize - 1, true); |
1007 |
|
} |
1008 |
|
|
1009 |
< |
static NavigableMap<Integer, Integer> newMap(Class cl) { |
1010 |
< |
NavigableMap<Integer, Integer> result = null; |
1011 |
< |
try { |
980 |
< |
result = (NavigableMap<Integer, Integer>) cl.newInstance(); |
981 |
< |
} catch(Exception e) { |
982 |
< |
fail(); |
983 |
< |
} |
1009 |
> |
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception { |
1010 |
> |
NavigableMap<Integer, Integer> result = |
1011 |
> |
(NavigableMap<Integer, Integer>) cl.newInstance(); |
1012 |
|
assertEquals(result.size(), 0); |
1013 |
|
assertFalse(result.keySet().iterator().hasNext()); |
1014 |
|
return result; |
1031 |
|
} |
1032 |
|
|
1033 |
|
// Remove a bunch of entries with iterator |
1034 |
< |
for(Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1034 |
> |
for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1035 |
|
if (rnd.nextBoolean()) { |
1036 |
|
bs.clear(it.next()); |
1037 |
|
it.remove(); |
1056 |
|
} |
1057 |
|
|
1058 |
|
// Remove a bunch of entries with iterator |
1059 |
< |
for(Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1059 |
> |
for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { |
1060 |
|
if (rnd.nextBoolean()) { |
1061 |
|
bs.clear(it.next()); |
1062 |
|
it.remove(); |
1071 |
|
} else { |
1072 |
|
try { |
1073 |
|
map.put(key, 2 * key); |
1074 |
< |
fail(); |
1075 |
< |
} catch(IllegalArgumentException e) { |
1048 |
< |
// expected |
1049 |
< |
} |
1074 |
> |
shouldThrow(); |
1075 |
> |
} catch (IllegalArgumentException success) {} |
1076 |
|
} |
1077 |
|
} |
1078 |
|
} |
1267 |
|
assertEq(rs.last(), -1); |
1268 |
|
try { |
1269 |
|
map.firstKey(); |
1270 |
< |
fail(); |
1271 |
< |
} catch(NoSuchElementException e) { |
1246 |
< |
// expected |
1247 |
< |
} |
1270 |
> |
shouldThrow(); |
1271 |
> |
} catch (NoSuchElementException success) {} |
1272 |
|
try { |
1273 |
|
map.lastKey(); |
1274 |
< |
fail(); |
1275 |
< |
} catch(NoSuchElementException e) { |
1252 |
< |
// expected |
1253 |
< |
} |
1274 |
> |
shouldThrow(); |
1275 |
> |
} catch (NoSuchElementException success) {} |
1276 |
|
} |
1277 |
|
} |
1278 |
|
|
1286 |
|
static boolean eq(Integer i, int j) { |
1287 |
|
return i == null ? j == -1 : i == j; |
1288 |
|
} |
1289 |
< |
|
1289 |
> |
|
1290 |
|
} |