--- jsr166/src/test/tck/JSR166TestCase.java 2011/05/21 06:24:33 1.81 +++ jsr166/src/test/tck/JSR166TestCase.java 2011/05/29 14:18:52 1.85 @@ -260,7 +260,6 @@ public class JSR166TestCase extends Test return 50; } - /** * Sets delays as multiples of SHORT_DELAY. */ @@ -284,7 +283,7 @@ public class JSR166TestCase extends Test * milliseconds in the future. */ Date delayedDate(long delayMillis) { - return new Date(new Date().getTime() + delayMillis); + return new Date(System.currentTimeMillis() + delayMillis); } /** @@ -308,9 +307,13 @@ public class JSR166TestCase extends Test } /** + * Extra checks that get done for all test cases. + * * Triggers test case failure if any thread assertions have failed, * by rethrowing, in the test harness thread, any exception recorded * earlier by threadRecordFailure. + * + * Triggers test case failure if interrupt status is set in the main thread. */ public void tearDown() throws Exception { Throwable t = threadFailure.getAndSet(null); @@ -328,6 +331,9 @@ public class JSR166TestCase extends Test throw afe; } } + + if (Thread.interrupted()) + throw new AssertionFailedError("interrupt status set in main thread"); } /** @@ -459,7 +465,7 @@ public class JSR166TestCase extends Test else { AssertionFailedError afe = new AssertionFailedError("unexpected exception: " + t); - t.initCause(t); + afe.initCause(t); throw afe; } } @@ -522,6 +528,29 @@ public class JSR166TestCase extends Test } /** + * Checks that future.get times out, with the default timeout of + * {@code timeoutMillis()}. + */ + void assertFutureTimesOut(Future future) { + assertFutureTimesOut(future, timeoutMillis()); + } + + /** + * Checks that future.get times out, with the given millisecond timeout. + */ + void assertFutureTimesOut(Future future, long timeoutMillis) { + long startTime = System.nanoTime(); + try { + future.get(timeoutMillis, MILLISECONDS); + shouldThrow(); + } catch (TimeoutException success) { + } catch (Exception e) { + threadUnexpectedException(e); + } finally { future.cancel(true); } + assertTrue(millisElapsedSince(startTime) >= timeoutMillis); + } + + /** * Fails with message "should throw exception". */ public void shouldThrow() { @@ -721,7 +750,7 @@ public class JSR166TestCase extends Test } catch (InterruptedException ie) { threadUnexpectedException(ie); } finally { - if (t.isAlive()) { + if (t.getState() != Thread.State.TERMINATED) { t.interrupt(); fail("Test timed out"); }