chia7712 commented on a change in pull request #9707: URL: https://github.com/apache/kafka/pull/9707#discussion_r537998894
########## File path: clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java ########## @@ -391,6 +391,23 @@ Sender newSender(LogContext logContext, KafkaClient kafkaClient, ProducerMetadat }; } + @Test(timeout = 10000) + public void testFlushInCallbackNotCauseDeadlock() throws InterruptedException { + Map<String, Object> configs = new HashMap<>(); + configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999"); + ProducerMetadata metadata = mock(ProducerMetadata.class); + + when(metadata.fetch()).thenReturn(emptyCluster, emptyCluster, emptyCluster, onePartitionCluster); + + KafkaProducer<String, String> producer = producerWithOverrideNewSender(configs, metadata); + ProducerRecord<String, String> record = new ProducerRecord<>(topic, "value"); + + producer.send(record, (metadata1, exception) -> producer.flush()); Review comment: Could you add a flag after ```producer.flush()```? We should make sure ```producer.flush()``` fails. ---------------------------------------------------------------- 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