rodesai commented on a change in pull request #11149: URL: https://github.com/apache/kafka/pull/11149#discussion_r688240676
########## File path: clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java ########## @@ -730,6 +732,41 @@ public void testFlushCompleteSendOfInflightBatches() { } } + private static Double getMetricValue(final KafkaProducer<?, ?> producer, final String name) { + Metrics metrics = producer.metrics; + Metric metric = metrics.metric(metrics.metricName(name, "producer-metrics")); + return (Double) metric.metricValue(); + } + + @Test + public void testFlushMeasureLatency() { + Map<String, Object> configs = new HashMap<>(); + configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9000"); + + Time time = new MockTime(1); + MetadataResponse initialUpdateResponse = RequestTestUtils.metadataUpdateWith(1, singletonMap("topic", 1)); + ProducerMetadata metadata = newMetadata(0, Long.MAX_VALUE); + + MockClient client = new MockClient(time, metadata); + client.updateMetadata(initialUpdateResponse); + + try (KafkaProducer<String, String> producer = kafkaProducer( + configs, + new StringSerializer(), + new StringSerializer(), + metadata, + client, + null, + time + )) { + producer.flush(); + double first = getMetricValue(producer, "flush-time-total"); + assertTrue(first > 999999.0); Review comment: It's using mock time, so the value here is well-known (should be 1 second). I'm using > rather than equalTo because I don't want the test to fail spuriously on floating point rounding errors. It would probably be better to use [isCloseTo](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/number/IsCloseTo.html) -- 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