unknowntpo commented on code in PR #16687:
URL: https://github.com/apache/kafka/pull/16687#discussion_r1690609481


##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -94,6 +94,59 @@ class PlaintextAdminIntegrationTest extends 
BaseAdminIntegrationTest {
     super.tearDown()
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("zk", "kraft"))
+  def testCreatePartitionWithOptionRetryOnQuotaViolation(): Unit = {
+    client = createAdminClient
+
+    val brokerIds = brokers.map(_.config.brokerId).toSet
+    brokerIds.foreach(id => TestUtils.waitForOnlineBroker(client, id))
+
+    val topicNums = 30
+
+    def makeTopics(): java.util.List[String] = {
+      val topics = for (i <- 0 until topicNums) yield {
+        val topicName = s"topic-$i"
+        createTopic(topicName)
+        topicName
+      }
+      topics.toList.asJava
+    }
+
+    val topics = makeTopics()
+
+    waitForTopics(client, topics.asScala.toSeq, List())
+    ensureConsistentKRaftMetadata()
+
+    val entity = new ClientQuotaEntity(Map(ClientQuotaEntity.CLIENT_ID -> 
"test-client-id").asJava)
+
+    val quotas = Seq(new 
ClientQuotaAlteration.Op(QuotaConfigs.CONTROLLER_MUTATION_RATE_OVERRIDE_CONFIG, 
1))
+    val alterResult = client.alterClientQuotas(Seq(new 
ClientQuotaAlteration(entity, quotas.asJava)).asJava)
+    alterResult.all.get
+
+    def makeCreatePartitionCalls(topics: java.util.List[String], 
numPartitions: Int, retry: Boolean): java.util.Collection[KafkaFuture[Void]] = {
+      val futures = topics.asScala.map{
+        topic => client.createPartitions(Map(topic -> 
NewPartitions.increaseTo(numPartitions)).asJava, new 
CreatePartitionsOptions().timeoutMs(30000).retryOnQuotaViolation(retry)).all()
+      }
+      futures.toList.asJavaCollection
+    }
+
+    def countFailedFutures(futures: java.util.Collection[KafkaFuture[Void]]): 
Int = {
+      futures.asScala.count {future =>
+        Try(future.get()) match {
+          case Failure(e: ExecutionException) if 
e.getCause.isInstanceOf[ThrottlingQuotaExceededException] => true
+          case _ => false
+        }
+      }
+    }
+
+    val failedFuture = makeCreatePartitionCalls(topics, 3, retry = false)
+    assert(countFailedFutures(failedFuture) > 0, s"Expected at least one 
future to fail, but none failed")
+
+    val successFutures = makeCreatePartitionCalls(topics, 3, retry = true)

Review Comment:
   Actually, I got lots of `TimeoutException` here, and when call 
`makeCreatePartitionCalls` with `numPartitions = 6` and `retry = true`, I still 
got some `ThrottlingQuotaExceededException`s.



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