9 |
|
import junit.framework.*; |
10 |
|
import java.util.*; |
11 |
|
import java.util.concurrent.*; |
12 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
13 |
|
import java.io.*; |
14 |
|
|
15 |
|
public class PriorityBlockingQueueTest extends JSR166TestCase { |
333 |
|
try { |
334 |
|
q.put(new Integer(0)); |
335 |
|
q.put(new Integer(0)); |
336 |
< |
threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
337 |
< |
threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
336 |
> |
threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS)); |
337 |
> |
threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS)); |
338 |
|
} finally { } |
339 |
|
} |
340 |
|
}); |
408 |
|
public void testTimedPoll0() throws InterruptedException { |
409 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
410 |
|
for (int i = 0; i < SIZE; ++i) { |
411 |
< |
assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); |
411 |
> |
assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); |
412 |
|
} |
413 |
< |
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
413 |
> |
assertNull(q.poll(0, MILLISECONDS)); |
414 |
|
} |
415 |
|
|
416 |
|
/** |
419 |
|
public void testTimedPoll() throws InterruptedException { |
420 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
421 |
|
for (int i = 0; i < SIZE; ++i) { |
422 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
422 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
423 |
|
} |
424 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
424 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
425 |
|
} |
426 |
|
|
427 |
|
/** |
433 |
|
public void realRun() throws InterruptedException { |
434 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
435 |
|
for (int i = 0; i < SIZE; ++i) { |
436 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
436 |
> |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
437 |
|
} |
438 |
|
try { |
439 |
< |
q.poll(SMALL_DELAY_MS, TimeUnit.MILLISECONDS); |
439 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
440 |
|
threadShouldThrow(); |
441 |
|
} catch (InterruptedException success) {} |
442 |
|
}}); |
455 |
|
final PriorityBlockingQueue q = new PriorityBlockingQueue(2); |
456 |
|
Thread t = new Thread(new CheckedRunnable() { |
457 |
|
public void realRun() throws InterruptedException { |
458 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
459 |
< |
threadAssertEquals(0, q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
458 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
459 |
> |
threadAssertEquals(0, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
460 |
|
try { |
461 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
461 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
462 |
|
threadShouldThrow(); |
463 |
|
} catch (InterruptedException success) {} |
464 |
|
}}); |
465 |
|
|
466 |
|
t.start(); |
467 |
|
Thread.sleep(SMALL_DELAY_MS); |
468 |
< |
assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
468 |
> |
assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS)); |
469 |
|
t.interrupt(); |
470 |
|
t.join(); |
471 |
|
} |
704 |
|
executor.execute(new CheckedRunnable() { |
705 |
|
public void realRun() throws InterruptedException { |
706 |
|
threadAssertNull(q.poll()); |
707 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
707 |
> |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
708 |
|
threadAssertTrue(q.isEmpty()); |
709 |
|
}}); |
710 |
|
|