5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
8 |
> |
import java.util.Arrays; |
9 |
> |
import java.util.ArrayList; |
10 |
> |
import java.util.Collection; |
11 |
> |
import java.util.Iterator; |
12 |
> |
import java.util.NoSuchElementException; |
13 |
> |
import java.util.concurrent.BlockingDeque; |
14 |
> |
import java.util.concurrent.BlockingQueue; |
15 |
> |
import java.util.concurrent.CountDownLatch; |
16 |
> |
import java.util.concurrent.Executors; |
17 |
> |
import java.util.concurrent.ExecutorService; |
18 |
> |
import java.util.concurrent.LinkedBlockingDeque; |
19 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
20 |
|
import java.io.*; |
21 |
|
|
89 |
|
} |
90 |
|
|
91 |
|
/** |
92 |
< |
* offer(null) throws NPE |
92 |
> |
* offerFirst(null) throws NullPointerException |
93 |
|
*/ |
94 |
|
public void testOfferFirstNull() { |
95 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(); |
96 |
|
try { |
87 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(); |
97 |
|
q.offerFirst(null); |
98 |
|
shouldThrow(); |
99 |
|
} catch (NullPointerException success) {} |
100 |
|
} |
101 |
|
|
102 |
|
/** |
103 |
+ |
* offerLast(null) throws NullPointerException |
104 |
+ |
*/ |
105 |
+ |
public void testOfferLastNull() { |
106 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(); |
107 |
+ |
try { |
108 |
+ |
q.offerLast(null); |
109 |
+ |
shouldThrow(); |
110 |
+ |
} catch (NullPointerException success) {} |
111 |
+ |
} |
112 |
+ |
|
113 |
+ |
/** |
114 |
|
* OfferFirst succeeds |
115 |
|
*/ |
116 |
|
public void testOfferFirst() { |
328 |
|
} |
329 |
|
|
330 |
|
/** |
331 |
< |
* Constructor throws IAE if capacity argument nonpositive |
331 |
> |
* Constructor throws IllegalArgumentException if capacity argument nonpositive |
332 |
|
*/ |
333 |
|
public void testConstructor2() { |
334 |
|
try { |
335 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(0); |
335 |
> |
new LinkedBlockingDeque(0); |
336 |
|
shouldThrow(); |
337 |
|
} catch (IllegalArgumentException success) {} |
338 |
|
} |
339 |
|
|
340 |
|
/** |
341 |
< |
* Initializing from null Collection throws NPE |
341 |
> |
* Initializing from null Collection throws NullPointerException |
342 |
|
*/ |
343 |
|
public void testConstructor3() { |
344 |
|
try { |
345 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(null); |
345 |
> |
new LinkedBlockingDeque(null); |
346 |
|
shouldThrow(); |
347 |
|
} catch (NullPointerException success) {} |
348 |
|
} |
349 |
|
|
350 |
|
/** |
351 |
< |
* Initializing from Collection of null elements throws NPE |
351 |
> |
* Initializing from Collection of null elements throws NullPointerException |
352 |
|
*/ |
353 |
|
public void testConstructor4() { |
354 |
+ |
Collection<Integer> elements = Arrays.asList(new Integer[SIZE]); |
355 |
|
try { |
356 |
< |
Integer[] ints = new Integer[SIZE]; |
336 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
356 |
> |
new LinkedBlockingDeque(elements); |
357 |
|
shouldThrow(); |
358 |
|
} catch (NullPointerException success) {} |
359 |
|
} |
360 |
|
|
361 |
|
/** |
362 |
< |
* Initializing from Collection with some null elements throws NPE |
362 |
> |
* Initializing from Collection with some null elements throws |
363 |
> |
* NullPointerException |
364 |
|
*/ |
365 |
|
public void testConstructor5() { |
366 |
+ |
Integer[] ints = new Integer[SIZE]; |
367 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
368 |
+ |
ints[i] = i; |
369 |
+ |
Collection<Integer> elements = Arrays.asList(ints); |
370 |
|
try { |
371 |
< |
Integer[] ints = new Integer[SIZE]; |
347 |
< |
for (int i = 0; i < SIZE-1; ++i) |
348 |
< |
ints[i] = new Integer(i); |
349 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
371 |
> |
new LinkedBlockingDeque(elements); |
372 |
|
shouldThrow(); |
373 |
|
} catch (NullPointerException success) {} |
374 |
|
} |
379 |
|
public void testConstructor6() { |
380 |
|
Integer[] ints = new Integer[SIZE]; |
381 |
|
for (int i = 0; i < SIZE; ++i) |
382 |
< |
ints[i] = new Integer(i); |
382 |
> |
ints[i] = i; |
383 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
384 |
|
for (int i = 0; i < SIZE; ++i) |
385 |
|
assertEquals(ints[i], q.poll()); |
418 |
|
} |
419 |
|
|
420 |
|
/** |
399 |
– |
* offer(null) throws NPE |
400 |
– |
*/ |
401 |
– |
public void testOfferNull() { |
402 |
– |
try { |
403 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
404 |
– |
q.offer(null); |
405 |
– |
shouldThrow(); |
406 |
– |
} catch (NullPointerException success) {} |
407 |
– |
} |
408 |
– |
|
409 |
– |
/** |
410 |
– |
* add(null) throws NPE |
411 |
– |
*/ |
412 |
– |
public void testAddNull() { |
413 |
– |
try { |
414 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
415 |
– |
q.add(null); |
416 |
– |
shouldThrow(); |
417 |
– |
} catch (NullPointerException success) {} |
418 |
– |
} |
419 |
– |
|
420 |
– |
/** |
421 |
|
* push(null) throws NPE |
422 |
|
*/ |
423 |
|
public void testPushNull() { |
482 |
|
* add succeeds if not full; throws ISE if full |
483 |
|
*/ |
484 |
|
public void testAdd() { |
485 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
486 |
+ |
for (int i = 0; i < SIZE; ++i) |
487 |
+ |
assertTrue(q.add(new Integer(i))); |
488 |
+ |
assertEquals(0, q.remainingCapacity()); |
489 |
|
try { |
486 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
487 |
– |
for (int i = 0; i < SIZE; ++i) { |
488 |
– |
assertTrue(q.add(new Integer(i))); |
489 |
– |
} |
490 |
– |
assertEquals(0, q.remainingCapacity()); |
490 |
|
q.add(new Integer(SIZE)); |
491 |
|
shouldThrow(); |
492 |
|
} catch (IllegalStateException success) {} |
493 |
|
} |
494 |
|
|
495 |
|
/** |
497 |
– |
* addAll(null) throws NPE |
498 |
– |
*/ |
499 |
– |
public void testAddAll1() { |
500 |
– |
try { |
501 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
502 |
– |
q.addAll(null); |
503 |
– |
shouldThrow(); |
504 |
– |
} catch (NullPointerException success) {} |
505 |
– |
} |
506 |
– |
|
507 |
– |
/** |
496 |
|
* addAll(this) throws IAE |
497 |
|
*/ |
498 |
|
public void testAddAllSelf() { |
499 |
+ |
LinkedBlockingDeque q = populatedDeque(SIZE); |
500 |
|
try { |
512 |
– |
LinkedBlockingDeque q = populatedDeque(SIZE); |
501 |
|
q.addAll(q); |
502 |
|
shouldThrow(); |
503 |
|
} catch (IllegalArgumentException success) {} |
504 |
|
} |
505 |
|
|
506 |
|
/** |
519 |
– |
* addAll of a collection with null elements throws NPE |
520 |
– |
*/ |
521 |
– |
public void testAddAll2() { |
522 |
– |
try { |
523 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
524 |
– |
Integer[] ints = new Integer[SIZE]; |
525 |
– |
q.addAll(Arrays.asList(ints)); |
526 |
– |
shouldThrow(); |
527 |
– |
} catch (NullPointerException success) {} |
528 |
– |
} |
529 |
– |
|
530 |
– |
/** |
507 |
|
* addAll of a collection with any null elements throws NPE after |
508 |
|
* possibly adding some elements |
509 |
|
*/ |
510 |
|
public void testAddAll3() { |
511 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
512 |
+ |
Integer[] ints = new Integer[SIZE]; |
513 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
514 |
+ |
ints[i] = new Integer(i); |
515 |
+ |
Collection<Integer> elements = Arrays.asList(ints); |
516 |
|
try { |
517 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
537 |
< |
Integer[] ints = new Integer[SIZE]; |
538 |
< |
for (int i = 0; i < SIZE-1; ++i) |
539 |
< |
ints[i] = new Integer(i); |
540 |
< |
q.addAll(Arrays.asList(ints)); |
517 |
> |
q.addAll(elements); |
518 |
|
shouldThrow(); |
519 |
|
} catch (NullPointerException success) {} |
520 |
|
} |
521 |
|
|
522 |
|
/** |
523 |
< |
* addAll throws ISE if not enough room |
523 |
> |
* addAll throws IllegalStateException if not enough room |
524 |
|
*/ |
525 |
|
public void testAddAll4() { |
526 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE - 1); |
527 |
+ |
Integer[] ints = new Integer[SIZE]; |
528 |
+ |
for (int i = 0; i < SIZE; ++i) |
529 |
+ |
ints[i] = new Integer(i); |
530 |
+ |
Collection<Integer> elements = Arrays.asList(ints); |
531 |
|
try { |
532 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
551 |
< |
Integer[] ints = new Integer[SIZE]; |
552 |
< |
for (int i = 0; i < SIZE; ++i) |
553 |
< |
ints[i] = new Integer(i); |
554 |
< |
q.addAll(Arrays.asList(ints)); |
532 |
> |
q.addAll(elements); |
533 |
|
shouldThrow(); |
534 |
|
} catch (IllegalStateException success) {} |
535 |
|
} |
550 |
|
} |
551 |
|
|
552 |
|
/** |
575 |
– |
* put(null) throws NPE |
576 |
– |
*/ |
577 |
– |
public void testPutNull() throws InterruptedException { |
578 |
– |
try { |
579 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
580 |
– |
q.put(null); |
581 |
– |
shouldThrow(); |
582 |
– |
} catch (NullPointerException success) {} |
583 |
– |
} |
584 |
– |
|
585 |
– |
/** |
553 |
|
* all elements successfully put are contained |
554 |
|
*/ |
555 |
|
public void testPut() throws InterruptedException { |
774 |
|
* putFirst(null) throws NPE |
775 |
|
*/ |
776 |
|
public void testPutFirstNull() throws InterruptedException { |
777 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
778 |
|
try { |
811 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
779 |
|
q.putFirst(null); |
780 |
|
shouldThrow(); |
781 |
|
} catch (NullPointerException success) {} |
1121 |
|
* putLast(null) throws NPE |
1122 |
|
*/ |
1123 |
|
public void testPutLastNull() throws InterruptedException { |
1124 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1125 |
|
try { |
1158 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1126 |
|
q.putLast(null); |
1127 |
|
shouldThrow(); |
1128 |
|
} catch (NullPointerException success) {} |
1520 |
|
} |
1521 |
|
|
1522 |
|
/** |
1556 |
– |
* toArray(null) throws NullPointerException |
1557 |
– |
*/ |
1558 |
– |
public void testToArray_NullArg() { |
1559 |
– |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1560 |
– |
try { |
1561 |
– |
q.toArray(null); |
1562 |
– |
shouldThrow(); |
1563 |
– |
} catch (NullPointerException success) {} |
1564 |
– |
} |
1565 |
– |
|
1566 |
– |
/** |
1523 |
|
* toArray(incompatible array type) throws ArrayStoreException |
1524 |
|
*/ |
1525 |
|
public void testToArray1_BadArg() { |
1734 |
|
} |
1735 |
|
|
1736 |
|
/** |
1781 |
– |
* drainTo(null) throws NPE |
1782 |
– |
*/ |
1783 |
– |
public void testDrainToNull() { |
1784 |
– |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1785 |
– |
try { |
1786 |
– |
q.drainTo(null); |
1787 |
– |
shouldThrow(); |
1788 |
– |
} catch (NullPointerException success) {} |
1789 |
– |
} |
1790 |
– |
|
1791 |
– |
/** |
1792 |
– |
* drainTo(this) throws IAE |
1793 |
– |
*/ |
1794 |
– |
public void testDrainToSelf() { |
1795 |
– |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1796 |
– |
try { |
1797 |
– |
q.drainTo(q); |
1798 |
– |
shouldThrow(); |
1799 |
– |
} catch (IllegalArgumentException success) {} |
1800 |
– |
} |
1801 |
– |
|
1802 |
– |
/** |
1737 |
|
* drainTo(c) empties deque into another collection c |
1738 |
|
*/ |
1739 |
|
public void testDrainTo() { |
1778 |
|
} |
1779 |
|
|
1780 |
|
/** |
1847 |
– |
* drainTo(null, n) throws NPE |
1848 |
– |
*/ |
1849 |
– |
public void testDrainToNullN() { |
1850 |
– |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1851 |
– |
try { |
1852 |
– |
q.drainTo(null, 0); |
1853 |
– |
shouldThrow(); |
1854 |
– |
} catch (NullPointerException success) {} |
1855 |
– |
} |
1856 |
– |
|
1857 |
– |
/** |
1858 |
– |
* drainTo(this, n) throws IAE |
1859 |
– |
*/ |
1860 |
– |
public void testDrainToSelfN() { |
1861 |
– |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1862 |
– |
try { |
1863 |
– |
q.drainTo(q, 0); |
1864 |
– |
shouldThrow(); |
1865 |
– |
} catch (IllegalArgumentException success) {} |
1866 |
– |
} |
1867 |
– |
|
1868 |
– |
/** |
1781 |
|
* drainTo(c, n) empties first min(n, size) elements of queue into c |
1782 |
|
*/ |
1783 |
|
public void testDrainToN() { |