use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicV1 in project kafka by apache.
the class StopReplicaRequestTest method testBuilderNormalization.
private void testBuilderNormalization(boolean deletePartitions) {
List<StopReplicaTopicState> topicStates = topicStates(deletePartitions);
Map<TopicPartition, StopReplicaPartitionState> expectedPartitionStates = StopReplicaRequestTest.partitionStates(topicStates);
for (short version : STOP_REPLICA.allVersions()) {
StopReplicaRequest request = new StopReplicaRequest.Builder(version, 0, 1, 0, deletePartitions, topicStates).build(version);
StopReplicaRequestData data = request.data();
if (version < 1) {
Set<TopicPartition> partitions = new HashSet<>();
for (StopReplicaPartitionV0 partition : data.ungroupedPartitions()) {
partitions.add(new TopicPartition(partition.topicName(), partition.partitionIndex()));
}
assertEquals(expectedPartitionStates.keySet(), partitions);
assertEquals(deletePartitions, data.deletePartitions());
} else if (version < 3) {
Set<TopicPartition> partitions = new HashSet<>();
for (StopReplicaTopicV1 topic : data.topics()) {
for (Integer partition : topic.partitionIndexes()) {
partitions.add(new TopicPartition(topic.name(), partition));
}
}
assertEquals(expectedPartitionStates.keySet(), partitions);
assertEquals(deletePartitions, data.deletePartitions());
} else {
Map<TopicPartition, StopReplicaPartitionState> partitionStates = StopReplicaRequestTest.partitionStates(data.topicStates());
assertEquals(expectedPartitionStates, partitionStates);
// Always false from V3 on
assertFalse(data.deletePartitions());
}
}
}
Aggregations