96 |
|
private static final boolean useSecurityManager = |
97 |
|
Boolean.getBoolean("jsr166.useSecurityManager"); |
98 |
|
|
99 |
+ |
protected static final boolean expensiveTests = |
100 |
+ |
Boolean.getBoolean("jsr166.expensiveTests"); |
101 |
+ |
|
102 |
+ |
/** |
103 |
+ |
* If true, report on stdout all "slow" tests, that is, ones that |
104 |
+ |
* take more than profileThreshold milliseconds to execute. |
105 |
+ |
*/ |
106 |
+ |
private static final boolean profileTests = |
107 |
+ |
Boolean.getBoolean("jsr166.profileTests"); |
108 |
+ |
|
109 |
+ |
/** |
110 |
+ |
* The number of milliseconds that tests are permitted for |
111 |
+ |
* execution without being reported, when profileTests is set. |
112 |
+ |
*/ |
113 |
+ |
private static final long profileThreshold = |
114 |
+ |
Long.getLong("jsr166.profileThreshold", 100); |
115 |
+ |
|
116 |
+ |
protected void runTest() throws Throwable { |
117 |
+ |
if (profileTests) |
118 |
+ |
runTestProfiled(); |
119 |
+ |
else |
120 |
+ |
super.runTest(); |
121 |
+ |
} |
122 |
+ |
|
123 |
+ |
protected void runTestProfiled() throws Throwable { |
124 |
+ |
long t0 = System.nanoTime(); |
125 |
+ |
try { |
126 |
+ |
super.runTest(); |
127 |
+ |
} finally { |
128 |
+ |
long elapsedMillis = |
129 |
+ |
(System.nanoTime() - t0) / (1000L * 1000L); |
130 |
+ |
if (elapsedMillis >= profileThreshold) |
131 |
+ |
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
132 |
+ |
} |
133 |
+ |
} |
134 |
+ |
|
135 |
|
/** |
136 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner |
137 |
|
*/ |
605 |
|
} |
606 |
|
|
607 |
|
/** |
608 |
+ |
* Waits up to the specified number of milliseconds for the given |
609 |
+ |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
610 |
+ |
*/ |
611 |
+ |
void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
612 |
+ |
long timeoutNanos = timeoutMillis * 1000L * 1000L; |
613 |
+ |
long t0 = System.nanoTime(); |
614 |
+ |
for (;;) { |
615 |
+ |
Thread.State s = thread.getState(); |
616 |
+ |
if (s == Thread.State.BLOCKED || |
617 |
+ |
s == Thread.State.WAITING || |
618 |
+ |
s == Thread.State.TIMED_WAITING || |
619 |
+ |
System.nanoTime() - t0 > timeoutNanos) |
620 |
+ |
return; |
621 |
+ |
Thread.yield(); |
622 |
+ |
} |
623 |
+ |
} |
624 |
+ |
|
625 |
+ |
/** |
626 |
|
* Returns a new started daemon Thread running the given runnable. |
627 |
|
*/ |
628 |
|
Thread newStartedThread(Runnable runnable) { |
764 |
|
|
765 |
|
public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) { |
766 |
|
return new CheckedCallable<String>() { |
767 |
< |
public String realCall() { |
767 |
> |
protected String realCall() { |
768 |
|
try { |
769 |
|
latch.await(); |
770 |
|
} catch (InterruptedException quittingTime) {} |
825 |
|
} |
826 |
|
} |
827 |
|
|
828 |
+ |
public Runnable possiblyInterruptedRunnable(final long timeoutMillis) { |
829 |
+ |
return new CheckedRunnable() { |
830 |
+ |
protected void realRun() { |
831 |
+ |
try { |
832 |
+ |
Thread.sleep(timeoutMillis); |
833 |
+ |
} catch (InterruptedException ok) {} |
834 |
+ |
}}; |
835 |
+ |
} |
836 |
+ |
|
837 |
|
public class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
838 |
|
protected void realRun() { |
839 |
|
try { |
859 |
|
} |
860 |
|
} |
861 |
|
|
862 |
+ |
public interface TrackedRunnable extends Runnable { |
863 |
+ |
boolean isDone(); |
864 |
+ |
} |
865 |
+ |
|
866 |
+ |
public static TrackedRunnable trackedRunnable(final long timeoutMillis) { |
867 |
+ |
return new TrackedRunnable() { |
868 |
+ |
private volatile boolean done = false; |
869 |
+ |
public boolean isDone() { return done; } |
870 |
+ |
public void run() { |
871 |
+ |
try { |
872 |
+ |
Thread.sleep(timeoutMillis); |
873 |
+ |
done = true; |
874 |
+ |
} catch (InterruptedException ok) {} |
875 |
+ |
} |
876 |
+ |
}; |
877 |
+ |
} |
878 |
+ |
|
879 |
|
public static class TrackedShortRunnable implements Runnable { |
880 |
|
public volatile boolean done = false; |
881 |
|
public void run() { |
882 |
|
try { |
883 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
884 |
+ |
done = true; |
885 |
+ |
} catch (InterruptedException ok) {} |
886 |
+ |
} |
887 |
+ |
} |
888 |
+ |
|
889 |
+ |
public static class TrackedSmallRunnable implements Runnable { |
890 |
+ |
public volatile boolean done = false; |
891 |
+ |
public void run() { |
892 |
+ |
try { |
893 |
|
Thread.sleep(SMALL_DELAY_MS); |
894 |
|
done = true; |
895 |
|
} catch (InterruptedException ok) {} |