175 |
|
* Queue contains all elements of collection used to initialize |
176 |
|
*/ |
177 |
|
public void testConstructor6() { |
178 |
< |
try { |
179 |
< |
PDelay[] ints = new PDelay[SIZE]; |
180 |
< |
for (int i = 0; i < SIZE; ++i) |
181 |
< |
ints[i] = new PDelay(i); |
182 |
< |
DelayQueue q = new DelayQueue(Arrays.asList(ints)); |
183 |
< |
for (int i = 0; i < SIZE; ++i) |
184 |
< |
assertEquals(ints[i], q.poll()); |
185 |
< |
} |
186 |
< |
finally {} |
178 |
> |
PDelay[] ints = new PDelay[SIZE]; |
179 |
> |
for (int i = 0; i < SIZE; ++i) |
180 |
> |
ints[i] = new PDelay(i); |
181 |
> |
DelayQueue q = new DelayQueue(Arrays.asList(ints)); |
182 |
> |
for (int i = 0; i < SIZE; ++i) |
183 |
> |
assertEquals(ints[i], q.poll()); |
184 |
|
} |
185 |
|
|
186 |
|
/** |
311 |
|
* Queue contains all elements of successful addAll |
312 |
|
*/ |
313 |
|
public void testAddAll5() { |
314 |
< |
try { |
315 |
< |
PDelay[] empty = new PDelay[0]; |
316 |
< |
PDelay[] ints = new PDelay[SIZE]; |
317 |
< |
for (int i = SIZE-1; i >= 0; --i) |
318 |
< |
ints[i] = new PDelay(i); |
319 |
< |
DelayQueue q = new DelayQueue(); |
320 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
321 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
322 |
< |
for (int i = 0; i < SIZE; ++i) |
326 |
< |
assertEquals(ints[i], q.poll()); |
327 |
< |
} |
328 |
< |
finally {} |
314 |
> |
PDelay[] empty = new PDelay[0]; |
315 |
> |
PDelay[] ints = new PDelay[SIZE]; |
316 |
> |
for (int i = SIZE-1; i >= 0; --i) |
317 |
> |
ints[i] = new PDelay(i); |
318 |
> |
DelayQueue q = new DelayQueue(); |
319 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
320 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
321 |
> |
for (int i = 0; i < SIZE; ++i) |
322 |
> |
assertEquals(ints[i], q.poll()); |
323 |
|
} |
324 |
|
|
325 |
|
/** |
476 |
|
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); |
477 |
|
} |
478 |
|
try { |
479 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
479 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
480 |
|
shouldThrow(); |
481 |
|
} catch (InterruptedException success) {} |
482 |
|
}}); |
493 |
|
*/ |
494 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
495 |
|
final DelayQueue q = new DelayQueue(); |
496 |
+ |
final PDelay pdelay = new PDelay(0); |
497 |
|
Thread t = new Thread(new CheckedRunnable() { |
498 |
|
public void realRun() throws InterruptedException { |
499 |
|
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
500 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
500 |
> |
assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
501 |
|
try { |
502 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
503 |
|
shouldThrow(); |
506 |
|
|
507 |
|
t.start(); |
508 |
|
Thread.sleep(SMALL_DELAY_MS); |
509 |
< |
assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); |
509 |
> |
assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS)); |
510 |
|
t.interrupt(); |
511 |
|
t.join(); |
512 |
|
} |