jolshan commented on code in PR #15023:
URL: https://github.com/apache/kafka/pull/15023#discussion_r1432810817
##########
clients/src/test/java/org/apache/kafka/clients/MetadataTest.java:
##########
@@ -1068,143 +1067,328 @@ protected boolean retainTopic(String topic, boolean
isInternal, long nowMs) {
}
@Test
- public void testUpdatePartitionLeadership() {
+ public void testTopicMetadataOnUpdatePartitionLeadership() {
+ String topic = "input-topic";
+ Uuid topicId = Uuid.randomUuid();
+
+ Time time = new MockTime();
+
+ metadata = new Metadata(
+ refreshBackoffMs,
+ refreshBackoffMaxMs,
+ metadataExpireMs,
+ new LogContext(),
+ new ClusterResourceListeners());
+ Node node1 = new Node(1, "localhost", 9091);
+ Node node2 = new Node(2, "localhost", 9091);
+
+ TopicPartition tp0 = new TopicPartition(topic, 0);
+ MetadataResponse.PartitionMetadata partition0 = new
MetadataResponse.PartitionMetadata(
+ Errors.NONE,
+ tp0,
+ Optional.of(1),
+ Optional.of(1),
+ Arrays.asList(1, 2),
+ Arrays.asList(1, 2),
+ Collections.emptyList()
+ );
+ TopicPartition tp1 = new TopicPartition(topic, 1);
+ MetadataResponse.PartitionMetadata partition1 =
+ new MetadataResponse.PartitionMetadata(
+ Errors.NONE,
+ tp1,
+ Optional.of(1),
+ Optional.of(1),
+ Arrays.asList(1, 2),
+ Arrays.asList(1, 2),
+ Collections.emptyList()
+ );
+ MetadataResponse.TopicMetadata topicMetadata = new
MetadataResponse.TopicMetadata(
+ Errors.NONE,
+ topic,
+ topicId,
+ false,
+ Arrays.asList(partition0, partition1),
+ MetadataResponse.AUTHORIZED_OPERATIONS_OMITTED
+ );
+
+ // Initialize metadata with two partitions
+ MetadataResponse response = RequestTestUtils.metadataResponse(
+ Arrays.asList(node1, node2),
+ "clusterId",
+ node1.id(),
+ Collections.singletonList(topicMetadata));
+ metadata.updateWithCurrentRequestVersion(
+ response,
+ false,
+ time.milliseconds());
+ assertEquals(2, metadata.fetch().partitionsForTopic(topic).size());
+ assertEquals(1, metadata.fetch().partition(tp0).leader().id());
+ assertEquals(1, metadata.fetch().partition(tp1).leader().id());
+
+ // "input-topic" partition 1 leader changes from node 1 to node 2
+ metadata.updatePartitionLeadership(
Review Comment:
Maybe we could just have a comment there (in the 1130 comment)
something like: In KIP-951 we can update leadership info for a single
partition. "input-topic partition 1...(everything else you said)
--
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]