Search in sources :

Example 1 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrRequestTest method testGetErrorResponse.

@Test
public void testGetErrorResponse() {
    Uuid topicId = Uuid.randomUuid();
    String topicName = "topic";
    int partition = 0;
    for (short version : LEADER_AND_ISR.allVersions()) {
        LeaderAndIsrRequest request = new LeaderAndIsrRequest.Builder(version, 0, 0, 0, Collections.singletonList(new LeaderAndIsrPartitionState().setTopicName(topicName).setPartitionIndex(partition)), Collections.singletonMap(topicName, topicId), Collections.emptySet()).build(version);
        LeaderAndIsrResponse response = request.getErrorResponse(0, new ClusterAuthorizationException("Not authorized"));
        assertEquals(Errors.CLUSTER_AUTHORIZATION_FAILED, response.error());
        if (version < 5) {
            assertEquals(Collections.singletonList(new LeaderAndIsrPartitionError().setTopicName(topicName).setPartitionIndex(partition).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code())), response.data().partitionErrors());
            assertEquals(0, response.data().topics().size());
        } else {
            LeaderAndIsrTopicError topicState = response.topics().find(topicId);
            assertEquals(topicId, topicState.topicId());
            assertEquals(Collections.singletonList(new LeaderAndIsrPartitionError().setPartitionIndex(partition).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code())), topicState.partitionErrors());
            assertEquals(0, response.data().partitionErrors().size());
        }
    }
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Uuid(org.apache.kafka.common.Uuid) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState) Test(org.junit.jupiter.api.Test)

Example 2 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrResponseTest method createPartitions.

private List<LeaderAndIsrPartitionError> createPartitions(String topicName, List<Errors> errors) {
    List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
    int partitionIndex = 0;
    for (Errors error : errors) {
        partitions.add(new LeaderAndIsrPartitionError().setTopicName(topicName).setPartitionIndex(partitionIndex++).setErrorCode(error.code()));
    }
    return partitions;
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) ArrayList(java.util.ArrayList)

Example 3 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrResponseTest method testToString.

@Test
public void testToString() {
    for (short version : LEADER_AND_ISR.allVersions()) {
        LeaderAndIsrResponse response;
        if (version < 5) {
            List<LeaderAndIsrPartitionError> partitions = createPartitions("foo", asList(Errors.NONE, Errors.CLUSTER_AUTHORIZATION_FAILED));
            response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setPartitionErrors(partitions), version);
            String responseStr = response.toString();
            assertTrue(responseStr.contains(LeaderAndIsrResponse.class.getSimpleName()));
            assertTrue(responseStr.contains(partitions.toString()));
            assertTrue(responseStr.contains("errorCode=" + Errors.NONE.code()));
        } else {
            Uuid id = Uuid.randomUuid();
            LeaderAndIsrTopicErrorCollection topics = createTopic(id, asList(Errors.NONE, Errors.CLUSTER_AUTHORIZATION_FAILED));
            response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setTopics(topics), version);
            String responseStr = response.toString();
            assertTrue(responseStr.contains(LeaderAndIsrResponse.class.getSimpleName()));
            assertTrue(responseStr.contains(topics.toString()));
            assertTrue(responseStr.contains(id.toString()));
            assertTrue(responseStr.contains("errorCode=" + Errors.NONE.code()));
        }
    }
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) Uuid(org.apache.kafka.common.Uuid) LeaderAndIsrTopicErrorCollection(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection) Test(org.junit.jupiter.api.Test)

Example 4 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrResponseTest method testErrorCountsNoTopLevelError.

@Test
public void testErrorCountsNoTopLevelError() {
    for (short version : LEADER_AND_ISR.allVersions()) {
        LeaderAndIsrResponse response;
        if (version < 5) {
            List<LeaderAndIsrPartitionError> partitions = createPartitions("foo", asList(Errors.NONE, Errors.CLUSTER_AUTHORIZATION_FAILED));
            response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setPartitionErrors(partitions), version);
        } else {
            Uuid id = Uuid.randomUuid();
            LeaderAndIsrTopicErrorCollection topics = createTopic(id, asList(Errors.NONE, Errors.CLUSTER_AUTHORIZATION_FAILED));
            response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setTopics(topics), version);
        }
        Map<Errors, Integer> errorCounts = response.errorCounts();
        assertEquals(2, errorCounts.size());
        assertEquals(2, errorCounts.get(Errors.NONE).intValue());
        assertEquals(1, errorCounts.get(Errors.CLUSTER_AUTHORIZATION_FAILED).intValue());
    }
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) Uuid(org.apache.kafka.common.Uuid) LeaderAndIsrTopicErrorCollection(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection) Test(org.junit.jupiter.api.Test)

Example 5 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrResponseTest method testErrorCountsWithTopLevelError.

@Test
public void testErrorCountsWithTopLevelError() {
    for (short version : LEADER_AND_ISR.allVersions()) {
        LeaderAndIsrResponse response;
        if (version < 5) {
            List<LeaderAndIsrPartitionError> partitions = createPartitions("foo", asList(Errors.NONE, Errors.NOT_LEADER_OR_FOLLOWER));
            response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.UNKNOWN_SERVER_ERROR.code()).setPartitionErrors(partitions), version);
        } else {
            Uuid id = Uuid.randomUuid();
            LeaderAndIsrTopicErrorCollection topics = createTopic(id, asList(Errors.NONE, Errors.NOT_LEADER_OR_FOLLOWER));
            response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.UNKNOWN_SERVER_ERROR.code()).setTopics(topics), version);
        }
        assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 3), response.errorCounts());
    }
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) Uuid(org.apache.kafka.common.Uuid) LeaderAndIsrTopicErrorCollection(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection) Test(org.junit.jupiter.api.Test)

Aggregations

LeaderAndIsrPartitionError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError)7 Uuid (org.apache.kafka.common.Uuid)4 LeaderAndIsrResponseData (org.apache.kafka.common.message.LeaderAndIsrResponseData)4 LeaderAndIsrTopicErrorCollection (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection)4 Errors (org.apache.kafka.common.protocol.Errors)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 LeaderAndIsrTopicError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)3 LeaderAndIsrPartitionState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)2 ClusterAuthorizationException (org.apache.kafka.common.errors.ClusterAuthorizationException)1 LeaderAndIsrTopicState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState)1