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.116 by jsr166, Sun Jun 8 00:15:50 2014 UTC vs.
Revision 1.125 by jsr166, Thu Jan 15 18:58:07 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
9 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 > import static java.util.concurrent.TimeUnit.NANOSECONDS;
11 >
12   import java.io.ByteArrayInputStream;
13   import java.io.ByteArrayOutputStream;
14   import java.io.ObjectInputStream;
# Line 14 | Line 16 | import java.io.ObjectOutputStream;
16   import java.lang.management.ManagementFactory;
17   import java.lang.management.ThreadInfo;
18   import java.lang.reflect.Method;
19 + import java.security.CodeSource;
20 + import java.security.Permission;
21 + import java.security.PermissionCollection;
22 + import java.security.Permissions;
23 + import java.security.Policy;
24 + import java.security.ProtectionDomain;
25 + import java.security.SecurityPermission;
26   import java.util.ArrayList;
27   import java.util.Arrays;
28   import java.util.Date;
# Line 21 | Line 30 | import java.util.Enumeration;
30   import java.util.List;
31   import java.util.NoSuchElementException;
32   import java.util.PropertyPermission;
33 < import java.util.concurrent.*;
34 < import java.util.concurrent.atomic.AtomicBoolean;
33 > import java.util.concurrent.BlockingQueue;
34 > import java.util.concurrent.Callable;
35 > import java.util.concurrent.CountDownLatch;
36 > import java.util.concurrent.CyclicBarrier;
37 > import java.util.concurrent.ExecutorService;
38 > import java.util.concurrent.Future;
39 > import java.util.concurrent.RecursiveAction;
40 > import java.util.concurrent.RecursiveTask;
41 > import java.util.concurrent.RejectedExecutionHandler;
42 > import java.util.concurrent.Semaphore;
43 > import java.util.concurrent.ThreadFactory;
44 > import java.util.concurrent.ThreadPoolExecutor;
45 > import java.util.concurrent.TimeoutException;
46   import java.util.concurrent.atomic.AtomicReference;
27 import static java.util.concurrent.TimeUnit.MILLISECONDS;
28 import static java.util.concurrent.TimeUnit.NANOSECONDS;
47   import java.util.regex.Pattern;
48 < import java.security.CodeSource;
49 < import java.security.Permission;
50 < import java.security.PermissionCollection;
51 < import java.security.Permissions;
52 < import java.security.Policy;
35 < import java.security.ProtectionDomain;
36 < import java.security.SecurityPermission;
48 >
49 > import junit.framework.AssertionFailedError;
50 > import junit.framework.Test;
51 > import junit.framework.TestCase;
52 > import junit.framework.TestSuite;
53  
54   /**
55   * Base class for JSR166 Junit TCK tests.  Defines some constants,
# Line 116 | Line 132 | public class JSR166TestCase extends Test
132          Boolean.getBoolean("jsr166.expensiveTests");
133  
134      /**
135 +     * If true, also run tests that are not part of the official tck
136 +     * because they test unspecified implementation details.
137 +     */
138 +    protected static final boolean testImplementationDetails =
139 +        Boolean.getBoolean("jsr166.testImplementationDetails");
140 +
141 +    /**
142       * If true, report on stdout all "slow" tests, that is, ones that
143       * take more than profileThreshold milliseconds to execute.
144       */
# Line 442 | Line 465 | public class JSR166TestCase extends Test
465      }
466  
467      /**
468 <     * Find missing try { ... } finally { joinPool(e); }
468 >     * Finds missing try { ... } finally { joinPool(e); }
469       */
470      void checkForkJoinPoolThreadLeaks() throws InterruptedException {
471          Thread[] survivors = new Thread[5];
# Line 623 | Line 646 | public class JSR166TestCase extends Test
646      void joinPool(ExecutorService exec) {
647          try {
648              exec.shutdown();
649 <            assertTrue("ExecutorService did not terminate in a timely manner",
650 <                       exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS));
649 >            if (!exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS))
650 >                fail("ExecutorService " + exec +
651 >                     " did not terminate in a timely manner");
652          } catch (SecurityException ok) {
653              // Allowed in case test doesn't have privs
654          } catch (InterruptedException ie) {
# Line 900 | Line 924 | public class JSR166TestCase extends Test
924      /**
925       * Returns the number of milliseconds since time given by
926       * startNanoTime, which must have been previously returned from a
927 <     * call to {@link System.nanoTime()}.
927 >     * call to {@link System#nanoTime()}.
928       */
929 <    long millisElapsedSince(long startNanoTime) {
929 >    static long millisElapsedSince(long startNanoTime) {
930          return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime);
931      }
932  
933 + //     void assertTerminatesPromptly(long timeoutMillis, Runnable r) {
934 + //         long startTime = System.nanoTime();
935 + //         try {
936 + //             r.run();
937 + //         } catch (Throwable fail) { threadUnexpectedException(fail); }
938 + //         if (millisElapsedSince(startTime) > timeoutMillis/2)
939 + //             throw new AssertionFailedError("did not return promptly");
940 + //     }
941 +
942 + //     void assertTerminatesPromptly(Runnable r) {
943 + //         assertTerminatesPromptly(LONG_DELAY_MS/2, r);
944 + //     }
945 +
946 +    /**
947 +     * Checks that timed f.get() returns the expected value, and does not
948 +     * wait for the timeout to elapse before returning.
949 +     */
950 +    <T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) {
951 +        long startTime = System.nanoTime();
952 +        try {
953 +            assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
954 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
955 +        if (millisElapsedSince(startTime) > timeoutMillis/2)
956 +            throw new AssertionFailedError("timed get did not return promptly");
957 +    }
958 +
959 +    <T> void checkTimedGet(Future<T> f, T expectedValue) {
960 +        checkTimedGet(f, expectedValue, LONG_DELAY_MS);
961 +    }
962 +
963      /**
964       * Returns a new started daemon Thread running the given runnable.
965       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines