rreddy-22 commented on code in PR #15974: URL: https://github.com/apache/kafka/pull/15974#discussion_r1610388120
########## group-coordinator/src/test/java/org/apache/kafka/coordinator/group/AssignmentTestUtil.java: ########## @@ -82,4 +83,34 @@ public static void assertAssignment( assertEquals(expectedAssignment.get(memberId), computedAssignmentForMember); }); } + + /** + * Generate a reverse look up map of partition to member target assignments from the given member spec. + * + * @param memberSpec A map where the key is the member Id and the value is an + * AssignmentMemberSpec object containing the member's partition assignments. + * @return Map of topic partition to member assignments. + */ + public static Map<Uuid, Map<Integer, String>> invertedTargetAssignment( + Map<String, AssignmentMemberSpec> memberSpec + ) { + Map<Uuid, Map<Integer, String>> invertedTargetAssignment = new HashMap<>(); + for (Map.Entry<String, AssignmentMemberSpec> memberEntry : memberSpec.entrySet()) { + String memberId = memberEntry.getKey(); + Map<Uuid, Set<Integer>> topicsAndPartitions = memberEntry.getValue().assignedPartitions(); + + for (Map.Entry<Uuid, Set<Integer>> topicEntry : topicsAndPartitions.entrySet()) { + Uuid topicId = topicEntry.getKey(); + Set<Integer> partitions = topicEntry.getValue(); + + invertedTargetAssignment.putIfAbsent(topicId, new HashMap<>()); + Map<Integer, String> partitionMap = invertedTargetAssignment.get(topicId); Review Comment: It returns null, since putIdAbsent returns the prev value associated with the key ########## group-coordinator/src/test/java/org/apache/kafka/coordinator/group/AssignmentTestUtil.java: ########## @@ -82,4 +83,34 @@ public static void assertAssignment( assertEquals(expectedAssignment.get(memberId), computedAssignmentForMember); }); } + + /** + * Generate a reverse look up map of partition to member target assignments from the given member spec. + * + * @param memberSpec A map where the key is the member Id and the value is an + * AssignmentMemberSpec object containing the member's partition assignments. + * @return Map of topic partition to member assignments. + */ + public static Map<Uuid, Map<Integer, String>> invertedTargetAssignment( + Map<String, AssignmentMemberSpec> memberSpec + ) { + Map<Uuid, Map<Integer, String>> invertedTargetAssignment = new HashMap<>(); + for (Map.Entry<String, AssignmentMemberSpec> memberEntry : memberSpec.entrySet()) { + String memberId = memberEntry.getKey(); + Map<Uuid, Set<Integer>> topicsAndPartitions = memberEntry.getValue().assignedPartitions(); + + for (Map.Entry<Uuid, Set<Integer>> topicEntry : topicsAndPartitions.entrySet()) { + Uuid topicId = topicEntry.getKey(); + Set<Integer> partitions = topicEntry.getValue(); + + invertedTargetAssignment.putIfAbsent(topicId, new HashMap<>()); + Map<Integer, String> partitionMap = invertedTargetAssignment.get(topicId); Review Comment: It returns null, since putIfAbsent returns the prev value associated with the key -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org