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 |
5 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
12 |
|
|
13 |
|
public class DelayQueueTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
15 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
junit.textui.TestRunner.run (suite()); |
16 |
|
} |
17 |
|
|
18 |
|
public static Test suite() { |
19 |
< |
return new TestSuite(DelayQueueTest.class); |
19 |
> |
return new TestSuite(DelayQueueTest.class); |
20 |
|
} |
21 |
|
|
22 |
|
private static final int NOCAP = Integer.MAX_VALUE; |
25 |
|
* A delayed implementation for testing. |
26 |
|
* Most tests use Pseudodelays, where delays are all elapsed |
27 |
|
* (so, no blocking solely for delays) but are still ordered |
28 |
< |
*/ |
29 |
< |
static class PDelay implements Delayed { |
28 |
> |
*/ |
29 |
> |
static class PDelay implements Delayed { |
30 |
|
int pseudodelay; |
31 |
|
PDelay(int i) { pseudodelay = Integer.MIN_VALUE + i; } |
32 |
< |
public int compareTo(Object y) { |
32 |
> |
public int compareTo(PDelay y) { |
33 |
|
int i = pseudodelay; |
34 |
|
int j = ((PDelay)y).pseudodelay; |
35 |
|
if (i < j) return -1; |
37 |
|
return 0; |
38 |
|
} |
39 |
|
|
40 |
< |
public int compareTo(PDelay y) { |
40 |
> |
public int compareTo(Delayed y) { |
41 |
|
int i = pseudodelay; |
42 |
|
int j = ((PDelay)y).pseudodelay; |
43 |
|
if (i < j) return -1; |
69 |
|
/** |
70 |
|
* Delayed implementation that actually delays |
71 |
|
*/ |
72 |
< |
static class NanoDelay implements Delayed { |
72 |
> |
static class NanoDelay implements Delayed { |
73 |
|
long trigger; |
74 |
< |
NanoDelay(long i) { |
74 |
> |
NanoDelay(long i) { |
75 |
|
trigger = System.nanoTime() + i; |
76 |
|
} |
77 |
< |
public int compareTo(Object y) { |
77 |
> |
public int compareTo(NanoDelay y) { |
78 |
|
long i = trigger; |
79 |
|
long j = ((NanoDelay)y).trigger; |
80 |
|
if (i < j) return -1; |
82 |
|
return 0; |
83 |
|
} |
84 |
|
|
85 |
< |
public int compareTo(NanoDelay y) { |
85 |
> |
public int compareTo(Delayed y) { |
86 |
|
long i = trigger; |
87 |
|
long j = ((NanoDelay)y).trigger; |
88 |
|
if (i < j) return -1; |
119 |
|
private DelayQueue populatedQueue(int n) { |
120 |
|
DelayQueue q = new DelayQueue(); |
121 |
|
assertTrue(q.isEmpty()); |
122 |
< |
for(int i = n-1; i >= 0; i-=2) |
123 |
< |
assertTrue(q.offer(new PDelay(i))); |
124 |
< |
for(int i = (n & 1); i < n; i+=2) |
125 |
< |
assertTrue(q.offer(new PDelay(i))); |
122 |
> |
for (int i = n-1; i >= 0; i-=2) |
123 |
> |
assertTrue(q.offer(new PDelay(i))); |
124 |
> |
for (int i = (n & 1); i < n; i+=2) |
125 |
> |
assertTrue(q.offer(new PDelay(i))); |
126 |
|
assertFalse(q.isEmpty()); |
127 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
128 |
< |
assertEquals(n, q.size()); |
128 |
> |
assertEquals(n, q.size()); |
129 |
|
return q; |
130 |
|
} |
131 |
< |
|
131 |
> |
|
132 |
|
/** |
133 |
|
* A new queue has unbounded capacity |
134 |
|
*/ |
225 |
|
* offer(null) throws NPE |
226 |
|
*/ |
227 |
|
public void testOfferNull() { |
228 |
< |
try { |
228 |
> |
try { |
229 |
|
DelayQueue q = new DelayQueue(); |
230 |
|
q.offer(null); |
231 |
|
shouldThrow(); |
232 |
< |
} catch (NullPointerException success) { } |
232 |
> |
} catch (NullPointerException success) { } |
233 |
|
} |
234 |
|
|
235 |
|
/** |
236 |
|
* add(null) throws NPE |
237 |
|
*/ |
238 |
|
public void testAddNull() { |
239 |
< |
try { |
239 |
> |
try { |
240 |
|
DelayQueue q = new DelayQueue(); |
241 |
|
q.add(null); |
242 |
|
shouldThrow(); |
243 |
< |
} catch (NullPointerException success) { } |
243 |
> |
} catch (NullPointerException success) { } |
244 |
|
} |
245 |
|
|
246 |
|
/** |
338 |
|
* put(null) throws NPE |
339 |
|
*/ |
340 |
|
public void testPutNull() { |
341 |
< |
try { |
341 |
> |
try { |
342 |
|
DelayQueue q = new DelayQueue(); |
343 |
|
q.put(null); |
344 |
|
shouldThrow(); |
345 |
< |
} |
346 |
< |
catch (NullPointerException success){ |
347 |
< |
} |
345 |
> |
} |
346 |
> |
catch (NullPointerException success) { |
347 |
> |
} |
348 |
|
} |
349 |
|
|
350 |
|
/** |
392 |
|
q.take(); |
393 |
|
t.interrupt(); |
394 |
|
t.join(); |
395 |
< |
} catch (Exception e){ |
395 |
> |
} catch (Exception e) { |
396 |
|
unexpectedException(); |
397 |
|
} |
398 |
|
} |
412 |
|
} finally { } |
413 |
|
} |
414 |
|
}); |
415 |
< |
|
415 |
> |
|
416 |
|
try { |
417 |
|
t.start(); |
418 |
|
Thread.sleep(SMALL_DELAY_MS); |
419 |
|
t.interrupt(); |
420 |
|
t.join(); |
421 |
< |
} catch (Exception e){ |
421 |
> |
} catch (Exception e) { |
422 |
|
unexpectedException(); |
423 |
|
} |
424 |
|
} |
427 |
|
* take retrieves elements in priority order |
428 |
|
*/ |
429 |
|
public void testTake() { |
430 |
< |
try { |
430 |
> |
try { |
431 |
|
DelayQueue q = populatedQueue(SIZE); |
432 |
|
for (int i = 0; i < SIZE; ++i) { |
433 |
|
assertEquals(new PDelay(i), ((PDelay)q.take())); |
434 |
|
} |
435 |
< |
} catch (InterruptedException e){ |
436 |
< |
unexpectedException(); |
437 |
< |
} |
435 |
> |
} catch (InterruptedException e) { |
436 |
> |
unexpectedException(); |
437 |
> |
} |
438 |
|
} |
439 |
|
|
440 |
|
/** |
446 |
|
public void run() { |
447 |
|
try { |
448 |
|
q.take(); |
449 |
< |
threadShouldThrow(); |
450 |
< |
} catch (InterruptedException success){ } |
449 |
> |
threadShouldThrow(); |
450 |
> |
} catch (InterruptedException success) { } |
451 |
|
} |
452 |
|
}); |
453 |
|
try { |
455 |
|
Thread.sleep(SHORT_DELAY_MS); |
456 |
|
t.interrupt(); |
457 |
|
t.join(); |
458 |
< |
} catch (Exception e){ |
458 |
> |
} catch (Exception e) { |
459 |
|
unexpectedException(); |
460 |
|
} |
461 |
|
} |
473 |
|
} |
474 |
|
q.take(); |
475 |
|
threadShouldThrow(); |
476 |
< |
} catch (InterruptedException success){ |
477 |
< |
} |
476 |
> |
} catch (InterruptedException success) { |
477 |
> |
} |
478 |
|
}}); |
479 |
|
t.start(); |
480 |
< |
try { |
481 |
< |
Thread.sleep(SHORT_DELAY_MS); |
480 |
> |
try { |
481 |
> |
Thread.sleep(SHORT_DELAY_MS); |
482 |
|
t.interrupt(); |
483 |
|
t.join(); |
484 |
|
} |
485 |
|
catch (InterruptedException ie) { |
486 |
< |
unexpectedException(); |
486 |
> |
unexpectedException(); |
487 |
|
} |
488 |
|
} |
489 |
|
|
496 |
|
for (int i = 0; i < SIZE; ++i) { |
497 |
|
assertEquals(new PDelay(i), ((PDelay)q.poll())); |
498 |
|
} |
499 |
< |
assertNull(q.poll()); |
499 |
> |
assertNull(q.poll()); |
500 |
|
} |
501 |
|
|
502 |
|
/** |
509 |
|
assertEquals(new PDelay(i), ((PDelay)q.poll(0, TimeUnit.MILLISECONDS))); |
510 |
|
} |
511 |
|
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
512 |
< |
} catch (InterruptedException e){ |
513 |
< |
unexpectedException(); |
514 |
< |
} |
512 |
> |
} catch (InterruptedException e) { |
513 |
> |
unexpectedException(); |
514 |
> |
} |
515 |
|
} |
516 |
|
|
517 |
|
/** |
524 |
|
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS))); |
525 |
|
} |
526 |
|
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
527 |
< |
} catch (InterruptedException e){ |
528 |
< |
unexpectedException(); |
529 |
< |
} |
527 |
> |
} catch (InterruptedException e) { |
528 |
> |
unexpectedException(); |
529 |
> |
} |
530 |
|
} |
531 |
|
|
532 |
|
/** |
542 |
|
threadAssertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS))); |
543 |
|
} |
544 |
|
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
545 |
< |
} catch (InterruptedException success){ |
546 |
< |
} |
545 |
> |
} catch (InterruptedException success) { |
546 |
> |
} |
547 |
|
}}); |
548 |
|
t.start(); |
549 |
< |
try { |
550 |
< |
Thread.sleep(SHORT_DELAY_MS); |
549 |
> |
try { |
550 |
> |
Thread.sleep(SHORT_DELAY_MS); |
551 |
|
t.interrupt(); |
552 |
|
t.join(); |
553 |
|
} |
554 |
|
catch (InterruptedException ie) { |
555 |
< |
unexpectedException(); |
555 |
> |
unexpectedException(); |
556 |
|
} |
557 |
|
} |
558 |
|
|
568 |
|
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
569 |
|
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
570 |
|
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
571 |
< |
threadFail("Should block"); |
572 |
< |
} catch (InterruptedException success) { } |
571 |
> |
threadFail("Should block"); |
572 |
> |
} catch (InterruptedException success) { } |
573 |
|
} |
574 |
|
}); |
575 |
|
try { |
578 |
|
assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
579 |
|
t.interrupt(); |
580 |
|
t.join(); |
581 |
< |
} catch (Exception e){ |
581 |
> |
} catch (Exception e) { |
582 |
|
unexpectedException(); |
583 |
|
} |
584 |
< |
} |
584 |
> |
} |
585 |
|
|
586 |
|
|
587 |
|
/** |
592 |
|
for (int i = 0; i < SIZE; ++i) { |
593 |
|
assertEquals(new PDelay(i), ((PDelay)q.peek())); |
594 |
|
q.poll(); |
595 |
< |
assertTrue(q.peek() == null || |
596 |
< |
i != ((PDelay)q.peek()).intValue()); |
595 |
> |
if (q.isEmpty()) |
596 |
> |
assertNull(q.peek()); |
597 |
> |
else |
598 |
> |
assertTrue(i != ((PDelay)q.peek()).intValue()); |
599 |
|
} |
600 |
< |
assertNull(q.peek()); |
600 |
> |
assertNull(q.peek()); |
601 |
|
} |
602 |
|
|
603 |
|
/** |
627 |
|
try { |
628 |
|
q.remove(); |
629 |
|
shouldThrow(); |
630 |
< |
} catch (NoSuchElementException success){ |
631 |
< |
} |
630 |
> |
} catch (NoSuchElementException success) { |
631 |
> |
} |
632 |
|
} |
633 |
|
|
634 |
|
/** |
645 |
|
} |
646 |
|
assertTrue(q.isEmpty()); |
647 |
|
} |
648 |
< |
|
648 |
> |
|
649 |
|
/** |
650 |
|
* contains(x) reports true when elements added but not yet removed |
651 |
|
*/ |
667 |
|
assertTrue(q.isEmpty()); |
668 |
|
assertEquals(0, q.size()); |
669 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
670 |
< |
q.add(new PDelay(1)); |
670 |
> |
PDelay x = new PDelay(1); |
671 |
> |
q.add(x); |
672 |
|
assertFalse(q.isEmpty()); |
673 |
+ |
assertTrue(q.contains(x)); |
674 |
|
q.clear(); |
675 |
|
assertTrue(q.isEmpty()); |
676 |
|
} |
729 |
|
*/ |
730 |
|
public void testToArray() { |
731 |
|
DelayQueue q = populatedQueue(SIZE); |
732 |
< |
Object[] o = q.toArray(); |
732 |
> |
Object[] o = q.toArray(); |
733 |
|
Arrays.sort(o); |
734 |
< |
try { |
735 |
< |
for(int i = 0; i < o.length; i++) |
736 |
< |
assertEquals(o[i], q.take()); |
737 |
< |
} catch (InterruptedException e){ |
738 |
< |
unexpectedException(); |
739 |
< |
} |
734 |
> |
try { |
735 |
> |
for (int i = 0; i < o.length; i++) |
736 |
> |
assertEquals(o[i], q.take()); |
737 |
> |
} catch (InterruptedException e) { |
738 |
> |
unexpectedException(); |
739 |
> |
} |
740 |
|
} |
741 |
|
|
742 |
|
/** |
744 |
|
*/ |
745 |
|
public void testToArray2() { |
746 |
|
DelayQueue q = populatedQueue(SIZE); |
747 |
< |
PDelay[] ints = new PDelay[SIZE]; |
748 |
< |
ints = (PDelay[])q.toArray(ints); |
747 |
> |
PDelay[] ints = new PDelay[SIZE]; |
748 |
> |
ints = (PDelay[])q.toArray(ints); |
749 |
|
Arrays.sort(ints); |
750 |
< |
try { |
751 |
< |
for(int i = 0; i < ints.length; i++) |
752 |
< |
assertEquals(ints[i], q.take()); |
753 |
< |
} catch (InterruptedException e){ |
754 |
< |
unexpectedException(); |
755 |
< |
} |
750 |
> |
try { |
751 |
> |
for (int i = 0; i < ints.length; i++) |
752 |
> |
assertEquals(ints[i], q.take()); |
753 |
> |
} catch (InterruptedException e) { |
754 |
> |
unexpectedException(); |
755 |
> |
} |
756 |
|
} |
757 |
|
|
758 |
|
|
760 |
|
* toArray(null) throws NPE |
761 |
|
*/ |
762 |
|
public void testToArray_BadArg() { |
763 |
< |
try { |
763 |
> |
try { |
764 |
|
DelayQueue q = populatedQueue(SIZE); |
765 |
< |
Object o[] = q.toArray(null); |
766 |
< |
shouldThrow(); |
767 |
< |
} catch(NullPointerException success){} |
765 |
> |
Object o[] = q.toArray(null); |
766 |
> |
shouldThrow(); |
767 |
> |
} catch (NullPointerException success) {} |
768 |
|
} |
769 |
|
|
770 |
|
/** |
771 |
|
* toArray with incompatible array type throws CCE |
772 |
|
*/ |
773 |
|
public void testToArray1_BadArg() { |
774 |
< |
try { |
774 |
> |
try { |
775 |
|
DelayQueue q = populatedQueue(SIZE); |
776 |
< |
Object o[] = q.toArray(new String[10] ); |
777 |
< |
shouldThrow(); |
778 |
< |
} catch(ArrayStoreException success){} |
776 |
> |
Object o[] = q.toArray(new String[10] ); |
777 |
> |
shouldThrow(); |
778 |
> |
} catch (ArrayStoreException success) {} |
779 |
|
} |
780 |
< |
|
780 |
> |
|
781 |
|
/** |
782 |
|
* iterator iterates through all elements |
783 |
|
*/ |
784 |
|
public void testIterator() { |
785 |
|
DelayQueue q = populatedQueue(SIZE); |
786 |
|
int i = 0; |
787 |
< |
Iterator it = q.iterator(); |
788 |
< |
while(it.hasNext()) { |
787 |
> |
Iterator it = q.iterator(); |
788 |
> |
while (it.hasNext()) { |
789 |
|
assertTrue(q.contains(it.next())); |
790 |
|
++i; |
791 |
|
} |
819 |
|
for (int i = 0; i < SIZE; ++i) { |
820 |
|
assertTrue(s.indexOf(String.valueOf(Integer.MIN_VALUE+i)) >= 0); |
821 |
|
} |
822 |
< |
} |
822 |
> |
} |
823 |
|
|
824 |
|
/** |
825 |
|
* offer transfers elements across Executor tasks |
875 |
|
NanoDelay e = (NanoDelay)(q.take()); |
876 |
|
long tt = e.getTriggerTime(); |
877 |
|
assertTrue(tt <= System.nanoTime()); |
878 |
< |
if (i != 0) |
878 |
> |
if (i != 0) |
879 |
|
assertTrue(tt >= last); |
880 |
|
last = tt; |
881 |
|
} |
882 |
|
} |
883 |
< |
catch(InterruptedException ie) { |
883 |
> |
catch (InterruptedException ie) { |
884 |
|
unexpectedException(); |
885 |
|
} |
886 |
|
} |
887 |
|
|
888 |
+ |
/** |
889 |
+ |
* peek of a non-empty queue returns non-null even if not expired |
890 |
+ |
*/ |
891 |
+ |
public void testPeekDelayed() { |
892 |
+ |
DelayQueue q = new DelayQueue(); |
893 |
+ |
q.add(new NanoDelay(Long.MAX_VALUE)); |
894 |
+ |
assert(q.peek() != null); |
895 |
+ |
} |
896 |
+ |
|
897 |
+ |
|
898 |
+ |
/** |
899 |
+ |
* poll of a non-empty queue returns null if no expired elements. |
900 |
+ |
*/ |
901 |
+ |
public void testPollDelayed() { |
902 |
+ |
DelayQueue q = new DelayQueue(); |
903 |
+ |
q.add(new NanoDelay(Long.MAX_VALUE)); |
904 |
+ |
assertNull(q.poll()); |
905 |
+ |
} |
906 |
+ |
|
907 |
+ |
/** |
908 |
+ |
* timed poll of a non-empty queue returns null if no expired elements. |
909 |
+ |
*/ |
910 |
+ |
public void testTimedPollDelayed() { |
911 |
+ |
DelayQueue q = new DelayQueue(); |
912 |
+ |
q.add(new NanoDelay(LONG_DELAY_MS * 1000000L)); |
913 |
+ |
try { |
914 |
+ |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
915 |
+ |
} catch (Exception ex) { |
916 |
+ |
unexpectedException(); |
917 |
+ |
} |
918 |
+ |
} |
919 |
|
|
920 |
|
/** |
921 |
|
* drainTo(null) throws NPE |
922 |
< |
*/ |
922 |
> |
*/ |
923 |
|
public void testDrainToNull() { |
924 |
|
DelayQueue q = populatedQueue(SIZE); |
925 |
|
try { |
926 |
|
q.drainTo(null); |
927 |
|
shouldThrow(); |
928 |
< |
} catch(NullPointerException success) { |
928 |
> |
} catch (NullPointerException success) { |
929 |
|
} |
930 |
|
} |
931 |
|
|
932 |
|
/** |
933 |
|
* drainTo(this) throws IAE |
934 |
< |
*/ |
934 |
> |
*/ |
935 |
|
public void testDrainToSelf() { |
936 |
|
DelayQueue q = populatedQueue(SIZE); |
937 |
|
try { |
938 |
|
q.drainTo(q); |
939 |
|
shouldThrow(); |
940 |
< |
} catch(IllegalArgumentException success) { |
940 |
> |
} catch (IllegalArgumentException success) { |
941 |
|
} |
942 |
|
} |
943 |
|
|
944 |
|
/** |
945 |
|
* drainTo(c) empties queue into another collection c |
946 |
< |
*/ |
946 |
> |
*/ |
947 |
|
public void testDrainTo() { |
948 |
< |
DelayQueue q = populatedQueue(SIZE); |
948 |
> |
DelayQueue q = new DelayQueue(); |
949 |
> |
PDelay[] elems = new PDelay[SIZE]; |
950 |
> |
for (int i = 0; i < SIZE; ++i) { |
951 |
> |
elems[i] = new PDelay(i); |
952 |
> |
q.add(elems[i]); |
953 |
> |
} |
954 |
|
ArrayList l = new ArrayList(); |
955 |
|
q.drainTo(l); |
956 |
|
assertEquals(q.size(), 0); |
957 |
< |
assertEquals(l.size(), SIZE); |
957 |
> |
for (int i = 0; i < SIZE; ++i) |
958 |
> |
assertEquals(l.get(i), elems[i]); |
959 |
> |
q.add(elems[0]); |
960 |
> |
q.add(elems[1]); |
961 |
> |
assertFalse(q.isEmpty()); |
962 |
> |
assertTrue(q.contains(elems[0])); |
963 |
> |
assertTrue(q.contains(elems[1])); |
964 |
> |
l.clear(); |
965 |
> |
q.drainTo(l); |
966 |
> |
assertEquals(q.size(), 0); |
967 |
> |
assertEquals(l.size(), 2); |
968 |
> |
for (int i = 0; i < 2; ++i) |
969 |
> |
assertEquals(l.get(i), elems[i]); |
970 |
|
} |
971 |
|
|
972 |
|
/** |
973 |
|
* drainTo empties queue |
974 |
< |
*/ |
974 |
> |
*/ |
975 |
|
public void testDrainToWithActivePut() { |
976 |
|
final DelayQueue q = populatedQueue(SIZE); |
977 |
|
Thread t = new Thread(new Runnable() { |
985 |
|
q.drainTo(l); |
986 |
|
assertTrue(l.size() >= SIZE); |
987 |
|
t.join(); |
988 |
< |
assertTrue(q.size() + l.size() == SIZE+1); |
989 |
< |
} catch(Exception e){ |
988 |
> |
assertTrue(q.size() + l.size() >= SIZE); |
989 |
> |
} catch (Exception e) { |
990 |
|
unexpectedException(); |
991 |
|
} |
992 |
|
} |
993 |
|
|
994 |
|
/** |
995 |
|
* drainTo(null, n) throws NPE |
996 |
< |
*/ |
996 |
> |
*/ |
997 |
|
public void testDrainToNullN() { |
998 |
|
DelayQueue q = populatedQueue(SIZE); |
999 |
|
try { |
1000 |
|
q.drainTo(null, 0); |
1001 |
|
shouldThrow(); |
1002 |
< |
} catch(NullPointerException success) { |
1002 |
> |
} catch (NullPointerException success) { |
1003 |
|
} |
1004 |
|
} |
1005 |
|
|
1006 |
|
/** |
1007 |
|
* drainTo(this, n) throws IAE |
1008 |
< |
*/ |
1008 |
> |
*/ |
1009 |
|
public void testDrainToSelfN() { |
1010 |
|
DelayQueue q = populatedQueue(SIZE); |
1011 |
|
try { |
1012 |
|
q.drainTo(q, 0); |
1013 |
|
shouldThrow(); |
1014 |
< |
} catch(IllegalArgumentException success) { |
1014 |
> |
} catch (IllegalArgumentException success) { |
1015 |
|
} |
1016 |
|
} |
1017 |
|
|
1018 |
|
/** |
1019 |
|
* drainTo(c, n) empties first max {n, size} elements of queue into c |
1020 |
< |
*/ |
1020 |
> |
*/ |
1021 |
|
public void testDrainToN() { |
1022 |
|
for (int i = 0; i < SIZE + 2; ++i) { |
1023 |
|
DelayQueue q = populatedQueue(SIZE); |