Search in sources :

Example 6 with StopReplicaPartitionState

use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState in project kafka by apache.

the class StopReplicaRequestTest method testGetErrorResponse.

@Test
public void testGetErrorResponse() {
    List<StopReplicaTopicState> topicStates = topicStates(true);
    Set<StopReplicaPartitionError> expectedPartitions = new HashSet<>();
    for (StopReplicaTopicState topicState : topicStates) {
        for (StopReplicaPartitionState partitionState : topicState.partitionStates()) {
            expectedPartitions.add(new StopReplicaPartitionError().setTopicName(topicState.topicName()).setPartitionIndex(partitionState.partitionIndex()).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code()));
        }
    }
    for (short version : STOP_REPLICA.allVersions()) {
        StopReplicaRequest.Builder builder = new StopReplicaRequest.Builder(version, 0, 0, 0L, false, topicStates);
        StopReplicaRequest request = builder.build();
        StopReplicaResponse response = request.getErrorResponse(0, new ClusterAuthorizationException("Not authorized"));
        assertEquals(Errors.CLUSTER_AUTHORIZATION_FAILED, response.error());
        assertEquals(expectedPartitions, new HashSet<>(response.partitionErrors()));
    }
}
Also used : StopReplicaTopicState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState) StopReplicaPartitionError(org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError) StopReplicaPartitionState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 7 with StopReplicaPartitionState

use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState 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)

Example 8 with StopReplicaPartitionState

use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState in project kafka by apache.

the class StopReplicaRequestTest method testPartitionStatesNormalization.

@Test
public void testPartitionStatesNormalization() {
    List<StopReplicaTopicState> topicStates = topicStates(true);
    for (short version : STOP_REPLICA.allVersions()) {
        // Create a request for version to get its serialized form
        StopReplicaRequest baseRequest = new StopReplicaRequest.Builder(version, 0, 1, 0, true, topicStates).build(version);
        // Construct the request from the buffer
        StopReplicaRequest request = StopReplicaRequest.parse(baseRequest.serialize(), version);
        Map<TopicPartition, StopReplicaPartitionState> partitionStates = request.partitionStates();
        assertEquals(6, partitionStates.size());
        for (StopReplicaTopicState expectedTopicState : topicStates) {
            for (StopReplicaPartitionState expectedPartitionState : expectedTopicState.partitionStates()) {
                TopicPartition tp = new TopicPartition(expectedTopicState.topicName(), expectedPartitionState.partitionIndex());
                StopReplicaPartitionState partitionState = partitionStates.get(tp);
                assertEquals(expectedPartitionState.partitionIndex(), partitionState.partitionIndex());
                assertTrue(partitionState.deletePartition());
                if (version >= 3) {
                    assertEquals(expectedPartitionState.leaderEpoch(), partitionState.leaderEpoch());
                } else {
                    assertEquals(-1, partitionState.leaderEpoch());
                }
            }
        }
    }
}
Also used : StopReplicaTopicState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState) TopicPartition(org.apache.kafka.common.TopicPartition) StopReplicaPartitionState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState) Test(org.junit.jupiter.api.Test)

Example 9 with StopReplicaPartitionState

use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState in project kafka by apache.

the class StopReplicaResponseTest method testErrorCountsFromGetErrorResponse.

@Test
public void testErrorCountsFromGetErrorResponse() {
    List<StopReplicaTopicState> topicStates = new ArrayList<>();
    topicStates.add(new StopReplicaTopicState().setTopicName("foo").setPartitionStates(Arrays.asList(new StopReplicaPartitionState().setPartitionIndex(0), new StopReplicaPartitionState().setPartitionIndex(1))));
    for (short version : STOP_REPLICA.allVersions()) {
        StopReplicaRequest request = new StopReplicaRequest.Builder(version, 15, 20, 0, false, topicStates).build(version);
        StopReplicaResponse response = request.getErrorResponse(0, Errors.CLUSTER_AUTHORIZATION_FAILED.exception());
        assertEquals(Collections.singletonMap(Errors.CLUSTER_AUTHORIZATION_FAILED, 3), response.errorCounts());
    }
}
Also used : StopReplicaTopicState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState) ArrayList(java.util.ArrayList) StopReplicaPartitionState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState) Test(org.junit.jupiter.api.Test)

Aggregations

StopReplicaPartitionState (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState)9 StopReplicaTopicState (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState)9 ArrayList (java.util.ArrayList)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 Test (org.junit.jupiter.api.Test)4 StopReplicaPartitionError (org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 StopReplicaRequestData (org.apache.kafka.common.message.StopReplicaRequestData)2 StopReplicaPartitionV0 (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionV0)2 StopReplicaTopicV1 (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicV1)2 StopReplicaResponseData (org.apache.kafka.common.message.StopReplicaResponseData)2 Errors (org.apache.kafka.common.protocol.Errors)2 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ClusterAuthorizationException (org.apache.kafka.common.errors.ClusterAuthorizationException)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1