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.139 by jsr166, Sun Sep 6 21:14:12 2015 UTC vs.
Revision 1.145 by jsr166, Fri Sep 25 05:41:29 2015 UTC

# Line 67 | Line 67 | import junit.framework.TestSuite;
67   *
68   * <ol>
69   *
70 < * <li> All assertions in code running in generated threads must use
70 > * <li>All assertions in code running in generated threads must use
71   * the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link
72   * #threadAssertEquals}, or {@link #threadAssertNull}, (not
73   * {@code fail}, {@code assertTrue}, etc.) It is OK (but not
74   * particularly recommended) for other code to use these forms too.
75   * Only the most typically used JUnit assertion methods are defined
76 < * this way, but enough to live with.</li>
76 > * this way, but enough to live with.
77   *
78 < * <li> If you override {@link #setUp} or {@link #tearDown}, make sure
78 > * <li>If you override {@link #setUp} or {@link #tearDown}, make sure
79   * to invoke {@code super.setUp} and {@code super.tearDown} within
80   * them. These methods are used to clear and check for thread
81 < * assertion failures.</li>
81 > * assertion failures.
82   *
83   * <li>All delays and timeouts must use one of the constants {@code
84   * SHORT_DELAY_MS}, {@code SMALL_DELAY_MS}, {@code MEDIUM_DELAY_MS},
# Line 89 | Line 89 | import junit.framework.TestSuite;
89   * is always discriminable as larger than SHORT and smaller than
90   * MEDIUM.  And so on. These constants are set to conservative values,
91   * but even so, if there is ever any doubt, they can all be increased
92 < * in one spot to rerun tests on slower platforms.</li>
92 > * in one spot to rerun tests on slower platforms.
93   *
94 < * <li> All threads generated must be joined inside each test case
94 > * <li>All threads generated must be joined inside each test case
95   * method (or {@code fail} to do so) before returning from the
96   * method. The {@code joinPool} method can be used to do this when
97 < * using Executors.</li>
97 > * using Executors.
98   *
99   * </ol>
100   *
101   * <p><b>Other notes</b>
102   * <ul>
103   *
104 < * <li> Usually, there is one testcase method per JSR166 method
104 > * <li>Usually, there is one testcase method per JSR166 method
105   * covering "normal" operation, and then as many exception-testing
106   * methods as there are exceptions the method can throw. Sometimes
107   * there are multiple tests per JSR166 method when the different
108   * "normal" behaviors differ significantly. And sometimes testcases
109   * cover multiple methods when they cannot be tested in
110 < * isolation.</li>
110 > * isolation.
111   *
112 < * <li> The documentation style for testcases is to provide as javadoc
112 > * <li>The documentation style for testcases is to provide as javadoc
113   * a simple sentence or two describing the property that the testcase
114   * method purports to test. The javadocs do not say anything about how
115 < * the property is tested. To find out, read the code.</li>
115 > * the property is tested. To find out, read the code.
116   *
117 < * <li> These tests are "conformance tests", and do not attempt to
117 > * <li>These tests are "conformance tests", and do not attempt to
118   * test throughput, latency, scalability or other performance factors
119   * (see the separate "jtreg" tests for a set intended to check these
120   * for the most central aspects of functionality.) So, most tests use
121   * the smallest sensible numbers of threads, collection sizes, etc
122 < * needed to check basic conformance.</li>
122 > * needed to check basic conformance.
123   *
124   * <li>The test classes currently do not declare inclusion in
125   * any particular package to simplify things for people integrating
126 < * them in TCK test suites.</li>
126 > * them in TCK test suites.
127   *
128 < * <li> As a convenience, the {@code main} of this class (JSR166TestCase)
129 < * runs all JSR166 unit tests.</li>
128 > * <li>As a convenience, the {@code main} of this class (JSR166TestCase)
129 > * runs all JSR166 unit tests.
130   *
131   * </ul>
132   */
# Line 198 | Line 198 | public class JSR166TestCase extends Test
198      }
199  
200      protected void runTestProfiled() throws Throwable {
201 <        // Warmup run, notably to trigger all needed classloading.
202 <        super.runTest();
203 <        long t0 = System.nanoTime();
204 <        try {
201 >        for (int i = 0; i < 2; i++) {
202 >            long startTime = System.nanoTime();
203              super.runTest();
204 <        } finally {
205 <            long elapsedMillis = millisElapsedSince(t0);
206 <            if (elapsedMillis >= profileThreshold)
204 >            long elapsedMillis = millisElapsedSince(startTime);
205 >            if (elapsedMillis < profileThreshold)
206 >                break;
207 >            // Never report first run of any test; treat it as a
208 >            // warmup run, notably to trigger all needed classloading,
209 >            if (i > 0)
210                  System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
211          }
212      }
# Line 379 | Line 380 | public class JSR166TestCase extends Test
380                  "LongAdderTest",
381                  "SplittableRandomTest",
382                  "StampedLockTest",
383 +                "SubmissionPublisherTest",
384                  "ThreadLocalRandom8Test",
385              };
386              addNamedTestClasses(suite, java8TestClassNames);
# Line 387 | Line 389 | public class JSR166TestCase extends Test
389          // Java9+ test classes
390          if (atLeastJava9()) {
391              String[] java9TestClassNames = {
392 <                // Currently empty
392 >                // Currently empty, but expecting varhandle tests
393              };
394              addNamedTestClasses(suite, java9TestClassNames);
395          }
# Line 743 | Line 745 | public class JSR166TestCase extends Test
745      }
746  
747      /** Like Runnable, but with the freedom to throw anything */
748 <    interface Thunk { public void run() throws Throwable; }
748 >    interface Action { public void run() throws Throwable; }
749  
750      /**
751 <     * Runs all the given tasks in parallel, failing if any fail.
751 >     * Runs all the given actions in parallel, failing if any fail.
752       * Useful for running multiple variants of tests that are
753       * necessarily individually slow because they must block.
754       */
755 <    void testInParallel(Thunk ... thunks) {
755 >    void testInParallel(Action ... actions) {
756          ExecutorService pool = Executors.newCachedThreadPool();
757          try {
758 <            ArrayList<Future<?>> futures = new ArrayList<>(thunks.length);
759 <            for (final Thunk thunk : thunks)
758 >            ArrayList<Future<?>> futures = new ArrayList<>(actions.length);
759 >            for (final Action action : actions)
760                  futures.add(pool.submit(new CheckedRunnable() {
761 <                    public void realRun() throws Throwable { thunk.run();}}));
761 >                    public void realRun() throws Throwable { action.run();}}));
762              for (Future<?> future : futures)
763                  try {
764                      assertNull(future.get(LONG_DELAY_MS, MILLISECONDS));
# Line 1222 | Line 1224 | public class JSR166TestCase extends Test
1224      public static final String TEST_STRING = "a test string";
1225  
1226      public static class StringTask implements Callable<String> {
1227 <        public String call() { return TEST_STRING; }
1227 >        final String value;
1228 >        public StringTask() { this(TEST_STRING); }
1229 >        public StringTask(String value) { this.value = value; }
1230 >        public String call() { return value; }
1231      }
1232  
1233      public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines