534 |
|
} |
535 |
|
|
536 |
|
/** |
537 |
< |
* Sleep until the timeout has elapsed, or interrupted. |
537 |
> |
* Sleeps until the timeout has elapsed, or interrupted. |
538 |
|
* Does <em>NOT</em> throw InterruptedException. |
539 |
|
*/ |
540 |
|
void sleepTillInterrupted(long timeoutMillis) { |
553 |
|
return t; |
554 |
|
} |
555 |
|
|
556 |
+ |
/** |
557 |
+ |
* Waits for the specified time (in milliseconds) for the thread |
558 |
+ |
* to terminate (using {@link Thread#join(long)}), else interrupts |
559 |
+ |
* the thread (in the hope that it may terminate later) and fails. |
560 |
+ |
*/ |
561 |
+ |
void awaitTermination(Thread t, long timeoutMillis) { |
562 |
+ |
try { |
563 |
+ |
t.join(timeoutMillis); |
564 |
+ |
} catch (InterruptedException ie) { |
565 |
+ |
threadUnexpectedException(ie); |
566 |
+ |
} finally { |
567 |
+ |
if (t.isAlive()) { |
568 |
+ |
t.interrupt(); |
569 |
+ |
fail("Test timed out"); |
570 |
+ |
} |
571 |
+ |
} |
572 |
+ |
} |
573 |
+ |
|
574 |
|
// Some convenient Runnable classes |
575 |
|
|
576 |
|
public abstract class CheckedRunnable implements Runnable { |