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


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

Review Comment:
   The quota tests are almost time-based, and that is not stable in our CI. 
Maybe we can just verify the "settings". For example:
   
   1. add quota
   2. describe quota to make sure the quota are updated
   3. delete quota
   4. describe quota to make sure the quota are deleted
   
   WDYT?



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