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.189 by jsr166, Fri Mar 4 21:00:45 2016 UTC vs.
Revision 1.199 by jsr166, Sat Aug 6 16:24:05 2016 UTC

# Line 12 | Line 12
12   * @modules java.management
13   * @build *
14   * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
15 + * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase
16 + * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase
17   */
18  
19   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 58 | Line 60 | import java.util.concurrent.RecursiveAct
60   import java.util.concurrent.RecursiveTask;
61   import java.util.concurrent.RejectedExecutionHandler;
62   import java.util.concurrent.Semaphore;
63 + import java.util.concurrent.SynchronousQueue;
64   import java.util.concurrent.ThreadFactory;
65   import java.util.concurrent.ThreadPoolExecutor;
66   import java.util.concurrent.TimeoutException;
# Line 511 | Line 514 | public class JSR166TestCase extends Test
514                  "StampedLockTest",
515                  "SubmissionPublisherTest",
516                  "ThreadLocalRandom8Test",
517 +                "TimeUnit8Test",
518              };
519              addNamedTestClasses(suite, java8TestClassNames);
520          }
# Line 518 | Line 522 | public class JSR166TestCase extends Test
522          // Java9+ test classes
523          if (atLeastJava9()) {
524              String[] java9TestClassNames = {
525 <                // Currently empty, but expecting varhandle tests
525 >                "AtomicBoolean9Test",
526 >                "AtomicInteger9Test",
527 >                "AtomicIntegerArray9Test",
528 >                "AtomicLong9Test",
529 >                "AtomicLongArray9Test",
530 >                "AtomicReference9Test",
531 >                "AtomicReferenceArray9Test",
532 >                "ExecutorCompletionService9Test",
533              };
534              addNamedTestClasses(suite, java9TestClassNames);
535          }
# Line 945 | Line 956 | public class JSR166TestCase extends Test
956          }
957      }
958  
959 <    /** Like Runnable, but with the freedom to throw anything */
959 >    /**
960 >     * Like Runnable, but with the freedom to throw anything.
961 >     * junit folks had the same idea:
962 >     * http://junit.org/junit5/docs/snapshot/api/org/junit/gen5/api/Executable.html
963 >     */
964      interface Action { public void run() throws Throwable; }
965  
966      /**
# Line 976 | Line 991 | public class JSR166TestCase extends Test
991       * Uninteresting threads are filtered out.
992       */
993      static void dumpTestThreads() {
994 +        SecurityManager sm = System.getSecurityManager();
995 +        if (sm != null) {
996 +            try {
997 +                System.setSecurityManager(null);
998 +            } catch (SecurityException giveUp) {
999 +                return;
1000 +            }
1001 +        }
1002 +
1003          ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
1004          System.err.println("------ stacktrace dump start ------");
1005          for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
# Line 993 | Line 1017 | public class JSR166TestCase extends Test
1017              System.err.print(info);
1018          }
1019          System.err.println("------ stacktrace dump end ------");
1020 +
1021 +        if (sm != null) System.setSecurityManager(sm);
1022      }
1023  
1024      /**
# Line 1225 | Line 1251 | public class JSR166TestCase extends Test
1251       * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1252       */
1253      void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
1254 <        long startTime = System.nanoTime();
1254 >        long startTime = 0L;
1255          for (;;) {
1256              Thread.State s = thread.getState();
1257              if (s == Thread.State.BLOCKED ||
# Line 1234 | Line 1260 | public class JSR166TestCase extends Test
1260                  return;
1261              else if (s == Thread.State.TERMINATED)
1262                  fail("Unexpected thread termination");
1263 +            else if (startTime == 0L)
1264 +                startTime = System.nanoTime();
1265              else if (millisElapsedSince(startTime) > timeoutMillis) {
1266                  threadAssertTrue(thread.isAlive());
1267                  return;
# Line 1832 | Line 1860 | public class JSR166TestCase extends Test
1860          } catch (NoSuchElementException success) {}
1861          assertFalse(it.hasNext());
1862      }
1863 +
1864 +    public <T> Callable<T> callableThrowing(final Exception ex) {
1865 +        return new Callable<T>() { public T call() throws Exception { throw ex; }};
1866 +    }
1867 +
1868 +    public Runnable runnableThrowing(final RuntimeException ex) {
1869 +        return new Runnable() { public void run() { throw ex; }};
1870 +    }
1871 +
1872 +    /** A reusable thread pool to be shared by tests. */
1873 +    static final ExecutorService cachedThreadPool =
1874 +        new ThreadPoolExecutor(0, Integer.MAX_VALUE,
1875 +                               1000L, MILLISECONDS,
1876 +                               new SynchronousQueue<Runnable>());
1877 +
1878   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines