@@ -33,6 +33,7 @@ import org.apache.kafka.common.config.ConfigResource
3333import org .apache .kafka .common .config .ConfigResource .Type .{BROKER , BROKER_LOGGER }
3434import org .apache .kafka .common .errors .{ClusterAuthorizationException , UnsupportedVersionException }
3535import org .apache .kafka .common .internals .Topic
36+ import org .apache .kafka .common .internals .Topic .SHARE_GROUP_STATE_TOPIC_NAME
3637import org .apache .kafka .common .memory .MemoryPool
3738import org .apache .kafka .common .message .AddPartitionsToTxnRequestData .{AddPartitionsToTxnTopic , AddPartitionsToTxnTopicCollection , AddPartitionsToTxnTransaction , AddPartitionsToTxnTransactionCollection }
3839import org .apache .kafka .common .message .AddPartitionsToTxnResponseData .AddPartitionsToTxnResult
@@ -88,7 +89,7 @@ import org.apache.kafka.server.authorizer.{Action, AuthorizationResult, Authoriz
8889import org .apache .kafka .server .common .{FeatureVersion , FinalizedFeatures , GroupVersion , KRaftVersion , MetadataVersion , RequestLocal , TransactionVersion }
8990import org .apache .kafka .server .config .{KRaftConfigs , ReplicationConfigs , ServerConfigs , ServerLogConfigs }
9091import org .apache .kafka .server .metrics .ClientMetricsTestUtils
91- import org .apache .kafka .server .share .{CachedSharePartition , ErroneousAndValidPartitionData }
92+ import org .apache .kafka .server .share .{CachedSharePartition , ErroneousAndValidPartitionData , SharePartitionKey }
9293import org .apache .kafka .server .quota .ThrottleCallback
9394import org .apache .kafka .server .share .acknowledge .ShareAcknowledgementBatch
9495import org .apache .kafka .server .share .context .{FinalContext , ShareSessionContext }
@@ -789,6 +790,34 @@ class KafkaApisTest extends Logging {
789790 assertEquals(expectedResponse, response.data)
790791 }
791792
793+ @ Test
794+ def testFindCoordinatorWithValidSharePartitionKey (): Unit = {
795+ addTopicToMetadataCache(SHARE_GROUP_STATE_TOPIC_NAME , 10 , 3 )
796+ val key = SharePartitionKey .getInstance(" foo" , Uuid .randomUuid(), 10 )
797+
798+ val request = new FindCoordinatorRequestData ()
799+ .setKeyType(CoordinatorType .SHARE .id)
800+ .setCoordinatorKeys(asList(key.asCoordinatorKey))
801+
802+ val requestChannelRequest = buildRequest(new FindCoordinatorRequest .Builder (request).build())
803+
804+ kafkaApis = createKafkaApis()
805+ kafkaApis.handle(requestChannelRequest, RequestLocal .noCaching)
806+
807+ when(shareCoordinator.partitionFor(ArgumentMatchers .eq(key))).thenReturn(10 )
808+
809+ val expectedResponse = new FindCoordinatorResponseData ()
810+ .setCoordinators(asList(
811+ new FindCoordinatorResponseData .Coordinator ()
812+ .setKey(key.asCoordinatorKey)
813+ .setNodeId(0 )
814+ .setHost(" broker0" )
815+ .setPort(9092 )))
816+
817+ val response = verifyNoThrottling[FindCoordinatorResponse ](requestChannelRequest)
818+ assertEquals(expectedResponse, response.data)
819+ }
820+
792821 @ Test
793822 def testMetadataAutoTopicCreationForOffsetTopic (): Unit = {
794823 testMetadataAutoTopicCreation(Topic .GROUP_METADATA_TOPIC_NAME , enableAutoTopicCreation = true ,
0 commit comments