soondenana commented on a change in pull request #9054: URL: https://github.com/apache/kafka/pull/9054#discussion_r459103347
########## 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: Is it deterministic? I realize its mocktime, but threads can be scheduled in any order. Or using `MockTime` means all schedulers will get triggered before next line in test will get to run? ---------------------------------------------------------------- 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