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.195 by jsr166, Sat Jun 4 23:49:29 2016 UTC vs.
Revision 1.212 by jsr166, Fri Dec 9 04:24:07 2016 UTC

# Line 9 | Line 9
9   /*
10   * @test
11   * @summary JSR-166 tck tests
12 < * @modules java.management
12 > * @modules java.base/java.util.concurrent:open
13 > *          java.management
14   * @build *
15   * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
16   * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase
17 + * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase
18   */
19  
20   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 40 | Line 42 | import java.security.ProtectionDomain;
42   import java.security.SecurityPermission;
43   import java.util.ArrayList;
44   import java.util.Arrays;
45 + import java.util.Collection;
46 + import java.util.Collections;
47   import java.util.Date;
48   import java.util.Enumeration;
49   import java.util.Iterator;
# Line 61 | Line 65 | import java.util.concurrent.RejectedExec
65   import java.util.concurrent.Semaphore;
66   import java.util.concurrent.SynchronousQueue;
67   import java.util.concurrent.ThreadFactory;
68 + import java.util.concurrent.ThreadLocalRandom;
69   import java.util.concurrent.ThreadPoolExecutor;
70   import java.util.concurrent.TimeoutException;
71   import java.util.concurrent.atomic.AtomicBoolean;
# Line 444 | Line 449 | public class JSR166TestCase extends Test
449              AbstractQueuedLongSynchronizerTest.suite(),
450              ArrayBlockingQueueTest.suite(),
451              ArrayDequeTest.suite(),
452 +            ArrayListTest.suite(),
453              AtomicBooleanTest.suite(),
454              AtomicIntegerArrayTest.suite(),
455              AtomicIntegerFieldUpdaterTest.suite(),
# Line 466 | Line 472 | public class JSR166TestCase extends Test
472              CopyOnWriteArrayListTest.suite(),
473              CopyOnWriteArraySetTest.suite(),
474              CountDownLatchTest.suite(),
475 +            CountedCompleterTest.suite(),
476              CyclicBarrierTest.suite(),
477              DelayQueueTest.suite(),
478              EntryTest.suite(),
# Line 494 | Line 501 | public class JSR166TestCase extends Test
501              TreeMapTest.suite(),
502              TreeSetTest.suite(),
503              TreeSubMapTest.suite(),
504 <            TreeSubSetTest.suite());
504 >            TreeSubSetTest.suite(),
505 >            VectorTest.suite());
506  
507          // Java8+ test classes
508          if (atLeastJava8()) {
509              String[] java8TestClassNames = {
510 +                "ArrayDeque8Test",
511                  "Atomic8Test",
512                  "CompletableFutureTest",
513                  "ConcurrentHashMap8Test",
514 <                "CountedCompleterTest",
514 >                "CountedCompleter8Test",
515                  "DoubleAccumulatorTest",
516                  "DoubleAdderTest",
517                  "ForkJoinPool8Test",
# Line 521 | Line 530 | public class JSR166TestCase extends Test
530          // Java9+ test classes
531          if (atLeastJava9()) {
532              String[] java9TestClassNames = {
533 +                "AtomicBoolean9Test",
534 +                "AtomicInteger9Test",
535 +                "AtomicIntegerArray9Test",
536 +                "AtomicLong9Test",
537 +                "AtomicLongArray9Test",
538 +                "AtomicReference9Test",
539 +                "AtomicReferenceArray9Test",
540                  "ExecutorCompletionService9Test",
541              };
542              addNamedTestClasses(suite, java9TestClassNames);
# Line 948 | Line 964 | public class JSR166TestCase extends Test
964          }
965      }
966  
967 <    /** Like Runnable, but with the freedom to throw anything */
967 >    /**
968 >     * Like Runnable, but with the freedom to throw anything.
969 >     * junit folks had the same idea:
970 >     * http://junit.org/junit5/docs/snapshot/api/org/junit/gen5/api/Executable.html
971 >     */
972      interface Action { public void run() throws Throwable; }
973  
974      /**
# Line 991 | Line 1011 | public class JSR166TestCase extends Test
1011          ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
1012          System.err.println("------ stacktrace dump start ------");
1013          for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
1014 <            String name = info.getThreadName();
1014 >            final String name = info.getThreadName();
1015 >            String lockName;
1016              if ("Signal Dispatcher".equals(name))
1017                  continue;
1018              if ("Reference Handler".equals(name)
1019 <                && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
1019 >                && (lockName = info.getLockName()) != null
1020 >                && lockName.startsWith("java.lang.ref.Reference$Lock"))
1021                  continue;
1022              if ("Finalizer".equals(name)
1023 <                && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
1023 >                && (lockName = info.getLockName()) != null
1024 >                && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
1025                  continue;
1026              if ("checkForWedgedTest".equals(name))
1027                  continue;
# Line 1223 | Line 1246 | public class JSR166TestCase extends Test
1246       * Sleeps until the given time has elapsed.
1247       * Throws AssertionFailedError if interrupted.
1248       */
1249 <    void sleep(long millis) {
1249 >    static void sleep(long millis) {
1250          try {
1251              delay(millis);
1252          } catch (InterruptedException fail) {
# Line 1239 | Line 1262 | public class JSR166TestCase extends Test
1262       * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1263       */
1264      void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
1265 <        long startTime = System.nanoTime();
1265 >        long startTime = 0L;
1266          for (;;) {
1267              Thread.State s = thread.getState();
1268              if (s == Thread.State.BLOCKED ||
# Line 1248 | Line 1271 | public class JSR166TestCase extends Test
1271                  return;
1272              else if (s == Thread.State.TERMINATED)
1273                  fail("Unexpected thread termination");
1274 +            else if (startTime == 0L)
1275 +                startTime = System.nanoTime();
1276              else if (millisElapsedSince(startTime) > timeoutMillis) {
1277                  threadAssertTrue(thread.isAlive());
1278                  return;
# Line 1740 | Line 1765 | public class JSR166TestCase extends Test
1765       * A CyclicBarrier that uses timed await and fails with
1766       * AssertionFailedErrors instead of throwing checked exceptions.
1767       */
1768 <    public class CheckedBarrier extends CyclicBarrier {
1768 >    public static class CheckedBarrier extends CyclicBarrier {
1769          public CheckedBarrier(int parties) { super(parties); }
1770  
1771          public int await() {
# Line 1804 | Line 1829 | public class JSR166TestCase extends Test
1829          }
1830      }
1831  
1832 +    void assertImmutable(final Object o) {
1833 +        if (o instanceof Collection) {
1834 +            assertThrows(
1835 +                UnsupportedOperationException.class,
1836 +                new Runnable() { public void run() {
1837 +                        ((Collection) o).add(null);}});
1838 +        }
1839 +    }
1840 +
1841      @SuppressWarnings("unchecked")
1842      <T> T serialClone(T o) {
1843          try {
1844              ObjectInputStream ois = new ObjectInputStream
1845                  (new ByteArrayInputStream(serialBytes(o)));
1846              T clone = (T) ois.readObject();
1847 +            if (o == clone) assertImmutable(o);
1848              assertSame(o.getClass(), clone.getClass());
1849              return clone;
1850          } catch (Throwable fail) {
# Line 1818 | Line 1853 | public class JSR166TestCase extends Test
1853          }
1854      }
1855  
1856 +    /**
1857 +     * A version of serialClone that leaves error handling (for
1858 +     * e.g. NotSerializableException) up to the caller.
1859 +     */
1860 +    @SuppressWarnings("unchecked")
1861 +    <T> T serialClonePossiblyFailing(T o)
1862 +        throws ReflectiveOperationException, java.io.IOException {
1863 +        ByteArrayOutputStream bos = new ByteArrayOutputStream();
1864 +        ObjectOutputStream oos = new ObjectOutputStream(bos);
1865 +        oos.writeObject(o);
1866 +        oos.flush();
1867 +        oos.close();
1868 +        ObjectInputStream ois = new ObjectInputStream
1869 +            (new ByteArrayInputStream(bos.toByteArray()));
1870 +        T clone = (T) ois.readObject();
1871 +        if (o == clone) assertImmutable(o);
1872 +        assertSame(o.getClass(), clone.getClass());
1873 +        return clone;
1874 +    }
1875 +
1876 +    /**
1877 +     * If o implements Cloneable and has a public clone method,
1878 +     * returns a clone of o, else null.
1879 +     */
1880 +    @SuppressWarnings("unchecked")
1881 +    <T> T cloneableClone(T o) {
1882 +        if (!(o instanceof Cloneable)) return null;
1883 +        final T clone;
1884 +        try {
1885 +            clone = (T) o.getClass().getMethod("clone").invoke(o);
1886 +        } catch (NoSuchMethodException ok) {
1887 +            return null;
1888 +        } catch (ReflectiveOperationException unexpected) {
1889 +            throw new Error(unexpected);
1890 +        }
1891 +        assertNotSame(o, clone); // not 100% guaranteed by spec
1892 +        assertSame(o.getClass(), clone.getClass());
1893 +        return clone;
1894 +    }
1895 +
1896      public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
1897                               Runnable... throwingActions) {
1898          for (Runnable throwingAction : throwingActions) {
# Line 1861 | Line 1936 | public class JSR166TestCase extends Test
1936                                 1000L, MILLISECONDS,
1937                                 new SynchronousQueue<Runnable>());
1938  
1939 +    static <T> void shuffle(T[] array) {
1940 +        Collections.shuffle(Arrays.asList(array), ThreadLocalRandom.current());
1941 +    }
1942   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines