bbejeck commented on code in PR #17781: URL: https://github.com/apache/kafka/pull/17781#discussion_r1841165677
########## clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java: ########## @@ -224,6 +228,34 @@ public void cleanup() { } } + @ParameterizedTest + @EnumSource(GroupProtocol.class) + public void testSubscribingCustomMetricsDoesntAffectConsumerMetrics(GroupProtocol groupProtocol) { + Properties props = new Properties(); + props.setProperty(ConsumerConfig.GROUP_PROTOCOL_CONFIG, groupProtocol.name()); + props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999"); + consumer = newConsumer(props, new StringDeserializer(), new StringDeserializer()); + + Map<MetricName, KafkaMetric> customMetrics = customMetrics(); + customMetrics.forEach((name, metric) -> consumer.registerMetricForSubscription(metric)); + + Map<MetricName, ? extends Metric> consumerMetrics = consumer.metrics(); + customMetrics.forEach((name, metric) -> assertFalse(consumerMetrics.containsKey(name))); + } + + @ParameterizedTest + @EnumSource(GroupProtocol.class) + public void testUnSubscribingNonExisingMetricsDoesntCauseError(GroupProtocol groupProtocol) { + Properties props = new Properties(); + props.setProperty(ConsumerConfig.GROUP_PROTOCOL_CONFIG, groupProtocol.name()); + props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999"); + consumer = newConsumer(props, new StringDeserializer(), new StringDeserializer()); + + Map<MetricName, KafkaMetric> customMetrics = customMetrics(); + //Metrics never registered but removed should not cause an error + customMetrics.forEach((name, metric) -> assertDoesNotThrow(() -> consumer.unregisterMetricFromSubscription(metric))); Review Comment: done -- 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