divijvaidya commented on code in PR #13471: URL: https://github.com/apache/kafka/pull/13471#discussion_r1152441640
########## core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala: ########## @@ -4485,6 +4485,25 @@ class ReplicaManagerTest { assertTrue(response.usableBytes >= 0) } } + + @Test + def checkRemoveMetricsCountMatchRegisterCount(): Unit = { Review Comment: I have an idea with which we can avoid changing the KafkaMetricsGroup. Could you please consider the following. You can use mockito's `MockConstruction` to mock the KafkaMetricsGroup and count the number of invocations on that mock and later assert on number of invocations of add and remove. As an example, this test could be written as follows (rough example with Java code): ``` var numAddCount = 0; var numRemoveCount = 0; try (MockedConstruction<KafkaMetricsGroup> mockMetricsGroup = mockConstruction(KafkaMetricsGroup.class, (mock, context) -> { doAnswer(invocation -> { numAddCount++; }).when(mock).newGauge(anyString()); // similarly add mocks for newMeter etc. doAnswer(invocation -> { numRemoveCount++; }).when(mock).removeMetric(anyString()); })) { val rm = new ReplicaManager( metrics = metrics, config = config, time = time, scheduler = new MockScheduler(time), logManager = mockLogMgr, quotaManagers = quotaManager, metadataCache = MetadataCache.zkMetadataCache(config.brokerId, config.interBrokerProtocolVersion), logDirFailureChannel = new LogDirFailureChannel(config.logDirs.size), alterPartitionManager = alterPartitionManager, threadNamePrefix = Option(this.getClass.getName)) rm.shutdown() assertEquals(numAddCount, numRemoveCount) } ``` -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org