Search in sources :

Example 1 with LeaderAndIsrResponseData

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

the class RequestResponseTest method createLeaderAndIsrResponse.

private LeaderAndIsrResponse createLeaderAndIsrResponse(short version) {
    if (version < 5) {
        List<LeaderAndIsrResponseData.LeaderAndIsrPartitionError> partitions = new ArrayList<>();
        partitions.add(new LeaderAndIsrResponseData.LeaderAndIsrPartitionError().setTopicName("test").setPartitionIndex(0).setErrorCode(Errors.NONE.code()));
        return new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setPartitionErrors(partitions), version);
    } else {
        List<LeaderAndIsrResponseData.LeaderAndIsrPartitionError> partition = singletonList(new LeaderAndIsrResponseData.LeaderAndIsrPartitionError().setPartitionIndex(0).setErrorCode(Errors.NONE.code()));
        LeaderAndIsrTopicErrorCollection topics = new LeaderAndIsrTopicErrorCollection();
        topics.add(new LeaderAndIsrResponseData.LeaderAndIsrTopicError().setTopicId(Uuid.randomUuid()).setPartitionErrors(partition));
        return new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setTopics(topics), version);
    }
}
Also used : LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) LeaderAndIsrTopicErrorCollection(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection) ArrayList(java.util.ArrayList)

Example 2 with LeaderAndIsrResponseData

use of org.apache.kafka.common.message.LeaderAndIsrResponseData 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 3 with LeaderAndIsrResponseData

use of org.apache.kafka.common.message.LeaderAndIsrResponseData 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 4 with LeaderAndIsrResponseData

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

Example 5 with LeaderAndIsrResponseData

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

the class LeaderAndIsrRequest method getErrorResponse.

@Override
public LeaderAndIsrResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    LeaderAndIsrResponseData responseData = new LeaderAndIsrResponseData();
    Errors error = Errors.forException(e);
    responseData.setErrorCode(error.code());
    if (version() < 5) {
        List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
        for (LeaderAndIsrPartitionState partition : partitionStates()) {
            partitions.add(new LeaderAndIsrPartitionError().setTopicName(partition.topicName()).setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
        }
        responseData.setPartitionErrors(partitions);
    } else {
        for (LeaderAndIsrTopicState topicState : data.topicStates()) {
            List<LeaderAndIsrPartitionError> partitions = new ArrayList<>(topicState.partitionStates().size());
            for (LeaderAndIsrPartitionState partition : topicState.partitionStates()) {
                partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
            }
            responseData.topics().add(new LeaderAndIsrTopicError().setTopicId(topicState.topicId()).setPartitionErrors(partitions));
        }
    }
    return new LeaderAndIsrResponse(responseData, version());
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) ArrayList(java.util.ArrayList) LeaderAndIsrTopicState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)

Aggregations

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