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.203 by jsr166, Thu Sep 15 03:46:19 2016 UTC vs.
Revision 1.219 by jsr166, Sat Feb 18 16:37:49 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.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;
# Line 41 | Line 63 | import java.security.ProtectionDomain;
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;
# Line 447 | Line 470 | public class JSR166TestCase extends Test
470              AbstractQueuedLongSynchronizerTest.suite(),
471              ArrayBlockingQueueTest.suite(),
472              ArrayDequeTest.suite(),
473 +            ArrayListTest.suite(),
474              AtomicBooleanTest.suite(),
475              AtomicIntegerArrayTest.suite(),
476              AtomicIntegerFieldUpdaterTest.suite(),
# Line 469 | Line 493 | public class JSR166TestCase extends Test
493              CopyOnWriteArrayListTest.suite(),
494              CopyOnWriteArraySetTest.suite(),
495              CountDownLatchTest.suite(),
496 +            CountedCompleterTest.suite(),
497              CyclicBarrierTest.suite(),
498              DelayQueueTest.suite(),
499              EntryTest.suite(),
# Line 497 | Line 522 | public class JSR166TestCase extends Test
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",
# Line 532 | Line 561 | public class JSR166TestCase extends Test
561                  "AtomicReference9Test",
562                  "AtomicReferenceArray9Test",
563                  "ExecutorCompletionService9Test",
564 +                "ForkJoinPool9Test",
565              };
566              addNamedTestClasses(suite, java9TestClassNames);
567          }
# Line 542 | Line 572 | public class JSR166TestCase extends Test
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())
# Line 648 | Line 678 | public class JSR166TestCase extends Test
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
# Line 1210 | Line 1240 | public class JSR166TestCase extends 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;
# Line 1269 | Line 1299 | public class JSR166TestCase extends Test
1299                  startTime = System.nanoTime();
1300              else if (millisElapsedSince(startTime) > timeoutMillis) {
1301                  threadAssertTrue(thread.isAlive());
1302 <                return;
1302 >                fail("timed out waiting for thread to enter wait state");
1303 >            }
1304 >            Thread.yield();
1305 >        }
1306 >    }
1307 >
1308 >    /**
1309 >     * Spin-waits up to the specified number of milliseconds for the given
1310 >     * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1311 >     * and additionally satisfy the given condition.
1312 >     */
1313 >    void waitForThreadToEnterWaitState(
1314 >        Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) {
1315 >        long startTime = 0L;
1316 >        for (;;) {
1317 >            Thread.State s = thread.getState();
1318 >            if (s == Thread.State.BLOCKED ||
1319 >                s == Thread.State.WAITING ||
1320 >                s == Thread.State.TIMED_WAITING) {
1321 >                try {
1322 >                    if (waitingForGodot.call())
1323 >                        return;
1324 >                } catch (Throwable fail) { threadUnexpectedException(fail); }
1325 >            }
1326 >            else if (s == Thread.State.TERMINATED)
1327 >                fail("Unexpected thread termination");
1328 >            else if (startTime == 0L)
1329 >                startTime = System.nanoTime();
1330 >            else if (millisElapsedSince(startTime) > timeoutMillis) {
1331 >                threadAssertTrue(thread.isAlive());
1332 >                fail("timed out waiting for thread to enter wait state");
1333              }
1334              Thread.yield();
1335          }
1336      }
1337  
1338      /**
1339 <     * Waits up to LONG_DELAY_MS for the given thread to enter a wait
1340 <     * state: BLOCKED, WAITING, or TIMED_WAITING.
1339 >     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1340 >     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1341       */
1342      void waitForThreadToEnterWaitState(Thread thread) {
1343          waitForThreadToEnterWaitState(thread, LONG_DELAY_MS);
1344      }
1345  
1346      /**
1347 +     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1348 +     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1349 +     * and additionally satisfy the given condition.
1350 +     */
1351 +    void waitForThreadToEnterWaitState(
1352 +        Thread thread, Callable<Boolean> waitingForGodot) {
1353 +        waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot);
1354 +    }
1355 +
1356 +    /**
1357       * Returns the number of milliseconds since time given by
1358       * startNanoTime, which must have been previously returned from a
1359       * call to {@link System#nanoTime()}.
# Line 1823 | Line 1893 | public class JSR166TestCase extends Test
1893          }
1894      }
1895  
1896 +    void assertImmutable(final Object o) {
1897 +        if (o instanceof Collection) {
1898 +            assertThrows(
1899 +                UnsupportedOperationException.class,
1900 +                new Runnable() { public void run() {
1901 +                        ((Collection) o).add(null);}});
1902 +        }
1903 +    }
1904 +
1905      @SuppressWarnings("unchecked")
1906      <T> T serialClone(T o) {
1907          try {
1908              ObjectInputStream ois = new ObjectInputStream
1909                  (new ByteArrayInputStream(serialBytes(o)));
1910              T clone = (T) ois.readObject();
1911 +            if (o == clone) assertImmutable(o);
1912              assertSame(o.getClass(), clone.getClass());
1913              return clone;
1914          } catch (Throwable fail) {
# Line 1837 | Line 1917 | public class JSR166TestCase extends Test
1917          }
1918      }
1919  
1920 +    /**
1921 +     * A version of serialClone that leaves error handling (for
1922 +     * e.g. NotSerializableException) up to the caller.
1923 +     */
1924 +    @SuppressWarnings("unchecked")
1925 +    <T> T serialClonePossiblyFailing(T o)
1926 +        throws ReflectiveOperationException, java.io.IOException {
1927 +        ByteArrayOutputStream bos = new ByteArrayOutputStream();
1928 +        ObjectOutputStream oos = new ObjectOutputStream(bos);
1929 +        oos.writeObject(o);
1930 +        oos.flush();
1931 +        oos.close();
1932 +        ObjectInputStream ois = new ObjectInputStream
1933 +            (new ByteArrayInputStream(bos.toByteArray()));
1934 +        T clone = (T) ois.readObject();
1935 +        if (o == clone) assertImmutable(o);
1936 +        assertSame(o.getClass(), clone.getClass());
1937 +        return clone;
1938 +    }
1939 +
1940 +    /**
1941 +     * If o implements Cloneable and has a public clone method,
1942 +     * returns a clone of o, else null.
1943 +     */
1944 +    @SuppressWarnings("unchecked")
1945 +    <T> T cloneableClone(T o) {
1946 +        if (!(o instanceof Cloneable)) return null;
1947 +        final T clone;
1948 +        try {
1949 +            clone = (T) o.getClass().getMethod("clone").invoke(o);
1950 +        } catch (NoSuchMethodException ok) {
1951 +            return null;
1952 +        } catch (ReflectiveOperationException unexpected) {
1953 +            throw new Error(unexpected);
1954 +        }
1955 +        assertNotSame(o, clone); // not 100% guaranteed by spec
1956 +        assertSame(o.getClass(), clone.getClass());
1957 +        return clone;
1958 +    }
1959 +
1960      public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
1961                               Runnable... throwingActions) {
1962          for (Runnable throwingAction : throwingActions) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines