1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.*; |
11 |
< |
import java.util.concurrent.*; |
12 |
< |
import java.io.*; |
10 |
> |
import java.util.Arrays; |
11 |
> |
import java.util.Collection; |
12 |
> |
import java.util.Iterator; |
13 |
> |
import java.util.NoSuchElementException; |
14 |
> |
import java.util.Queue; |
15 |
> |
import java.util.Random; |
16 |
> |
import java.util.concurrent.ConcurrentLinkedDeque; |
17 |
|
|
18 |
|
public class ConcurrentLinkedDequeTest extends JSR166TestCase { |
19 |
|
|
435 |
|
public void testRemoveElement() { |
436 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
437 |
|
for (int i = 1; i < SIZE; i+=2) { |
438 |
< |
assertTrue(q.remove(new Integer(i))); |
438 |
> |
assertTrue(q.contains(i)); |
439 |
> |
assertTrue(q.remove(i)); |
440 |
> |
assertFalse(q.contains(i)); |
441 |
> |
assertTrue(q.contains(i-1)); |
442 |
|
} |
443 |
|
for (int i = 0; i < SIZE; i+=2) { |
444 |
< |
assertTrue(q.remove(new Integer(i))); |
445 |
< |
assertFalse(q.remove(new Integer(i+1))); |
444 |
> |
assertTrue(q.contains(i)); |
445 |
> |
assertTrue(q.remove(i)); |
446 |
> |
assertFalse(q.contains(i)); |
447 |
> |
assertFalse(q.remove(i+1)); |
448 |
> |
assertFalse(q.contains(i+1)); |
449 |
|
} |
450 |
|
assertTrue(q.isEmpty()); |
451 |
|
} |
839 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
840 |
|
String s = q.toString(); |
841 |
|
for (int i = 0; i < SIZE; ++i) { |
842 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
842 |
> |
assertTrue(s.contains(String.valueOf(i))); |
843 |
|
} |
844 |
|
} |
845 |
|
|
847 |
|
* A deserialized serialized deque has same elements in same order |
848 |
|
*/ |
849 |
|
public void testSerialization() throws Exception { |
850 |
< |
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
851 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
852 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
853 |
< |
out.writeObject(q); |
854 |
< |
out.close(); |
855 |
< |
|
856 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
857 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
858 |
< |
ConcurrentLinkedDeque r = (ConcurrentLinkedDeque)in.readObject(); |
859 |
< |
assertEquals(q.size(), r.size()); |
860 |
< |
while (!q.isEmpty()) |
861 |
< |
assertEquals(q.remove(), r.remove()); |
850 |
> |
Queue x = populatedDeque(SIZE); |
851 |
> |
Queue y = serialClone(x); |
852 |
> |
|
853 |
> |
assertTrue(x != y); |
854 |
> |
assertEquals(x.size(), y.size()); |
855 |
> |
assertEquals(x.toString(), y.toString()); |
856 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
857 |
> |
while (!x.isEmpty()) { |
858 |
> |
assertFalse(y.isEmpty()); |
859 |
> |
assertEquals(x.remove(), y.remove()); |
860 |
> |
} |
861 |
> |
assertTrue(y.isEmpty()); |
862 |
|
} |
863 |
|
|
864 |
|
} |