chickenchickenlove commented on code in PR #23855:
URL: https://github.com/apache/kafka/pull/23855#discussion_r4411104794


##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/streams/StreamsTopologyTest.java:
##########
@@ -122,6 +128,142 @@ public void 
fromHeartbeatRequestShouldCreateCorrectTopology() {
         assertEquals(mkSubtopology2(), 
topology.subtopologies().get(SUBTOPOLOGY_ID_2));
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {"source", "regex", "repartition"})
+    public void copartitionOrderShouldNotAffectMatching(String topicType) {
+        // request has - [[0], [0, 1], [2, 3]]
+        // replayed has - [[3, 2], [1, 0], [0]]
+        StreamsGroupHeartbeatRequestData.Topology request = 
topologyWithCopartitionGroups(topicType);
+        StreamsGroupHeartbeatRequestData.Topology originalRequest = 
request.duplicate();
+
+        StreamsGroupTopologyValue record = 
StreamsCoordinatorRecordHelpers.convertToStreamsGroupTopologyRecord(request).duplicate();
+        List<StreamsGroupTopologyValue.CopartitionGroup> groups = 
record.subtopologies().get(0).copartitionGroups();
+        Collections.reverse(groups);
+        for (StreamsGroupTopologyValue.CopartitionGroup group : groups) {
+            Collections.reverse(group.sourceTopics());
+            Collections.reverse(group.sourceTopicRegex());
+            Collections.reverse(group.repartitionSourceTopics());
+        }
+        StreamsGroupTopologyValue originalRecord = record.duplicate();
+
+        StreamsTopology replayed = StreamsTopology.fromRecord(record);
+        StreamsTopology received = 
StreamsTopology.fromHeartbeatRequest(request);
+
+        assertTrue(replayed.matches(request));
+        assertTrue(received.matches(request));
+        assertNotEquals(received, replayed);
+        assertEquals(originalRecord, record);
+        assertEquals(originalRequest, request);
+    }
+
+    @Test
+    public void mixedCopartitionGroupsShouldMatchRegardlessOfOrder() {
+        // request has 'source - [1] / repartition - [3, 2]' and 'source - 
[1], repartition - [0]'
+        // reordered has 'source - [1], repartition - [0' and 'source - [1], 
repartition = [2, 3]'
+        StreamsGroupHeartbeatRequestData.Topology request = 
topologyWithCopartitionGroups("source");
+        request.subtopologies().get(0).setCopartitionGroups(List.of(
+            new StreamsGroupHeartbeatRequestData.CopartitionGroup()
+                .setSourceTopics(List.of((short) 1))
+                .setRepartitionSourceTopics(List.of((short) 3, (short) 2)),
+            new StreamsGroupHeartbeatRequestData.CopartitionGroup()
+                .setSourceTopics(List.of((short) 1))
+                .setRepartitionSourceTopics(List.of((short) 0))
+        ));
+
+        StreamsGroupTopologyValue record = 
StreamsCoordinatorRecordHelpers.convertToStreamsGroupTopologyRecord(request);
+        StreamsTopology replayed = StreamsTopology.fromRecord(record);
+
+        StreamsGroupHeartbeatRequestData.Topology reorderedRequest = 
request.duplicate();
+        
Collections.reverse(reorderedRequest.subtopologies().get(0).copartitionGroups());
+        reorderedRequest.subtopologies().get(0).copartitionGroups().get(1)
+            .setRepartitionSourceTopics(List.of((short) 2, (short) 3));
+
+        assertTrue(replayed.matches(reorderedRequest));
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"source", "regex", "repartition"})
+    public void differentCopartitionConstraintsShouldNotMatch(String 
topicType) {

Review Comment:
   I've added another parameterized 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]

Reply via email to