[cvs] / jsr166 / src / test / tck / SystemTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/SystemTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13, Sat Apr 25 04:55:31 2015 UTC revision 1.14, Sun May 14 03:09:25 2017 UTC
# Line 27  Line 27 
27    
28      /**      /**
29       * Nanos between readings of millis is no longer than millis (plus       * Nanos between readings of millis is no longer than millis (plus
30       * possible rounding).       * possible rounding), and vice versa.
31       * This shows only that nano timing not (much) worse than milli.       * This shows only that nano timing not (much) worse than milli.
32       */       */
33      public void testNanoTime1() throws InterruptedException {      public void testNanoTime() throws InterruptedException {
34          long m1 = System.currentTimeMillis();          long m0 = System.currentTimeMillis();
35          Thread.sleep(1);          long n0 = System.nanoTime();
         long n1 = System.nanoTime();  
         Thread.sleep(SHORT_DELAY_MS);  
         long n2 = System.nanoTime();  
         Thread.sleep(1);  
         long m2 = System.currentTimeMillis();  
         long millis = m2 - m1;  
         long nanos = n2 - n1;  
         assertTrue(nanos >= 0);  
         long nanosAsMillis = nanos / 1000000;  
         assertTrue(nanosAsMillis <= millis + MILLIS_ROUND);  
     }  
   
     /**  
      * Millis between readings of nanos is less than nanos, adjusting  
      * for rounding.  
      * This shows only that nano timing not (much) worse than milli.  
      */  
     public void testNanoTime2() throws InterruptedException {  
         long n1 = System.nanoTime();  
36          Thread.sleep(1);          Thread.sleep(1);
37          long m1 = System.currentTimeMillis();          long m1 = System.currentTimeMillis();
38          Thread.sleep(SHORT_DELAY_MS);          long n1 = System.nanoTime();
39            Thread.sleep(50);       // avoid possibly scaled SHORT_DELAY_MS
40          long m2 = System.currentTimeMillis();          long m2 = System.currentTimeMillis();
         Thread.sleep(1);  
41          long n2 = System.nanoTime();          long n2 = System.nanoTime();
42          long millis = m2 - m1;          Thread.sleep(1);
43          long nanos = n2 - n1;          long m3 = System.currentTimeMillis();
44            long n3 = System.nanoTime();
45          assertTrue(nanos >= 0);          assertTrue((n2 - n1) / 1_000_000 <= m3 - m0 + MILLIS_ROUND);
46          long nanosAsMillis = nanos / 1000000;          assertTrue(m2 - m1 <= (n3 - n0) / 1_000_000 + MILLIS_ROUND);
         assertTrue(millis <= nanosAsMillis + MILLIS_ROUND);  
47      }      }
   
48  }  }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8