brandboat commented on code in PR #18448: URL: https://github.com/apache/kafka/pull/18448#discussion_r1915313092
########## core/src/test/scala/integration/kafka/coordinator/transaction/ProducerIntegrationTest.scala: ########## @@ -0,0 +1,185 @@ +/** + * 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 kafka.coordinator.transaction + +import kafka.network.SocketServer +import kafka.server.IntegrationTestUtils +import org.apache.kafka.clients.admin.{Admin, TransactionState} +import org.apache.kafka.clients.consumer.{Consumer, ConsumerConfig, ConsumerRecords, OffsetAndMetadata} +import org.apache.kafka.clients.producer.{Producer, ProducerConfig, ProducerRecord} +import org.apache.kafka.common.TopicPartition +import org.apache.kafka.common.test.api.{ClusterConfigProperty, ClusterFeature, ClusterInstance, ClusterTest, ClusterTestDefaults, ClusterTestExtensions, ClusterTests, Type} +import org.apache.kafka.common.message.InitProducerIdRequestData +import org.apache.kafka.common.network.ListenerName +import org.apache.kafka.common.protocol.Errors +import org.apache.kafka.common.record.RecordBatch +import org.apache.kafka.common.requests.{InitProducerIdRequest, InitProducerIdResponse} +import org.apache.kafka.common.test.TestUtils +import org.apache.kafka.coordinator.group.GroupCoordinatorConfig +import org.apache.kafka.coordinator.transaction.TransactionLogConfig +import org.apache.kafka.server.common.{Feature, MetadataVersion} +import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue} +import org.junit.jupiter.api.extension.ExtendWith + +import java.time.Duration +import java.util +import java.util.Collections +import java.util.stream.{Collectors, IntStream, StreamSupport} +import scala.concurrent.duration.DurationInt +import scala.jdk.CollectionConverters._ + +@ClusterTestDefaults(types = Array(Type.KRAFT), serverProperties = Array( + new ClusterConfigProperty(key = TransactionLogConfig.TRANSACTIONS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "1"), + new ClusterConfigProperty(key = TransactionLogConfig.TRANSACTIONS_TOPIC_PARTITIONS_CONFIG, value = "1"), + new ClusterConfigProperty(key = TransactionLogConfig.TRANSACTIONS_TOPIC_MIN_ISR_CONFIG, value = "1"), + new ClusterConfigProperty(key = GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "1"), + new ClusterConfigProperty(key = GroupCoordinatorConfig.OFFSETS_TOPIC_PARTITIONS_CONFIG, value = "1"), +)) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +class ProducerIntegrationTest { + + @ClusterTests(Array( + new ClusterTest(metadataVersion = MetadataVersion.IBP_3_3_IV0) + )) + def testUniqueProducerIds(clusterInstance: ClusterInstance): Unit = { + verifyUniqueIds(clusterInstance) + } + + @ClusterTests(Array( + new ClusterTest(features = Array( + new ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 0))), + new ClusterTest(features = Array( + new ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 1))), + new ClusterTest(features = Array( + new ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 2))), + )) + def testTransactionWithAndWithoutSend(cluster: ClusterInstance): Unit = { + val properties = new util.HashMap[String, Object] + properties.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "foobar") + properties.put(ProducerConfig.CLIENT_ID_CONFIG, "test") + properties.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true") + val producer: Producer[Array[Byte], Array[Byte]] = cluster.producer(properties) + try { + producer.initTransactions() + producer.beginTransaction() + producer.send(new ProducerRecord[Array[Byte], Array[Byte]]("test", "key".getBytes, "value".getBytes)) + producer.commitTransaction() + + producer.beginTransaction() + producer.commitTransaction() + } finally if (producer != null) producer.close() + } + + @ClusterTests(Array( + new ClusterTest(features = Array( + new ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 0))), + new ClusterTest(features = Array( + new ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 1))), + new ClusterTest(features = Array( + new ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 2))), + )) + def testTransactionWithSendOffset(cluster: ClusterInstance): Unit = { Review Comment: > I think the main thing I wanted to confirm is that if we attempted to send a record/offset, we can no longer do an empty commit. Sorry for the delay, I was a little bit confused about this comment, what does an empty commit means? Does `testTransactionWithAndWithoutSend` in ProducerIntegrationTest.scala cover that? -- 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]
