From 142d4fdbea00d82be2499f2247ac557350e78418 Mon Sep 17 00:00:00 2001 From: John Mannooparambil Date: Tue, 16 Apr 2024 11:15:51 -0400 Subject: [PATCH 1/2] add TopicImageNodeTest.java --- .../kafka/image/node/TopicImageNodeTest.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java b/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java index 83855d94b8c4..52bf6153091b 100644 --- a/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java +++ b/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java @@ -17,13 +17,19 @@ package org.apache.kafka.image.node; +import org.apache.kafka.common.DirectoryId; import org.apache.kafka.common.Uuid; import org.apache.kafka.image.TopicImage; +import org.apache.kafka.metadata.LeaderRecoveryState; +import org.apache.kafka.metadata.PartitionRegistration; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import java.util.Arrays; -import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.kafka.image.node.printer.NodeStringifier; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -32,11 +38,21 @@ @Timeout(value = 40) public class TopicImageNodeTest { - private final static TopicImageNode NODE = new TopicImageNode(new TopicImage("topic-image-node-test-topic", Uuid.ZERO_UUID, Collections.emptyMap())); + private final static TopicImageNode NODE = new TopicImageNode(newTopicImage("topic-image-node-test-topic", Uuid.ZERO_UUID, new PartitionRegistration.Builder().setReplicas(new int[] {2, 3, 4}). + setDirectories(DirectoryId.migratingArray(3)). + setIsr(new int[] {2, 3}).setLeader(2).setLeaderRecoveryState(LeaderRecoveryState.RECOVERED).setLeaderEpoch(1).setPartitionEpoch(345).build())); + private static TopicImage newTopicImage(String name, Uuid id, PartitionRegistration... partitions) { + Map partitionMap = new HashMap<>(); + int i = 0; + for (PartitionRegistration partition : partitions) { + partitionMap.put(i++, partition); + } + return new TopicImage(name, id, partitionMap); + } @Test public void testChildNames() { - assertEquals(Arrays.asList("name", "id"), NODE.childNames()); + assertEquals(Arrays.asList("name", "id", "0"), NODE.childNames()); } @Test @@ -57,4 +73,24 @@ public void testIdChild() { public void testUnknownChild() { assertNull(NODE.child("unknown")); } + + @Test + public void testChildPartitionId() { + MetadataNode child = NODE.child("0"); + assertNotNull(child); + NodeStringifier stringifier = new NodeStringifier(); + child.print(stringifier); + assertEquals("PartitionRegistration(replicas=[2, 3, 4], " + + "directories=[AAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAA], " + + "isr=[2, 3], removingReplicas=[], addingReplicas=[], elr=[], lastKnownElr=[], leader=2, " + + "leaderRecoveryState=RECOVERED, leaderEpoch=1, partitionEpoch=345)", stringifier.toString()); + } + + @Test + public void testChildPartitionIdNull() { + MetadataNode child1 = NODE.child("1"); + MetadataNode child2 = NODE.child("a"); + assertNull(child1); + assertNull(child2); + } } From 8f352abda37617197f235b3fc4b606a8220bc303 Mon Sep 17 00:00:00 2001 From: John Mannooparambil Date: Tue, 16 Apr 2024 12:35:07 -0400 Subject: [PATCH 2/2] remove unused imports --- .../java/org/apache/kafka/image/node/TopicImageNodeTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java b/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java index 52bf6153091b..8ecd4be28c90 100644 --- a/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java +++ b/metadata/src/test/java/org/apache/kafka/image/node/TopicImageNodeTest.java @@ -20,17 +20,14 @@ import org.apache.kafka.common.DirectoryId; import org.apache.kafka.common.Uuid; import org.apache.kafka.image.TopicImage; +import org.apache.kafka.image.node.printer.NodeStringifier; import org.apache.kafka.metadata.LeaderRecoveryState; import org.apache.kafka.metadata.PartitionRegistration; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; - import java.util.Arrays; import java.util.HashMap; import java.util.Map; - -import org.apache.kafka.image.node.printer.NodeStringifier; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull;