6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
+ |
/* |
10 |
+ |
* @test |
11 |
+ |
* @summary JSR-166 tck tests |
12 |
+ |
* @modules java.management |
13 |
+ |
* @build * |
14 |
+ |
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
15 |
+ |
*/ |
16 |
+ |
|
17 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
18 |
|
import static java.util.concurrent.TimeUnit.MINUTES; |
19 |
|
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
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 |
+ |
/** |
188 |
+ |
* Returns the value of the system property, or NaN if not defined. |
189 |
+ |
*/ |
190 |
+ |
private static float systemPropertyValue(String name) { |
191 |
+ |
String floatString = System.getProperty(name); |
192 |
+ |
if (floatString == null) |
193 |
+ |
return Float.NaN; |
194 |
+ |
try { |
195 |
+ |
return Float.parseFloat(floatString); |
196 |
+ |
} catch (NumberFormatException ex) { |
197 |
+ |
throw new IllegalArgumentException( |
198 |
+ |
String.format("Bad float value in system property %s=%s", |
199 |
+ |
name, floatString)); |
200 |
+ |
} |
201 |
+ |
} |
202 |
+ |
|
203 |
+ |
/** |
204 |
+ |
* The scaling factor to apply to standard delays used in tests. |
205 |
+ |
* May be initialized from any of: |
206 |
+ |
* - the "jsr166.delay.factor" system property |
207 |
+ |
* - the "test.timeout.factor" system property (as used by jtreg) |
208 |
+ |
* See: http://openjdk.java.net/jtreg/tag-spec.html |
209 |
+ |
* - hard-coded fuzz factor when using a known slowpoke VM |
210 |
+ |
*/ |
211 |
+ |
private static final float delayFactor = delayFactor(); |
212 |
+ |
|
213 |
+ |
private static float delayFactor() { |
214 |
+ |
float x; |
215 |
+ |
if (!Float.isNaN(x = systemPropertyValue("jsr166.delay.factor"))) |
216 |
+ |
return x; |
217 |
+ |
if (!Float.isNaN(x = systemPropertyValue("test.timeout.factor"))) |
218 |
+ |
return x; |
219 |
+ |
String prop = System.getProperty("java.vm.version"); |
220 |
+ |
if (prop != null && prop.matches(".*debug.*")) |
221 |
+ |
return 4.0f; // How much slower is fastdebug than product?! |
222 |
+ |
return 1.0f; |
223 |
+ |
} |
224 |
+ |
|
225 |
|
public JSR166TestCase() { super(); } |
226 |
|
public JSR166TestCase(String name) { super(name); } |
227 |
|
|
595 |
|
public static long LONG_DELAY_MS; |
596 |
|
|
597 |
|
/** |
598 |
< |
* Returns the shortest timed delay. This could |
599 |
< |
* be reimplemented to use for example a Property. |
598 |
> |
* Returns the shortest timed delay. This can be scaled up for |
599 |
> |
* slow machines using the jsr166.delay.factor system property, |
600 |
> |
* or via jtreg's -timeoutFactor: flag. |
601 |
> |
* http://openjdk.java.net/jtreg/command-help.html |
602 |
|
*/ |
603 |
|
protected long getShortDelay() { |
604 |
< |
return 50; |
604 |
> |
return (long) (50 * delayFactor); |
605 |
|
} |
606 |
|
|
607 |
|
/** |
914 |
|
}}; |
915 |
|
} |
916 |
|
|
917 |
+ |
PoolCleaner cleaner(ExecutorService pool, AtomicBoolean flag) { |
918 |
+ |
return new PoolCleanerWithReleaser(pool, releaser(flag)); |
919 |
+ |
} |
920 |
+ |
|
921 |
+ |
Runnable releaser(final AtomicBoolean flag) { |
922 |
+ |
return new Runnable() { public void run() { flag.set(true); }}; |
923 |
+ |
} |
924 |
+ |
|
925 |
|
/** |
926 |
|
* Waits out termination of a thread pool or fails doing so. |
927 |
|
*/ |
1478 |
|
return new LatchAwaiter(latch); |
1479 |
|
} |
1480 |
|
|
1481 |
< |
public void await(CountDownLatch latch) { |
1481 |
> |
public void await(CountDownLatch latch, long timeoutMillis) { |
1482 |
|
try { |
1483 |
< |
if (!latch.await(LONG_DELAY_MS, MILLISECONDS)) |
1483 |
> |
if (!latch.await(timeoutMillis, MILLISECONDS)) |
1484 |
|
fail("timed out waiting for CountDownLatch for " |
1485 |
< |
+ (LONG_DELAY_MS/1000) + " sec"); |
1485 |
> |
+ (timeoutMillis/1000) + " sec"); |
1486 |
|
} catch (Throwable fail) { |
1487 |
|
threadUnexpectedException(fail); |
1488 |
|
} |
1489 |
|
} |
1490 |
|
|
1491 |
+ |
public void await(CountDownLatch latch) { |
1492 |
+ |
await(latch, LONG_DELAY_MS); |
1493 |
+ |
} |
1494 |
+ |
|
1495 |
|
public void await(Semaphore semaphore) { |
1496 |
|
try { |
1497 |
|
if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)) |