7 |
|
import junit.framework.*; |
8 |
|
import java.util.*; |
9 |
|
import java.util.concurrent.*; |
10 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
11 |
|
import java.io.*; |
12 |
|
|
13 |
|
public class LinkedBlockingDequeTest extends JSR166TestCase { |
71 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(); |
72 |
|
q.offerFirst(null); |
73 |
|
shouldThrow(); |
74 |
< |
} catch (NullPointerException success) { |
74 |
< |
} |
74 |
> |
} catch (NullPointerException success) {} |
75 |
|
} |
76 |
|
|
77 |
|
/** |
168 |
|
try { |
169 |
|
q.getFirst(); |
170 |
|
shouldThrow(); |
171 |
< |
} |
172 |
< |
catch (NoSuchElementException success) {} |
171 |
> |
} catch (NoSuchElementException success) {} |
172 |
|
} |
173 |
|
|
174 |
|
/** |
183 |
|
try { |
184 |
|
q.getLast(); |
185 |
|
shouldThrow(); |
186 |
< |
} |
188 |
< |
catch (NoSuchElementException success) {} |
186 |
> |
} catch (NoSuchElementException success) {} |
187 |
|
assertNull(q.peekLast()); |
188 |
|
} |
189 |
|
|
198 |
|
try { |
199 |
|
q.removeFirst(); |
200 |
|
shouldThrow(); |
201 |
< |
} catch (NoSuchElementException success) { |
204 |
< |
} |
201 |
> |
} catch (NoSuchElementException success) {} |
202 |
|
} |
203 |
|
|
204 |
|
/** |
212 |
|
try { |
213 |
|
q.remove(); |
214 |
|
shouldThrow(); |
215 |
< |
} catch (NoSuchElementException success) { |
219 |
< |
} |
215 |
> |
} catch (NoSuchElementException success) {} |
216 |
|
} |
217 |
|
|
218 |
|
/** |
282 |
|
try { |
283 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(0); |
284 |
|
shouldThrow(); |
285 |
< |
} |
290 |
< |
catch (IllegalArgumentException success) {} |
285 |
> |
} catch (IllegalArgumentException success) {} |
286 |
|
} |
287 |
|
|
288 |
|
/** |
292 |
|
try { |
293 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(null); |
294 |
|
shouldThrow(); |
295 |
< |
} |
301 |
< |
catch (NullPointerException success) {} |
295 |
> |
} catch (NullPointerException success) {} |
296 |
|
} |
297 |
|
|
298 |
|
/** |
303 |
|
Integer[] ints = new Integer[SIZE]; |
304 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
305 |
|
shouldThrow(); |
306 |
< |
} |
313 |
< |
catch (NullPointerException success) {} |
306 |
> |
} catch (NullPointerException success) {} |
307 |
|
} |
308 |
|
|
309 |
|
/** |
316 |
|
ints[i] = new Integer(i); |
317 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
318 |
|
shouldThrow(); |
319 |
< |
} |
327 |
< |
catch (NullPointerException success) {} |
319 |
> |
} catch (NullPointerException success) {} |
320 |
|
} |
321 |
|
|
322 |
|
/** |
374 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
375 |
|
q.offer(null); |
376 |
|
shouldThrow(); |
377 |
< |
} catch (NullPointerException success) { } |
377 |
> |
} catch (NullPointerException success) {} |
378 |
|
} |
379 |
|
|
380 |
|
/** |
385 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
386 |
|
q.add(null); |
387 |
|
shouldThrow(); |
388 |
< |
} catch (NullPointerException success) { } |
388 |
> |
} catch (NullPointerException success) {} |
389 |
|
} |
390 |
|
|
391 |
|
/** |
396 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
397 |
|
q.push(null); |
398 |
|
shouldThrow(); |
399 |
< |
} catch (NullPointerException success) { } |
399 |
> |
} catch (NullPointerException success) {} |
400 |
|
} |
401 |
|
|
402 |
|
/** |
412 |
|
} |
413 |
|
assertEquals(0, q.remainingCapacity()); |
414 |
|
q.push(new Integer(SIZE)); |
415 |
< |
} catch (IllegalStateException success) { |
416 |
< |
} |
415 |
> |
shouldThrow(); |
416 |
> |
} catch (IllegalStateException success) {} |
417 |
|
} |
418 |
|
|
419 |
|
/** |
438 |
|
try { |
439 |
|
q.pop(); |
440 |
|
shouldThrow(); |
441 |
< |
} catch (NoSuchElementException success) { |
450 |
< |
} |
441 |
> |
} catch (NoSuchElementException success) {} |
442 |
|
} |
443 |
|
|
444 |
|
|
462 |
|
} |
463 |
|
assertEquals(0, q.remainingCapacity()); |
464 |
|
q.add(new Integer(SIZE)); |
465 |
< |
} catch (IllegalStateException success) { |
466 |
< |
} |
465 |
> |
shouldThrow(); |
466 |
> |
} catch (IllegalStateException success) {} |
467 |
|
} |
468 |
|
|
469 |
|
/** |
474 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
475 |
|
q.addAll(null); |
476 |
|
shouldThrow(); |
477 |
< |
} |
487 |
< |
catch (NullPointerException success) {} |
477 |
> |
} catch (NullPointerException success) {} |
478 |
|
} |
479 |
|
|
480 |
|
/** |
485 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
486 |
|
q.addAll(q); |
487 |
|
shouldThrow(); |
488 |
< |
} |
499 |
< |
catch (IllegalArgumentException success) {} |
488 |
> |
} catch (IllegalArgumentException success) {} |
489 |
|
} |
490 |
|
|
491 |
|
/** |
497 |
|
Integer[] ints = new Integer[SIZE]; |
498 |
|
q.addAll(Arrays.asList(ints)); |
499 |
|
shouldThrow(); |
500 |
< |
} |
512 |
< |
catch (NullPointerException success) {} |
500 |
> |
} catch (NullPointerException success) {} |
501 |
|
} |
502 |
|
/** |
503 |
|
* addAll of a collection with any null elements throws NPE after |
511 |
|
ints[i] = new Integer(i); |
512 |
|
q.addAll(Arrays.asList(ints)); |
513 |
|
shouldThrow(); |
514 |
< |
} |
527 |
< |
catch (NullPointerException success) {} |
514 |
> |
} catch (NullPointerException success) {} |
515 |
|
} |
516 |
|
/** |
517 |
|
* addAll throws ISE if not enough room |
524 |
|
ints[i] = new Integer(i); |
525 |
|
q.addAll(Arrays.asList(ints)); |
526 |
|
shouldThrow(); |
527 |
< |
} |
541 |
< |
catch (IllegalStateException success) {} |
527 |
> |
} catch (IllegalStateException success) {} |
528 |
|
} |
529 |
|
/** |
530 |
|
* Deque contains all elements, in traversal order, of successful addAll |
548 |
|
/** |
549 |
|
* put(null) throws NPE |
550 |
|
*/ |
551 |
< |
public void testPutNull() { |
551 |
> |
public void testPutNull() throws InterruptedException { |
552 |
|
try { |
553 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
554 |
|
q.put(null); |
555 |
|
shouldThrow(); |
556 |
< |
} |
557 |
< |
catch (NullPointerException success) { |
572 |
< |
} |
573 |
< |
catch (InterruptedException ie) { |
574 |
< |
unexpectedException(); |
575 |
< |
} |
576 |
< |
} |
556 |
> |
} catch (NullPointerException success) {} |
557 |
> |
} |
558 |
|
|
559 |
|
/** |
560 |
|
* all elements successfully put are contained |
561 |
|
*/ |
562 |
< |
public void testPut() { |
563 |
< |
try { |
564 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
565 |
< |
for (int i = 0; i < SIZE; ++i) { |
566 |
< |
Integer I = new Integer(i); |
567 |
< |
q.put(I); |
587 |
< |
assertTrue(q.contains(I)); |
588 |
< |
} |
589 |
< |
assertEquals(0, q.remainingCapacity()); |
590 |
< |
} |
591 |
< |
catch (InterruptedException ie) { |
592 |
< |
unexpectedException(); |
562 |
> |
public void testPut() throws InterruptedException { |
563 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
564 |
> |
for (int i = 0; i < SIZE; ++i) { |
565 |
> |
Integer I = new Integer(i); |
566 |
> |
q.put(I); |
567 |
> |
assertTrue(q.contains(I)); |
568 |
|
} |
569 |
+ |
assertEquals(0, q.remainingCapacity()); |
570 |
|
} |
571 |
|
|
572 |
|
/** |
573 |
|
* put blocks interruptibly if full |
574 |
|
*/ |
575 |
< |
public void testBlockingPut() { |
576 |
< |
Thread t = new Thread(new Runnable() { |
577 |
< |
public void run() { |
578 |
< |
int added = 0; |
579 |
< |
try { |
580 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
581 |
< |
for (int i = 0; i < SIZE; ++i) { |
582 |
< |
q.put(new Integer(i)); |
583 |
< |
++added; |
608 |
< |
} |
609 |
< |
q.put(new Integer(SIZE)); |
610 |
< |
threadShouldThrow(); |
611 |
< |
} catch (InterruptedException ie) { |
612 |
< |
threadAssertEquals(added, SIZE); |
575 |
> |
public void testBlockingPut() throws InterruptedException { |
576 |
> |
Thread t = new Thread(new CheckedRunnable() { |
577 |
> |
public void realRun() { |
578 |
> |
int added = 0; |
579 |
> |
try { |
580 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
581 |
> |
for (int i = 0; i < SIZE; ++i) { |
582 |
> |
q.put(new Integer(i)); |
583 |
> |
++added; |
584 |
|
} |
585 |
< |
}}); |
585 |
> |
q.put(new Integer(SIZE)); |
586 |
> |
threadShouldThrow(); |
587 |
> |
} catch (InterruptedException success) { |
588 |
> |
threadAssertEquals(added, SIZE); |
589 |
> |
} |
590 |
> |
}}); |
591 |
> |
|
592 |
|
t.start(); |
593 |
< |
try { |
594 |
< |
Thread.sleep(SHORT_DELAY_MS); |
595 |
< |
t.interrupt(); |
619 |
< |
t.join(); |
620 |
< |
} |
621 |
< |
catch (InterruptedException ie) { |
622 |
< |
unexpectedException(); |
623 |
< |
} |
593 |
> |
Thread.sleep(SHORT_DELAY_MS); |
594 |
> |
t.interrupt(); |
595 |
> |
t.join(); |
596 |
|
} |
597 |
|
|
598 |
|
/** |
599 |
|
* put blocks waiting for take when full |
600 |
|
*/ |
601 |
< |
public void testPutWithTake() { |
601 |
> |
public void testPutWithTake() throws InterruptedException { |
602 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
603 |
< |
Thread t = new Thread(new Runnable() { |
604 |
< |
public void run() { |
605 |
< |
int added = 0; |
606 |
< |
try { |
607 |
< |
q.put(new Object()); |
608 |
< |
++added; |
609 |
< |
q.put(new Object()); |
610 |
< |
++added; |
611 |
< |
q.put(new Object()); |
612 |
< |
++added; |
613 |
< |
q.put(new Object()); |
614 |
< |
++added; |
615 |
< |
threadShouldThrow(); |
616 |
< |
} catch (InterruptedException e) { |
617 |
< |
threadAssertTrue(added >= 2); |
646 |
< |
} |
603 |
> |
Thread t = new Thread(new CheckedRunnable() { |
604 |
> |
public void realRun() { |
605 |
> |
int added = 0; |
606 |
> |
try { |
607 |
> |
q.put(new Object()); |
608 |
> |
++added; |
609 |
> |
q.put(new Object()); |
610 |
> |
++added; |
611 |
> |
q.put(new Object()); |
612 |
> |
++added; |
613 |
> |
q.put(new Object()); |
614 |
> |
++added; |
615 |
> |
threadShouldThrow(); |
616 |
> |
} catch (InterruptedException success) { |
617 |
> |
threadAssertTrue(added >= 2); |
618 |
|
} |
619 |
< |
}); |
620 |
< |
try { |
621 |
< |
t.start(); |
622 |
< |
Thread.sleep(SHORT_DELAY_MS); |
623 |
< |
q.take(); |
624 |
< |
t.interrupt(); |
625 |
< |
t.join(); |
655 |
< |
} catch (Exception e) { |
656 |
< |
unexpectedException(); |
657 |
< |
} |
619 |
> |
}}); |
620 |
> |
|
621 |
> |
t.start(); |
622 |
> |
Thread.sleep(SHORT_DELAY_MS); |
623 |
> |
q.take(); |
624 |
> |
t.interrupt(); |
625 |
> |
t.join(); |
626 |
|
} |
627 |
|
|
628 |
|
/** |
629 |
|
* timed offer times out if full and elements not taken |
630 |
|
*/ |
631 |
< |
public void testTimedOffer() { |
631 |
> |
public void testTimedOffer() throws InterruptedException { |
632 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
633 |
< |
Thread t = new Thread(new Runnable() { |
634 |
< |
public void run() { |
635 |
< |
try { |
636 |
< |
q.put(new Object()); |
637 |
< |
q.put(new Object()); |
638 |
< |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
639 |
< |
q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
672 |
< |
threadShouldThrow(); |
673 |
< |
} catch (InterruptedException success) {} |
674 |
< |
} |
675 |
< |
}); |
633 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
634 |
> |
public void realRun() throws InterruptedException { |
635 |
> |
q.put(new Object()); |
636 |
> |
q.put(new Object()); |
637 |
> |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
638 |
> |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
639 |
> |
}}; |
640 |
|
|
641 |
< |
try { |
642 |
< |
t.start(); |
643 |
< |
Thread.sleep(SMALL_DELAY_MS); |
644 |
< |
t.interrupt(); |
681 |
< |
t.join(); |
682 |
< |
} catch (Exception e) { |
683 |
< |
unexpectedException(); |
684 |
< |
} |
641 |
> |
t.start(); |
642 |
> |
Thread.sleep(SMALL_DELAY_MS); |
643 |
> |
t.interrupt(); |
644 |
> |
t.join(); |
645 |
|
} |
646 |
|
|
647 |
|
/** |
648 |
|
* take retrieves elements in FIFO order |
649 |
|
*/ |
650 |
< |
public void testTake() { |
651 |
< |
try { |
652 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
653 |
< |
for (int i = 0; i < SIZE; ++i) { |
694 |
< |
assertEquals(i, ((Integer)q.take()).intValue()); |
695 |
< |
} |
696 |
< |
} catch (InterruptedException e) { |
697 |
< |
unexpectedException(); |
650 |
> |
public void testTake() throws InterruptedException { |
651 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
652 |
> |
for (int i = 0; i < SIZE; ++i) { |
653 |
> |
assertEquals(i, ((Integer)q.take()).intValue()); |
654 |
|
} |
655 |
|
} |
656 |
|
|
657 |
|
/** |
658 |
|
* take blocks interruptibly when empty |
659 |
|
*/ |
660 |
< |
public void testTakeFromEmpty() { |
660 |
> |
public void testTakeFromEmpty() throws InterruptedException { |
661 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
662 |
< |
Thread t = new Thread(new Runnable() { |
663 |
< |
public void run() { |
664 |
< |
try { |
665 |
< |
q.take(); |
666 |
< |
threadShouldThrow(); |
667 |
< |
} catch (InterruptedException success) { } |
668 |
< |
} |
669 |
< |
}); |
670 |
< |
try { |
715 |
< |
t.start(); |
716 |
< |
Thread.sleep(SHORT_DELAY_MS); |
717 |
< |
t.interrupt(); |
718 |
< |
t.join(); |
719 |
< |
} catch (Exception e) { |
720 |
< |
unexpectedException(); |
721 |
< |
} |
662 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
663 |
> |
public void realRun() throws InterruptedException { |
664 |
> |
q.take(); |
665 |
> |
}}; |
666 |
> |
|
667 |
> |
t.start(); |
668 |
> |
Thread.sleep(SHORT_DELAY_MS); |
669 |
> |
t.interrupt(); |
670 |
> |
t.join(); |
671 |
|
} |
672 |
|
|
673 |
|
/** |
674 |
|
* Take removes existing elements until empty, then blocks interruptibly |
675 |
|
*/ |
676 |
< |
public void testBlockingTake() { |
677 |
< |
Thread t = new Thread(new Runnable() { |
678 |
< |
public void run() { |
679 |
< |
try { |
680 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
681 |
< |
for (int i = 0; i < SIZE; ++i) { |
682 |
< |
assertEquals(i, ((Integer)q.take()).intValue()); |
683 |
< |
} |
684 |
< |
q.take(); |
685 |
< |
threadShouldThrow(); |
737 |
< |
} catch (InterruptedException success) { |
738 |
< |
} |
739 |
< |
}}); |
676 |
> |
public void testBlockingTake() throws InterruptedException { |
677 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
678 |
> |
public void realRun() throws InterruptedException { |
679 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
680 |
> |
for (int i = 0; i < SIZE; ++i) { |
681 |
> |
assertEquals(i, ((Integer)q.take()).intValue()); |
682 |
> |
} |
683 |
> |
q.take(); |
684 |
> |
}}; |
685 |
> |
|
686 |
|
t.start(); |
687 |
< |
try { |
688 |
< |
Thread.sleep(SHORT_DELAY_MS); |
689 |
< |
t.interrupt(); |
744 |
< |
t.join(); |
745 |
< |
} |
746 |
< |
catch (InterruptedException ie) { |
747 |
< |
unexpectedException(); |
748 |
< |
} |
687 |
> |
Thread.sleep(SHORT_DELAY_MS); |
688 |
> |
t.interrupt(); |
689 |
> |
t.join(); |
690 |
|
} |
691 |
|
|
692 |
|
|
704 |
|
/** |
705 |
|
* timed poll with zero timeout succeeds when non-empty, else times out |
706 |
|
*/ |
707 |
< |
public void testTimedPoll0() { |
708 |
< |
try { |
709 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
710 |
< |
for (int i = 0; i < SIZE; ++i) { |
770 |
< |
assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); |
771 |
< |
} |
772 |
< |
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
773 |
< |
} catch (InterruptedException e) { |
774 |
< |
unexpectedException(); |
707 |
> |
public void testTimedPoll0() throws InterruptedException { |
708 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
709 |
> |
for (int i = 0; i < SIZE; ++i) { |
710 |
> |
assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); |
711 |
|
} |
712 |
+ |
assertNull(q.poll(0, MILLISECONDS)); |
713 |
|
} |
714 |
|
|
715 |
|
/** |
716 |
|
* timed poll with nonzero timeout succeeds when non-empty, else times out |
717 |
|
*/ |
718 |
< |
public void testTimedPoll() { |
719 |
< |
try { |
720 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
721 |
< |
for (int i = 0; i < SIZE; ++i) { |
785 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
786 |
< |
} |
787 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
788 |
< |
} catch (InterruptedException e) { |
789 |
< |
unexpectedException(); |
718 |
> |
public void testTimedPoll() throws InterruptedException { |
719 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
720 |
> |
for (int i = 0; i < SIZE; ++i) { |
721 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
722 |
|
} |
723 |
+ |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
724 |
|
} |
725 |
|
|
726 |
|
/** |
727 |
|
* Interrupted timed poll throws InterruptedException instead of |
728 |
|
* returning timeout status |
729 |
|
*/ |
730 |
< |
public void testInterruptedTimedPoll() { |
731 |
< |
Thread t = new Thread(new Runnable() { |
732 |
< |
public void run() { |
733 |
< |
try { |
734 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
735 |
< |
for (int i = 0; i < SIZE; ++i) { |
736 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
737 |
< |
} |
738 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
739 |
< |
} catch (InterruptedException success) { |
807 |
< |
} |
808 |
< |
}}); |
730 |
> |
public void testInterruptedTimedPoll() throws InterruptedException { |
731 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
732 |
> |
public void realRun() throws InterruptedException { |
733 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
734 |
> |
for (int i = 0; i < SIZE; ++i) { |
735 |
> |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
736 |
> |
} |
737 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
738 |
> |
}}; |
739 |
> |
|
740 |
|
t.start(); |
741 |
< |
try { |
742 |
< |
Thread.sleep(SHORT_DELAY_MS); |
743 |
< |
t.interrupt(); |
813 |
< |
t.join(); |
814 |
< |
} |
815 |
< |
catch (InterruptedException ie) { |
816 |
< |
unexpectedException(); |
817 |
< |
} |
741 |
> |
Thread.sleep(SHORT_DELAY_MS); |
742 |
> |
t.interrupt(); |
743 |
> |
t.join(); |
744 |
|
} |
745 |
|
|
746 |
|
/** |
747 |
|
* timed poll before a delayed offer fails; after offer succeeds; |
748 |
|
* on interruption throws |
749 |
|
*/ |
750 |
< |
public void testTimedPollWithOffer() { |
750 |
> |
public void testTimedPollWithOffer() throws InterruptedException { |
751 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
752 |
< |
Thread t = new Thread(new Runnable() { |
753 |
< |
public void run() { |
754 |
< |
try { |
755 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
756 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
757 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
758 |
< |
threadShouldThrow(); |
759 |
< |
} catch (InterruptedException success) { } |
760 |
< |
} |
761 |
< |
}); |
762 |
< |
try { |
763 |
< |
t.start(); |
838 |
< |
Thread.sleep(SMALL_DELAY_MS); |
839 |
< |
assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
840 |
< |
t.interrupt(); |
841 |
< |
t.join(); |
842 |
< |
} catch (Exception e) { |
843 |
< |
unexpectedException(); |
844 |
< |
} |
752 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
753 |
> |
public void realRun() throws InterruptedException { |
754 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
755 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
756 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
757 |
> |
}}; |
758 |
> |
|
759 |
> |
t.start(); |
760 |
> |
Thread.sleep(SMALL_DELAY_MS); |
761 |
> |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
762 |
> |
t.interrupt(); |
763 |
> |
t.join(); |
764 |
|
} |
765 |
|
|
766 |
|
|
767 |
|
/** |
768 |
|
* putFirst(null) throws NPE |
769 |
|
*/ |
770 |
< |
public void testPutFirstNull() { |
770 |
> |
public void testPutFirstNull() throws InterruptedException { |
771 |
|
try { |
772 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
773 |
|
q.putFirst(null); |
774 |
|
shouldThrow(); |
775 |
< |
} |
857 |
< |
catch (NullPointerException success) { |
858 |
< |
} |
859 |
< |
catch (InterruptedException ie) { |
860 |
< |
unexpectedException(); |
861 |
< |
} |
775 |
> |
} catch (NullPointerException success) {} |
776 |
|
} |
777 |
|
|
778 |
|
/** |
779 |
|
* all elements successfully putFirst are contained |
780 |
|
*/ |
781 |
< |
public void testPutFirst() { |
782 |
< |
try { |
783 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
784 |
< |
for (int i = 0; i < SIZE; ++i) { |
785 |
< |
Integer I = new Integer(i); |
786 |
< |
q.putFirst(I); |
873 |
< |
assertTrue(q.contains(I)); |
874 |
< |
} |
875 |
< |
assertEquals(0, q.remainingCapacity()); |
781 |
> |
public void testPutFirst() throws InterruptedException { |
782 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
783 |
> |
for (int i = 0; i < SIZE; ++i) { |
784 |
> |
Integer I = new Integer(i); |
785 |
> |
q.putFirst(I); |
786 |
> |
assertTrue(q.contains(I)); |
787 |
|
} |
788 |
< |
catch (InterruptedException ie) { |
878 |
< |
unexpectedException(); |
879 |
< |
} |
788 |
> |
assertEquals(0, q.remainingCapacity()); |
789 |
|
} |
790 |
|
|
791 |
|
/** |
792 |
|
* putFirst blocks interruptibly if full |
793 |
|
*/ |
794 |
< |
public void testBlockingPutFirst() { |
794 |
> |
public void testBlockingPutFirst() throws InterruptedException { |
795 |
|
Thread t = new Thread(new Runnable() { |
796 |
|
public void run() { |
797 |
|
int added = 0; |
803 |
|
} |
804 |
|
q.putFirst(new Integer(SIZE)); |
805 |
|
threadShouldThrow(); |
806 |
< |
} catch (InterruptedException ie) { |
806 |
> |
} catch (InterruptedException success) { |
807 |
|
threadAssertEquals(added, SIZE); |
808 |
|
} |
809 |
|
}}); |
810 |
+ |
|
811 |
|
t.start(); |
812 |
< |
try { |
813 |
< |
Thread.sleep(SHORT_DELAY_MS); |
814 |
< |
t.interrupt(); |
905 |
< |
t.join(); |
906 |
< |
} |
907 |
< |
catch (InterruptedException ie) { |
908 |
< |
unexpectedException(); |
909 |
< |
} |
812 |
> |
Thread.sleep(SHORT_DELAY_MS); |
813 |
> |
t.interrupt(); |
814 |
> |
t.join(); |
815 |
|
} |
816 |
|
|
817 |
|
/** |
818 |
|
* putFirst blocks waiting for take when full |
819 |
|
*/ |
820 |
< |
public void testPutFirstWithTake() { |
820 |
> |
public void testPutFirstWithTake() throws InterruptedException { |
821 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
822 |
|
Thread t = new Thread(new Runnable() { |
823 |
|
public void run() { |
832 |
|
q.putFirst(new Object()); |
833 |
|
++added; |
834 |
|
threadShouldThrow(); |
835 |
< |
} catch (InterruptedException e) { |
835 |
> |
} catch (InterruptedException success) { |
836 |
|
threadAssertTrue(added >= 2); |
837 |
|
} |
838 |
|
} |
839 |
|
}); |
840 |
< |
try { |
841 |
< |
t.start(); |
842 |
< |
Thread.sleep(SHORT_DELAY_MS); |
843 |
< |
q.take(); |
844 |
< |
t.interrupt(); |
845 |
< |
t.join(); |
941 |
< |
} catch (Exception e) { |
942 |
< |
unexpectedException(); |
943 |
< |
} |
840 |
> |
|
841 |
> |
t.start(); |
842 |
> |
Thread.sleep(SHORT_DELAY_MS); |
843 |
> |
q.take(); |
844 |
> |
t.interrupt(); |
845 |
> |
t.join(); |
846 |
|
} |
847 |
|
|
848 |
|
/** |
849 |
|
* timed offerFirst times out if full and elements not taken |
850 |
|
*/ |
851 |
< |
public void testTimedOfferFirst() { |
851 |
> |
public void testTimedOfferFirst() throws InterruptedException { |
852 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
853 |
< |
Thread t = new Thread(new Runnable() { |
854 |
< |
public void run() { |
855 |
< |
try { |
856 |
< |
q.putFirst(new Object()); |
857 |
< |
q.putFirst(new Object()); |
858 |
< |
threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
859 |
< |
q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
958 |
< |
threadShouldThrow(); |
959 |
< |
} catch (InterruptedException success) {} |
960 |
< |
} |
961 |
< |
}); |
853 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
854 |
> |
public void realRun() throws InterruptedException { |
855 |
> |
q.putFirst(new Object()); |
856 |
> |
q.putFirst(new Object()); |
857 |
> |
threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
858 |
> |
q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS); |
859 |
> |
}}; |
860 |
|
|
861 |
< |
try { |
862 |
< |
t.start(); |
863 |
< |
Thread.sleep(SMALL_DELAY_MS); |
864 |
< |
t.interrupt(); |
967 |
< |
t.join(); |
968 |
< |
} catch (Exception e) { |
969 |
< |
unexpectedException(); |
970 |
< |
} |
861 |
> |
t.start(); |
862 |
> |
Thread.sleep(SMALL_DELAY_MS); |
863 |
> |
t.interrupt(); |
864 |
> |
t.join(); |
865 |
|
} |
866 |
|
|
867 |
|
/** |
868 |
|
* take retrieves elements in FIFO order |
869 |
|
*/ |
870 |
< |
public void testTakeFirst() { |
871 |
< |
try { |
872 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
873 |
< |
for (int i = 0; i < SIZE; ++i) { |
980 |
< |
assertEquals(i, ((Integer)q.takeFirst()).intValue()); |
981 |
< |
} |
982 |
< |
} catch (InterruptedException e) { |
983 |
< |
unexpectedException(); |
870 |
> |
public void testTakeFirst() throws InterruptedException { |
871 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
872 |
> |
for (int i = 0; i < SIZE; ++i) { |
873 |
> |
assertEquals(i, ((Integer)q.takeFirst()).intValue()); |
874 |
|
} |
875 |
|
} |
876 |
|
|
877 |
|
/** |
878 |
|
* takeFirst blocks interruptibly when empty |
879 |
|
*/ |
880 |
< |
public void testTakeFirstFromEmpty() { |
880 |
> |
public void testTakeFirstFromEmpty() throws InterruptedException { |
881 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
882 |
< |
Thread t = new Thread(new Runnable() { |
883 |
< |
public void run() { |
884 |
< |
try { |
885 |
< |
q.takeFirst(); |
886 |
< |
threadShouldThrow(); |
887 |
< |
} catch (InterruptedException success) { } |
888 |
< |
} |
889 |
< |
}); |
890 |
< |
try { |
1001 |
< |
t.start(); |
1002 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1003 |
< |
t.interrupt(); |
1004 |
< |
t.join(); |
1005 |
< |
} catch (Exception e) { |
1006 |
< |
unexpectedException(); |
1007 |
< |
} |
882 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
883 |
> |
public void realRun() throws InterruptedException { |
884 |
> |
q.takeFirst(); |
885 |
> |
}}; |
886 |
> |
|
887 |
> |
t.start(); |
888 |
> |
Thread.sleep(SHORT_DELAY_MS); |
889 |
> |
t.interrupt(); |
890 |
> |
t.join(); |
891 |
|
} |
892 |
|
|
893 |
|
/** |
894 |
|
* TakeFirst removes existing elements until empty, then blocks interruptibly |
895 |
|
*/ |
896 |
< |
public void testBlockingTakeFirst() { |
897 |
< |
Thread t = new Thread(new Runnable() { |
898 |
< |
public void run() { |
899 |
< |
try { |
900 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
901 |
< |
for (int i = 0; i < SIZE; ++i) { |
902 |
< |
assertEquals(i, ((Integer)q.takeFirst()).intValue()); |
903 |
< |
} |
904 |
< |
q.takeFirst(); |
905 |
< |
threadShouldThrow(); |
1023 |
< |
} catch (InterruptedException success) { |
1024 |
< |
} |
1025 |
< |
}}); |
896 |
> |
public void testBlockingTakeFirst() throws InterruptedException { |
897 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
898 |
> |
public void realRun() throws InterruptedException { |
899 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
900 |
> |
for (int i = 0; i < SIZE; ++i) { |
901 |
> |
assertEquals(i, ((Integer)q.takeFirst()).intValue()); |
902 |
> |
} |
903 |
> |
q.takeFirst(); |
904 |
> |
}}; |
905 |
> |
|
906 |
|
t.start(); |
907 |
< |
try { |
908 |
< |
Thread.sleep(SHORT_DELAY_MS); |
909 |
< |
t.interrupt(); |
1030 |
< |
t.join(); |
1031 |
< |
} |
1032 |
< |
catch (InterruptedException ie) { |
1033 |
< |
unexpectedException(); |
1034 |
< |
} |
907 |
> |
Thread.sleep(SHORT_DELAY_MS); |
908 |
> |
t.interrupt(); |
909 |
> |
t.join(); |
910 |
|
} |
911 |
|
|
912 |
|
|
913 |
|
/** |
914 |
|
* timed pollFirst with zero timeout succeeds when non-empty, else times out |
915 |
|
*/ |
916 |
< |
public void testTimedPollFirst0() { |
917 |
< |
try { |
918 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
919 |
< |
for (int i = 0; i < SIZE; ++i) { |
1045 |
< |
assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue()); |
1046 |
< |
} |
1047 |
< |
assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS)); |
1048 |
< |
} catch (InterruptedException e) { |
1049 |
< |
unexpectedException(); |
916 |
> |
public void testTimedPollFirst0() throws InterruptedException { |
917 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
918 |
> |
for (int i = 0; i < SIZE; ++i) { |
919 |
> |
assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue()); |
920 |
|
} |
921 |
+ |
assertNull(q.pollFirst(0, MILLISECONDS)); |
922 |
|
} |
923 |
|
|
924 |
|
/** |
925 |
|
* timed pollFirst with nonzero timeout succeeds when non-empty, else times out |
926 |
|
*/ |
927 |
< |
public void testTimedPollFirst() { |
928 |
< |
try { |
929 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
930 |
< |
for (int i = 0; i < SIZE; ++i) { |
1060 |
< |
assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1061 |
< |
} |
1062 |
< |
assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1063 |
< |
} catch (InterruptedException e) { |
1064 |
< |
unexpectedException(); |
927 |
> |
public void testTimedPollFirst() throws InterruptedException { |
928 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
929 |
> |
for (int i = 0; i < SIZE; ++i) { |
930 |
> |
assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
931 |
|
} |
932 |
+ |
assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
933 |
|
} |
934 |
|
|
935 |
|
/** |
936 |
|
* Interrupted timed pollFirst throws InterruptedException instead of |
937 |
|
* returning timeout status |
938 |
|
*/ |
939 |
< |
public void testInterruptedTimedPollFirst() { |
940 |
< |
Thread t = new Thread(new Runnable() { |
941 |
< |
public void run() { |
942 |
< |
try { |
943 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
944 |
< |
for (int i = 0; i < SIZE; ++i) { |
945 |
< |
threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
946 |
< |
} |
947 |
< |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
948 |
< |
} catch (InterruptedException success) { |
1082 |
< |
} |
1083 |
< |
}}); |
939 |
> |
public void testInterruptedTimedPollFirst() throws InterruptedException { |
940 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
941 |
> |
public void realRun() throws InterruptedException { |
942 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
943 |
> |
for (int i = 0; i < SIZE; ++i) { |
944 |
> |
threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
945 |
> |
} |
946 |
> |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
947 |
> |
}}; |
948 |
> |
|
949 |
|
t.start(); |
950 |
< |
try { |
951 |
< |
Thread.sleep(SHORT_DELAY_MS); |
952 |
< |
t.interrupt(); |
1088 |
< |
t.join(); |
1089 |
< |
} |
1090 |
< |
catch (InterruptedException ie) { |
1091 |
< |
unexpectedException(); |
1092 |
< |
} |
950 |
> |
Thread.sleep(SHORT_DELAY_MS); |
951 |
> |
t.interrupt(); |
952 |
> |
t.join(); |
953 |
|
} |
954 |
|
|
955 |
|
/** |
956 |
|
* timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds; |
957 |
|
* on interruption throws |
958 |
|
*/ |
959 |
< |
public void testTimedPollFirstWithOfferFirst() { |
959 |
> |
public void testTimedPollFirstWithOfferFirst() throws InterruptedException { |
960 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
961 |
< |
Thread t = new Thread(new Runnable() { |
962 |
< |
public void run() { |
963 |
< |
try { |
964 |
< |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
965 |
< |
q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
966 |
< |
q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
967 |
< |
threadShouldThrow(); |
968 |
< |
} catch (InterruptedException success) { } |
969 |
< |
} |
970 |
< |
}); |
971 |
< |
try { |
972 |
< |
t.start(); |
1113 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1114 |
< |
assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1115 |
< |
t.interrupt(); |
1116 |
< |
t.join(); |
1117 |
< |
} catch (Exception e) { |
1118 |
< |
unexpectedException(); |
1119 |
< |
} |
961 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
962 |
> |
public void realRun() throws InterruptedException { |
963 |
> |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
964 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
965 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
966 |
> |
}}; |
967 |
> |
|
968 |
> |
t.start(); |
969 |
> |
Thread.sleep(SMALL_DELAY_MS); |
970 |
> |
assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS)); |
971 |
> |
t.interrupt(); |
972 |
> |
t.join(); |
973 |
|
} |
974 |
|
|
975 |
|
/** |
976 |
|
* putLast(null) throws NPE |
977 |
|
*/ |
978 |
< |
public void testPutLastNull() { |
978 |
> |
public void testPutLastNull() throws InterruptedException { |
979 |
|
try { |
980 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
981 |
|
q.putLast(null); |
982 |
|
shouldThrow(); |
983 |
< |
} |
1131 |
< |
catch (NullPointerException success) { |
1132 |
< |
} |
1133 |
< |
catch (InterruptedException ie) { |
1134 |
< |
unexpectedException(); |
1135 |
< |
} |
983 |
> |
} catch (NullPointerException success) {} |
984 |
|
} |
985 |
|
|
986 |
|
/** |
987 |
|
* all elements successfully putLast are contained |
988 |
|
*/ |
989 |
< |
public void testPutLast() { |
990 |
< |
try { |
991 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
992 |
< |
for (int i = 0; i < SIZE; ++i) { |
993 |
< |
Integer I = new Integer(i); |
994 |
< |
q.putLast(I); |
1147 |
< |
assertTrue(q.contains(I)); |
1148 |
< |
} |
1149 |
< |
assertEquals(0, q.remainingCapacity()); |
989 |
> |
public void testPutLast() throws InterruptedException { |
990 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
991 |
> |
for (int i = 0; i < SIZE; ++i) { |
992 |
> |
Integer I = new Integer(i); |
993 |
> |
q.putLast(I); |
994 |
> |
assertTrue(q.contains(I)); |
995 |
|
} |
996 |
< |
catch (InterruptedException ie) { |
1152 |
< |
unexpectedException(); |
1153 |
< |
} |
996 |
> |
assertEquals(0, q.remainingCapacity()); |
997 |
|
} |
998 |
|
|
999 |
|
/** |
1000 |
|
* putLast blocks interruptibly if full |
1001 |
|
*/ |
1002 |
< |
public void testBlockingPutLast() { |
1002 |
> |
public void testBlockingPutLast() throws InterruptedException { |
1003 |
|
Thread t = new Thread(new Runnable() { |
1004 |
|
public void run() { |
1005 |
|
int added = 0; |
1011 |
|
} |
1012 |
|
q.putLast(new Integer(SIZE)); |
1013 |
|
threadShouldThrow(); |
1014 |
< |
} catch (InterruptedException ie) { |
1014 |
> |
} catch (InterruptedException success) { |
1015 |
|
threadAssertEquals(added, SIZE); |
1016 |
|
} |
1017 |
|
}}); |
1018 |
|
t.start(); |
1019 |
< |
try { |
1020 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1021 |
< |
t.interrupt(); |
1179 |
< |
t.join(); |
1180 |
< |
} |
1181 |
< |
catch (InterruptedException ie) { |
1182 |
< |
unexpectedException(); |
1183 |
< |
} |
1019 |
> |
Thread.sleep(SHORT_DELAY_MS); |
1020 |
> |
t.interrupt(); |
1021 |
> |
t.join(); |
1022 |
|
} |
1023 |
|
|
1024 |
|
/** |
1025 |
|
* putLast blocks waiting for take when full |
1026 |
|
*/ |
1027 |
< |
public void testPutLastWithTake() { |
1027 |
> |
public void testPutLastWithTake() throws InterruptedException { |
1028 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1029 |
|
Thread t = new Thread(new Runnable() { |
1030 |
|
public void run() { |
1039 |
|
q.putLast(new Object()); |
1040 |
|
++added; |
1041 |
|
threadShouldThrow(); |
1042 |
< |
} catch (InterruptedException e) { |
1042 |
> |
} catch (InterruptedException success) { |
1043 |
|
threadAssertTrue(added >= 2); |
1044 |
|
} |
1045 |
|
} |
1046 |
|
}); |
1047 |
< |
try { |
1048 |
< |
t.start(); |
1049 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1050 |
< |
q.take(); |
1051 |
< |
t.interrupt(); |
1052 |
< |
t.join(); |
1215 |
< |
} catch (Exception e) { |
1216 |
< |
unexpectedException(); |
1217 |
< |
} |
1047 |
> |
|
1048 |
> |
t.start(); |
1049 |
> |
Thread.sleep(SHORT_DELAY_MS); |
1050 |
> |
q.take(); |
1051 |
> |
t.interrupt(); |
1052 |
> |
t.join(); |
1053 |
|
} |
1054 |
|
|
1055 |
|
/** |
1056 |
|
* timed offerLast times out if full and elements not taken |
1057 |
|
*/ |
1058 |
< |
public void testTimedOfferLast() { |
1058 |
> |
public void testTimedOfferLast() throws InterruptedException { |
1059 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1060 |
< |
Thread t = new Thread(new Runnable() { |
1061 |
< |
public void run() { |
1062 |
< |
try { |
1063 |
< |
q.putLast(new Object()); |
1064 |
< |
q.putLast(new Object()); |
1065 |
< |
threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1066 |
< |
q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1232 |
< |
threadShouldThrow(); |
1233 |
< |
} catch (InterruptedException success) {} |
1234 |
< |
} |
1235 |
< |
}); |
1060 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1061 |
> |
public void realRun() throws InterruptedException { |
1062 |
> |
q.putLast(new Object()); |
1063 |
> |
q.putLast(new Object()); |
1064 |
> |
threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
1065 |
> |
q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1066 |
> |
}}; |
1067 |
|
|
1068 |
< |
try { |
1069 |
< |
t.start(); |
1070 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1071 |
< |
t.interrupt(); |
1241 |
< |
t.join(); |
1242 |
< |
} catch (Exception e) { |
1243 |
< |
unexpectedException(); |
1244 |
< |
} |
1068 |
> |
t.start(); |
1069 |
> |
Thread.sleep(SMALL_DELAY_MS); |
1070 |
> |
t.interrupt(); |
1071 |
> |
t.join(); |
1072 |
|
} |
1073 |
|
|
1074 |
|
/** |
1075 |
|
* takeLast retrieves elements in FIFO order |
1076 |
|
*/ |
1077 |
< |
public void testTakeLast() { |
1078 |
< |
try { |
1079 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1080 |
< |
for (int i = 0; i < SIZE; ++i) { |
1254 |
< |
assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue()); |
1255 |
< |
} |
1256 |
< |
} catch (InterruptedException e) { |
1257 |
< |
unexpectedException(); |
1077 |
> |
public void testTakeLast() throws InterruptedException { |
1078 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1079 |
> |
for (int i = 0; i < SIZE; ++i) { |
1080 |
> |
assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue()); |
1081 |
|
} |
1082 |
|
} |
1083 |
|
|
1084 |
|
/** |
1085 |
|
* takeLast blocks interruptibly when empty |
1086 |
|
*/ |
1087 |
< |
public void testTakeLastFromEmpty() { |
1087 |
> |
public void testTakeLastFromEmpty() throws InterruptedException { |
1088 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1089 |
< |
Thread t = new Thread(new Runnable() { |
1090 |
< |
public void run() { |
1091 |
< |
try { |
1092 |
< |
q.takeLast(); |
1093 |
< |
threadShouldThrow(); |
1094 |
< |
} catch (InterruptedException success) { } |
1095 |
< |
} |
1096 |
< |
}); |
1097 |
< |
try { |
1275 |
< |
t.start(); |
1276 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1277 |
< |
t.interrupt(); |
1278 |
< |
t.join(); |
1279 |
< |
} catch (Exception e) { |
1280 |
< |
unexpectedException(); |
1281 |
< |
} |
1089 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1090 |
> |
public void realRun() throws InterruptedException { |
1091 |
> |
q.takeLast(); |
1092 |
> |
}}; |
1093 |
> |
|
1094 |
> |
t.start(); |
1095 |
> |
Thread.sleep(SHORT_DELAY_MS); |
1096 |
> |
t.interrupt(); |
1097 |
> |
t.join(); |
1098 |
|
} |
1099 |
|
|
1100 |
|
/** |
1101 |
|
* TakeLast removes existing elements until empty, then blocks interruptibly |
1102 |
|
*/ |
1103 |
< |
public void testBlockingTakeLast() { |
1104 |
< |
Thread t = new Thread(new Runnable() { |
1105 |
< |
public void run() { |
1106 |
< |
try { |
1107 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1108 |
< |
for (int i = 0; i < SIZE; ++i) { |
1109 |
< |
assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue()); |
1110 |
< |
} |
1111 |
< |
q.takeLast(); |
1112 |
< |
threadShouldThrow(); |
1297 |
< |
} catch (InterruptedException success) { |
1298 |
< |
} |
1299 |
< |
}}); |
1103 |
> |
public void testBlockingTakeLast() throws InterruptedException { |
1104 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1105 |
> |
public void realRun() throws InterruptedException { |
1106 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1107 |
> |
for (int i = 0; i < SIZE; ++i) { |
1108 |
> |
assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue()); |
1109 |
> |
} |
1110 |
> |
q.takeLast(); |
1111 |
> |
}}; |
1112 |
> |
|
1113 |
|
t.start(); |
1114 |
< |
try { |
1115 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1116 |
< |
t.interrupt(); |
1304 |
< |
t.join(); |
1305 |
< |
} |
1306 |
< |
catch (InterruptedException ie) { |
1307 |
< |
unexpectedException(); |
1308 |
< |
} |
1114 |
> |
Thread.sleep(SHORT_DELAY_MS); |
1115 |
> |
t.interrupt(); |
1116 |
> |
t.join(); |
1117 |
|
} |
1118 |
|
|
1119 |
|
|
1120 |
|
/** |
1121 |
|
* timed pollLast with zero timeout succeeds when non-empty, else times out |
1122 |
|
*/ |
1123 |
< |
public void testTimedPollLast0() { |
1124 |
< |
try { |
1125 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1126 |
< |
for (int i = 0; i < SIZE; ++i) { |
1319 |
< |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue()); |
1320 |
< |
} |
1321 |
< |
assertNull(q.pollLast(0, TimeUnit.MILLISECONDS)); |
1322 |
< |
} catch (InterruptedException e) { |
1323 |
< |
unexpectedException(); |
1123 |
> |
public void testTimedPollLast0() throws InterruptedException { |
1124 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1125 |
> |
for (int i = 0; i < SIZE; ++i) { |
1126 |
> |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue()); |
1127 |
|
} |
1128 |
+ |
assertNull(q.pollLast(0, MILLISECONDS)); |
1129 |
|
} |
1130 |
|
|
1131 |
|
/** |
1132 |
|
* timed pollLast with nonzero timeout succeeds when non-empty, else times out |
1133 |
|
*/ |
1134 |
< |
public void testTimedPollLast() { |
1135 |
< |
try { |
1136 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1137 |
< |
for (int i = 0; i < SIZE; ++i) { |
1334 |
< |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1335 |
< |
} |
1336 |
< |
assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1337 |
< |
} catch (InterruptedException e) { |
1338 |
< |
unexpectedException(); |
1134 |
> |
public void testTimedPollLast() throws InterruptedException { |
1135 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1136 |
> |
for (int i = 0; i < SIZE; ++i) { |
1137 |
> |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1138 |
|
} |
1139 |
+ |
assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS)); |
1140 |
|
} |
1141 |
|
|
1142 |
|
/** |
1143 |
|
* Interrupted timed pollLast throws InterruptedException instead of |
1144 |
|
* returning timeout status |
1145 |
|
*/ |
1146 |
< |
public void testInterruptedTimedPollLast() { |
1147 |
< |
Thread t = new Thread(new Runnable() { |
1148 |
< |
public void run() { |
1149 |
< |
try { |
1150 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1151 |
< |
for (int i = 0; i < SIZE; ++i) { |
1152 |
< |
threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1153 |
< |
} |
1154 |
< |
threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1155 |
< |
} catch (InterruptedException success) { |
1356 |
< |
} |
1357 |
< |
}}); |
1146 |
> |
public void testInterruptedTimedPollLast() throws InterruptedException { |
1147 |
> |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1148 |
> |
public void realRun() throws InterruptedException { |
1149 |
> |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1150 |
> |
for (int i = 0; i < SIZE; ++i) { |
1151 |
> |
threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1152 |
> |
} |
1153 |
> |
q.pollLast(SMALL_DELAY_MS, MILLISECONDS); |
1154 |
> |
}}; |
1155 |
> |
|
1156 |
|
t.start(); |
1157 |
< |
try { |
1158 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1159 |
< |
t.interrupt(); |
1362 |
< |
t.join(); |
1363 |
< |
} |
1364 |
< |
catch (InterruptedException ie) { |
1365 |
< |
unexpectedException(); |
1366 |
< |
} |
1157 |
> |
Thread.sleep(SHORT_DELAY_MS); |
1158 |
> |
t.interrupt(); |
1159 |
> |
t.join(); |
1160 |
|
} |
1161 |
|
|
1162 |
|
/** |
1163 |
|
* timed poll before a delayed offerLast fails; after offerLast succeeds; |
1164 |
|
* on interruption throws |
1165 |
|
*/ |
1166 |
< |
public void testTimedPollWithOfferLast() { |
1166 |
> |
public void testTimedPollWithOfferLast() throws InterruptedException { |
1167 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1168 |
< |
Thread t = new Thread(new Runnable() { |
1169 |
< |
public void run() { |
1170 |
< |
try { |
1171 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1172 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1173 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1174 |
< |
threadShouldThrow(); |
1175 |
< |
} catch (InterruptedException success) { } |
1176 |
< |
} |
1177 |
< |
}); |
1178 |
< |
try { |
1179 |
< |
t.start(); |
1180 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1181 |
< |
assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1182 |
< |
t.interrupt(); |
1390 |
< |
t.join(); |
1391 |
< |
} catch (Exception e) { |
1392 |
< |
unexpectedException(); |
1393 |
< |
} |
1168 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1169 |
> |
public void realRun() throws InterruptedException { |
1170 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
1171 |
> |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
1172 |
> |
try { |
1173 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
1174 |
> |
shouldThrow(); |
1175 |
> |
} catch (InterruptedException success) {} |
1176 |
> |
}}); |
1177 |
> |
|
1178 |
> |
t.start(); |
1179 |
> |
Thread.sleep(SMALL_DELAY_MS); |
1180 |
> |
assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS)); |
1181 |
> |
t.interrupt(); |
1182 |
> |
t.join(); |
1183 |
|
} |
1184 |
|
|
1185 |
|
|
1195 |
|
try { |
1196 |
|
q.element(); |
1197 |
|
shouldThrow(); |
1198 |
< |
} |
1410 |
< |
catch (NoSuchElementException success) {} |
1198 |
> |
} catch (NoSuchElementException success) {} |
1199 |
|
} |
1200 |
|
|
1201 |
|
/** |
1293 |
|
/** |
1294 |
|
* toArray contains all elements |
1295 |
|
*/ |
1296 |
< |
public void testToArray() { |
1296 |
> |
public void testToArray() throws InterruptedException{ |
1297 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1298 |
|
Object[] o = q.toArray(); |
1511 |
– |
try { |
1299 |
|
for (int i = 0; i < o.length; i++) |
1300 |
|
assertEquals(o[i], q.take()); |
1514 |
– |
} catch (InterruptedException e) { |
1515 |
– |
unexpectedException(); |
1516 |
– |
} |
1301 |
|
} |
1302 |
|
|
1303 |
|
/** |
1304 |
|
* toArray(a) contains all elements |
1305 |
|
*/ |
1306 |
< |
public void testToArray2() { |
1306 |
> |
public void testToArray2() throws InterruptedException { |
1307 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1308 |
|
Integer[] ints = new Integer[SIZE]; |
1309 |
|
ints = (Integer[])q.toArray(ints); |
1310 |
< |
try { |
1311 |
< |
for (int i = 0; i < ints.length; i++) |
1528 |
< |
assertEquals(ints[i], q.take()); |
1529 |
< |
} catch (InterruptedException e) { |
1530 |
< |
unexpectedException(); |
1531 |
< |
} |
1310 |
> |
for (int i = 0; i < ints.length; i++) |
1311 |
> |
assertEquals(ints[i], q.take()); |
1312 |
|
} |
1313 |
|
|
1314 |
|
/** |
1330 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1331 |
|
Object o[] = q.toArray(new String[10] ); |
1332 |
|
shouldThrow(); |
1333 |
< |
} catch (ArrayStoreException success) {} |
1333 |
> |
} catch (ArrayStoreException success) {} |
1334 |
|
} |
1335 |
|
|
1336 |
|
|
1337 |
|
/** |
1338 |
|
* iterator iterates through all elements |
1339 |
|
*/ |
1340 |
< |
public void testIterator() { |
1340 |
> |
public void testIterator() throws InterruptedException { |
1341 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1342 |
|
Iterator it = q.iterator(); |
1343 |
< |
try { |
1344 |
< |
while (it.hasNext()) { |
1565 |
< |
assertEquals(it.next(), q.take()); |
1566 |
< |
} |
1567 |
< |
} catch (InterruptedException e) { |
1568 |
< |
unexpectedException(); |
1343 |
> |
while (it.hasNext()) { |
1344 |
> |
assertEquals(it.next(), q.take()); |
1345 |
|
} |
1346 |
|
} |
1347 |
|
|
1390 |
|
q.add(one); |
1391 |
|
q.add(two); |
1392 |
|
q.add(three); |
1393 |
< |
try { |
1394 |
< |
for (Iterator it = q.iterator(); it.hasNext();) { |
1395 |
< |
q.remove(); |
1620 |
< |
it.next(); |
1621 |
< |
} |
1622 |
< |
} |
1623 |
< |
catch (ConcurrentModificationException e) { |
1624 |
< |
unexpectedException(); |
1393 |
> |
for (Iterator it = q.iterator(); it.hasNext();) { |
1394 |
> |
q.remove(); |
1395 |
> |
it.next(); |
1396 |
|
} |
1397 |
|
assertEquals(0, q.size()); |
1398 |
|
} |
1413 |
|
assertFalse(it.hasNext()); |
1414 |
|
try { |
1415 |
|
it.next(); |
1416 |
< |
} catch (NoSuchElementException success) { |
1417 |
< |
} |
1416 |
> |
shouldThrow(); |
1417 |
> |
} catch (NoSuchElementException success) {} |
1418 |
|
} |
1419 |
|
|
1420 |
|
/** |
1482 |
|
q.add(one); |
1483 |
|
q.add(two); |
1484 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
1485 |
< |
executor.execute(new Runnable() { |
1486 |
< |
public void run() { |
1485 |
> |
executor.execute(new CheckedRunnable() { |
1486 |
> |
public void realRun() throws InterruptedException { |
1487 |
|
threadAssertFalse(q.offer(three)); |
1488 |
< |
try { |
1489 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
1490 |
< |
threadAssertEquals(0, q.remainingCapacity()); |
1491 |
< |
} |
1492 |
< |
catch (InterruptedException e) { |
1493 |
< |
threadUnexpectedException(); |
1494 |
< |
} |
1495 |
< |
} |
1496 |
< |
}); |
1726 |
< |
|
1727 |
< |
executor.execute(new Runnable() { |
1728 |
< |
public void run() { |
1729 |
< |
try { |
1730 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1731 |
< |
threadAssertEquals(one, q.take()); |
1732 |
< |
} |
1733 |
< |
catch (InterruptedException e) { |
1734 |
< |
threadUnexpectedException(); |
1735 |
< |
} |
1736 |
< |
} |
1737 |
< |
}); |
1488 |
> |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
1489 |
> |
threadAssertEquals(0, q.remainingCapacity()); |
1490 |
> |
}}); |
1491 |
> |
|
1492 |
> |
executor.execute(new CheckedRunnable() { |
1493 |
> |
public void realRun() throws InterruptedException { |
1494 |
> |
Thread.sleep(SMALL_DELAY_MS); |
1495 |
> |
threadAssertEquals(one, q.take()); |
1496 |
> |
}}); |
1497 |
|
|
1498 |
|
joinPool(executor); |
1499 |
|
} |
1504 |
|
public void testPollInExecutor() { |
1505 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1506 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
1507 |
< |
executor.execute(new Runnable() { |
1508 |
< |
public void run() { |
1507 |
> |
executor.execute(new CheckedRunnable() { |
1508 |
> |
public void realRun() throws InterruptedException { |
1509 |
|
threadAssertNull(q.poll()); |
1510 |
< |
try { |
1511 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
1512 |
< |
threadAssertTrue(q.isEmpty()); |
1513 |
< |
} |
1514 |
< |
catch (InterruptedException e) { |
1515 |
< |
threadUnexpectedException(); |
1516 |
< |
} |
1517 |
< |
} |
1518 |
< |
}); |
1760 |
< |
|
1761 |
< |
executor.execute(new Runnable() { |
1762 |
< |
public void run() { |
1763 |
< |
try { |
1764 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1765 |
< |
q.put(one); |
1766 |
< |
} |
1767 |
< |
catch (InterruptedException e) { |
1768 |
< |
threadUnexpectedException(); |
1769 |
< |
} |
1770 |
< |
} |
1771 |
< |
}); |
1510 |
> |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1511 |
> |
threadAssertTrue(q.isEmpty()); |
1512 |
> |
}}); |
1513 |
> |
|
1514 |
> |
executor.execute(new CheckedRunnable() { |
1515 |
> |
public void realRun() throws InterruptedException { |
1516 |
> |
Thread.sleep(SMALL_DELAY_MS); |
1517 |
> |
q.put(one); |
1518 |
> |
}}); |
1519 |
|
|
1520 |
|
joinPool(executor); |
1521 |
|
} |
1523 |
|
/** |
1524 |
|
* A deserialized serialized deque has same elements in same order |
1525 |
|
*/ |
1526 |
< |
public void testSerialization() { |
1526 |
> |
public void testSerialization() throws Exception { |
1527 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1528 |
|
|
1529 |
< |
try { |
1530 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1531 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1532 |
< |
out.writeObject(q); |
1533 |
< |
out.close(); |
1534 |
< |
|
1535 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1536 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1537 |
< |
LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject(); |
1538 |
< |
assertEquals(q.size(), r.size()); |
1539 |
< |
while (!q.isEmpty()) |
1793 |
< |
assertEquals(q.remove(), r.remove()); |
1794 |
< |
} catch (Exception e) { |
1795 |
< |
unexpectedException(); |
1796 |
< |
} |
1529 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1530 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1531 |
> |
out.writeObject(q); |
1532 |
> |
out.close(); |
1533 |
> |
|
1534 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1535 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1536 |
> |
LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject(); |
1537 |
> |
assertEquals(q.size(), r.size()); |
1538 |
> |
while (!q.isEmpty()) |
1539 |
> |
assertEquals(q.remove(), r.remove()); |
1540 |
|
} |
1541 |
|
|
1542 |
|
/** |
1547 |
|
try { |
1548 |
|
q.drainTo(null); |
1549 |
|
shouldThrow(); |
1550 |
< |
} catch (NullPointerException success) { |
1808 |
< |
} |
1550 |
> |
} catch (NullPointerException success) {} |
1551 |
|
} |
1552 |
|
|
1553 |
|
/** |
1558 |
|
try { |
1559 |
|
q.drainTo(q); |
1560 |
|
shouldThrow(); |
1561 |
< |
} catch (IllegalArgumentException success) { |
1820 |
< |
} |
1561 |
> |
} catch (IllegalArgumentException success) {} |
1562 |
|
} |
1563 |
|
|
1564 |
|
/** |
1588 |
|
/** |
1589 |
|
* drainTo empties full deque, unblocking a waiting put. |
1590 |
|
*/ |
1591 |
< |
public void testDrainToWithActivePut() { |
1591 |
> |
public void testDrainToWithActivePut() throws InterruptedException { |
1592 |
|
final LinkedBlockingDeque q = populatedDeque(SIZE); |
1593 |
< |
Thread t = new Thread(new Runnable() { |
1594 |
< |
public void run() { |
1595 |
< |
try { |
1596 |
< |
q.put(new Integer(SIZE+1)); |
1597 |
< |
} catch (InterruptedException ie) { |
1598 |
< |
threadUnexpectedException(); |
1599 |
< |
} |
1600 |
< |
} |
1601 |
< |
}); |
1602 |
< |
try { |
1603 |
< |
t.start(); |
1604 |
< |
ArrayList l = new ArrayList(); |
1605 |
< |
q.drainTo(l); |
1865 |
< |
assertTrue(l.size() >= SIZE); |
1866 |
< |
for (int i = 0; i < SIZE; ++i) |
1867 |
< |
assertEquals(l.get(i), new Integer(i)); |
1868 |
< |
t.join(); |
1869 |
< |
assertTrue(q.size() + l.size() >= SIZE); |
1870 |
< |
} catch (Exception e) { |
1871 |
< |
unexpectedException(); |
1872 |
< |
} |
1593 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1594 |
> |
public void realRun() throws InterruptedException { |
1595 |
> |
q.put(new Integer(SIZE+1)); |
1596 |
> |
}}); |
1597 |
> |
|
1598 |
> |
t.start(); |
1599 |
> |
ArrayList l = new ArrayList(); |
1600 |
> |
q.drainTo(l); |
1601 |
> |
assertTrue(l.size() >= SIZE); |
1602 |
> |
for (int i = 0; i < SIZE; ++i) |
1603 |
> |
assertEquals(l.get(i), new Integer(i)); |
1604 |
> |
t.join(); |
1605 |
> |
assertTrue(q.size() + l.size() >= SIZE); |
1606 |
|
} |
1607 |
|
|
1608 |
|
/** |
1613 |
|
try { |
1614 |
|
q.drainTo(null, 0); |
1615 |
|
shouldThrow(); |
1616 |
< |
} catch (NullPointerException success) { |
1884 |
< |
} |
1616 |
> |
} catch (NullPointerException success) {} |
1617 |
|
} |
1618 |
|
|
1619 |
|
/** |
1624 |
|
try { |
1625 |
|
q.drainTo(q, 0); |
1626 |
|
shouldThrow(); |
1627 |
< |
} catch (IllegalArgumentException success) { |
1896 |
< |
} |
1627 |
> |
} catch (IllegalArgumentException success) {} |
1628 |
|
} |
1629 |
|
|
1630 |
|
/** |