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.197 by jsr166, Wed Jun 22 14:40:36 2016 UTC vs.
Revision 1.213 by jsr166, Fri Dec 9 06:58:57 2016 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 + * @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
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;
# Line 40 | Line 49 | import java.security.ProtectionDomain;
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;
56   import java.util.Iterator;
# Line 61 | Line 72 | import java.util.concurrent.RejectedExec
72   import java.util.concurrent.Semaphore;
73   import java.util.concurrent.SynchronousQueue;
74   import java.util.concurrent.ThreadFactory;
75 + import java.util.concurrent.ThreadLocalRandom;
76   import java.util.concurrent.ThreadPoolExecutor;
77   import java.util.concurrent.TimeoutException;
78   import java.util.concurrent.atomic.AtomicBoolean;
# Line 444 | Line 456 | public class JSR166TestCase extends Test
456              AbstractQueuedLongSynchronizerTest.suite(),
457              ArrayBlockingQueueTest.suite(),
458              ArrayDequeTest.suite(),
459 +            ArrayListTest.suite(),
460              AtomicBooleanTest.suite(),
461              AtomicIntegerArrayTest.suite(),
462              AtomicIntegerFieldUpdaterTest.suite(),
# Line 466 | Line 479 | public class JSR166TestCase extends Test
479              CopyOnWriteArrayListTest.suite(),
480              CopyOnWriteArraySetTest.suite(),
481              CountDownLatchTest.suite(),
482 +            CountedCompleterTest.suite(),
483              CyclicBarrierTest.suite(),
484              DelayQueueTest.suite(),
485              EntryTest.suite(),
# Line 494 | Line 508 | public class JSR166TestCase extends Test
508              TreeMapTest.suite(),
509              TreeSetTest.suite(),
510              TreeSubMapTest.suite(),
511 <            TreeSubSetTest.suite());
511 >            TreeSubSetTest.suite(),
512 >            VectorTest.suite());
513  
514          // Java8+ test classes
515          if (atLeastJava8()) {
516              String[] java8TestClassNames = {
517 +                "ArrayDeque8Test",
518                  "Atomic8Test",
519                  "CompletableFutureTest",
520                  "ConcurrentHashMap8Test",
521 <                "CountedCompleterTest",
521 >                "CountedCompleter8Test",
522                  "DoubleAccumulatorTest",
523                  "DoubleAdderTest",
524                  "ForkJoinPool8Test",
# Line 1002 | Line 1018 | public class JSR166TestCase extends Test
1018          ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
1019          System.err.println("------ stacktrace dump start ------");
1020          for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
1021 <            String name = info.getThreadName();
1021 >            final String name = info.getThreadName();
1022 >            String lockName;
1023              if ("Signal Dispatcher".equals(name))
1024                  continue;
1025              if ("Reference Handler".equals(name)
1026 <                && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
1026 >                && (lockName = info.getLockName()) != null
1027 >                && lockName.startsWith("java.lang.ref.Reference$Lock"))
1028                  continue;
1029              if ("Finalizer".equals(name)
1030 <                && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
1030 >                && (lockName = info.getLockName()) != null
1031 >                && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
1032                  continue;
1033              if ("checkForWedgedTest".equals(name))
1034                  continue;
# Line 1234 | Line 1253 | public class JSR166TestCase extends Test
1253       * Sleeps until the given time has elapsed.
1254       * Throws AssertionFailedError if interrupted.
1255       */
1256 <    void sleep(long millis) {
1256 >    static void sleep(long millis) {
1257          try {
1258              delay(millis);
1259          } catch (InterruptedException fail) {
# Line 1250 | Line 1269 | public class JSR166TestCase extends Test
1269       * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1270       */
1271      void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
1272 <        long startTime = System.nanoTime();
1272 >        long startTime = 0L;
1273          for (;;) {
1274              Thread.State s = thread.getState();
1275              if (s == Thread.State.BLOCKED ||
# Line 1259 | Line 1278 | public class JSR166TestCase extends Test
1278                  return;
1279              else if (s == Thread.State.TERMINATED)
1280                  fail("Unexpected thread termination");
1281 +            else if (startTime == 0L)
1282 +                startTime = System.nanoTime();
1283              else if (millisElapsedSince(startTime) > timeoutMillis) {
1284                  threadAssertTrue(thread.isAlive());
1285                  return;
# Line 1751 | Line 1772 | public class JSR166TestCase extends Test
1772       * A CyclicBarrier that uses timed await and fails with
1773       * AssertionFailedErrors instead of throwing checked exceptions.
1774       */
1775 <    public class CheckedBarrier extends CyclicBarrier {
1775 >    public static class CheckedBarrier extends CyclicBarrier {
1776          public CheckedBarrier(int parties) { super(parties); }
1777  
1778          public int await() {
# Line 1815 | Line 1836 | public class JSR166TestCase extends Test
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) {
# Line 1829 | Line 1860 | public class JSR166TestCase extends Test
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) {
# Line 1872 | Line 1943 | public class JSR166TestCase extends Test
1943                                 1000L, MILLISECONDS,
1944                                 new SynchronousQueue<Runnable>());
1945  
1946 +    static <T> void shuffle(T[] array) {
1947 +        Collections.shuffle(Arrays.asList(array), ThreadLocalRandom.current());
1948 +    }
1949   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines