9 |
|
import junit.framework.*; |
10 |
|
import java.util.Arrays; |
11 |
|
import java.util.ArrayList; |
12 |
+ |
import java.util.Collection; |
13 |
|
import java.util.Iterator; |
14 |
|
import java.util.NoSuchElementException; |
15 |
|
import java.util.concurrent.BlockingQueue; |
63 |
|
return (other instanceof PDelay) && |
64 |
|
this.pseudodelay == ((PDelay)other).pseudodelay; |
65 |
|
} |
66 |
+ |
// suppress [overrides] javac warning |
67 |
+ |
public int hashCode() { return pseudodelay; } |
68 |
|
public long getDelay(TimeUnit ignore) { |
69 |
|
return Integer.MIN_VALUE + pseudodelay; |
70 |
|
} |
100 |
|
return other.trigger == trigger; |
101 |
|
} |
102 |
|
|
103 |
+ |
// suppress [overrides] javac warning |
104 |
+ |
public int hashCode() { return (int) trigger; } |
105 |
+ |
|
106 |
|
public long getDelay(TimeUnit unit) { |
107 |
|
long n = trigger - System.nanoTime(); |
108 |
|
return unit.convert(n, TimeUnit.NANOSECONDS); |
118 |
|
} |
119 |
|
|
120 |
|
/** |
121 |
< |
* Create a queue of given size containing consecutive |
121 |
> |
* Returns a new queue of given size containing consecutive |
122 |
|
* PDelays 0 ... n. |
123 |
|
*/ |
124 |
|
private DelayQueue<PDelay> populatedQueue(int n) { |
626 |
|
it.next(); |
627 |
|
it.remove(); |
628 |
|
it = q.iterator(); |
629 |
< |
assertEquals(it.next(), new PDelay(2)); |
630 |
< |
assertEquals(it.next(), new PDelay(3)); |
629 |
> |
assertEquals(new PDelay(2), it.next()); |
630 |
> |
assertEquals(new PDelay(3), it.next()); |
631 |
|
assertFalse(it.hasNext()); |
632 |
|
} |
633 |
|
|
652 |
|
public void realRun() throws InterruptedException { |
653 |
|
assertNull(q.poll()); |
654 |
|
threadsStarted.await(); |
655 |
< |
assertTrue(null != q.poll(LONG_DELAY_MS, MILLISECONDS)); |
655 |
> |
assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS)); |
656 |
|
checkEmpty(q); |
657 |
|
}}); |
658 |
|
|
726 |
|
q.drainTo(l); |
727 |
|
assertEquals(0, q.size()); |
728 |
|
for (int i = 0; i < SIZE; ++i) |
729 |
< |
assertEquals(l.get(i), elems[i]); |
729 |
> |
assertEquals(elems[i], l.get(i)); |
730 |
|
q.add(elems[0]); |
731 |
|
q.add(elems[1]); |
732 |
|
assertFalse(q.isEmpty()); |
737 |
|
assertEquals(0, q.size()); |
738 |
|
assertEquals(2, l.size()); |
739 |
|
for (int i = 0; i < 2; ++i) |
740 |
< |
assertEquals(l.get(i), elems[i]); |
740 |
> |
assertEquals(elems[i], l.get(i)); |
741 |
|
} |
742 |
|
|
743 |
|
/** |
767 |
|
ArrayList l = new ArrayList(); |
768 |
|
q.drainTo(l, i); |
769 |
|
int k = (i < SIZE) ? i : SIZE; |
770 |
< |
assertEquals(q.size(), SIZE-k); |
771 |
< |
assertEquals(l.size(), k); |
770 |
> |
assertEquals(SIZE-k, q.size()); |
771 |
> |
assertEquals(k, l.size()); |
772 |
|
} |
773 |
|
} |
774 |
|
|
775 |
+ |
/** |
776 |
+ |
* remove(null), contains(null) always return false |
777 |
+ |
*/ |
778 |
+ |
public void testNeverContainsNull() { |
779 |
+ |
Collection<?> q = populatedQueue(SIZE); |
780 |
+ |
assertFalse(q.contains(null)); |
781 |
+ |
assertFalse(q.remove(null)); |
782 |
+ |
} |
783 |
|
} |