Search in sources :

Example 1 with OffsetFetchResponseTopics

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics in project kafka by apache.

the class OffsetFetchResponse method buildResponseData.

private Map<TopicPartition, PartitionData> buildResponseData(String groupId) {
    Map<TopicPartition, PartitionData> responseData = new HashMap<>();
    OffsetFetchResponseGroup group = data.groups().stream().filter(g -> g.groupId().equals(groupId)).collect(Collectors.toList()).get(0);
    for (OffsetFetchResponseTopics topic : group.topics()) {
        for (OffsetFetchResponsePartitions partition : topic.partitions()) {
            responseData.put(new TopicPartition(topic.name(), partition.partitionIndex()), new PartitionData(partition.committedOffset(), RequestUtils.getLeaderEpoch(partition.committedLeaderEpoch()), partition.metadata(), Errors.forCode(partition.errorCode())));
        }
    }
    return responseData;
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)

Example 2 with OffsetFetchResponseTopics

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics in project kafka by apache.

the class OffsetFetchResponseTest method testUseDefaultLeaderEpochV8.

@Test
public void testUseDefaultLeaderEpochV8() {
    final Optional<Integer> emptyLeaderEpoch = Optional.empty();
    partitionDataMap.clear();
    partitionDataMap.put(new TopicPartition(topicOne, partitionOne), new PartitionData(offset, emptyLeaderEpoch, metadata, Errors.UNKNOWN_TOPIC_OR_PARTITION));
    OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.NOT_COORDINATOR), Collections.singletonMap(groupOne, partitionDataMap));
    OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(metadata))))).setErrorCode(Errors.NOT_COORDINATOR.code()))).setThrottleTimeMs(throttleTimeMs);
    assertEquals(expectedData, response.data());
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 3 with OffsetFetchResponseTopics

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics in project kafka by apache.

the class OffsetFetchResponseTest method testNullableMetadataV8AndAbove.

@Test
public void testNullableMetadataV8AndAbove() {
    PartitionData pd = new PartitionData(offset, leaderEpochOne, null, Errors.UNKNOWN_TOPIC_OR_PARTITION);
    // test PartitionData.equals with null metadata
    assertEquals(pd, pd);
    partitionDataMap.clear();
    partitionDataMap.put(new TopicPartition(topicOne, partitionOne), pd);
    OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.GROUP_AUTHORIZATION_FAILED), Collections.singletonMap(groupOne, partitionDataMap));
    OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpochOne.orElse(-1)).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(null))))).setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code()))).setThrottleTimeMs(throttleTimeMs);
    assertEquals(expectedData, response.data());
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 4 with OffsetFetchResponseTopics

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics 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 5 with OffsetFetchResponseTopics

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

OffsetFetchResponseGroup (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup)5 OffsetFetchResponsePartitions (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)5 OffsetFetchResponseTopics (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics)5 Test (org.junit.jupiter.api.Test)4 TopicPartition (org.apache.kafka.common.TopicPartition)3 OffsetFetchRequestGroup (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup)2 OffsetFetchRequestTopics (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics)2 OffsetFetchResponseData (org.apache.kafka.common.message.OffsetFetchResponseData)2 PartitionData (org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData)2 HashMap (java.util.HashMap)1