FrankYang0529 commented on code in PR #19635:
URL: https://github.com/apache/kafka/pull/19635#discussion_r2073385142


##########
core/src/test/scala/unit/kafka/server/KafkaApisTest.scala:
##########
@@ -2354,6 +2354,65 @@ class KafkaApisTest extends Logging {
     }
   }
 
+  @Test
+  def shouldReturnUnauthorizationForNonExistingTopicInProduceResponse(): Unit 
= {
+    val topic = "topic"
+    val topicId = Uuid.fromString("d2Gg8tgzJa2JYK2eTHUapg")
+    val tp = new TopicIdPartition(topicId, 0, topic)
+
+    val authorizer: Authorizer = mock(classOf[Authorizer])
+    when(authorizer.authorize(any[RequestContext], any[util.List[Action]]))
+      .thenReturn(Seq(AuthorizationResult.DENIED).asJava)
+    for (version <- ApiKeys.PRODUCE.oldestVersion to 
ApiKeys.PRODUCE.latestVersion) {
+
+      reset(replicaManager, clientQuotaManager, clientRequestQuotaManager, 
requestChannel, txnCoordinator)
+
+      val produceData = new ProduceRequestData.TopicProduceData()
+        .setPartitionData(util.List.of(
+          new ProduceRequestData.PartitionProduceData()
+            .setIndex(tp.partition)
+            .setRecords(MemoryRecords.withRecords(Compression.NONE, new 
SimpleRecord("test".getBytes)))))
+
+      if (version >= 13 ) {
+        produceData.setTopicId(topicId)
+      } else {
+        produceData.setName(tp.topic)
+      }
+
+      val produceRequest = ProduceRequest.builder(new ProduceRequestData()
+          .setTopicData(new ProduceRequestData.TopicProduceDataCollection(
+            util.List.of(produceData)
+              .iterator))
+          .setAcks(1.toShort)
+          .setTimeoutMs(5000))
+        .build(version.toShort)
+      val request = buildRequest(produceRequest)
+
+      
when(clientRequestQuotaManager.maybeRecordAndGetThrottleTimeMs(any[RequestChannel.Request](),
+        any[Long])).thenReturn(0)
+      when(clientQuotaManager.maybeRecordAndGetThrottleTimeMs(
+        any[RequestChannel.Request](), anyDouble, anyLong)).thenReturn(0)
+      val kafkaApis = createKafkaApis(authorizer = Some(authorizer))
+      try {
+        kafkaApis.handleProduceRequest(request, 
RequestLocal.withThreadConfinedCaching)
+
+        val response = verifyNoThrottling[ProduceResponse](request)
+
+        assertEquals(1, response.data.responses.size)
+        val topicProduceResponse = response.data.responses.asScala.head
+        assertEquals(1, topicProduceResponse.partitionResponses.size)
+        val partitionProduceResponse = 
topicProduceResponse.partitionResponses.asScala.head
+        if (version >= 13 ) {

Review Comment:
   @chia7712 Thanks for review. I change to use integration test. Could you 
review again? Thanks.



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