ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.205 by jsr166, Mon Oct 17 17:52:30 2016 UTC vs.
Revision 1.217 by jsr166, Tue Jan 24 22:57:02 2017 UTC

# Line 8 | Line 8
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;
# Line 41 | Line 62 | import java.security.ProtectionDomain;
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;
# Line 499 | Line 521 | public class JSR166TestCase extends Test
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",
# Line 512 | Line 536 | public class JSR166TestCase extends Test
536                  "DoubleAdderTest",
537                  "ForkJoinPool8Test",
538                  "ForkJoinTask8Test",
539 +                "LinkedBlockingDeque8Test",
540 +                "LinkedBlockingQueue8Test",
541                  "LongAccumulatorTest",
542                  "LongAdderTest",
543                  "SplittableRandomTest",
# Line 544 | Line 570 | public class JSR166TestCase extends Test
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())
# Line 650 | Line 676 | public class JSR166TestCase extends Test
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
# Line 1212 | Line 1238 | public class JSR166TestCase extends Test
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;
# Line 1825 | Line 1851 | public class JSR166TestCase extends Test
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) {
# Line 1839 | Line 1875 | public class JSR166TestCase extends Test
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) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines