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) { |
544 |
|
} |
545 |
|
|
546 |
|
/** |
547 |
< |
* Returns a new started Thread running the given runnable. |
547 |
> |
* Returns a new started daemon Thread running the given runnable. |
548 |
|
*/ |
549 |
|
Thread newStartedThread(Runnable runnable) { |
550 |
|
Thread t = new Thread(runnable); |
551 |
+ |
t.setDaemon(true); |
552 |
|
t.start(); |
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 { |