ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/SystemTest.java
(Generate patch)

Comparing jsr166/src/test/tck/SystemTest.java (file contents):
Revision 1.10 by jsr166, Sat Oct 9 19:30:35 2010 UTC vs.
Revision 1.14 by jsr166, Sun May 14 03:09:25 2017 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
9 > import junit.framework.Test;
10 > import junit.framework.TestSuite;
11  
12   public class SystemTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run(suite());
14 >        main(suite(), args);
15      }
16  
17      public static Test suite() {
# Line 26 | Line 27 | public class SystemTest extends JSR166Te
27  
28      /**
29       * Nanos between readings of millis is no longer than millis (plus
30 <     * possible rounding).
30 >     * possible rounding), and vice versa.
31       * This shows only that nano timing not (much) worse than milli.
32       */
33 <    public void testNanoTime1() throws InterruptedException {
34 <        long m1 = System.currentTimeMillis();
35 <        Thread.sleep(1);
35 <        long n1 = System.nanoTime();
36 <        Thread.sleep(SHORT_DELAY_MS);
37 <        long n2 = System.nanoTime();
38 <        Thread.sleep(1);
39 <        long m2 = System.currentTimeMillis();
40 <        long millis = m2 - m1;
41 <        long nanos = n2 - n1;
42 <        assertTrue(nanos >= 0);
43 <        long nanosAsMillis = nanos / 1000000;
44 <        assertTrue(nanosAsMillis <= millis + MILLIS_ROUND);
45 <    }
46 <
47 <    /**
48 <     * Millis between readings of nanos is less than nanos, adjusting
49 <     * for rounding.
50 <     * This shows only that nano timing not (much) worse than milli.
51 <     */
52 <    public void testNanoTime2() throws InterruptedException {
53 <        long n1 = System.nanoTime();
33 >    public void testNanoTime() throws InterruptedException {
34 >        long m0 = System.currentTimeMillis();
35 >        long n0 = System.nanoTime();
36          Thread.sleep(1);
37          long m1 = System.currentTimeMillis();
38 <        Thread.sleep(SHORT_DELAY_MS);
38 >        long n1 = System.nanoTime();
39 >        Thread.sleep(50);       // avoid possibly scaled SHORT_DELAY_MS
40          long m2 = System.currentTimeMillis();
58        Thread.sleep(1);
41          long n2 = System.nanoTime();
42 <        long millis = m2 - m1;
43 <        long nanos = n2 - n1;
44 <
45 <        assertTrue(nanos >= 0);
46 <        long nanosAsMillis = nanos / 1000000;
65 <        assertTrue(millis <= nanosAsMillis + MILLIS_ROUND);
42 >        Thread.sleep(1);
43 >        long m3 = System.currentTimeMillis();
44 >        long n3 = System.nanoTime();
45 >        assertTrue((n2 - n1) / 1_000_000 <= m3 - m0 + MILLIS_ROUND);
46 >        assertTrue(m2 - m1 <= (n3 - n0) / 1_000_000 + MILLIS_ROUND);
47      }
67
48   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines