chia7712 commented on a change in pull request #9707:
URL: https://github.com/apache/kafka/pull/9707#discussion_r538511924



##########
File path: 
clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
##########
@@ -391,6 +391,31 @@ 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");
+
+        AtomicBoolean  exceptionThrow = new AtomicBoolean(false);

Review comment:
       Could you save the exception caused by ```producer.flush()``` and then 
check the error type in the test thread?

##########
File path: 
clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
##########
@@ -1115,6 +1119,9 @@ private void ensureValidRecordSize(int size) {
      */
     @Override
     public void flush() {
+        if (isInvokedFromCallback())
+            throw new UnsupportedOperationException("Can't specify flush 
method in callback.");

Review comment:
       It seems to me ```IllegalStateException``` is more suitable for this 
case. Also, please update docs of ```flush()```




----------------------------------------------------------------
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


Reply via email to