kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject kafka git commit: MINOR: Use `hiResClockMs` in `testRequestExpiry` to fix transient test failure
Date Fri, 07 Oct 2016 16:00:31 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.10.1 7232a031b -> e409d8afd


MINOR: Use `hiResClockMs` in `testRequestExpiry` to fix transient test failure

We recently switched `SystemTimer` to use `hiResClockMs` (based on `nanoTime`), but we
were still using `System.currentTimeMillis` in the test. That would sometimes mean
that we would measure elapsed time as lower than expected.

Author: Ismael Juma <ismael@juma.me.uk>

Reviewers: Rajini Sivaram <rajinisivaram@googlemail.com>, Jason Gustafson <jason@confluent.io>

Closes #1890 from ijuma/fix-test-request-satisfaction-transient-failure

(cherry picked from commit 615cd4fd3ad7abe7600e4f80ce6c36f7125f599e)
Signed-off-by: Jason Gustafson <jason@confluent.io>


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

Branch: refs/heads/0.10.1
Commit: e409d8afd235a719f44cc4ec2473a99c53ad0bc2
Parents: 7232a03
Author: Ismael Juma <ismael@juma.me.uk>
Authored: Fri Oct 7 09:00:12 2016 -0700
Committer: Jason Gustafson <jason@confluent.io>
Committed: Fri Oct 7 09:00:50 2016 -0700

----------------------------------------------------------------------
 .../test/scala/unit/kafka/server/DelayedOperationTest.scala   | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/e409d8af/core/src/test/scala/unit/kafka/server/DelayedOperationTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/server/DelayedOperationTest.scala b/core/src/test/scala/unit/kafka/server/DelayedOperationTest.scala
index 2c70137..ae0d12f 100644
--- a/core/src/test/scala/unit/kafka/server/DelayedOperationTest.scala
+++ b/core/src/test/scala/unit/kafka/server/DelayedOperationTest.scala
@@ -17,6 +17,7 @@
 
 package kafka.server
 
+import kafka.utils.SystemTime
 import org.junit.{After, Before, Test}
 import org.junit.Assert._
 
@@ -54,16 +55,16 @@ class DelayedOperationTest {
   @Test
   def testRequestExpiry() {
     val expiration = 20L
-    val start = System.currentTimeMillis
+    val start = SystemTime.hiResClockMs
     val r1 = new MockDelayedOperation(expiration)
     val r2 = new MockDelayedOperation(200000L)
     assertFalse("r1 not satisfied and hence watched", purgatory.tryCompleteElseWatch(r1,
Array("test1")))
     assertFalse("r2 not satisfied and hence watched", purgatory.tryCompleteElseWatch(r2,
Array("test2")))
     r1.awaitExpiration()
-    val elapsed = System.currentTimeMillis - start
+    val elapsed = SystemTime.hiResClockMs - start
     assertTrue("r1 completed due to expiration", r1.isCompleted())
     assertFalse("r2 hasn't completed", r2.isCompleted())
-    assertTrue("Time for expiration %d should at least %d".format(elapsed, expiration), elapsed
>= expiration)
+    assertTrue(s"Time for expiration $elapsed should at least $expiration", elapsed >=
expiration)
   }
 
   @Test


Mime
View raw message