kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gwens...@apache.org
Subject kafka git commit: MINOR: Clean `Metrics.defaultRegistry` to avoid transient failures in `testSessionExpireListenerMetrics`
Date Thu, 23 Jun 2016 22:05:15 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 6cd031e7c -> ef42c224a


MINOR: Clean `Metrics.defaultRegistry` to avoid transient failures in `testSessionExpireListenerMetrics`

The failure could manifest itself if the default metrics registry had some entries from other
tests:

`java.lang.AssertionError: Unexpected meter count expected:<0> but was:<3>`

I also removed an unused variable and improved the error message to include the metric name.

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

Reviewers: Gwen Shapira

Closes #1544 from ijuma/fix-transient-session-expire-listener-metrics-failure


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

Branch: refs/heads/trunk
Commit: ef42c224a701161a15e046de73c11982024bbc53
Parents: 6cd031e
Author: Ismael Juma <ismael@juma.me.uk>
Authored: Thu Jun 23 15:05:11 2016 -0700
Committer: Gwen Shapira <cshapi@gmail.com>
Committed: Thu Jun 23 15:05:11 2016 -0700

----------------------------------------------------------------------
 .../kafka/server/SessionExpireListenerTest.scala     | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/ef42c224/core/src/test/scala/unit/kafka/server/SessionExpireListenerTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/server/SessionExpireListenerTest.scala b/core/src/test/scala/unit/kafka/server/SessionExpireListenerTest.scala
index 4ffb189..5f466c5 100644
--- a/core/src/test/scala/unit/kafka/server/SessionExpireListenerTest.scala
+++ b/core/src/test/scala/unit/kafka/server/SessionExpireListenerTest.scala
@@ -22,28 +22,33 @@ import kafka.utils.ZkUtils
 import org.I0Itec.zkclient.ZkClient
 import org.apache.zookeeper.Watcher
 import org.easymock.EasyMock
-import org.junit.{Assert, Before, Test}
+import org.junit.{Assert, Test}
 import Assert._
 import com.yammer.metrics.Metrics
-import com.yammer.metrics.core.{Meter, Metric, MetricName}
-import org.apache.kafka.common.utils.MockTime
+import com.yammer.metrics.core.Meter
 import scala.collection.JavaConverters._
 
 class SessionExpireListenerTest {
 
-  private var time = new MockTime
   private val brokerId = 1
 
+  private def cleanMetricsRegistry() {
+    val metrics = Metrics.defaultRegistry
+    metrics.allMetrics.keySet.asScala.foreach(metrics.removeMetric)
+  }
+
   @Test
   def testSessionExpireListenerMetrics() {
 
+    cleanMetricsRegistry()
+
     val metrics = Metrics.defaultRegistry
 
     def checkMeterCount(name: String, expected: Long) {
       val meter = metrics.allMetrics.asScala.collectFirst {
         case (metricName, meter: Meter) if metricName.getName == name => meter
       }.getOrElse(sys.error(s"Unable to find meter with name $name"))
-      assertEquals("Unexpected meter count", expected, meter.count)
+      assertEquals(s"Unexpected meter count for $name", expected, meter.count)
     }
 
     val zkClient = EasyMock.mock(classOf[ZkClient])


Mime
View raw message