449 |
|
*/ |
450 |
|
public static void delay(long ms) throws InterruptedException { |
451 |
|
long startTime = System.nanoTime(); |
452 |
< |
long ns = ms * 1000 * 1000; |
452 |
> |
long ns = ms * 1000 * 1000; |
453 |
|
for (;;) { |
454 |
|
if (ms > 0L) |
455 |
|
Thread.sleep(ms); |
457 |
|
Thread.yield(); |
458 |
|
long d = ns - (System.nanoTime() - startTime); |
459 |
|
if (d > 0L) |
460 |
< |
ms = d / (1000 * 1000); |
460 |
> |
ms = d / (1000 * 1000); |
461 |
|
else |
462 |
|
break; |
463 |
|
} |
478 |
|
} |
479 |
|
} |
480 |
|
|
481 |
+ |
/** |
482 |
+ |
* Checks that thread does not terminate within timeoutMillis |
483 |
+ |
* milliseconds (that is, Thread.join times out). |
484 |
+ |
*/ |
485 |
+ |
public void assertThreadJoinTimesOut(Thread thread, long timeoutMillis) { |
486 |
+ |
try { |
487 |
+ |
long startTime = System.nanoTime(); |
488 |
+ |
thread.join(timeoutMillis); |
489 |
+ |
assertTrue(thread.isAlive()); |
490 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
491 |
+ |
} catch (InterruptedException ie) { |
492 |
+ |
fail("Unexpected InterruptedException"); |
493 |
+ |
} |
494 |
+ |
} |
495 |
|
|
496 |
|
/** |
497 |
|
* Fails with message "should throw exception". |