dajac commented on code in PR #14099: URL: https://github.com/apache/kafka/pull/14099#discussion_r1276663083
########## group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupMetadataManagerTest.java: ########## @@ -5692,12 +5725,60 @@ private void assertApiMessageAndVersionEquals( fromTopicPartitions(actualValue.partitionsPendingRevocation())); assertEquals(fromTopicPartitions(expectedValue.partitionsPendingAssignment()), fromTopicPartitions(actualValue.partitionsPendingAssignment())); - } else { - assertEquals(expected.message(), actual.message()); + } else if (actual.message() instanceof ConsumerGroupPartitionMetadataValue) { + // The order of the racks stored in PartitionMetadata of ConsumerGroupPartitionMetadataValue is not + // always guaranteed. Therefore, we need a special comparator. + ConsumerGroupPartitionMetadataValue expectedValue = + (ConsumerGroupPartitionMetadataValue) expected.message(); + ConsumerGroupPartitionMetadataValue actualValue = + (ConsumerGroupPartitionMetadataValue) actual.message(); + + List<ConsumerGroupPartitionMetadataValue.TopicMetadata> expectedTopicMetadataList = + expectedValue.topics(); + List<ConsumerGroupPartitionMetadataValue.TopicMetadata> actualTopicMetadataList = + actualValue.topics(); + + if (expectedTopicMetadataList.size() != actualTopicMetadataList.size()) { + fail("Topic metadata lists have different sizes"); + } + + for (int i = 0; i < expectedValue.topics().size(); i++) { + ConsumerGroupPartitionMetadataValue.TopicMetadata expectedTopicMetadata = + expectedTopicMetadataList.get(i); + ConsumerGroupPartitionMetadataValue.TopicMetadata actualTopicMetadata = + actualTopicMetadataList.get(i); + + assertEquals(expectedTopicMetadata.topicId(), actualTopicMetadata.topicId()); + assertEquals(expectedTopicMetadata.topicName(), actualTopicMetadata.topicName()); + assertEquals(expectedTopicMetadata.numPartitions(), actualTopicMetadata.numPartitions()); + + List<ConsumerGroupPartitionMetadataValue.PartitionMetadata> expectedPartitionMetadataList = + expectedTopicMetadata.partitionMetadata(); + List<ConsumerGroupPartitionMetadataValue.PartitionMetadata> actualPartitionMetadataList = + actualTopicMetadata.partitionMetadata(); + + // If the list is empty, rack information wasn't available for any replica of + // the partition and hence, the entry wasn't added to the record. + if (expectedPartitionMetadataList.size() != actualPartitionMetadataList.size()) { + fail("Partition metadata lists have different sizes"); + } else if (!expectedPartitionMetadataList.isEmpty() && !actualPartitionMetadataList.isEmpty()) { + for (int j = 0; j < expectedTopicMetadata.numPartitions(); j++) { Review Comment: Using numPartitions seems incorrect here as it could be larger than the number of partition metadata. -- 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