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.114 by jsr166, Tue Sep 17 06:38:36 2013 UTC vs.
Revision 1.122 by jsr166, Wed Dec 31 16:44:02 2014 UTC

# Line 22 | Line 22 | import java.util.List;
22   import java.util.NoSuchElementException;
23   import java.util.PropertyPermission;
24   import java.util.concurrent.*;
25 import java.util.concurrent.atomic.AtomicBoolean;
25   import java.util.concurrent.atomic.AtomicReference;
26   import static java.util.concurrent.TimeUnit.MILLISECONDS;
27   import static java.util.concurrent.TimeUnit.NANOSECONDS;
# Line 116 | Line 115 | public class JSR166TestCase extends Test
115          Boolean.getBoolean("jsr166.expensiveTests");
116  
117      /**
118 +     * If true, also run tests that are not part of the official tck
119 +     * because they test unspecified implementation details.
120 +     */
121 +    protected static final boolean testImplementationDetails =
122 +        Boolean.getBoolean("jsr166.testImplementationDetails");
123 +
124 +    /**
125       * If true, report on stdout all "slow" tests, that is, ones that
126       * take more than profileThreshold milliseconds to execute.
127       */
# Line 160 | Line 166 | public class JSR166TestCase extends Test
166      }
167  
168      protected void runTestProfiled() throws Throwable {
169 +        // Warmup run, notably to trigger all needed classloading.
170 +        super.runTest();
171          long t0 = System.nanoTime();
172          try {
173              super.runTest();
174          } finally {
175 <            long elapsedMillis =
168 <                (System.nanoTime() - t0) / (1000L * 1000L);
175 >            long elapsedMillis = millisElapsedSince(t0);
176              if (elapsedMillis >= profileThreshold)
177                  System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
178          }
# Line 221 | Line 228 | public class JSR166TestCase extends Test
228      }
229  
230      public static final double JAVA_CLASS_VERSION;
231 +    public static final String JAVA_SPECIFICATION_VERSION;
232      static {
233          try {
234              JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged(
235                  new java.security.PrivilegedAction<Double>() {
236                  public Double run() {
237                      return Double.valueOf(System.getProperty("java.class.version"));}});
238 +            JAVA_SPECIFICATION_VERSION = java.security.AccessController.doPrivileged(
239 +                new java.security.PrivilegedAction<String>() {
240 +                public String run() {
241 +                    return System.getProperty("java.specification.version");}});
242          } catch (Throwable t) {
243              throw new Error(t);
244          }
# Line 235 | Line 247 | public class JSR166TestCase extends Test
247      public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; }
248      public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; }
249      public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; }
250 +    public static boolean atLeastJava9() {
251 +        // As of 2014-05, java9 still uses 52.0 class file version
252 +        return JAVA_SPECIFICATION_VERSION.startsWith("1.9");
253 +    }
254  
255      /**
256       * Collects all JSR166 unit tests as one suite.
# Line 327 | Line 343 | public class JSR166TestCase extends Test
343              addNamedTestClasses(suite, java8TestClassNames);
344          }
345  
346 +        // Java9+ test classes
347 +        if (atLeastJava9()) {
348 +            String[] java9TestClassNames = {
349 +                "ThreadPoolExecutor9Test",
350 +            };
351 +            addNamedTestClasses(suite, java9TestClassNames);
352 +        }
353 +
354          return suite;
355      }
356  
# Line 605 | Line 629 | public class JSR166TestCase extends Test
629      void joinPool(ExecutorService exec) {
630          try {
631              exec.shutdown();
632 <            assertTrue("ExecutorService did not terminate in a timely manner",
633 <                       exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS));
632 >            if (!exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS))
633 >                fail("ExecutorService " + exec +
634 >                     " did not terminate in a timely manner");
635          } catch (SecurityException ok) {
636              // Allowed in case test doesn't have privs
637          } catch (InterruptedException ie) {
# Line 884 | Line 909 | public class JSR166TestCase extends Test
909       * startNanoTime, which must have been previously returned from a
910       * call to {@link System.nanoTime()}.
911       */
912 <    long millisElapsedSince(long startNanoTime) {
912 >    static long millisElapsedSince(long startNanoTime) {
913          return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime);
914      }
915  
916 + //     void assertTerminatesPromptly(long timeoutMillis, Runnable r) {
917 + //         long startTime = System.nanoTime();
918 + //         try {
919 + //             r.run();
920 + //         } catch (Throwable fail) { threadUnexpectedException(fail); }
921 + //         if (millisElapsedSince(startTime) > timeoutMillis/2)
922 + //             throw new AssertionFailedError("did not return promptly");
923 + //     }
924 +
925 + //     void assertTerminatesPromptly(Runnable r) {
926 + //         assertTerminatesPromptly(LONG_DELAY_MS/2, r);
927 + //     }
928 +
929 +    /**
930 +     * Checks that timed f.get() returns the expected value, and does not
931 +     * wait for the timeout to elapse before returning.
932 +     */
933 +    <T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) {
934 +        long startTime = System.nanoTime();
935 +        try {
936 +            assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
937 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
938 +        if (millisElapsedSince(startTime) > timeoutMillis/2)
939 +            throw new AssertionFailedError("timed get did not return promptly");
940 +    }
941 +
942 +    <T> void checkTimedGet(Future<T> f, T expectedValue) {
943 +        checkTimedGet(f, expectedValue, LONG_DELAY_MS);
944 +    }
945 +
946      /**
947       * Returns a new started daemon Thread running the given runnable.
948       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines