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.209 by jsr166, Sun Nov 6 05:00:55 2016 UTC vs.
Revision 1.221 by jsr166, Tue Mar 14 00:54:27 2017 UTC

# Line 1 | Line 1
1   /*
2 < * Written by Doug Lea with assistance from members of JCP JSR-166
3 < * Expert Group and released to the public domain, as explained at
2 > * Written by Doug Lea and Martin Buchholz with assistance from
3 > * members of JCP JSR-166 Expert Group and released to the public
4 > * domain, as explained at
5   * http://creativecommons.org/publicdomain/zero/1.0/
6   * Other contributors include Andrew Wright, Jeffrey Hayes,
7   * Pat Fisher, Mike Judd.
# Line 8 | Line 9
9  
10   /*
11   * @test
12 < * @summary JSR-166 tck tests
13 < * @modules java.management
12 > * @summary JSR-166 tck tests, in a number of variations.
13 > *          The first is the conformance testing variant,
14 > *          while others also test implementation details.
15   * @build *
16 < * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
17 < * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase
18 < * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase
16 > * @modules java.management
17 > * @run junit/othervm/timeout=1000 JSR166TestCase
18 > * @run junit/othervm/timeout=1000
19 > *      --add-opens java.base/java.util.concurrent=ALL-UNNAMED
20 > *      --add-opens java.base/java.lang=ALL-UNNAMED
21 > *      -Djsr166.testImplementationDetails=true
22 > *      JSR166TestCase
23 > * @run junit/othervm/timeout=1000
24 > *      --add-opens java.base/java.util.concurrent=ALL-UNNAMED
25 > *      --add-opens java.base/java.lang=ALL-UNNAMED
26 > *      -Djsr166.testImplementationDetails=true
27 > *      -Djava.util.concurrent.ForkJoinPool.common.parallelism=0
28 > *      JSR166TestCase
29 > * @run junit/othervm/timeout=1000
30 > *      --add-opens java.base/java.util.concurrent=ALL-UNNAMED
31 > *      --add-opens java.base/java.lang=ALL-UNNAMED
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 > *      --add-opens java.base/java.util.concurrent=ALL-UNNAMED
38 > *      --add-opens java.base/java.lang=ALL-UNNAMED
39 > *      -Djsr166.testImplementationDetails=true
40 > *      JSR166TestCase
41   */
42  
43   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 30 | Line 54 | import java.lang.management.ThreadMXBean
54   import java.lang.reflect.Constructor;
55   import java.lang.reflect.Method;
56   import java.lang.reflect.Modifier;
33 import java.nio.file.Files;
34 import java.nio.file.Paths;
57   import java.security.CodeSource;
58   import java.security.Permission;
59   import java.security.PermissionCollection;
# Line 69 | Line 91 | import java.util.concurrent.ThreadPoolEx
91   import java.util.concurrent.TimeoutException;
92   import java.util.concurrent.atomic.AtomicBoolean;
93   import java.util.concurrent.atomic.AtomicReference;
72 import java.util.regex.Matcher;
94   import java.util.regex.Pattern;
95  
96   import junit.framework.AssertionFailedError;
# Line 279 | Line 300 | public class JSR166TestCase extends Test
300  
301   //     public static String cpuModel() {
302   //         try {
303 < //             Matcher matcher = Pattern.compile("model name\\s*: (.*)")
303 > //             java.util.regex.Matcher matcher
304 > //               = Pattern.compile("model name\\s*: (.*)")
305   //                 .matcher(new String(
306 < //                      Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
306 > //                     java.nio.file.Files.readAllBytes(
307 > //                         java.nio.file.Paths.get("/proc/cpuinfo")), "UTF-8"));
308   //             matcher.find();
309   //             return matcher.group(1);
310   //         } catch (Exception ex) { return null; }
# Line 515 | Line 538 | public class JSR166TestCase extends Test
538                  "DoubleAdderTest",
539                  "ForkJoinPool8Test",
540                  "ForkJoinTask8Test",
541 +                "LinkedBlockingDeque8Test",
542 +                "LinkedBlockingQueue8Test",
543                  "LongAccumulatorTest",
544                  "LongAdderTest",
545                  "SplittableRandomTest",
# Line 537 | Line 562 | public class JSR166TestCase extends Test
562                  "AtomicReference9Test",
563                  "AtomicReferenceArray9Test",
564                  "ExecutorCompletionService9Test",
565 +                "ForkJoinPool9Test",
566              };
567              addNamedTestClasses(suite, java9TestClassNames);
568          }
# Line 547 | Line 573 | public class JSR166TestCase extends Test
573      /** Returns list of junit-style test method names in given class. */
574      public static ArrayList<String> testMethodNames(Class<?> testClass) {
575          Method[] methods = testClass.getDeclaredMethods();
576 <        ArrayList<String> names = new ArrayList<String>(methods.length);
576 >        ArrayList<String> names = new ArrayList<>(methods.length);
577          for (Method method : methods) {
578              if (method.getName().startsWith("test")
579                  && Modifier.isPublic(method.getModifiers())
# Line 653 | Line 679 | public class JSR166TestCase extends Test
679       * The first exception encountered if any threadAssertXXX method fails.
680       */
681      private final AtomicReference<Throwable> threadFailure
682 <        = new AtomicReference<Throwable>(null);
682 >        = new AtomicReference<>(null);
683  
684      /**
685       * Records an exception so that it can be rethrown later in the test
# Line 1215 | Line 1241 | public class JSR166TestCase extends Test
1241          }
1242          public void refresh() {}
1243          public String toString() {
1244 <            List<Permission> ps = new ArrayList<Permission>();
1244 >            List<Permission> ps = new ArrayList<>();
1245              for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();)
1246                  ps.add(e.nextElement());
1247              return "AdjustablePolicy with permissions " + ps;
# Line 1274 | Line 1300 | public class JSR166TestCase extends Test
1300                  startTime = System.nanoTime();
1301              else if (millisElapsedSince(startTime) > timeoutMillis) {
1302                  threadAssertTrue(thread.isAlive());
1303 <                return;
1303 >                fail("timed out waiting for thread to enter wait state");
1304 >            }
1305 >            Thread.yield();
1306 >        }
1307 >    }
1308 >
1309 >    /**
1310 >     * Spin-waits up to the specified number of milliseconds for the given
1311 >     * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1312 >     * and additionally satisfy the given condition.
1313 >     */
1314 >    void waitForThreadToEnterWaitState(
1315 >        Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) {
1316 >        long startTime = 0L;
1317 >        for (;;) {
1318 >            Thread.State s = thread.getState();
1319 >            if (s == Thread.State.BLOCKED ||
1320 >                s == Thread.State.WAITING ||
1321 >                s == Thread.State.TIMED_WAITING) {
1322 >                try {
1323 >                    if (waitingForGodot.call())
1324 >                        return;
1325 >                } catch (Throwable fail) { threadUnexpectedException(fail); }
1326 >            }
1327 >            else if (s == Thread.State.TERMINATED)
1328 >                fail("Unexpected thread termination");
1329 >            else if (startTime == 0L)
1330 >                startTime = System.nanoTime();
1331 >            else if (millisElapsedSince(startTime) > timeoutMillis) {
1332 >                threadAssertTrue(thread.isAlive());
1333 >                fail("timed out waiting for thread to enter wait state");
1334              }
1335              Thread.yield();
1336          }
1337      }
1338  
1339      /**
1340 <     * Waits up to LONG_DELAY_MS for the given thread to enter a wait
1341 <     * state: BLOCKED, WAITING, or TIMED_WAITING.
1340 >     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1341 >     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1342       */
1343      void waitForThreadToEnterWaitState(Thread thread) {
1344          waitForThreadToEnterWaitState(thread, LONG_DELAY_MS);
1345      }
1346  
1347      /**
1348 +     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1349 +     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1350 +     * and additionally satisfy the given condition.
1351 +     */
1352 +    void waitForThreadToEnterWaitState(
1353 +        Thread thread, Callable<Boolean> waitingForGodot) {
1354 +        waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot);
1355 +    }
1356 +
1357 +    /**
1358       * Returns the number of milliseconds since time given by
1359       * startNanoTime, which must have been previously returned from a
1360       * call to {@link System#nanoTime()}.
# Line 1828 | Line 1894 | public class JSR166TestCase extends Test
1894          }
1895      }
1896  
1897 <    void assertImmutable(Object o) {
1897 >    void assertImmutable(final Object o) {
1898          if (o instanceof Collection) {
1899              assertThrows(
1900                  UnsupportedOperationException.class,
# Line 1853 | Line 1919 | public class JSR166TestCase extends Test
1919      }
1920  
1921      /**
1922 +     * A version of serialClone that leaves error handling (for
1923 +     * e.g. NotSerializableException) up to the caller.
1924 +     */
1925 +    @SuppressWarnings("unchecked")
1926 +    <T> T serialClonePossiblyFailing(T o)
1927 +        throws ReflectiveOperationException, java.io.IOException {
1928 +        ByteArrayOutputStream bos = new ByteArrayOutputStream();
1929 +        ObjectOutputStream oos = new ObjectOutputStream(bos);
1930 +        oos.writeObject(o);
1931 +        oos.flush();
1932 +        oos.close();
1933 +        ObjectInputStream ois = new ObjectInputStream
1934 +            (new ByteArrayInputStream(bos.toByteArray()));
1935 +        T clone = (T) ois.readObject();
1936 +        if (o == clone) assertImmutable(o);
1937 +        assertSame(o.getClass(), clone.getClass());
1938 +        return clone;
1939 +    }
1940 +
1941 +    /**
1942       * If o implements Cloneable and has a public clone method,
1943       * returns a clone of o, else null.
1944       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines