8 |
|
|
9 |
|
/* |
10 |
|
* @test |
11 |
< |
* @summary JSR-166 tck tests |
11 |
> |
* @summary JSR-166 tck tests (conformance testing mode) |
12 |
> |
* @build * |
13 |
|
* @modules java.management |
14 |
+ |
* @run junit/othervm/timeout=1000 JSR166TestCase |
15 |
+ |
*/ |
16 |
+ |
|
17 |
+ |
/* |
18 |
+ |
* @test |
19 |
+ |
* @summary JSR-166 tck tests (whitebox tests allowed) |
20 |
|
* @build * |
21 |
< |
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
22 |
< |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase |
23 |
< |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase |
21 |
> |
* @modules java.base/java.util.concurrent:open |
22 |
> |
* java.base/java.lang:open |
23 |
> |
* java.management |
24 |
> |
* @run junit/othervm/timeout=1000 |
25 |
> |
* -Djsr166.testImplementationDetails=true |
26 |
> |
* JSR166TestCase |
27 |
> |
* @run junit/othervm/timeout=1000 |
28 |
> |
* -Djsr166.testImplementationDetails=true |
29 |
> |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 |
30 |
> |
* JSR166TestCase |
31 |
> |
* @run junit/othervm/timeout=1000 |
32 |
> |
* -Djsr166.testImplementationDetails=true |
33 |
> |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 |
34 |
> |
* -Djava.util.secureRandomSeed=true |
35 |
> |
* JSR166TestCase |
36 |
> |
* @run junit/othervm/timeout=1000/policy=tck.policy |
37 |
> |
* -Djsr166.testImplementationDetails=true |
38 |
> |
* JSR166TestCase |
39 |
|
*/ |
40 |
|
|
41 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
63 |
|
import java.security.SecurityPermission; |
64 |
|
import java.util.ArrayList; |
65 |
|
import java.util.Arrays; |
66 |
+ |
import java.util.Collection; |
67 |
|
import java.util.Collections; |
68 |
|
import java.util.Date; |
69 |
|
import java.util.Enumeration; |
470 |
|
AbstractQueuedLongSynchronizerTest.suite(), |
471 |
|
ArrayBlockingQueueTest.suite(), |
472 |
|
ArrayDequeTest.suite(), |
473 |
+ |
ArrayListTest.suite(), |
474 |
|
AtomicBooleanTest.suite(), |
475 |
|
AtomicIntegerArrayTest.suite(), |
476 |
|
AtomicIntegerFieldUpdaterTest.suite(), |
493 |
|
CopyOnWriteArrayListTest.suite(), |
494 |
|
CopyOnWriteArraySetTest.suite(), |
495 |
|
CountDownLatchTest.suite(), |
496 |
+ |
CountedCompleterTest.suite(), |
497 |
|
CyclicBarrierTest.suite(), |
498 |
|
DelayQueueTest.suite(), |
499 |
|
EntryTest.suite(), |
522 |
|
TreeMapTest.suite(), |
523 |
|
TreeSetTest.suite(), |
524 |
|
TreeSubMapTest.suite(), |
525 |
< |
TreeSubSetTest.suite()); |
525 |
> |
TreeSubSetTest.suite(), |
526 |
> |
VectorTest.suite()); |
527 |
|
|
528 |
|
// Java8+ test classes |
529 |
|
if (atLeastJava8()) { |
530 |
|
String[] java8TestClassNames = { |
531 |
+ |
"ArrayDeque8Test", |
532 |
|
"Atomic8Test", |
533 |
|
"CompletableFutureTest", |
534 |
|
"ConcurrentHashMap8Test", |
535 |
< |
"CountedCompleterTest", |
535 |
> |
"CountedCompleter8Test", |
536 |
|
"DoubleAccumulatorTest", |
537 |
|
"DoubleAdderTest", |
538 |
|
"ForkJoinPool8Test", |
539 |
|
"ForkJoinTask8Test", |
540 |
+ |
"LinkedBlockingDeque8Test", |
541 |
+ |
"LinkedBlockingQueue8Test", |
542 |
|
"LongAccumulatorTest", |
543 |
|
"LongAdderTest", |
544 |
|
"SplittableRandomTest", |
561 |
|
"AtomicReference9Test", |
562 |
|
"AtomicReferenceArray9Test", |
563 |
|
"ExecutorCompletionService9Test", |
564 |
+ |
"ForkJoinPool9Test", |
565 |
|
}; |
566 |
|
addNamedTestClasses(suite, java9TestClassNames); |
567 |
|
} |
572 |
|
/** Returns list of junit-style test method names in given class. */ |
573 |
|
public static ArrayList<String> testMethodNames(Class<?> testClass) { |
574 |
|
Method[] methods = testClass.getDeclaredMethods(); |
575 |
< |
ArrayList<String> names = new ArrayList<String>(methods.length); |
575 |
> |
ArrayList<String> names = new ArrayList<>(methods.length); |
576 |
|
for (Method method : methods) { |
577 |
|
if (method.getName().startsWith("test") |
578 |
|
&& Modifier.isPublic(method.getModifiers()) |
678 |
|
* The first exception encountered if any threadAssertXXX method fails. |
679 |
|
*/ |
680 |
|
private final AtomicReference<Throwable> threadFailure |
681 |
< |
= new AtomicReference<Throwable>(null); |
681 |
> |
= new AtomicReference<>(null); |
682 |
|
|
683 |
|
/** |
684 |
|
* Records an exception so that it can be rethrown later in the test |
1240 |
|
} |
1241 |
|
public void refresh() {} |
1242 |
|
public String toString() { |
1243 |
< |
List<Permission> ps = new ArrayList<Permission>(); |
1243 |
> |
List<Permission> ps = new ArrayList<>(); |
1244 |
|
for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();) |
1245 |
|
ps.add(e.nextElement()); |
1246 |
|
return "AdjustablePolicy with permissions " + ps; |
1853 |
|
} |
1854 |
|
} |
1855 |
|
|
1856 |
+ |
void assertImmutable(final Object o) { |
1857 |
+ |
if (o instanceof Collection) { |
1858 |
+ |
assertThrows( |
1859 |
+ |
UnsupportedOperationException.class, |
1860 |
+ |
new Runnable() { public void run() { |
1861 |
+ |
((Collection) o).add(null);}}); |
1862 |
+ |
} |
1863 |
+ |
} |
1864 |
+ |
|
1865 |
|
@SuppressWarnings("unchecked") |
1866 |
|
<T> T serialClone(T o) { |
1867 |
|
try { |
1868 |
|
ObjectInputStream ois = new ObjectInputStream |
1869 |
|
(new ByteArrayInputStream(serialBytes(o))); |
1870 |
|
T clone = (T) ois.readObject(); |
1871 |
+ |
if (o == clone) assertImmutable(o); |
1872 |
|
assertSame(o.getClass(), clone.getClass()); |
1873 |
|
return clone; |
1874 |
|
} catch (Throwable fail) { |
1877 |
|
} |
1878 |
|
} |
1879 |
|
|
1880 |
+ |
/** |
1881 |
+ |
* A version of serialClone that leaves error handling (for |
1882 |
+ |
* e.g. NotSerializableException) up to the caller. |
1883 |
+ |
*/ |
1884 |
+ |
@SuppressWarnings("unchecked") |
1885 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1886 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1887 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1888 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1889 |
+ |
oos.writeObject(o); |
1890 |
+ |
oos.flush(); |
1891 |
+ |
oos.close(); |
1892 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1893 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1894 |
+ |
T clone = (T) ois.readObject(); |
1895 |
+ |
if (o == clone) assertImmutable(o); |
1896 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1897 |
+ |
return clone; |
1898 |
+ |
} |
1899 |
+ |
|
1900 |
+ |
/** |
1901 |
+ |
* If o implements Cloneable and has a public clone method, |
1902 |
+ |
* returns a clone of o, else null. |
1903 |
+ |
*/ |
1904 |
+ |
@SuppressWarnings("unchecked") |
1905 |
+ |
<T> T cloneableClone(T o) { |
1906 |
+ |
if (!(o instanceof Cloneable)) return null; |
1907 |
+ |
final T clone; |
1908 |
+ |
try { |
1909 |
+ |
clone = (T) o.getClass().getMethod("clone").invoke(o); |
1910 |
+ |
} catch (NoSuchMethodException ok) { |
1911 |
+ |
return null; |
1912 |
+ |
} catch (ReflectiveOperationException unexpected) { |
1913 |
+ |
throw new Error(unexpected); |
1914 |
+ |
} |
1915 |
+ |
assertNotSame(o, clone); // not 100% guaranteed by spec |
1916 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1917 |
+ |
return clone; |
1918 |
+ |
} |
1919 |
+ |
|
1920 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1921 |
|
Runnable... throwingActions) { |
1922 |
|
for (Runnable throwingAction : throwingActions) { |