--- jsr166/src/test/tck/SynchronousQueueTest.java 2011/03/15 19:47:07 1.31 +++ jsr166/src/test/tck/SynchronousQueueTest.java 2011/05/21 06:24:33 1.34 @@ -159,7 +159,7 @@ public class SynchronousQueueTest extend q.put(null); shouldThrow(); } catch (NullPointerException success) {} - } + } /** * put blocks interruptibly if no active taker @@ -172,7 +172,7 @@ public class SynchronousQueueTest extend }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -196,9 +196,9 @@ public class SynchronousQueueTest extend }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(0, q.take()); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -211,21 +211,19 @@ public class SynchronousQueueTest extend final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - long t0 = System.nanoTime(); - assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); - assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); + long startTime = System.nanoTime(); + assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); pleaseInterrupt.countDown(); - t0 = System.nanoTime(); try { - q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); + q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} - assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); }}); - assertTrue(pleaseInterrupt.await(MEDIUM_DELAY_MS, MILLISECONDS)); + await(pleaseInterrupt); t.interrupt(); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -253,7 +251,7 @@ public class SynchronousQueueTest extend }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -277,9 +275,9 @@ public class SynchronousQueueTest extend }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(0, q.take()); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -295,7 +293,7 @@ public class SynchronousQueueTest extend }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -346,7 +344,7 @@ public class SynchronousQueueTest extend }}); threadStarted.await(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); awaitTermination(t, MEDIUM_DELAY_MS); } @@ -573,7 +571,7 @@ public class SynchronousQueueTest extend executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); assertSame(one, q.take()); }}); @@ -595,7 +593,7 @@ public class SynchronousQueueTest extend executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); q.put(one); }}); @@ -665,7 +663,7 @@ public class SynchronousQueueTest extend t.start(); ArrayList l = new ArrayList(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); q.drainTo(l); assertTrue(l.size() <= 1); if (l.size() > 0) @@ -714,7 +712,7 @@ public class SynchronousQueueTest extend t1.start(); t2.start(); ArrayList l = new ArrayList(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); q.drainTo(l, 1); assertEquals(1, l.size()); q.drainTo(l, 1);