39 |
|
} |
40 |
|
|
41 |
|
public static Test suite() { |
42 |
+ |
class Implementation implements CollectionImplementation { |
43 |
+ |
public Class<?> klazz() { return DelayQueue.class; } |
44 |
+ |
public Collection emptyCollection() { return new DelayQueue(); } |
45 |
+ |
public Object makeElement(int i) { return new PDelay(i); } |
46 |
+ |
public boolean isConcurrent() { return true; } |
47 |
+ |
public boolean permitsNulls() { return false; } |
48 |
+ |
} |
49 |
|
return newTestSuite(DelayQueueTest.class, |
50 |
< |
new Generic().testSuite()); |
50 |
> |
new Generic().testSuite(), |
51 |
> |
CollectionTest.testSuite(new Implementation())); |
52 |
|
} |
53 |
|
|
54 |
|
/** |
102 |
|
} |
103 |
|
|
104 |
|
public boolean equals(Object other) { |
105 |
< |
return equals((NanoDelay)other); |
106 |
< |
} |
99 |
< |
public boolean equals(NanoDelay other) { |
100 |
< |
return other.trigger == trigger; |
105 |
> |
return (other instanceof NanoDelay) && |
106 |
> |
this.trigger == ((NanoDelay)other).trigger; |
107 |
|
} |
108 |
|
|
109 |
|
// suppress [overrides] javac warning |
125 |
|
|
126 |
|
/** |
127 |
|
* Returns a new queue of given size containing consecutive |
128 |
< |
* PDelays 0 ... n. |
128 |
> |
* PDelays 0 ... n - 1. |
129 |
|
*/ |
130 |
|
private DelayQueue<PDelay> populatedQueue(int n) { |
131 |
|
DelayQueue<PDelay> q = new DelayQueue<PDelay>(); |
137 |
|
assertFalse(q.isEmpty()); |
138 |
|
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
139 |
|
assertEquals(n, q.size()); |
140 |
+ |
assertEquals(new PDelay(0), q.peek()); |
141 |
|
return q; |
142 |
|
} |
143 |
|
|
419 |
|
*/ |
420 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
421 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
422 |
+ |
final DelayQueue q = populatedQueue(SIZE); |
423 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
424 |
|
public void realRun() throws InterruptedException { |
425 |
< |
DelayQueue q = populatedQueue(SIZE); |
425 |
> |
long startTime = System.nanoTime(); |
426 |
|
for (int i = 0; i < SIZE; ++i) { |
427 |
< |
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); |
427 |
> |
assertEquals(new PDelay(i), |
428 |
> |
((PDelay)q.poll(LONG_DELAY_MS, MILLISECONDS))); |
429 |
|
} |
430 |
|
|
431 |
|
Thread.currentThread().interrupt(); |
441 |
|
shouldThrow(); |
442 |
|
} catch (InterruptedException success) {} |
443 |
|
assertFalse(Thread.interrupted()); |
444 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
445 |
|
}}); |
446 |
|
|
447 |
|
await(pleaseInterrupt); |
448 |
|
assertThreadStaysAlive(t); |
449 |
|
t.interrupt(); |
450 |
|
awaitTermination(t); |
451 |
+ |
checkEmpty(q); |
452 |
|
} |
453 |
|
|
454 |
|
/** |