5 |
|
* Other contributors include John Vint |
6 |
|
*/ |
7 |
|
|
8 |
< |
import java.io.BufferedInputStream; |
9 |
< |
import java.io.BufferedOutputStream; |
10 |
< |
import java.io.ByteArrayInputStream; |
11 |
< |
import java.io.ByteArrayOutputStream; |
12 |
< |
import java.io.ObjectInputStream; |
13 |
< |
import java.io.ObjectOutputStream; |
14 |
< |
import java.util.ArrayList; |
8 |
> |
import junit.framework.*; |
9 |
|
import java.util.Arrays; |
10 |
+ |
import java.util.ArrayList; |
11 |
|
import java.util.Collection; |
12 |
|
import java.util.Iterator; |
13 |
|
import java.util.List; |
14 |
|
import java.util.NoSuchElementException; |
15 |
+ |
import java.util.Queue; |
16 |
|
import java.util.concurrent.BlockingQueue; |
17 |
|
import java.util.concurrent.CountDownLatch; |
18 |
|
import java.util.concurrent.Executors; |
20 |
|
import java.util.concurrent.LinkedTransferQueue; |
21 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
22 |
|
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
27 |
– |
import junit.framework.Test; |
28 |
– |
import junit.framework.TestSuite; |
23 |
|
|
24 |
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
25 |
|
public class LinkedTransferQueueTest extends JSR166TestCase { |
368 |
|
} |
369 |
|
|
370 |
|
/** |
377 |
– |
* remove(x) removes x and returns true if present |
378 |
– |
*/ |
379 |
– |
public void testRemoveElement() throws InterruptedException { |
380 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
381 |
– |
for (int i = 1; i < SIZE; i+=2) { |
382 |
– |
assertTrue(q.contains(i)); |
383 |
– |
assertTrue(q.remove(i)); |
384 |
– |
assertFalse(q.contains(i)); |
385 |
– |
assertTrue(q.contains(i-1)); |
386 |
– |
} |
387 |
– |
for (int i = 0; i < SIZE; i+=2) { |
388 |
– |
assertTrue(q.contains(i)); |
389 |
– |
assertTrue(q.remove(i)); |
390 |
– |
assertFalse(q.contains(i)); |
391 |
– |
assertFalse(q.remove(i+1)); |
392 |
– |
assertFalse(q.contains(i+1)); |
393 |
– |
} |
394 |
– |
checkEmpty(q); |
395 |
– |
} |
396 |
– |
|
397 |
– |
/** |
371 |
|
* An add following remove(x) succeeds |
372 |
|
*/ |
373 |
|
public void testRemoveElementAndAdd() throws InterruptedException { |
622 |
|
* A deserialized serialized queue has same elements in same order |
623 |
|
*/ |
624 |
|
public void testSerialization() throws Exception { |
625 |
< |
LinkedTransferQueue q = populatedQueue(SIZE); |
625 |
> |
Queue x = populatedQueue(SIZE); |
626 |
> |
Queue y = serialClone(x); |
627 |
|
|
628 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
629 |
< |
ObjectOutputStream out |
630 |
< |
= new ObjectOutputStream(new BufferedOutputStream(bout)); |
631 |
< |
out.writeObject(q); |
632 |
< |
out.close(); |
633 |
< |
|
634 |
< |
ByteArrayInputStream bin |
661 |
< |
= new ByteArrayInputStream(bout.toByteArray()); |
662 |
< |
ObjectInputStream in |
663 |
< |
= new ObjectInputStream(new BufferedInputStream(bin)); |
664 |
< |
LinkedTransferQueue r = (LinkedTransferQueue) in.readObject(); |
665 |
< |
|
666 |
< |
assertEquals(q.size(), r.size()); |
667 |
< |
assertEquals(q.toString(), r.toString()); |
668 |
< |
assertTrue(Arrays.equals(q.toArray(), r.toArray())); |
669 |
< |
while (!q.isEmpty()) { |
670 |
< |
assertEquals(q.remove(), r.remove()); |
628 |
> |
assertTrue(x != y); |
629 |
> |
assertEquals(x.size(), y.size()); |
630 |
> |
assertEquals(x.toString(), y.toString()); |
631 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
632 |
> |
while (!x.isEmpty()) { |
633 |
> |
assertFalse(y.isEmpty()); |
634 |
> |
assertEquals(x.remove(), y.remove()); |
635 |
|
} |
636 |
+ |
assertTrue(y.isEmpty()); |
637 |
|
} |
638 |
|
|
639 |
|
/** |