--- jsr166/src/test/tck/PriorityBlockingQueueTest.java 2010/11/18 20:21:53 1.39 +++ jsr166/src/test/tck/PriorityBlockingQueueTest.java 2011/05/06 11:22:07 1.43 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ * Other contributors include Andrew Wright, Jeffrey Hayes, * Pat Fisher, Mike Judd. */ @@ -296,25 +296,25 @@ public class PriorityBlockingQueueTest e /** * put(null) throws NPE */ - public void testPutNull() { + public void testPutNull() { try { PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); q.put(null); shouldThrow(); } catch (NullPointerException success) {} - } + } /** * all elements successfully put are contained */ - public void testPut() { - PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); - for (int i = 0; i < SIZE; ++i) { - Integer I = new Integer(i); - q.put(I); - assertTrue(q.contains(I)); - } - assertEquals(SIZE, q.size()); + public void testPut() { + PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); + for (int i = 0; i < SIZE; ++i) { + Integer I = new Integer(i); + q.put(I); + assertTrue(q.contains(I)); + } + assertEquals(SIZE, q.size()); } /** @@ -330,7 +330,7 @@ public class PriorityBlockingQueueTest e }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(q.size(), size); q.take(); t.interrupt(); @@ -351,7 +351,7 @@ public class PriorityBlockingQueueTest e }}); t.start(); - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); t.interrupt(); t.join(); } @@ -383,7 +383,7 @@ public class PriorityBlockingQueueTest e }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -427,22 +427,29 @@ public class PriorityBlockingQueueTest e * 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 { - PriorityBlockingQueue 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); } /** @@ -691,7 +698,7 @@ public class PriorityBlockingQueueTest e executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); q.put(one); }});