Search in sources :

Example 1 with OffsetFetchResponseTopic

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

the class OffsetFetchResponseTest method testNullableMetadataV0ToV7.

@Test
public void testNullableMetadataV0ToV7() {
    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, Errors.GROUP_AUTHORIZATION_FAILED, partitionDataMap);
    OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code()).setThrottleTimeMs(throttleTimeMs).setTopics(Collections.singletonList(new OffsetFetchResponseTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartition().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpochOne.orElse(-1)).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(null)))));
    assertEquals(expectedData, response.data());
}
Also used : OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) OffsetFetchResponseTopic(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponsePartition(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition) Test(org.junit.jupiter.api.Test)

Example 2 with OffsetFetchResponseTopic

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

Example 3 with OffsetFetchResponseTopic

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

the class OffsetFetchResponseTest method testUseDefaultLeaderEpochV0ToV7.

@Test
public void testUseDefaultLeaderEpochV0ToV7() {
    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, Errors.NOT_COORDINATOR, partitionDataMap);
    OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setErrorCode(Errors.NOT_COORDINATOR.code()).setThrottleTimeMs(throttleTimeMs).setTopics(Collections.singletonList(new OffsetFetchResponseTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartition().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(metadata)))));
    assertEquals(expectedData, response.data());
}
Also used : OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) OffsetFetchResponseTopic(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponsePartition(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetFetchResponsePartition (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition)3 OffsetFetchResponseTopic (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic)3 Test (org.junit.jupiter.api.Test)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 OffsetFetchResponseData (org.apache.kafka.common.message.OffsetFetchResponseData)2 PartitionData (org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData)2 OffsetFetchRequestTopic (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic)1