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 |
|
*/ |
36 |
|
|
37 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
59 |
|
import java.security.SecurityPermission; |
60 |
|
import java.util.ArrayList; |
61 |
|
import java.util.Arrays; |
62 |
+ |
import java.util.Collection; |
63 |
|
import java.util.Collections; |
64 |
|
import java.util.Date; |
65 |
|
import java.util.Enumeration; |
1846 |
|
} |
1847 |
|
} |
1848 |
|
|
1849 |
+ |
void assertImmutable(final Object o) { |
1850 |
+ |
if (o instanceof Collection) { |
1851 |
+ |
assertThrows( |
1852 |
+ |
UnsupportedOperationException.class, |
1853 |
+ |
new Runnable() { public void run() { |
1854 |
+ |
((Collection) o).add(null);}}); |
1855 |
+ |
} |
1856 |
+ |
} |
1857 |
+ |
|
1858 |
|
@SuppressWarnings("unchecked") |
1859 |
|
<T> T serialClone(T o) { |
1860 |
|
try { |
1861 |
|
ObjectInputStream ois = new ObjectInputStream |
1862 |
|
(new ByteArrayInputStream(serialBytes(o))); |
1863 |
|
T clone = (T) ois.readObject(); |
1864 |
+ |
if (o == clone) assertImmutable(o); |
1865 |
|
assertSame(o.getClass(), clone.getClass()); |
1866 |
|
return clone; |
1867 |
|
} catch (Throwable fail) { |
1870 |
|
} |
1871 |
|
} |
1872 |
|
|
1873 |
+ |
/** |
1874 |
+ |
* A version of serialClone that leaves error handling (for |
1875 |
+ |
* e.g. NotSerializableException) up to the caller. |
1876 |
+ |
*/ |
1877 |
+ |
@SuppressWarnings("unchecked") |
1878 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1879 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1880 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1881 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1882 |
+ |
oos.writeObject(o); |
1883 |
+ |
oos.flush(); |
1884 |
+ |
oos.close(); |
1885 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1886 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1887 |
+ |
T clone = (T) ois.readObject(); |
1888 |
+ |
if (o == clone) assertImmutable(o); |
1889 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1890 |
+ |
return clone; |
1891 |
+ |
} |
1892 |
+ |
|
1893 |
+ |
/** |
1894 |
+ |
* If o implements Cloneable and has a public clone method, |
1895 |
+ |
* returns a clone of o, else null. |
1896 |
+ |
*/ |
1897 |
+ |
@SuppressWarnings("unchecked") |
1898 |
+ |
<T> T cloneableClone(T o) { |
1899 |
+ |
if (!(o instanceof Cloneable)) return null; |
1900 |
+ |
final T clone; |
1901 |
+ |
try { |
1902 |
+ |
clone = (T) o.getClass().getMethod("clone").invoke(o); |
1903 |
+ |
} catch (NoSuchMethodException ok) { |
1904 |
+ |
return null; |
1905 |
+ |
} catch (ReflectiveOperationException unexpected) { |
1906 |
+ |
throw new Error(unexpected); |
1907 |
+ |
} |
1908 |
+ |
assertNotSame(o, clone); // not 100% guaranteed by spec |
1909 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1910 |
+ |
return clone; |
1911 |
+ |
} |
1912 |
+ |
|
1913 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1914 |
|
Runnable... throwingActions) { |
1915 |
|
for (Runnable throwingAction : throwingActions) { |