9 |
|
/* |
10 |
|
* @test |
11 |
|
* @summary JSR-166 tck tests |
12 |
+ |
* @modules java.management |
13 |
|
* @build * |
14 |
< |
* @run junit/othervm/timeout=1000 JSR166TestCase |
14 |
> |
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
15 |
|
*/ |
16 |
|
|
17 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
61 |
|
import java.util.concurrent.ThreadFactory; |
62 |
|
import java.util.concurrent.ThreadPoolExecutor; |
63 |
|
import java.util.concurrent.TimeoutException; |
64 |
+ |
import java.util.concurrent.atomic.AtomicBoolean; |
65 |
|
import java.util.concurrent.atomic.AtomicReference; |
66 |
|
import java.util.regex.Matcher; |
67 |
|
import java.util.regex.Pattern; |
184 |
|
private static final int suiteRuns = |
185 |
|
Integer.getInteger("jsr166.suiteRuns", 1); |
186 |
|
|
187 |
+ |
private static float systemPropertyValue(String name, float defaultValue) { |
188 |
+ |
String floatString = System.getProperty(name); |
189 |
+ |
if (floatString == null) |
190 |
+ |
return defaultValue; |
191 |
+ |
try { |
192 |
+ |
return Float.parseFloat(floatString); |
193 |
+ |
} catch (NumberFormatException ex) { |
194 |
+ |
throw new IllegalArgumentException( |
195 |
+ |
String.format("Bad float value in system property %s=%s", |
196 |
+ |
name, floatString)); |
197 |
+ |
} |
198 |
+ |
} |
199 |
+ |
|
200 |
|
/** |
201 |
|
* The scaling factor to apply to standard delays used in tests. |
202 |
|
*/ |
203 |
< |
private static final int delayFactor = |
204 |
< |
Integer.getInteger("jsr166.delay.factor", 1); |
203 |
> |
private static final float delayFactor = |
204 |
> |
systemPropertyValue("jsr166.delay.factor", 1.0f); |
205 |
> |
|
206 |
> |
/** |
207 |
> |
* The timeout factor as used in the jtreg test harness. |
208 |
> |
* See: http://openjdk.java.net/jtreg/tag-spec.html |
209 |
> |
*/ |
210 |
> |
private static final float jtregTestTimeoutFactor |
211 |
> |
= systemPropertyValue("test.timeout.factor", 1.0f); |
212 |
|
|
213 |
|
public JSR166TestCase() { super(); } |
214 |
|
public JSR166TestCase(String name) { super(name); } |
584 |
|
|
585 |
|
/** |
586 |
|
* Returns the shortest timed delay. This can be scaled up for |
587 |
< |
* slow machines using the jsr166.delay.factor system property. |
587 |
> |
* slow machines using the jsr166.delay.factor system property, |
588 |
> |
* or via jtreg's -timeoutFactor: flag. |
589 |
> |
* http://openjdk.java.net/jtreg/command-help.html |
590 |
|
*/ |
591 |
|
protected long getShortDelay() { |
592 |
< |
return 50 * delayFactor; |
592 |
> |
return (long) (50 * delayFactor * jtregTestTimeoutFactor); |
593 |
|
} |
594 |
|
|
595 |
|
/** |
902 |
|
}}; |
903 |
|
} |
904 |
|
|
905 |
+ |
PoolCleaner cleaner(ExecutorService pool, AtomicBoolean flag) { |
906 |
+ |
return new PoolCleanerWithReleaser(pool, releaser(flag)); |
907 |
+ |
} |
908 |
+ |
|
909 |
+ |
Runnable releaser(final AtomicBoolean flag) { |
910 |
+ |
return new Runnable() { public void run() { flag.set(true); }}; |
911 |
+ |
} |
912 |
+ |
|
913 |
|
/** |
914 |
|
* Waits out termination of a thread pool or fails doing so. |
915 |
|
*/ |