hachikuji commented on code in PR #14088:
URL: https://github.com/apache/kafka/pull/14088#discussion_r1275544007


##########
clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java:
##########
@@ -3107,6 +3099,45 @@ public void 
testReceiveFailedBatchTwiceWithTransactions() throws Exception {
         txnManager.beginTransaction();
     }
 
+    @Test
+    public void testInvalidTxnStateIsAnAbortableError() throws Exception {
+        ProducerIdAndEpoch producerIdAndEpoch = new 
ProducerIdAndEpoch(123456L, (short) 0);
+        apiVersions.update("0", 
NodeApiVersions.create(ApiKeys.INIT_PRODUCER_ID.id, (short) 0, (short) 3));
+        TransactionManager txnManager = new TransactionManager(logContext, 
"testInvalidTxnState", 60000, 100, apiVersions);
+
+        setupWithTransactionState(txnManager);
+        doInitTransactions(txnManager, producerIdAndEpoch);
+
+        txnManager.beginTransaction();
+        txnManager.maybeAddPartition(tp0);
+        client.prepareResponse(buildAddPartitionsToTxnResponseData(0, 
Collections.singletonMap(tp0, Errors.NONE)));
+        sender.runOnce();
+
+        Future<RecordMetadata> request = appendToAccumulator(tp0);
+        sender.runOnce();  // send request
+        sendIdempotentProducerResponse(0, tp0, Errors.INVALID_TXN_STATE, -1);
+
+        // Return InvalidTxnState error. It should be abortable.
+        sender.runOnce();
+        assertFutureFailure(request, InvalidTxnStateException.class);
+        assertTrue(txnManager.hasAbortableError());
+        TransactionalRequestResult result = txnManager.beginAbort();
+        sender.runOnce();
+
+        // Once the transaction is aborted, we should be able to begin a new 
one.
+        respondToEndTxn(Errors.NONE);
+        sender.runOnce();
+        assertTrue(txnManager::isInitializing);
+        prepareInitProducerResponse(Errors.NONE, 
producerIdAndEpoch.producerId, producerIdAndEpoch.epoch);

Review Comment:
   Does the current logic force us to reset the epoch after any error which 
causes an abort? It seems like a good idea, but just wanted to confirm what the 
trigger is.



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

Reply via email to