jolshan commented on code in PR #13391:
URL: https://github.com/apache/kafka/pull/13391#discussion_r1163418845


##########
core/src/test/scala/unit/kafka/server/AddPartitionsToTxnManagerTest.scala:
##########
@@ -0,0 +1,238 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package unit.kafka.server
+
+import kafka.common.RequestAndCompletionHandler
+import kafka.server.{AddPartitionsToTxnManager, KafkaConfig}
+import kafka.utils.TestUtils
+import org.apache.kafka.clients.{ClientResponse, NetworkClient}
+import org.apache.kafka.common.errors.{AuthenticationException, 
SaslAuthenticationException, UnsupportedVersionException}
+import 
org.apache.kafka.common.message.AddPartitionsToTxnRequestData.{AddPartitionsToTxnTopic,
 AddPartitionsToTxnTopicCollection, AddPartitionsToTxnTransaction, 
AddPartitionsToTxnTransactionCollection}
+import org.apache.kafka.common.message.AddPartitionsToTxnResponseData
+import 
org.apache.kafka.common.message.AddPartitionsToTxnResponseData.AddPartitionsToTxnResultCollection
+import org.apache.kafka.common.{Node, TopicPartition}
+import org.apache.kafka.common.protocol.Errors
+import org.apache.kafka.common.requests.{AbstractResponse, 
AddPartitionsToTxnRequest, AddPartitionsToTxnResponse}
+import org.apache.kafka.common.utils.MockTime
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.mockito.Mockito.mock
+
+import scala.collection.mutable
+import scala.jdk.CollectionConverters._
+
+class AddPartitionsToTxnManagerTest {
+  private val networkClient: NetworkClient = mock(classOf[NetworkClient])
+
+  private val time = new MockTime
+
+  private var addPartitionsToTxnManager: AddPartitionsToTxnManager = _
+
+  val topic = "foo"
+  val topicPartitions = List(new TopicPartition(topic, 1), new 
TopicPartition(topic, 2), new TopicPartition(topic, 3))
+
+  private val node0 = new Node(0, "host1", 0)
+  private val node1 = new Node(1, "host2", 1)
+  private val node2 = new Node(2, "host2", 2)
+
+  private val transactionalId1 = "txn1"
+  private val transactionalId2 = "txn2"
+  private val transactionalId3 = "txn3"
+
+  private val producerId1 = 0L
+  private val producerId2 = 1L
+  private val producerId3 = 2L
+
+  private val authenticationErrorResponse = clientResponse(null, authException 
= new SaslAuthenticationException(""))
+  private val versionMismatchResponse = clientResponse(null, mismatchException 
= new UnsupportedVersionException(""))  
+
+  @BeforeEach
+  def setup(): Unit = {
+    addPartitionsToTxnManager = new AddPartitionsToTxnManager(
+      KafkaConfig.fromProps(TestUtils.createBrokerConfig(1, "localhost:2181")),
+      networkClient,
+      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)
+    }
+  }
+
+  @Test
+  def testAddTxnData(): Unit = {
+    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))
+
+    val transaction1AgainErrorsOldEpoch = mutable.Map[TopicPartition, Errors]()
+    val transaction1AgainErrorsNewEpoch = mutable.Map[TopicPartition, Errors]()
+    // Trying to add more transactional data for the same transactional ID, 
producer ID, and epoch should simply replace the old data. The error map should 
remain empty.

Review Comment:
   It means that we didn't complete the request. If we returned an error 
response, we would populate the map. But if it just replaced the old data, we 
don't send a response.



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