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.126 by jsr166, Sat Jan 17 22:55:06 2015 UTC vs.
Revision 1.133 by jsr166, Sun May 24 01:53:55 2015 UTC

# Line 50 | Line 50 | import java.util.regex.Pattern;
50   import junit.framework.AssertionFailedError;
51   import junit.framework.Test;
52   import junit.framework.TestCase;
53 + import junit.framework.TestResult;
54   import junit.framework.TestSuite;
55  
56   /**
# Line 160 | Line 161 | public class JSR166TestCase extends Test
161          Integer.getInteger("jsr166.runsPerTest", 1);
162  
163      /**
164 +     * The number of repetitions of the test suite (for finding leaks?).
165 +     */
166 +    private static final int suiteRuns =
167 +        Integer.getInteger("jsr166.suiteRuns", 1);
168 +
169 +    /**
170       * A filter for tests to run, matching strings of the form
171       * methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)"
172       * Usefully combined with jsr166.runsPerTest.
# Line 198 | Line 205 | public class JSR166TestCase extends Test
205  
206      /**
207       * Runs all JSR166 unit tests using junit.textui.TestRunner.
201     * Optional command line arg provides the number of iterations to
202     * repeat running the tests.
208       */
209      public static void main(String[] args) {
210 +        main(suite(), args);
211 +    }
212 +
213 +    /**
214 +     * Runs all unit tests in the given test suite.
215 +     * Actual behavior influenced by jsr166.* system properties.
216 +     */
217 +    static void main(Test suite, String[] args) {
218          if (useSecurityManager) {
219              System.err.println("Setting a permissive security manager");
220              Policy.setPolicy(permissivePolicy());
221              System.setSecurityManager(new SecurityManager());
222          }
223 <        int iters = (args.length == 0) ? 1 : Integer.parseInt(args[0]);
224 <
225 <        Test s = suite();
226 <        for (int i = 0; i < iters; ++i) {
214 <            junit.textui.TestRunner.run(s);
223 >        for (int i = 0; i < suiteRuns; i++) {
224 >            TestResult result = junit.textui.TestRunner.run(suite);
225 >            if (!result.wasSuccessful())
226 >                System.exit(1);
227              System.gc();
228              System.runFinalization();
229          }
218        System.exit(0);
230      }
231  
232      public static TestSuite newTestSuite(Object... suiteOrClasses) {
# Line 265 | Line 276 | public class JSR166TestCase extends Test
276      public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; }
277      public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; }
278      public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; }
279 <    public static boolean atLeastJava9() {
269 <        // As of 2014-05, java9 still uses 52.0 class file version
270 <        return JAVA_SPECIFICATION_VERSION.startsWith("1.9");
271 <    }
279 >    public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; }
280  
281      /**
282       * Collects all JSR166 unit tests as one suite.
# Line 478 | Line 486 | public class JSR166TestCase extends Test
486                  // give thread some time to terminate
487                  thread.join(LONG_DELAY_MS);
488                  if (!thread.isAlive()) continue;
481                thread.stop();
489                  throw new AssertionFailedError
490                      (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n",
491                                     toString(), name));
# Line 564 | Line 571 | public class JSR166TestCase extends Test
571      public void threadAssertEquals(Object x, Object y) {
572          try {
573              assertEquals(x, y);
574 <        } catch (AssertionFailedError t) {
575 <            threadRecordFailure(t);
576 <            throw t;
577 <        } catch (Throwable t) {
578 <            threadUnexpectedException(t);
574 >        } catch (AssertionFailedError fail) {
575 >            threadRecordFailure(fail);
576 >            throw fail;
577 >        } catch (Throwable fail) {
578 >            threadUnexpectedException(fail);
579          }
580      }
581  
# Line 580 | Line 587 | public class JSR166TestCase extends Test
587      public void threadAssertSame(Object x, Object y) {
588          try {
589              assertSame(x, y);
590 <        } catch (AssertionFailedError t) {
591 <            threadRecordFailure(t);
592 <            throw t;
590 >        } catch (AssertionFailedError fail) {
591 >            threadRecordFailure(fail);
592 >            throw fail;
593          }
594      }
595  
# Line 652 | Line 659 | public class JSR166TestCase extends Test
659                       " did not terminate in a timely manner");
660          } catch (SecurityException ok) {
661              // Allowed in case test doesn't have privs
662 <        } catch (InterruptedException ie) {
662 >        } catch (InterruptedException fail) {
663              fail("Unexpected InterruptedException");
664          }
665      }
# Line 683 | Line 690 | public class JSR166TestCase extends Test
690              // No need to optimize the failing case via Thread.join.
691              delay(millis);
692              assertTrue(thread.isAlive());
693 <        } catch (InterruptedException ie) {
693 >        } catch (InterruptedException fail) {
694              fail("Unexpected InterruptedException");
695          }
696      }
# Line 705 | Line 712 | public class JSR166TestCase extends Test
712              delay(millis);
713              for (Thread thread : threads)
714                  assertTrue(thread.isAlive());
715 <        } catch (InterruptedException ie) {
715 >        } catch (InterruptedException fail) {
716              fail("Unexpected InterruptedException");
717          }
718      }
# Line 727 | Line 734 | public class JSR166TestCase extends Test
734              future.get(timeoutMillis, MILLISECONDS);
735              shouldThrow();
736          } catch (TimeoutException success) {
737 <        } catch (Exception e) {
738 <            threadUnexpectedException(e);
737 >        } catch (Exception fail) {
738 >            threadUnexpectedException(fail);
739          } finally { future.cancel(true); }
740          assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
741      }
# Line 884 | Line 891 | public class JSR166TestCase extends Test
891      void sleep(long millis) {
892          try {
893              delay(millis);
894 <        } catch (InterruptedException ie) {
894 >        } catch (InterruptedException fail) {
895              AssertionFailedError afe =
896                  new AssertionFailedError("Unexpected InterruptedException");
897 <            afe.initCause(ie);
897 >            afe.initCause(fail);
898              throw afe;
899          }
900      }
# Line 979 | Line 986 | public class JSR166TestCase extends Test
986      void awaitTermination(Thread t, long timeoutMillis) {
987          try {
988              t.join(timeoutMillis);
989 <        } catch (InterruptedException ie) {
990 <            threadUnexpectedException(ie);
989 >        } catch (InterruptedException fail) {
990 >            threadUnexpectedException(fail);
991          } finally {
992              if (t.getState() != Thread.State.TERMINATED) {
993                  t.interrupt();
# Line 1006 | Line 1013 | public class JSR166TestCase extends Test
1013          public final void run() {
1014              try {
1015                  realRun();
1016 <            } catch (Throwable t) {
1017 <                threadUnexpectedException(t);
1016 >            } catch (Throwable fail) {
1017 >                threadUnexpectedException(fail);
1018              }
1019          }
1020      }
# Line 1061 | Line 1068 | public class JSR166TestCase extends Test
1068                  threadShouldThrow("InterruptedException");
1069              } catch (InterruptedException success) {
1070                  threadAssertFalse(Thread.interrupted());
1071 <            } catch (Throwable t) {
1072 <                threadUnexpectedException(t);
1071 >            } catch (Throwable fail) {
1072 >                threadUnexpectedException(fail);
1073              }
1074          }
1075      }
# Line 1073 | Line 1080 | public class JSR166TestCase extends Test
1080          public final T call() {
1081              try {
1082                  return realCall();
1083 <            } catch (Throwable t) {
1084 <                threadUnexpectedException(t);
1083 >            } catch (Throwable fail) {
1084 >                threadUnexpectedException(fail);
1085                  return null;
1086              }
1087          }
# Line 1091 | Line 1098 | public class JSR166TestCase extends Test
1098                  return result;
1099              } catch (InterruptedException success) {
1100                  threadAssertFalse(Thread.interrupted());
1101 <            } catch (Throwable t) {
1102 <                threadUnexpectedException(t);
1101 >            } catch (Throwable fail) {
1102 >                threadUnexpectedException(fail);
1103              }
1104              return null;
1105          }
# Line 1132 | Line 1139 | public class JSR166TestCase extends Test
1139      public void await(CountDownLatch latch) {
1140          try {
1141              assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS));
1142 <        } catch (Throwable t) {
1143 <            threadUnexpectedException(t);
1142 >        } catch (Throwable fail) {
1143 >            threadUnexpectedException(fail);
1144          }
1145      }
1146  
1147      public void await(Semaphore semaphore) {
1148          try {
1149              assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
1150 <        } catch (Throwable t) {
1151 <            threadUnexpectedException(t);
1150 >        } catch (Throwable fail) {
1151 >            threadUnexpectedException(fail);
1152          }
1153      }
1154  
# Line 1335 | Line 1342 | public class JSR166TestCase extends Test
1342          @Override protected final void compute() {
1343              try {
1344                  realCompute();
1345 <            } catch (Throwable t) {
1346 <                threadUnexpectedException(t);
1345 >            } catch (Throwable fail) {
1346 >                threadUnexpectedException(fail);
1347              }
1348          }
1349      }
# Line 1350 | Line 1357 | public class JSR166TestCase extends Test
1357          @Override protected final T compute() {
1358              try {
1359                  return realCompute();
1360 <            } catch (Throwable t) {
1361 <                threadUnexpectedException(t);
1360 >            } catch (Throwable fail) {
1361 >                threadUnexpectedException(fail);
1362                  return null;
1363              }
1364          }
# Line 1375 | Line 1382 | public class JSR166TestCase extends Test
1382          public int await() {
1383              try {
1384                  return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
1385 <            } catch (TimeoutException e) {
1385 >            } catch (TimeoutException timedOut) {
1386                  throw new AssertionFailedError("timed out");
1387 <            } catch (Exception e) {
1387 >            } catch (Exception fail) {
1388                  AssertionFailedError afe =
1389 <                    new AssertionFailedError("Unexpected exception: " + e);
1390 <                afe.initCause(e);
1389 >                    new AssertionFailedError("Unexpected exception: " + fail);
1390 >                afe.initCause(fail);
1391                  throw afe;
1392              }
1393          }
# Line 1408 | Line 1415 | public class JSR166TestCase extends Test
1415                  q.remove();
1416                  shouldThrow();
1417              } catch (NoSuchElementException success) {}
1418 <        } catch (InterruptedException ie) {
1412 <            threadUnexpectedException(ie);
1413 <        }
1418 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
1419      }
1420  
1421      void assertSerialEquals(Object x, Object y) {
# Line 1429 | Line 1434 | public class JSR166TestCase extends Test
1434              oos.flush();
1435              oos.close();
1436              return bos.toByteArray();
1437 <        } catch (Throwable t) {
1438 <            threadUnexpectedException(t);
1437 >        } catch (Throwable fail) {
1438 >            threadUnexpectedException(fail);
1439              return new byte[0];
1440          }
1441      }
# Line 1443 | Line 1448 | public class JSR166TestCase extends Test
1448              T clone = (T) ois.readObject();
1449              assertSame(o.getClass(), clone.getClass());
1450              return clone;
1451 <        } catch (Throwable t) {
1452 <            threadUnexpectedException(t);
1451 >        } catch (Throwable fail) {
1452 >            threadUnexpectedException(fail);
1453              return null;
1454          }
1455      }
# Line 1476 | Line 1481 | public class JSR166TestCase extends Test
1481              shouldThrow();
1482          } catch (NoSuchElementException success) {}
1483          assertFalse(it.hasNext());
1484 <    }        
1484 >    }
1485   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines