cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcken...@apache.org
Subject cassandra git commit: Fix NanoTimeTocurrentTimeMillisTest on Windows
Date Mon, 24 Aug 2015 21:11:30 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 4994f0c7e -> 06a053ddc


Fix NanoTimeTocurrentTimeMillisTest on Windows

Patch by pmotta; reviewed by aweisberg for CASSANDRA-10139


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/06a053dd
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/06a053dd
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/06a053dd

Branch: refs/heads/cassandra-2.2
Commit: 06a053ddc928cb8a65c5ff6d1e83947f0bb81fc6
Parents: 4994f0c
Author: Paulo Motta <pauloricardomg@gmail.com>
Authored: Mon Aug 24 17:10:26 2015 -0400
Committer: Joshua McKenzie <jmckenzie@apache.org>
Committed: Mon Aug 24 17:10:26 2015 -0400

----------------------------------------------------------------------
 .../utils/NanoTimeToCurrentTimeMillis.java          |  2 +-
 .../utils/NanoTimeToCurrentTimeMillisTest.java      | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/06a053dd/src/java/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillis.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillis.java b/src/java/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillis.java
index a6c5d28..f124383 100644
--- a/src/java/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillis.java
+++ b/src/java/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillis.java
@@ -46,7 +46,7 @@ public class NanoTimeToCurrentTimeMillis
      * There is also the issue of how scalable nanoTime() and currentTimeMillis() are which
is a moving target.
      *
      * These timestamps don't order with System.currentTimeMillis() because currentTimeMillis()
can tick over
-     * before this one does. I have seen it behind by as much as 2 milliseconds.
+     * before this one does. I have seen it behind by as much as 2ms on Linux and 25ms on
Windows.
      */
     public static final long convert(long nanoTime)
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/06a053dd/test/unit/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillisTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillisTest.java b/test/unit/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillisTest.java
index 5c025cf..1662e77 100644
--- a/test/unit/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillisTest.java
+++ b/test/unit/org/apache/cassandra/utils/NanoTimeToCurrentTimeMillisTest.java
@@ -40,13 +40,19 @@ public class NanoTimeToCurrentTimeMillisTest
                 }
                 Thread.sleep(1);
             }
-            nowNanos = Math.max(now, System.nanoTime());
+
+            nowNanos = Math.max(nowNanos, System.nanoTime());
             long convertedNow = NanoTimeToCurrentTimeMillis.convert(nowNanos);
-            assertTrue("convertedNow = " + convertedNow + " lastConverted = " + lastConverted
+ " in iteration " + ii, convertedNow >= (lastConverted - 1));
-            lastConverted = convertedNow;
-            //Seems to be off by as much as two milliseconds sadly
-            assertTrue("now = " + now + " convertedNow = " + convertedNow + " in iteration
" + ii, (now - 2) <= convertedNow);
 
+            int maxDiff = FBUtilities.isWindows()? 15 : 1;
+            assertTrue("convertedNow = " + convertedNow + " lastConverted = " + lastConverted
+ " in iteration " + ii,
+                       convertedNow >= (lastConverted - maxDiff));
+
+            maxDiff = FBUtilities.isWindows()? 25 : 2;
+            assertTrue("now = " + now + " convertedNow = " + convertedNow + " in iteration
" + ii,
+                       (maxDiff - 2) <= convertedNow);
+
+            lastConverted = convertedNow;
         }
     }
 }


Mime
View raw message