Search in sources :

Example 1 with StopReplicaTopicV1

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());
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StopReplicaRequestData(org.apache.kafka.common.message.StopReplicaRequestData) StopReplicaPartitionV0(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionV0) StopReplicaTopicState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState) TopicPartition(org.apache.kafka.common.TopicPartition) StopReplicaPartitionState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) StopReplicaTopicV1(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicV1)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 StopReplicaRequestData (org.apache.kafka.common.message.StopReplicaRequestData)1 StopReplicaPartitionState (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState)1 StopReplicaPartitionV0 (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionV0)1 StopReplicaTopicState (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState)1 StopReplicaTopicV1 (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicV1)1