11 |
|
|
12 |
|
public class ConcurrentSkipListSubSetTest 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(ConcurrentSkipListSubSetTest.class); |
17 |
> |
return new TestSuite(ConcurrentSkipListSubSetTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
static class MyReverseComparator implements Comparator { |
35 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
36 |
|
assertTrue(q.isEmpty()); |
37 |
|
|
38 |
< |
for(int i = n-1; i >= 0; i-=2) |
39 |
< |
assertTrue(q.add(new Integer(i))); |
40 |
< |
for(int i = (n & 1); i < n; i+=2) |
41 |
< |
assertTrue(q.add(new Integer(i))); |
38 |
> |
for (int i = n-1; i >= 0; i-=2) |
39 |
> |
assertTrue(q.add(new Integer(i))); |
40 |
> |
for (int i = (n & 1); i < n; i+=2) |
41 |
> |
assertTrue(q.add(new Integer(i))); |
42 |
|
assertTrue(q.add(new Integer(-n))); |
43 |
|
assertTrue(q.add(new Integer(n))); |
44 |
|
NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false); |
45 |
|
assertFalse(s.isEmpty()); |
46 |
< |
assertEquals(n, s.size()); |
46 |
> |
assertEquals(n, s.size()); |
47 |
|
return s; |
48 |
|
} |
49 |
|
|
61 |
|
q.add(zero); |
62 |
|
q.add(seven); |
63 |
|
NavigableSet s = q.subSet(one, true, seven, false); |
64 |
< |
assertEquals(5, s.size()); |
64 |
> |
assertEquals(5, s.size()); |
65 |
|
return s; |
66 |
|
} |
67 |
|
|
77 |
|
q.add(m4); |
78 |
|
q.add(m5); |
79 |
|
NavigableSet s = q.descendingSet(); |
80 |
< |
assertEquals(5, s.size()); |
80 |
> |
assertEquals(5, s.size()); |
81 |
|
return s; |
82 |
|
} |
83 |
|
|
84 |
|
private static NavigableSet set0() { |
85 |
< |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
85 |
> |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
86 |
|
assertTrue(set.isEmpty()); |
87 |
|
return set.tailSet(m1, true); |
88 |
|
} |
89 |
|
|
90 |
|
private static NavigableSet dset0() { |
91 |
< |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
91 |
> |
ConcurrentSkipListSet set = new ConcurrentSkipListSet(); |
92 |
|
assertTrue(set.isEmpty()); |
93 |
|
return set; |
94 |
|
} |
134 |
|
* add(null) throws NPE |
135 |
|
*/ |
136 |
|
public void testAddNull() { |
137 |
< |
try { |
137 |
> |
try { |
138 |
|
NavigableSet q = set0(); |
139 |
|
q.add(null); |
140 |
|
shouldThrow(); |
141 |
< |
} catch (NullPointerException success) { } |
141 |
> |
} catch (NullPointerException success) {} |
142 |
|
} |
143 |
|
|
144 |
|
/** |
168 |
|
q.add(new Object()); |
169 |
|
q.add(new Object()); |
170 |
|
shouldThrow(); |
171 |
< |
} |
172 |
< |
catch(ClassCastException success) {} |
171 |
> |
} catch (ClassCastException success) {} |
172 |
|
} |
173 |
|
|
174 |
|
|
180 |
|
NavigableSet q = set0(); |
181 |
|
q.addAll(null); |
182 |
|
shouldThrow(); |
183 |
< |
} |
185 |
< |
catch (NullPointerException success) {} |
183 |
> |
} catch (NullPointerException success) {} |
184 |
|
} |
185 |
|
/** |
186 |
|
* addAll of a collection with null elements throws NPE |
191 |
|
Integer[] ints = new Integer[SIZE]; |
192 |
|
q.addAll(Arrays.asList(ints)); |
193 |
|
shouldThrow(); |
194 |
< |
} |
197 |
< |
catch (NullPointerException success) {} |
194 |
> |
} catch (NullPointerException success) {} |
195 |
|
} |
196 |
|
/** |
197 |
|
* addAll of a collection with any null elements throws NPE after |
205 |
|
ints[i] = new Integer(i+SIZE); |
206 |
|
q.addAll(Arrays.asList(ints)); |
207 |
|
shouldThrow(); |
208 |
< |
} |
212 |
< |
catch (NullPointerException success) {} |
208 |
> |
} catch (NullPointerException success) {} |
209 |
|
} |
210 |
|
|
211 |
|
/** |
234 |
|
for (int i = 0; i < SIZE; ++i) { |
235 |
|
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
236 |
|
} |
237 |
< |
assertNull(q.pollFirst()); |
237 |
> |
assertNull(q.pollFirst()); |
238 |
|
} |
239 |
|
|
240 |
|
/** |
410 |
|
*/ |
411 |
|
public void testToArray() { |
412 |
|
NavigableSet q = populatedSet(SIZE); |
413 |
< |
Object[] o = q.toArray(); |
413 |
> |
Object[] o = q.toArray(); |
414 |
|
Arrays.sort(o); |
415 |
< |
for(int i = 0; i < o.length; i++) |
416 |
< |
assertEquals(o[i], q.pollFirst()); |
415 |
> |
for (int i = 0; i < o.length; i++) |
416 |
> |
assertEquals(o[i], q.pollFirst()); |
417 |
|
} |
418 |
|
|
419 |
|
/** |
421 |
|
*/ |
422 |
|
public void testToArray2() { |
423 |
|
NavigableSet q = populatedSet(SIZE); |
424 |
< |
Integer[] ints = new Integer[SIZE]; |
425 |
< |
ints = (Integer[])q.toArray(ints); |
424 |
> |
Integer[] ints = new Integer[SIZE]; |
425 |
> |
ints = (Integer[])q.toArray(ints); |
426 |
|
Arrays.sort(ints); |
427 |
< |
for(int i = 0; i < ints.length; i++) |
427 |
> |
for (int i = 0; i < ints.length; i++) |
428 |
|
assertEquals(ints[i], q.pollFirst()); |
429 |
|
} |
430 |
|
|
434 |
|
public void testIterator() { |
435 |
|
NavigableSet q = populatedSet(SIZE); |
436 |
|
int i = 0; |
437 |
< |
Iterator it = q.iterator(); |
438 |
< |
while(it.hasNext()) { |
437 |
> |
Iterator it = q.iterator(); |
438 |
> |
while (it.hasNext()) { |
439 |
|
assertTrue(q.contains(it.next())); |
440 |
|
++i; |
441 |
|
} |
448 |
|
public void testEmptyIterator() { |
449 |
|
NavigableSet q = set0(); |
450 |
|
int i = 0; |
451 |
< |
Iterator it = q.iterator(); |
452 |
< |
while(it.hasNext()) { |
451 |
> |
Iterator it = q.iterator(); |
452 |
> |
while (it.hasNext()) { |
453 |
|
assertTrue(q.contains(it.next())); |
454 |
|
++i; |
455 |
|
} |
490 |
|
/** |
491 |
|
* A deserialized serialized set has same elements |
492 |
|
*/ |
493 |
< |
public void testSerialization() { |
493 |
> |
public void testSerialization() throws Exception { |
494 |
|
NavigableSet q = populatedSet(SIZE); |
495 |
< |
try { |
496 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
497 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
498 |
< |
out.writeObject(q); |
499 |
< |
out.close(); |
500 |
< |
|
501 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
502 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
503 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
504 |
< |
assertEquals(q.size(), r.size()); |
505 |
< |
while (!q.isEmpty()) |
510 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
511 |
< |
} catch(Exception e){ |
512 |
< |
e.printStackTrace(); |
513 |
< |
unexpectedException(); |
514 |
< |
} |
495 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
496 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
497 |
> |
out.writeObject(q); |
498 |
> |
out.close(); |
499 |
> |
|
500 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
501 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
502 |
> |
NavigableSet r = (NavigableSet)in.readObject(); |
503 |
> |
assertEquals(q.size(), r.size()); |
504 |
> |
while (!q.isEmpty()) |
505 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
506 |
|
} |
507 |
|
|
508 |
|
/** |
643 |
|
* add(null) throws NPE |
644 |
|
*/ |
645 |
|
public void testDescendingAddNull() { |
646 |
< |
try { |
646 |
> |
try { |
647 |
|
NavigableSet q = dset0(); |
648 |
|
q.add(null); |
649 |
|
shouldThrow(); |
650 |
< |
} catch (NullPointerException success) { } |
650 |
> |
} catch (NullPointerException success) {} |
651 |
|
} |
652 |
|
|
653 |
|
/** |
677 |
|
q.add(new Object()); |
678 |
|
q.add(new Object()); |
679 |
|
shouldThrow(); |
680 |
< |
} |
690 |
< |
catch(ClassCastException success) {} |
680 |
> |
} catch (ClassCastException success) {} |
681 |
|
} |
682 |
|
|
683 |
|
|
689 |
|
NavigableSet q = dset0(); |
690 |
|
q.addAll(null); |
691 |
|
shouldThrow(); |
692 |
< |
} |
703 |
< |
catch (NullPointerException success) {} |
692 |
> |
} catch (NullPointerException success) {} |
693 |
|
} |
694 |
|
/** |
695 |
|
* addAll of a collection with null elements throws NPE |
700 |
|
Integer[] ints = new Integer[SIZE]; |
701 |
|
q.addAll(Arrays.asList(ints)); |
702 |
|
shouldThrow(); |
703 |
< |
} |
715 |
< |
catch (NullPointerException success) {} |
703 |
> |
} catch (NullPointerException success) {} |
704 |
|
} |
705 |
|
/** |
706 |
|
* addAll of a collection with any null elements throws NPE after |
714 |
|
ints[i] = new Integer(i+SIZE); |
715 |
|
q.addAll(Arrays.asList(ints)); |
716 |
|
shouldThrow(); |
717 |
< |
} |
730 |
< |
catch (NullPointerException success) {} |
717 |
> |
} catch (NullPointerException success) {} |
718 |
|
} |
719 |
|
|
720 |
|
/** |
743 |
|
for (int i = 0; i < SIZE; ++i) { |
744 |
|
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
745 |
|
} |
746 |
< |
assertNull(q.pollFirst()); |
746 |
> |
assertNull(q.pollFirst()); |
747 |
|
} |
748 |
|
|
749 |
|
/** |
919 |
|
*/ |
920 |
|
public void testDescendingToArray() { |
921 |
|
NavigableSet q = populatedSet(SIZE); |
922 |
< |
Object[] o = q.toArray(); |
922 |
> |
Object[] o = q.toArray(); |
923 |
|
Arrays.sort(o); |
924 |
< |
for(int i = 0; i < o.length; i++) |
925 |
< |
assertEquals(o[i], q.pollFirst()); |
924 |
> |
for (int i = 0; i < o.length; i++) |
925 |
> |
assertEquals(o[i], q.pollFirst()); |
926 |
|
} |
927 |
|
|
928 |
|
/** |
930 |
|
*/ |
931 |
|
public void testDescendingToArray2() { |
932 |
|
NavigableSet q = populatedSet(SIZE); |
933 |
< |
Integer[] ints = new Integer[SIZE]; |
934 |
< |
ints = (Integer[])q.toArray(ints); |
933 |
> |
Integer[] ints = new Integer[SIZE]; |
934 |
> |
ints = (Integer[])q.toArray(ints); |
935 |
|
Arrays.sort(ints); |
936 |
< |
for(int i = 0; i < ints.length; i++) |
936 |
> |
for (int i = 0; i < ints.length; i++) |
937 |
|
assertEquals(ints[i], q.pollFirst()); |
938 |
|
} |
939 |
|
|
943 |
|
public void testDescendingIterator() { |
944 |
|
NavigableSet q = populatedSet(SIZE); |
945 |
|
int i = 0; |
946 |
< |
Iterator it = q.iterator(); |
947 |
< |
while(it.hasNext()) { |
946 |
> |
Iterator it = q.iterator(); |
947 |
> |
while (it.hasNext()) { |
948 |
|
assertTrue(q.contains(it.next())); |
949 |
|
++i; |
950 |
|
} |
957 |
|
public void testDescendingEmptyIterator() { |
958 |
|
NavigableSet q = dset0(); |
959 |
|
int i = 0; |
960 |
< |
Iterator it = q.iterator(); |
961 |
< |
while(it.hasNext()) { |
960 |
> |
Iterator it = q.iterator(); |
961 |
> |
while (it.hasNext()) { |
962 |
|
assertTrue(q.contains(it.next())); |
963 |
|
++i; |
964 |
|
} |
999 |
|
/** |
1000 |
|
* A deserialized serialized set has same elements |
1001 |
|
*/ |
1002 |
< |
public void testDescendingSerialization() { |
1002 |
> |
public void testDescendingSerialization() throws Exception { |
1003 |
|
NavigableSet q = populatedSet(SIZE); |
1004 |
< |
try { |
1005 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1006 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1007 |
< |
out.writeObject(q); |
1008 |
< |
out.close(); |
1009 |
< |
|
1010 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1011 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1012 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
1013 |
< |
assertEquals(q.size(), r.size()); |
1014 |
< |
while (!q.isEmpty()) |
1028 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
1029 |
< |
} catch(Exception e){ |
1030 |
< |
e.printStackTrace(); |
1031 |
< |
unexpectedException(); |
1032 |
< |
} |
1004 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1005 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1006 |
> |
out.writeObject(q); |
1007 |
> |
out.close(); |
1008 |
> |
|
1009 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1010 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1011 |
> |
NavigableSet r = (NavigableSet)in.readObject(); |
1012 |
> |
assertEquals(q.size(), r.size()); |
1013 |
> |
while (!q.isEmpty()) |
1014 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
1015 |
|
} |
1016 |
|
|
1017 |
|
/** |