Search in sources :

Example 1 with OffsetFetchRequestTopic

use of org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic in project kafka by apache.

the class OffsetFetchRequest method getErrorResponse.

public OffsetFetchResponse getErrorResponse(int throttleTimeMs, Errors error) {
    Map<TopicPartition, OffsetFetchResponse.PartitionData> responsePartitions = new HashMap<>();
    if (version() < 2) {
        OffsetFetchResponse.PartitionData partitionError = new OffsetFetchResponse.PartitionData(OffsetFetchResponse.INVALID_OFFSET, Optional.empty(), OffsetFetchResponse.NO_METADATA, error);
        for (OffsetFetchRequestTopic topic : this.data.topics()) {
            for (int partitionIndex : topic.partitionIndexes()) {
                responsePartitions.put(new TopicPartition(topic.name(), partitionIndex), partitionError);
            }
        }
        return new OffsetFetchResponse(error, responsePartitions);
    }
    if (version() == 2) {
        return new OffsetFetchResponse(error, responsePartitions);
    }
    if (version() >= 3 && version() < 8) {
        return new OffsetFetchResponse(throttleTimeMs, error, responsePartitions);
    }
    List<String> groupIds = groupIds();
    Map<String, Errors> errorsMap = new HashMap<>(groupIds.size());
    Map<String, Map<TopicPartition, OffsetFetchResponse.PartitionData>> partitionMap = new HashMap<>(groupIds.size());
    for (String g : groupIds) {
        errorsMap.put(g, error);
        partitionMap.put(g, responsePartitions);
    }
    return new OffsetFetchResponse(throttleTimeMs, errorsMap, partitionMap);
}
Also used : HashMap(java.util.HashMap) OffsetFetchRequestTopic(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic) Errors(org.apache.kafka.common.protocol.Errors) TopicPartition(org.apache.kafka.common.TopicPartition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with OffsetFetchRequestTopic

use of org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic in project kafka by apache.

the class MessageTest method testOffsetFetchV0ToV7.

@Test
public void testOffsetFetchV0ToV7() throws Exception {
    String groupId = "groupId";
    String topicName = "topic";
    List<OffsetFetchRequestTopic> topics = Collections.singletonList(new OffsetFetchRequestTopic().setName(topicName).setPartitionIndexes(Collections.singletonList(5)));
    testAllMessageRoundTripsOffsetFetchV0ToV7(new OffsetFetchRequestData().setTopics(new ArrayList<>()).setGroupId(groupId));
    testAllMessageRoundTripsOffsetFetchV0ToV7(new OffsetFetchRequestData().setGroupId(groupId).setTopics(topics));
    OffsetFetchRequestData allPartitionData = new OffsetFetchRequestData().setGroupId(groupId).setTopics(null);
    OffsetFetchRequestData requireStableData = new OffsetFetchRequestData().setGroupId(groupId).setTopics(topics).setRequireStable(true);
    for (int version : listOfVersionsNonBatchOffsetFetch) {
        final short finalVersion = (short) version;
        if (version < 2) {
            assertThrows(NullPointerException.class, () -> testAllMessageRoundTripsOffsetFetchFromVersionV0ToV7(finalVersion, allPartitionData));
        } else {
            testAllMessageRoundTripsOffsetFetchFromVersionV0ToV7((short) version, allPartitionData);
        }
        if (version < 7) {
            assertThrows(UnsupportedVersionException.class, () -> testAllMessageRoundTripsOffsetFetchFromVersionV0ToV7(finalVersion, requireStableData));
        } else {
            testAllMessageRoundTripsOffsetFetchFromVersionV0ToV7(finalVersion, requireStableData);
        }
    }
    Supplier<OffsetFetchResponseData> response = () -> new OffsetFetchResponseData().setTopics(Collections.singletonList(new OffsetFetchResponseTopic().setName(topicName).setPartitions(Collections.singletonList(new OffsetFetchResponsePartition().setPartitionIndex(5).setMetadata(null).setCommittedOffset(100).setCommittedLeaderEpoch(3).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()))))).setErrorCode(Errors.NOT_COORDINATOR.code()).setThrottleTimeMs(10);
    for (int version : listOfVersionsNonBatchOffsetFetch) {
        OffsetFetchResponseData responseData = response.get();
        if (version <= 1) {
            responseData.setErrorCode(Errors.NONE.code());
        }
        if (version <= 2) {
            responseData.setThrottleTimeMs(0);
        }
        if (version <= 4) {
            responseData.topics().get(0).partitions().get(0).setCommittedLeaderEpoch(-1);
        }
        testAllMessageRoundTripsOffsetFetchFromVersionV0ToV7((short) version, responseData);
    }
}
Also used : OffsetFetchRequestTopic(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic) OffsetFetchResponseTopic(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic) OffsetFetchResponsePartition(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetFetchRequestTopic (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 OffsetFetchResponsePartition (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition)1 OffsetFetchResponseTopic (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic)1 Errors (org.apache.kafka.common.protocol.Errors)1 Test (org.junit.jupiter.api.Test)1