frankvicky commented on code in PR #24148:
URL: https://github.com/apache/kafka/pull/24148#discussion_r4514259482


##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/streams/topics/InternalTopicManagerTest.java:
##########
@@ -108,6 +109,99 @@ void testConfigureTopics() {
         assertEquals(expectedConfiguredTopology, 
configuredTopology.subtopologies());
     }
 
+    @Test
+    void 
testConfigureTopicsIgnoresUnrelatedFixedRepartitionTopicsForCopartitionGroup() {
+        MetadataImage metadataImage = new MetadataImageBuilder()
+            .addTopic(Uuid.randomUuid(), "left", 2)
+            .addTopic(Uuid.randomUuid(), "right", 4)
+            .addTopic(Uuid.randomUuid(), "other-a", 1)
+            .addTopic(Uuid.randomUuid(), "other-b", 1)
+            .build();
+
+        final ConfiguredTopology configuredTopology = 
InternalTopicManager.configureTopics(
+            LOG, "test-group", "test-member", 0, 
makeTopologyWithUnrelatedFixedRepartitionTopics(),
+            new KRaftCoordinatorMetadataImage(metadataImage), TIME);
+
+        assertEquals(
+            Optional.of(Status.MISSING_INTERNAL_TOPICS),
+            
configuredTopology.topicConfigurationException().map(TopicConfigurationException::status));
+        final Map<String, CreatableTopic> toCreate = 
configuredTopology.internalTopicsToBeCreated();
+        assertEquals(4, toCreate.get("left-repartition").numPartitions());
+        assertEquals(4, toCreate.get("right-repartition").numPartitions());
+        assertEquals(3, toCreate.get("fixed-3-repartition").numPartitions());
+        assertEquals(5, toCreate.get("fixed-5-repartition").numPartitions());
+
+        final ConfiguredSubtopology joinSubtopology = 
configuredTopology.subtopologies().orElseThrow().get("join-sub");
+        assertEquals(4, joinSubtopology.numberOfTasks());
+        assertEquals(4, 
joinSubtopology.repartitionSourceTopics().get("left-repartition").numberOfPartitions());
+        assertEquals(4, 
joinSubtopology.repartitionSourceTopics().get("right-repartition").numberOfPartitions());
+    }
+
+    @Test
+    void 
testConfigureTopicsCreatesMissingCopartitionedRepartitionTopicWithPartitionCountOfExistingSibling()
 {
+        // "left-repartition" already exists with more partitions than its 
sources suggest, "right-repartition" is missing.
+        MetadataImage metadataImage = new MetadataImageBuilder()
+            .addTopic(Uuid.randomUuid(), "left", 2)
+            .addTopic(Uuid.randomUuid(), "right", 4)
+            .addTopic(Uuid.randomUuid(), "other-a", 1)
+            .addTopic(Uuid.randomUuid(), "other-b", 1)
+            .addTopic(Uuid.randomUuid(), "left-repartition", 6)
+            .build();
+
+        final ConfiguredTopology configuredTopology = 
InternalTopicManager.configureTopics(
+            LOG, "test-group", "test-member", 0, 
makeTopologyWithUnrelatedFixedRepartitionTopics(),
+            new KRaftCoordinatorMetadataImage(metadataImage), TIME);
+
+        final Map<String, CreatableTopic> toCreate = 
configuredTopology.internalTopicsToBeCreated();
+        assertEquals(6, toCreate.get("right-repartition").numPartitions());

Review Comment:
   nit: For symmetry with the test above, could we assert the status first?
   
   ```java
   assertEquals(
       Optional.of(Status.MISSING_INTERNAL_TOPICS),
       
configuredTopology.topicConfigurationException().map(TopicConfigurationException::status));
   ```
   
   If the enforcer ever picked 4 instead of 6 here, `missingInternalTopics` 
would throw `INCORRECTLY_PARTITIONED_TOPICS` for the existing 
`left-repartition`, `internalTopicsToBeCreated()` would be empty, and this test 
would fail with an NPE on this line rather than with the actual status.



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

Reply via email to