--- jsr166/src/test/tck/ArrayBlockingQueueTest.java 2010/11/04 01:04:54 1.40 +++ jsr166/src/test/tck/ArrayBlockingQueueTest.java 2010/11/28 08:43:53 1.42 @@ -41,8 +41,8 @@ public class ArrayBlockingQueueTest exte * Create a queue of given size containing consecutive * Integers 0 ... n. */ - private ArrayBlockingQueue populatedQueue(int n) { - ArrayBlockingQueue q = new ArrayBlockingQueue(n); + private ArrayBlockingQueue populatedQueue(int n) { + ArrayBlockingQueue q = new ArrayBlockingQueue(n); assertTrue(q.isEmpty()); for (int i = 0; i < n; i++) assertTrue(q.offer(new Integer(i))); @@ -453,22 +453,30 @@ public class ArrayBlockingQueueTest exte * returning timeout status */ public void testInterruptedTimedPoll() throws InterruptedException { - Thread t = new Thread(new CheckedRunnable() { + final BlockingQueue q = populatedQueue(SIZE); + final CountDownLatch aboutToWait = new CountDownLatch(1); + Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));; + long t0 = System.nanoTime(); + assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); } + long t0 = System.nanoTime(); + aboutToWait.countDown(); try { - q.poll(SMALL_DELAY_MS, MILLISECONDS); + q.poll(MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); - } catch (InterruptedException success) {} + } catch (InterruptedException success) { + assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); + } }}); - t.start(); - Thread.sleep(SHORT_DELAY_MS); + aboutToWait.await(); + waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); t.interrupt(); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); + checkEmpty(q); } /** @@ -620,9 +628,10 @@ public class ArrayBlockingQueueTest exte * toArray(a) contains all elements in FIFO order */ public void testToArray2() { - ArrayBlockingQueue q = populatedQueue(SIZE); + ArrayBlockingQueue q = populatedQueue(SIZE); Integer[] ints = new Integer[SIZE]; - assertSame(ints, q.toArray(ints)); + Integer[] array = q.toArray(ints); + assertSame(ints, array); for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.poll()); }