bob-barrett commented on a change in pull request #9054:
URL: https://github.com/apache/kafka/pull/9054#discussion_r459142570



##########
File path: core/src/test/scala/unit/kafka/log/LogManagerTest.scala
##########
@@ -563,4 +565,39 @@ class LogManagerTest {
     logManager.topicConfigUpdated("test-topic")
     assertTrue(logManager.partitionsInitializing.isEmpty)
   }
+
+  @Test
+  def testMetricsExistWhenLogIsRecreatedBeforeDeletion(): Unit = {
+    val topicName = "metric-test"
+    def logMetrics = 
KafkaYammerMetrics.defaultRegistry.allMetrics.keySet.asScala.
+      filter(_.getType == "Log").filter(_.getScope.contains(topicName))
+
+    val tp = new TopicPartition(topicName, 0)
+    logManager.getOrCreateLog(tp, () => logConfig)
+
+    val metricTag = s"topic=${tp.topic},partition=${tp.partition}"
+
+    assertEquals(LogMetricNames.allMetricNames.size, logMetrics.size)
+    logMetrics.foreach { metric =>
+      assertTrue(metric.getMBeanName.contains(metricTag))
+    }
+
+    logManager.asyncDelete(tp)
+
+    assertTrue(logMetrics.isEmpty)
+
+    logManager.getOrCreateLog(tp, () => logConfig)
+
+    assertEquals(LogMetricNames.allMetricNames.size, logMetrics.size)
+    logMetrics.foreach { metric =>
+      assertTrue(metric.getMBeanName.contains(metricTag))
+    }
+
+    time.sleep(logConfig.fileDeleteDelayMs + 1)

Review comment:
       Yes, `MockTime` contains a `MockScheduler`, which explicitly checks for 
any scheduled tasks that need to be run whenever we sleep. And we pass that 
`MockScheduler` into the `Log` and `LogManager` constructors in the tests. See 
https://github.com/apache/kafka/blob/trunk/core/src/test/scala/unit/kafka/utils/MockScheduler.scala#L59.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to