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 |
+ |
* @modules java.base/java.util.concurrent:open |
22 |
+ |
* java.management |
23 |
|
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
24 |
< |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase |
16 |
< |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase |
24 |
> |
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 JSR166TestCase |
25 |
|
*/ |
26 |
|
|
27 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
49 |
|
import java.security.SecurityPermission; |
50 |
|
import java.util.ArrayList; |
51 |
|
import java.util.Arrays; |
52 |
+ |
import java.util.Collection; |
53 |
|
import java.util.Collections; |
54 |
|
import java.util.Date; |
55 |
|
import java.util.Enumeration; |
1836 |
|
} |
1837 |
|
} |
1838 |
|
|
1839 |
+ |
void assertImmutable(final Object o) { |
1840 |
+ |
if (o instanceof Collection) { |
1841 |
+ |
assertThrows( |
1842 |
+ |
UnsupportedOperationException.class, |
1843 |
+ |
new Runnable() { public void run() { |
1844 |
+ |
((Collection) o).add(null);}}); |
1845 |
+ |
} |
1846 |
+ |
} |
1847 |
+ |
|
1848 |
|
@SuppressWarnings("unchecked") |
1849 |
|
<T> T serialClone(T o) { |
1850 |
|
try { |
1851 |
|
ObjectInputStream ois = new ObjectInputStream |
1852 |
|
(new ByteArrayInputStream(serialBytes(o))); |
1853 |
|
T clone = (T) ois.readObject(); |
1854 |
+ |
if (o == clone) assertImmutable(o); |
1855 |
|
assertSame(o.getClass(), clone.getClass()); |
1856 |
|
return clone; |
1857 |
|
} catch (Throwable fail) { |
1860 |
|
} |
1861 |
|
} |
1862 |
|
|
1863 |
+ |
/** |
1864 |
+ |
* A version of serialClone that leaves error handling (for |
1865 |
+ |
* e.g. NotSerializableException) up to the caller. |
1866 |
+ |
*/ |
1867 |
+ |
@SuppressWarnings("unchecked") |
1868 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1869 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1870 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1871 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1872 |
+ |
oos.writeObject(o); |
1873 |
+ |
oos.flush(); |
1874 |
+ |
oos.close(); |
1875 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1876 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1877 |
+ |
T clone = (T) ois.readObject(); |
1878 |
+ |
if (o == clone) assertImmutable(o); |
1879 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1880 |
+ |
return clone; |
1881 |
+ |
} |
1882 |
+ |
|
1883 |
+ |
/** |
1884 |
+ |
* If o implements Cloneable and has a public clone method, |
1885 |
+ |
* returns a clone of o, else null. |
1886 |
+ |
*/ |
1887 |
+ |
@SuppressWarnings("unchecked") |
1888 |
+ |
<T> T cloneableClone(T o) { |
1889 |
+ |
if (!(o instanceof Cloneable)) return null; |
1890 |
+ |
final T clone; |
1891 |
+ |
try { |
1892 |
+ |
clone = (T) o.getClass().getMethod("clone").invoke(o); |
1893 |
+ |
} catch (NoSuchMethodException ok) { |
1894 |
+ |
return null; |
1895 |
+ |
} catch (ReflectiveOperationException unexpected) { |
1896 |
+ |
throw new Error(unexpected); |
1897 |
+ |
} |
1898 |
+ |
assertNotSame(o, clone); // not 100% guaranteed by spec |
1899 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1900 |
+ |
return clone; |
1901 |
+ |
} |
1902 |
+ |
|
1903 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1904 |
|
Runnable... throwingActions) { |
1905 |
|
for (Runnable throwingAction : throwingActions) { |