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.management |
23 |
> |
* @run junit/othervm/timeout=1000 |
24 |
> |
* -Djsr166.testImplementationDetails=true |
25 |
> |
* JSR166TestCase |
26 |
> |
* @run junit/othervm/timeout=1000 |
27 |
> |
* -Djsr166.testImplementationDetails=true |
28 |
> |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 |
29 |
> |
* JSR166TestCase |
30 |
> |
* @run junit/othervm/timeout=1000 |
31 |
> |
* -Djsr166.testImplementationDetails=true |
32 |
> |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 |
33 |
> |
* -Djava.util.secureRandomSeed=true |
34 |
> |
* JSR166TestCase |
35 |
> |
* @run junit/othervm/timeout=1000/policy=tck.policy |
36 |
> |
* -Djsr166.testImplementationDetails=true |
37 |
> |
* JSR166TestCase |
38 |
|
*/ |
39 |
|
|
40 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
62 |
|
import java.security.SecurityPermission; |
63 |
|
import java.util.ArrayList; |
64 |
|
import java.util.Arrays; |
65 |
+ |
import java.util.Collection; |
66 |
|
import java.util.Collections; |
67 |
|
import java.util.Date; |
68 |
|
import java.util.Enumeration; |
469 |
|
AbstractQueuedLongSynchronizerTest.suite(), |
470 |
|
ArrayBlockingQueueTest.suite(), |
471 |
|
ArrayDequeTest.suite(), |
472 |
+ |
ArrayListTest.suite(), |
473 |
|
AtomicBooleanTest.suite(), |
474 |
|
AtomicIntegerArrayTest.suite(), |
475 |
|
AtomicIntegerFieldUpdaterTest.suite(), |
492 |
|
CopyOnWriteArrayListTest.suite(), |
493 |
|
CopyOnWriteArraySetTest.suite(), |
494 |
|
CountDownLatchTest.suite(), |
495 |
+ |
CountedCompleterTest.suite(), |
496 |
|
CyclicBarrierTest.suite(), |
497 |
|
DelayQueueTest.suite(), |
498 |
|
EntryTest.suite(), |
521 |
|
TreeMapTest.suite(), |
522 |
|
TreeSetTest.suite(), |
523 |
|
TreeSubMapTest.suite(), |
524 |
< |
TreeSubSetTest.suite()); |
524 |
> |
TreeSubSetTest.suite(), |
525 |
> |
VectorTest.suite()); |
526 |
|
|
527 |
|
// Java8+ test classes |
528 |
|
if (atLeastJava8()) { |
529 |
|
String[] java8TestClassNames = { |
530 |
+ |
"ArrayDeque8Test", |
531 |
|
"Atomic8Test", |
532 |
|
"CompletableFutureTest", |
533 |
|
"ConcurrentHashMap8Test", |
534 |
< |
"CountedCompleterTest", |
534 |
> |
"CountedCompleter8Test", |
535 |
|
"DoubleAccumulatorTest", |
536 |
|
"DoubleAdderTest", |
537 |
|
"ForkJoinPool8Test", |
538 |
|
"ForkJoinTask8Test", |
539 |
+ |
"LinkedBlockingDeque8Test", |
540 |
+ |
"LinkedBlockingQueue8Test", |
541 |
|
"LongAccumulatorTest", |
542 |
|
"LongAdderTest", |
543 |
|
"SplittableRandomTest", |
570 |
|
/** Returns list of junit-style test method names in given class. */ |
571 |
|
public static ArrayList<String> testMethodNames(Class<?> testClass) { |
572 |
|
Method[] methods = testClass.getDeclaredMethods(); |
573 |
< |
ArrayList<String> names = new ArrayList<String>(methods.length); |
573 |
> |
ArrayList<String> names = new ArrayList<>(methods.length); |
574 |
|
for (Method method : methods) { |
575 |
|
if (method.getName().startsWith("test") |
576 |
|
&& Modifier.isPublic(method.getModifiers()) |
676 |
|
* The first exception encountered if any threadAssertXXX method fails. |
677 |
|
*/ |
678 |
|
private final AtomicReference<Throwable> threadFailure |
679 |
< |
= new AtomicReference<Throwable>(null); |
679 |
> |
= new AtomicReference<>(null); |
680 |
|
|
681 |
|
/** |
682 |
|
* Records an exception so that it can be rethrown later in the test |
1033 |
|
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
1034 |
|
System.err.println("------ stacktrace dump start ------"); |
1035 |
|
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |
1036 |
< |
String name = info.getThreadName(); |
1036 |
> |
final String name = info.getThreadName(); |
1037 |
> |
String lockName; |
1038 |
|
if ("Signal Dispatcher".equals(name)) |
1039 |
|
continue; |
1040 |
|
if ("Reference Handler".equals(name) |
1041 |
< |
&& info.getLockName().startsWith("java.lang.ref.Reference$Lock")) |
1041 |
> |
&& (lockName = info.getLockName()) != null |
1042 |
> |
&& lockName.startsWith("java.lang.ref.Reference$Lock")) |
1043 |
|
continue; |
1044 |
|
if ("Finalizer".equals(name) |
1045 |
< |
&& info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) |
1045 |
> |
&& (lockName = info.getLockName()) != null |
1046 |
> |
&& lockName.startsWith("java.lang.ref.ReferenceQueue$Lock")) |
1047 |
|
continue; |
1048 |
|
if ("checkForWedgedTest".equals(name)) |
1049 |
|
continue; |
1238 |
|
} |
1239 |
|
public void refresh() {} |
1240 |
|
public String toString() { |
1241 |
< |
List<Permission> ps = new ArrayList<Permission>(); |
1241 |
> |
List<Permission> ps = new ArrayList<>(); |
1242 |
|
for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();) |
1243 |
|
ps.add(e.nextElement()); |
1244 |
|
return "AdjustablePolicy with permissions " + ps; |
1268 |
|
* Sleeps until the given time has elapsed. |
1269 |
|
* Throws AssertionFailedError if interrupted. |
1270 |
|
*/ |
1271 |
< |
void sleep(long millis) { |
1271 |
> |
static void sleep(long millis) { |
1272 |
|
try { |
1273 |
|
delay(millis); |
1274 |
|
} catch (InterruptedException fail) { |
1787 |
|
* A CyclicBarrier that uses timed await and fails with |
1788 |
|
* AssertionFailedErrors instead of throwing checked exceptions. |
1789 |
|
*/ |
1790 |
< |
public class CheckedBarrier extends CyclicBarrier { |
1790 |
> |
public static class CheckedBarrier extends CyclicBarrier { |
1791 |
|
public CheckedBarrier(int parties) { super(parties); } |
1792 |
|
|
1793 |
|
public int await() { |
1851 |
|
} |
1852 |
|
} |
1853 |
|
|
1854 |
+ |
void assertImmutable(final Object o) { |
1855 |
+ |
if (o instanceof Collection) { |
1856 |
+ |
assertThrows( |
1857 |
+ |
UnsupportedOperationException.class, |
1858 |
+ |
new Runnable() { public void run() { |
1859 |
+ |
((Collection) o).add(null);}}); |
1860 |
+ |
} |
1861 |
+ |
} |
1862 |
+ |
|
1863 |
|
@SuppressWarnings("unchecked") |
1864 |
|
<T> T serialClone(T o) { |
1865 |
|
try { |
1866 |
|
ObjectInputStream ois = new ObjectInputStream |
1867 |
|
(new ByteArrayInputStream(serialBytes(o))); |
1868 |
|
T clone = (T) ois.readObject(); |
1869 |
+ |
if (o == clone) assertImmutable(o); |
1870 |
|
assertSame(o.getClass(), clone.getClass()); |
1871 |
|
return clone; |
1872 |
|
} catch (Throwable fail) { |
1875 |
|
} |
1876 |
|
} |
1877 |
|
|
1878 |
+ |
/** |
1879 |
+ |
* A version of serialClone that leaves error handling (for |
1880 |
+ |
* e.g. NotSerializableException) up to the caller. |
1881 |
+ |
*/ |
1882 |
+ |
@SuppressWarnings("unchecked") |
1883 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1884 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1885 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1886 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1887 |
+ |
oos.writeObject(o); |
1888 |
+ |
oos.flush(); |
1889 |
+ |
oos.close(); |
1890 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1891 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1892 |
+ |
T clone = (T) ois.readObject(); |
1893 |
+ |
if (o == clone) assertImmutable(o); |
1894 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1895 |
+ |
return clone; |
1896 |
+ |
} |
1897 |
+ |
|
1898 |
+ |
/** |
1899 |
+ |
* If o implements Cloneable and has a public clone method, |
1900 |
+ |
* returns a clone of o, else null. |
1901 |
+ |
*/ |
1902 |
+ |
@SuppressWarnings("unchecked") |
1903 |
+ |
<T> T cloneableClone(T o) { |
1904 |
+ |
if (!(o instanceof Cloneable)) return null; |
1905 |
+ |
final T clone; |
1906 |
+ |
try { |
1907 |
+ |
clone = (T) o.getClass().getMethod("clone").invoke(o); |
1908 |
+ |
} catch (NoSuchMethodException ok) { |
1909 |
+ |
return null; |
1910 |
+ |
} catch (ReflectiveOperationException unexpected) { |
1911 |
+ |
throw new Error(unexpected); |
1912 |
+ |
} |
1913 |
+ |
assertNotSame(o, clone); // not 100% guaranteed by spec |
1914 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1915 |
+ |
return clone; |
1916 |
+ |
} |
1917 |
+ |
|
1918 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1919 |
|
Runnable... throwingActions) { |
1920 |
|
for (Runnable throwingAction : throwingActions) { |