zhaohaidao commented on a change in pull request #9311:
URL: https://github.com/apache/kafka/pull/9311#discussion_r502917729



##########
File path: core/src/test/scala/integration/kafka/api/TransactionsTest.scala
##########
@@ -580,6 +580,52 @@ class TransactionsTest extends KafkaServerTestHarness {
     assertTrue(transactionalRecords.isEmpty)
   }
 
+  @Test
+  def testProducerUsableAfterTxnTimeOutAbortExcetion(): Unit = {
+    val producer = createTransactionalProducer("expiringProducer", 
transactionTimeoutMs = 100)
+
+    producer.initTransactions()
+    producer.beginTransaction()
+
+    // The first message and hence the first AddPartitions request should be 
successfully sent.
+    val firstMessageResult = 
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(topic1, 
null, "1", "1", willBeCommitted = false)).get()
+    assertTrue(firstMessageResult.hasOffset)
+
+    // Wait for the expiration cycle to kick in.
+    Thread.sleep(600)
+
+    try {
+      // Now that the transaction has expired, the second send should fail 
with a ProducerFencedException.
+      producer.commitTransaction()
+      fail("should have raised a TransactionTimeOutException since the 
transaction has expired")
+    } catch {
+      case _: TransactionTimeoutException =>
+      case e: ExecutionException =>
+        assertTrue(e.getCause.isInstanceOf[TransactionTimeoutException])
+    }
+
+    val transactionalConsumer = transactionalConsumers.head
+    transactionalConsumer.subscribe(List(topic1).asJava)
+
+    val transactionalRecords = 
TestUtils.consumeRecordsFor(transactionalConsumer, 1000)
+    assertTrue(transactionalRecords.isEmpty)
+
+    producer.abortTransaction()
+    producer.beginTransaction()
+    // The second message and hence the second AddPartitions request should be 
successfully sent.

Review comment:
       This comment refers to other cases, which is meaningless. I will remove 
it.




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