public static AssignReplicasToDirsRequestData buildRequestData(int brokerId, long brokerEpoch, Map<TopicIdPartition, Uuid> assignment) {
        Map<Uuid, AssignReplicasToDirsRequestData.DirectoryData> directoryMap = new HashMap<>();
        Map<Uuid, Map<Uuid, AssignReplicasToDirsRequestData.TopicData>> topicMap = new HashMap<>();
        for (Map.Entry<TopicIdPartition, Uuid> entry : assignment.entrySet()) {
            TopicIdPartition topicPartition = entry.getKey();
            Uuid directoryId = entry.getValue();
            AssignReplicasToDirsRequestData.DirectoryData directory = directoryMap.computeIfAbsent(directoryId, d -> new AssignReplicasToDirsRequestData.DirectoryData().setId(directoryId));
            AssignReplicasToDirsRequestData.TopicData topic = topicMap.computeIfAbsent(directoryId, d -> new HashMap<>())
                    .computeIfAbsent(topicPartition.topicId(), topicId -> {
                        AssignReplicasToDirsRequestData.TopicData data = new AssignReplicasToDirsRequestData.TopicData().setTopicId(topicId);
                        directory.topics().add(data);
                        return data;
                    });
            AssignReplicasToDirsRequestData.PartitionData partition = new AssignReplicasToDirsRequestData.PartitionData().setPartitionIndex(topicPartition.partitionId());
            topic.partitions().add(partition);
        }
        return new AssignReplicasToDirsRequestData()
                .setBrokerId(brokerId)
                .setBrokerEpoch(brokerEpoch)
                .setDirectories(new ArrayList<>(directoryMap.values()));
    }
@Test
    public void testBuildRequestData() {
        Map<TopicIdPartition, Uuid> assignment = new HashMap<TopicIdPartition, Uuid>() {{
                put(new TopicIdPartition(TOPIC_1, 1), DIR_1);
                put(new TopicIdPartition(TOPIC_1, 2), DIR_2);
                put(new TopicIdPartition(TOPIC_1, 3), DIR_3);
                put(new TopicIdPartition(TOPIC_1, 4), DIR_1);
                put(new TopicIdPartition(TOPIC_2, 5), DIR_2);
            }};
        AssignReplicasToDirsRequestData built = AssignmentsHelper.buildRequestData(8, 100L, assignment);
        AssignReplicasToDirsRequestData expected = new AssignReplicasToDirsRequestData()
                .setBrokerId(8)
                .setBrokerEpoch(100L)
                .setDirectories(Arrays.asList(
                        new AssignReplicasToDirsRequestData.DirectoryData()
                                .setId(DIR_2)
                                .setTopics(Arrays.asList(
                                        new AssignReplicasToDirsRequestData.TopicData()
                                                .setTopicId(TOPIC_1)
                                                .setPartitions(Collections.singletonList(
                                                        new AssignReplicasToDirsRequestData.PartitionData()
                                                                .setPartitionIndex(2)
                                                )),
                                        new AssignReplicasToDirsRequestData.TopicData()
                                                .setTopicId(TOPIC_2)
                                                .setPartitions(Collections.singletonList(
                                                        new AssignReplicasToDirsRequestData.PartitionData()
                                                                .setPartitionIndex(5)
                                                ))
                                )),
                        new AssignReplicasToDirsRequestData.DirectoryData()
                                .setId(DIR_3)
                                .setTopics(Collections.singletonList(
                                        new AssignReplicasToDirsRequestData.TopicData()
                                                .setTopicId(TOPIC_1)
                                                .setPartitions(Collections.singletonList(
                                                        new AssignReplicasToDirsRequestData.PartitionData()
                                                                .setPartitionIndex(3)
                                                ))
                                )),
                        new AssignReplicasToDirsRequestData.DirectoryData()
                                .setId(DIR_1)
                                .setTopics(Collections.singletonList(
                                        new AssignReplicasToDirsRequestData.TopicData()
                                                .setTopicId(TOPIC_1)
                                                .setPartitions(Arrays.asList(
                                                        new AssignReplicasToDirsRequestData.PartitionData()
                                                                .setPartitionIndex(4),
                                                        new AssignReplicasToDirsRequestData.PartitionData()
                                                                .setPartitionIndex(1)
                                                ))
                                ))
                ));
        assertEquals(AssignmentsHelper.normalize(expected), AssignmentsHelper.normalize(built));
    }