TaiJuWu commented on code in PR #18542:
URL: https://github.com/apache/kafka/pull/18542#discussion_r1918818927
##########
core/src/test/scala/unit/kafka/server/KafkaApisTest.scala:
##########
@@ -3612,175 +3569,6 @@ class KafkaApisTest extends Logging {
assertEquals(Set(0), response.brokers.asScala.map(_.id).toSet)
}
-
- /**
- * Metadata request to fetch all topics should not result in the followings:
- * 1) Auto topic creation
- * 2) UNKNOWN_TOPIC_OR_PARTITION
- *
- * This case is testing the case that a topic is being deleted from
MetadataCache right after
- * authorization but before checking in MetadataCache.
- */
- @Test
- def
testGetAllTopicMetadataShouldNotCreateTopicOrReturnUnknownTopicPartition():
Unit = {
- // Setup: authorizer authorizes 2 topics, but one got deleted in metadata
cache
- metadataCache = mock(classOf[ZkMetadataCache])
- when(metadataCache.getAliveBrokerNodes(any())).thenReturn(List(new
Node(brokerId,"localhost", 0)))
- when(metadataCache.getControllerId).thenReturn(None)
-
- // 2 topics returned for authorization in during handle
- val topicsReturnedFromMetadataCacheForAuthorization =
Set("remaining-topic", "later-deleted-topic")
-
when(metadataCache.getAllTopics()).thenReturn(topicsReturnedFromMetadataCacheForAuthorization)
- // 1 topic is deleted from metadata right at the time between
authorization and the next getTopicMetadata() call
- when(metadataCache.getTopicMetadata(
- ArgumentMatchers.eq(topicsReturnedFromMetadataCacheForAuthorization),
- any[ListenerName],
- anyBoolean,
- anyBoolean
- )).thenReturn(Seq(
- new MetadataResponseTopic()
- .setErrorCode(Errors.NONE.code)
- .setName("remaining-topic")
- .setIsInternal(false)
- ))
-
-
- var createTopicIsCalled: Boolean = false
- // Specific mock on zkClient for this use case
- // Expect it's never called to do auto topic creation
- when(zkClient.setOrCreateEntityConfigs(
- ArgumentMatchers.eq(ConfigType.TOPIC),
- anyString,
- any[Properties]
- )).thenAnswer(_ => {
- createTopicIsCalled = true
- })
- // No need to use
- when(zkClient.getAllBrokersInCluster)
- .thenReturn(Seq(new Broker(
- brokerId, "localhost", 9902,
- ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT),
SecurityProtocol.PLAINTEXT
- )))
-
-
- val (requestListener, _) = updateMetadataCacheWithInconsistentListeners()
- val response =
sendMetadataRequestWithInconsistentListeners(requestListener)
-
- assertFalse(createTopicIsCalled)
- val responseTopics = response.topicMetadata().asScala.map { metadata =>
metadata.topic() }
- assertEquals(List("remaining-topic"), responseTopics)
-
assertTrue(response.topicsByError(Errors.UNKNOWN_TOPIC_OR_PARTITION).isEmpty)
- }
-
- @Test
- def testUnauthorizedTopicMetadataRequest(): Unit = {
Review Comment:
Sorry for misunderstanding at that time.
File https://github.com/apache/kafka/pull/18578 to retrieve this test.
--
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]