182 |
|
return suite; |
183 |
|
} |
184 |
|
|
185 |
< |
static void addTestReflectively(TestSuite suite, String testClassName) { |
186 |
< |
try { |
187 |
< |
Class klazz = Class.forName(testClassName); |
188 |
< |
Method m = klazz.getDeclaredMethod("suite", new Class<?>[0]); |
189 |
< |
suite.addTest(newTestSuite((Test)m.invoke(null))); |
190 |
< |
} catch (Exception e) { |
191 |
< |
throw new Error(e); |
185 |
> |
public static void addNamedTestClasses(TestSuite suite, |
186 |
> |
String... testClassNames) { |
187 |
> |
for (String testClassName : testClassNames) { |
188 |
> |
try { |
189 |
> |
Class<?> testClass = Class.forName(testClassName); |
190 |
> |
Method m = testClass.getDeclaredMethod("suite", |
191 |
> |
new Class<?>[0]); |
192 |
> |
suite.addTest(newTestSuite((Test)m.invoke(null))); |
193 |
> |
} catch (Exception e) { |
194 |
> |
throw new Error("Missing test class", e); |
195 |
> |
} |
196 |
|
} |
197 |
|
} |
198 |
|
|
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
< |
public static boolean isAtLeastJdk6() { return JAVA_CLASS_VERSION >= 50.0; } |
212 |
< |
public static boolean isAtLeastJdk7() { return JAVA_CLASS_VERSION >= 51.0; } |
213 |
< |
public static boolean isAtLeastJdk8() { return JAVA_CLASS_VERSION >= 52.0; } |
211 |
> |
public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } |
212 |
> |
public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } |
213 |
> |
public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } |
214 |
|
|
215 |
|
/** |
216 |
|
* Collects all JSR166 unit tests as one suite. |
217 |
|
*/ |
218 |
|
public static Test suite() { |
219 |
+ |
// Java7+ test classes |
220 |
|
TestSuite suite = newTestSuite( |
221 |
|
ForkJoinPoolTest.suite(), |
222 |
|
ForkJoinTaskTest.suite(), |
282 |
|
TreeSetTest.suite(), |
283 |
|
TreeSubMapTest.suite(), |
284 |
|
TreeSubSetTest.suite()); |
285 |
< |
if (isAtLeastJdk8()) { |
286 |
< |
addTestReflectively(suite, "StampedLockTest"); |
285 |
> |
|
286 |
> |
// Java8+ test classes |
287 |
> |
if (atLeastJava8()) { |
288 |
> |
String[] java8TestClassNames = { |
289 |
> |
"CompletableFutureTest", |
290 |
> |
"ConcurrentHashMap8Test", |
291 |
> |
"CountedCompleterTest", |
292 |
> |
"DoubleAccumulatorTest", |
293 |
> |
"DoubleAdderTest", |
294 |
> |
"ForkJoinPool8Test", |
295 |
> |
"LongAccumulatorTest", |
296 |
> |
"LongAdderTest", |
297 |
> |
"StampedLockTest", |
298 |
> |
}; |
299 |
> |
addNamedTestClasses(suite, java8TestClassNames); |
300 |
|
} |
301 |
+ |
|
302 |
|
return suite; |
303 |
|
} |
304 |
|
|
391 |
|
|
392 |
|
if (Thread.interrupted()) |
393 |
|
throw new AssertionFailedError("interrupt status set in main thread"); |
394 |
+ |
|
395 |
+ |
checkForkJoinPoolThreadLeaks(); |
396 |
+ |
} |
397 |
+ |
|
398 |
+ |
/** |
399 |
+ |
* Find missing try { ... } finally { joinPool(e); } |
400 |
+ |
*/ |
401 |
+ |
void checkForkJoinPoolThreadLeaks() throws InterruptedException { |
402 |
+ |
Thread[] survivors = new Thread[5]; |
403 |
+ |
int count = Thread.enumerate(survivors); |
404 |
+ |
for (int i = 0; i < count; i++) { |
405 |
+ |
Thread thread = survivors[i]; |
406 |
+ |
String name = thread.getName(); |
407 |
+ |
if (name.startsWith("ForkJoinPool-")) { |
408 |
+ |
// give thread some time to terminate |
409 |
+ |
thread.join(LONG_DELAY_MS); |
410 |
+ |
if (!thread.isAlive()) continue; |
411 |
+ |
thread.stop(); |
412 |
+ |
throw new AssertionFailedError |
413 |
+ |
(String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n", |
414 |
+ |
toString(), name)); |
415 |
+ |
} |
416 |
+ |
} |
417 |
|
} |
418 |
|
|
419 |
|
/** |