6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
< |
import junit.framework.*; |
10 |
< |
import java.util.Arrays; |
9 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
> |
|
11 |
|
import java.util.ArrayList; |
12 |
+ |
import java.util.Arrays; |
13 |
+ |
import java.util.Collection; |
14 |
|
import java.util.Iterator; |
15 |
|
import java.util.NoSuchElementException; |
16 |
|
import java.util.concurrent.BlockingQueue; |
20 |
|
import java.util.concurrent.Executors; |
21 |
|
import java.util.concurrent.ExecutorService; |
22 |
|
import java.util.concurrent.TimeUnit; |
23 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
23 |
> |
|
24 |
> |
import junit.framework.Test; |
25 |
|
|
26 |
|
public class DelayQueueTest extends JSR166TestCase { |
27 |
|
|
65 |
|
return (other instanceof PDelay) && |
66 |
|
this.pseudodelay == ((PDelay)other).pseudodelay; |
67 |
|
} |
68 |
+ |
// suppress [overrides] javac warning |
69 |
+ |
public int hashCode() { return pseudodelay; } |
70 |
|
public long getDelay(TimeUnit ignore) { |
71 |
|
return Integer.MIN_VALUE + pseudodelay; |
72 |
|
} |
102 |
|
return other.trigger == trigger; |
103 |
|
} |
104 |
|
|
105 |
+ |
// suppress [overrides] javac warning |
106 |
+ |
public int hashCode() { return (int) trigger; } |
107 |
+ |
|
108 |
|
public long getDelay(TimeUnit unit) { |
109 |
|
long n = trigger - System.nanoTime(); |
110 |
|
return unit.convert(n, TimeUnit.NANOSECONDS); |
120 |
|
} |
121 |
|
|
122 |
|
/** |
123 |
< |
* Creates a queue of given size containing consecutive |
123 |
> |
* Returns a new queue of given size containing consecutive |
124 |
|
* PDelays 0 ... n. |
125 |
|
*/ |
126 |
|
private DelayQueue<PDelay> populatedQueue(int n) { |
127 |
|
DelayQueue<PDelay> q = new DelayQueue<PDelay>(); |
128 |
|
assertTrue(q.isEmpty()); |
129 |
< |
for (int i = n-1; i >= 0; i-=2) |
129 |
> |
for (int i = n-1; i >= 0; i -= 2) |
130 |
|
assertTrue(q.offer(new PDelay(i))); |
131 |
< |
for (int i = (n & 1); i < n; i+=2) |
131 |
> |
for (int i = (n & 1); i < n; i += 2) |
132 |
|
assertTrue(q.offer(new PDelay(i))); |
133 |
|
assertFalse(q.isEmpty()); |
134 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
654 |
|
public void realRun() throws InterruptedException { |
655 |
|
assertNull(q.poll()); |
656 |
|
threadsStarted.await(); |
657 |
< |
assertTrue(null != q.poll(LONG_DELAY_MS, MILLISECONDS)); |
657 |
> |
assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS)); |
658 |
|
checkEmpty(q); |
659 |
|
}}); |
660 |
|
|
774 |
|
} |
775 |
|
} |
776 |
|
|
777 |
+ |
/** |
778 |
+ |
* remove(null), contains(null) always return false |
779 |
+ |
*/ |
780 |
+ |
public void testNeverContainsNull() { |
781 |
+ |
Collection<?> q = populatedQueue(SIZE); |
782 |
+ |
assertFalse(q.contains(null)); |
783 |
+ |
assertFalse(q.remove(null)); |
784 |
+ |
} |
785 |
|
} |