Repository: kafka
Updated Branches:
  refs/heads/trunk 5e4600ae4 -> 615cd4fd3


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 <[email protected]>

Reviewers: Rajini Sivaram <[email protected]>, Jason Gustafson 
<[email protected]>

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


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

Branch: refs/heads/trunk
Commit: 615cd4fd3ad7abe7600e4f80ce6c36f7125f599e
Parents: 5e4600a
Author: Ismael Juma <[email protected]>
Authored: Fri Oct 7 09:00:12 2016 -0700
Committer: Jason Gustafson <[email protected]>
Committed: Fri Oct 7 09:00:12 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/615cd4fd/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

Reply via email to