ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ArrayBlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.41 by jsr166, Fri Nov 5 00:17:22 2010 UTC vs.
Revision 1.43 by jsr166, Tue Mar 15 19:47:06 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 453 | Line 453 | public class ArrayBlockingQueueTest exte
453       * returning timeout status
454       */
455      public void testInterruptedTimedPoll() throws InterruptedException {
456 <        Thread t = new Thread(new CheckedRunnable() {
456 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
457 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
458 >        Thread t = newStartedThread(new CheckedRunnable() {
459              public void realRun() throws InterruptedException {
458                ArrayBlockingQueue q = populatedQueue(SIZE);
460                  for (int i = 0; i < SIZE; ++i) {
461 <                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));;
461 >                    long t0 = System.nanoTime();
462 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
463 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
464                  }
465 +                long t0 = System.nanoTime();
466 +                aboutToWait.countDown();
467                  try {
468 <                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
468 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
469                      shouldThrow();
470 <                } catch (InterruptedException success) {}
470 >                } catch (InterruptedException success) {
471 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
472 >                }
473              }});
474  
475 <        t.start();
476 <        Thread.sleep(SHORT_DELAY_MS);
475 >        aboutToWait.await();
476 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
477          t.interrupt();
478 <        t.join();
478 >        awaitTermination(t, MEDIUM_DELAY_MS);
479 >        checkEmpty(q);
480      }
481  
482      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines