260 |
|
return 50; |
261 |
|
} |
262 |
|
|
263 |
– |
|
263 |
|
/** |
264 |
|
* Sets delays as multiples of SHORT_DELAY. |
265 |
|
*/ |
521 |
|
} |
522 |
|
|
523 |
|
/** |
524 |
+ |
* Checks that future.get times out, with the default timeout of |
525 |
+ |
* {@code timeoutMillis()}. |
526 |
+ |
*/ |
527 |
+ |
void assertFutureTimesOut(Future future) { |
528 |
+ |
assertFutureTimesOut(future, timeoutMillis()); |
529 |
+ |
} |
530 |
+ |
|
531 |
+ |
/** |
532 |
+ |
* Checks that future.get times out, with the given millisecond timeout. |
533 |
+ |
*/ |
534 |
+ |
void assertFutureTimesOut(Future future, long timeoutMillis) { |
535 |
+ |
long startTime = System.nanoTime(); |
536 |
+ |
try { |
537 |
+ |
future.get(timeoutMillis, MILLISECONDS); |
538 |
+ |
shouldThrow(); |
539 |
+ |
} catch (TimeoutException success) { |
540 |
+ |
} catch (Exception e) { |
541 |
+ |
threadUnexpectedException(e); |
542 |
+ |
} finally { future.cancel(true); } |
543 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
544 |
+ |
} |
545 |
+ |
|
546 |
+ |
/** |
547 |
|
* Fails with message "should throw exception". |
548 |
|
*/ |
549 |
|
public void shouldThrow() { |
743 |
|
} catch (InterruptedException ie) { |
744 |
|
threadUnexpectedException(ie); |
745 |
|
} finally { |
746 |
< |
if (t.isAlive()) { |
746 |
> |
if (t.getState() != Thread.State.TERMINATED) { |
747 |
|
t.interrupt(); |
748 |
|
fail("Test timed out"); |
749 |
|
} |