rodesai commented on a change in pull request #11149: URL: https://github.com/apache/kafka/pull/11149#discussion_r695342570
########## File path: clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java ########## @@ -905,6 +971,57 @@ public void testSendTxnOffsetsWithGroupId() { } } + private double getAndAssertDuration(KafkaProducer<?, ?> producer, String name, double floor) { + double value = getMetricValue(producer, name); + assertTrue(value > floor); + return value; + } + + @Test + public void testMeasureTransactionDurations() { + Map<String, Object> configs = new HashMap<>(); + configs.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "some.id"); + configs.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 10000); + 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); + client.prepareResponse(FindCoordinatorResponse.prepareResponse(Errors.NONE, "some.id", host1)); + client.prepareResponse(initProducerIdResponse(1L, (short) 5, Errors.NONE)); + + try (KafkaProducer<String, String> producer = kafkaProducer(configs, new StringSerializer(), + new StringSerializer(), metadata, client, null, time)) { + producer.initTransactions(); + assertTrue(getMetricValue(producer, "txn-init-time-total") > 999999); Review comment: I'm verifying that something was measured and that it's at least 1 tick of the clock. The clock is shared between multiple threads (e.g. the io threads) so the number of ticks depends on what threads get scheduled while we're in `initTransactions`. -- 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