rreddy-22 commented on code in PR #23630:
URL: https://github.com/apache/kafka/pull/23630#discussion_r4147613675


##########
core/src/test/scala/unit/kafka/coordinator/transaction/TransactionCoordinatorConcurrencyTest.scala:
##########
@@ -172,6 +175,60 @@ class TransactionCoordinatorConcurrencyTest extends 
AbstractCoordinatorConcurren
     verifyConcurrentRandomSequences(createTransactions, allOperations)
   }
 
+  @Test
+  def testEndTxnReturnsNotCoordinatorAfterLosingLeadershipBeforeResignation(): 
Unit = {
+    val transactionalId = "stale-coordinator"
+    val producerEpoch: Short = 5
+    txnStateManager.putTransactionStateIfNotExists(new 
TransactionMetadata(transactionalId, producerId,
+      RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_ID, producerEpoch, 
(producerEpoch - 1).toShort, 60000,
+      TransactionState.COMPLETE_COMMIT, new util.HashSet[TopicPartition](), 
time.milliseconds(), time.milliseconds(),
+      TransactionVersion.TV_2))
+    val txnPartition = txnStateManager.partitionFor(transactionalId)
+
+    def commit(): Errors = {
+      var error: Errors = null
+      transactionCoordinator.handleEndTransaction(transactionalId, producerId, 
producerEpoch, TransactionResult.COMMIT,
+        TransactionVersion.TV_2, (e, _, _) => error = e)
+      error
+    }
+
+    // committing at the current epoch with no new transaction is invalid
+    assertEquals(Errors.INVALID_TXN_STATE, commit())
+
+    // the replica became a follower but the partition has not been unloaded 
yet
+    loseLeadership(txnPartition)
+    assertEquals(Errors.NOT_COORDINATOR, commit())
+  }
+
+  @Test
+  def 
testVerifyPartitionsReturnsNotCoordinatorAfterLosingLeadershipBeforeResignation():
 Unit = {
+    val transactionalId = "stale-coordinator-verify"
+    val producerEpoch: Short = 5
+    val partition = new TopicPartition("topic", 0)
+    txnStateManager.putTransactionStateIfNotExists(new 
TransactionMetadata(transactionalId, producerId,
+      RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_ID, producerEpoch, 
(producerEpoch - 1).toShort, 60000,
+      TransactionState.ONGOING, new 
util.HashSet[TopicPartition](util.Set.of(partition)), time.milliseconds(),
+      time.milliseconds(), TransactionVersion.TV_0))
+
+    def verify(): Errors = {
+      var errors: util.Map[TopicPartition, Errors] = null
+      
transactionCoordinator.handleVerifyPartitionsInTransaction(transactionalId, 
producerId, producerEpoch,

Review Comment:
   good point, lemme look into the potential cases there and add tests if needed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to