dajac commented on code in PR #14402: URL: https://github.com/apache/kafka/pull/14402#discussion_r1331072039
########## core/src/test/scala/unit/kafka/server/AddPartitionsToTxnManagerTest.scala: ########## @@ -68,87 +71,143 @@ class AddPartitionsToTxnManagerTest { private val versionMismatchResponse = clientResponse(null, mismatchException = new UnsupportedVersionException("")) private val disconnectedResponse = clientResponse(null, disconnected = true) + private val config = KafkaConfig.fromProps(TestUtils.createBrokerConfig(1, "localhost:2181")) + @BeforeEach def setup(): Unit = { addPartitionsToTxnManager = new AddPartitionsToTxnManager( - KafkaConfig.fromProps(TestUtils.createBrokerConfig(1, "localhost:2181")), + config, networkClient, - time) + metadataCache, + partitionFor, + time + ) } @AfterEach def teardown(): Unit = { addPartitionsToTxnManager.shutdown() } - def setErrors(errors: mutable.Map[TopicPartition, Errors])(callbackErrors: Map[TopicPartition, Errors]): Unit = { - callbackErrors.foreach { - case (tp, error) => errors.put(tp, error) - } + private def setErrors(errors: mutable.Map[TopicPartition, Errors])(callbackErrors: Map[TopicPartition, Errors]): Unit = { + callbackErrors.forKeyValue(errors.put) } @Test def testAddTxnData(): Unit = { + when(partitionFor.apply(transactionalId1)).thenReturn(0) + when(partitionFor.apply(transactionalId2)).thenReturn(1) + when(partitionFor.apply(transactionalId3)).thenReturn(0) + when(metadataCache.getTopicMetadata(Set(Topic.TRANSACTION_STATE_TOPIC_NAME), config.interBrokerListenerName)) + .thenReturn(Seq( + new MetadataResponseData.MetadataResponseTopic() + .setName(Topic.TRANSACTION_STATE_TOPIC_NAME) + .setPartitions(List( + new MetadataResponseData.MetadataResponsePartition() + .setPartitionIndex(0) + .setLeaderId(0), + new MetadataResponseData.MetadataResponsePartition() + .setPartitionIndex(1) + .setLeaderId(1) + ).asJava) + )) + when(metadataCache.getAliveBrokerNode(0, config.interBrokerListenerName)) + .thenReturn(Some(node0)) + when(metadataCache.getAliveBrokerNode(1, config.interBrokerListenerName)) + .thenReturn(Some(node1)) + val transaction1Errors = mutable.Map[TopicPartition, Errors]() val transaction2Errors = mutable.Map[TopicPartition, Errors]() val transaction3Errors = mutable.Map[TopicPartition, Errors]() - addPartitionsToTxnManager.addTxnData(node0, transactionData(transactionalId1, producerId1), setErrors(transaction1Errors)) - addPartitionsToTxnManager.addTxnData(node1, transactionData(transactionalId2, producerId2), setErrors(transaction2Errors)) - addPartitionsToTxnManager.addTxnData(node0, transactionData(transactionalId3, producerId3), setErrors(transaction3Errors)) + addPartitionsToTxnManager.addTxnData(transactionalId1, producerId1, producerEpoch = 0, verifyOnly = true, topicPartitions, setErrors(transaction1Errors)) Review Comment: Right. -- 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