Search in sources :

Example 1 with OffsetFetchRequestTopics

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

the class OffsetFetchRequest method groupIdsToPartitions.

public Map<String, List<TopicPartition>> groupIdsToPartitions() {
    Map<String, List<TopicPartition>> groupIdsToPartitions = new HashMap<>();
    for (OffsetFetchRequestGroup group : data.groups()) {
        List<TopicPartition> tpList = null;
        if (group.topics() != ALL_TOPIC_PARTITIONS_BATCH) {
            tpList = new ArrayList<>();
            for (OffsetFetchRequestTopics topic : group.topics()) {
                for (Integer partitionIndex : topic.partitionIndexes()) {
                    tpList.add(new TopicPartition(topic.name(), partitionIndex));
                }
            }
        }
        groupIdsToPartitions.put(group.groupId(), tpList);
    }
    return groupIdsToPartitions;
}
Also used : HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchRequestGroup(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup) ArrayList(java.util.ArrayList) List(java.util.List) OffsetFetchRequestTopics(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics)

Example 2 with OffsetFetchRequestTopics

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

the class MessageTest method testOffsetFetchV8AndAbove.

@Test
public void testOffsetFetchV8AndAbove() throws Exception {
    String groupOne = "group1";
    String groupTwo = "group2";
    String groupThree = "group3";
    String groupFour = "group4";
    String groupFive = "group5";
    String topic1 = "topic1";
    String topic2 = "topic2";
    String topic3 = "topic3";
    OffsetFetchRequestTopics topicOne = new OffsetFetchRequestTopics().setName(topic1).setPartitionIndexes(Collections.singletonList(5));
    OffsetFetchRequestTopics topicTwo = new OffsetFetchRequestTopics().setName(topic2).setPartitionIndexes(Collections.singletonList(10));
    OffsetFetchRequestTopics topicThree = new OffsetFetchRequestTopics().setName(topic3).setPartitionIndexes(Collections.singletonList(15));
    List<OffsetFetchRequestTopics> groupOneTopics = singletonList(topicOne);
    OffsetFetchRequestGroup group1 = new OffsetFetchRequestGroup().setGroupId(groupOne).setTopics(groupOneTopics);
    List<OffsetFetchRequestTopics> groupTwoTopics = Arrays.asList(topicOne, topicTwo);
    OffsetFetchRequestGroup group2 = new OffsetFetchRequestGroup().setGroupId(groupTwo).setTopics(groupTwoTopics);
    List<OffsetFetchRequestTopics> groupThreeTopics = Arrays.asList(topicOne, topicTwo, topicThree);
    OffsetFetchRequestGroup group3 = new OffsetFetchRequestGroup().setGroupId(groupThree).setTopics(groupThreeTopics);
    OffsetFetchRequestGroup group4 = new OffsetFetchRequestGroup().setGroupId(groupFour).setTopics(null);
    OffsetFetchRequestGroup group5 = new OffsetFetchRequestGroup().setGroupId(groupFive).setTopics(null);
    OffsetFetchRequestData requestData = new OffsetFetchRequestData().setGroups(Arrays.asList(group1, group2, group3, group4, group5)).setRequireStable(true);
    testAllMessageRoundTripsOffsetFetchV8AndAbove(requestData);
    testAllMessageRoundTripsOffsetFetchV8AndAbove(requestData.setRequireStable(false));
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version >= 8) {
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, requestData);
        }
    }
    OffsetFetchResponseTopics responseTopic1 = new OffsetFetchResponseTopics().setName(topic1).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(5).setMetadata(null).setCommittedOffset(100).setCommittedLeaderEpoch(3).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code())));
    OffsetFetchResponseTopics responseTopic2 = new OffsetFetchResponseTopics().setName(topic2).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(10).setMetadata("foo").setCommittedOffset(200).setCommittedLeaderEpoch(2).setErrorCode(Errors.TOPIC_AUTHORIZATION_FAILED.code())));
    OffsetFetchResponseTopics responseTopic3 = new OffsetFetchResponseTopics().setName(topic3).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(15).setMetadata("bar").setCommittedOffset(300).setCommittedLeaderEpoch(1).setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code())));
    OffsetFetchResponseGroup responseGroup1 = new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(responseTopic1)).setErrorCode(Errors.NOT_COORDINATOR.code());
    OffsetFetchResponseGroup responseGroup2 = new OffsetFetchResponseGroup().setGroupId(groupTwo).setTopics(Arrays.asList(responseTopic1, responseTopic2)).setErrorCode(Errors.COORDINATOR_LOAD_IN_PROGRESS.code());
    OffsetFetchResponseGroup responseGroup3 = new OffsetFetchResponseGroup().setGroupId(groupThree).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
    OffsetFetchResponseGroup responseGroup4 = new OffsetFetchResponseGroup().setGroupId(groupFour).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
    OffsetFetchResponseGroup responseGroup5 = new OffsetFetchResponseGroup().setGroupId(groupFive).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
    Supplier<OffsetFetchResponseData> response = () -> new OffsetFetchResponseData().setGroups(Arrays.asList(responseGroup1, responseGroup2, responseGroup3, responseGroup4, responseGroup5)).setThrottleTimeMs(10);
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version >= 8) {
            OffsetFetchResponseData responseData = response.get();
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, responseData);
        }
    }
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchRequestGroup(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchRequestTopics(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 3 with OffsetFetchRequestTopics

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

the class MessageTest method testOffsetFetchV8AndAboveSingleGroup.

@Test
public void testOffsetFetchV8AndAboveSingleGroup() throws Exception {
    String groupId = "groupId";
    String topicName = "topic";
    List<OffsetFetchRequestTopics> topic = Collections.singletonList(new OffsetFetchRequestTopics().setName(topicName).setPartitionIndexes(Collections.singletonList(5)));
    OffsetFetchRequestData allPartitionData = new OffsetFetchRequestData().setGroups(Collections.singletonList(new OffsetFetchRequestGroup().setGroupId(groupId).setTopics(null)));
    OffsetFetchRequestData specifiedPartitionData = new OffsetFetchRequestData().setGroups(Collections.singletonList(new OffsetFetchRequestGroup().setGroupId(groupId).setTopics(topic))).setRequireStable(true);
    testAllMessageRoundTripsOffsetFetchV8AndAbove(allPartitionData);
    testAllMessageRoundTripsOffsetFetchV8AndAbove(specifiedPartitionData);
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version >= 8) {
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, specifiedPartitionData);
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, allPartitionData);
        }
    }
    Supplier<OffsetFetchResponseData> response = () -> new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupId).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(5).setMetadata(null).setCommittedOffset(100).setCommittedLeaderEpoch(3).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()))))).setErrorCode(Errors.NOT_COORDINATOR.code()))).setThrottleTimeMs(10);
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version >= 8) {
            OffsetFetchResponseData responseData = response.get();
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, responseData);
        }
    }
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchRequestGroup(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchRequestTopics(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetFetchRequestGroup (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup)3 OffsetFetchRequestTopics (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics)3 OffsetFetchResponseGroup (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup)2 OffsetFetchResponsePartitions (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)2 OffsetFetchResponseTopics (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TopicPartition (org.apache.kafka.common.TopicPartition)1