Search in sources :

Example 1 with OffsetFetchResponseData

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

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

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

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

the class OffsetFetchResponseTest method testStructBuild.

/**
 * Test behavior changes over the versions. Refer to resources.common.messages.OffsetFetchResponse.json
 */
@Test
public void testStructBuild() {
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version < 8) {
            partitionDataMap.put(new TopicPartition(topicTwo, partitionTwo), new PartitionData(offset, leaderEpochTwo, metadata, Errors.GROUP_AUTHORIZATION_FAILED));
            OffsetFetchResponse latestResponse = new OffsetFetchResponse(throttleTimeMs, Errors.NONE, partitionDataMap);
            OffsetFetchResponseData data = new OffsetFetchResponseData(new ByteBufferAccessor(latestResponse.serialize(version)), version);
            OffsetFetchResponse oldResponse = new OffsetFetchResponse(data, version);
            if (version <= 1) {
                assertEquals(Errors.NONE.code(), data.errorCode());
                // Partition level error populated in older versions.
                assertEquals(Errors.GROUP_AUTHORIZATION_FAILED, oldResponse.error());
                assertEquals(Utils.mkMap(Utils.mkEntry(Errors.GROUP_AUTHORIZATION_FAILED, 2), Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1)), oldResponse.errorCounts());
            } else {
                assertEquals(Errors.NONE.code(), data.errorCode());
                assertEquals(Errors.NONE, oldResponse.error());
                assertEquals(Utils.mkMap(Utils.mkEntry(Errors.NONE, 1), Utils.mkEntry(Errors.GROUP_AUTHORIZATION_FAILED, 1), Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1)), oldResponse.errorCounts());
            }
            if (version <= 2) {
                assertEquals(DEFAULT_THROTTLE_TIME, oldResponse.throttleTimeMs());
            } else {
                assertEquals(throttleTimeMs, oldResponse.throttleTimeMs());
            }
            Map<TopicPartition, PartitionData> expectedDataMap = new HashMap<>();
            for (Map.Entry<TopicPartition, PartitionData> entry : partitionDataMap.entrySet()) {
                PartitionData partitionData = entry.getValue();
                expectedDataMap.put(entry.getKey(), new PartitionData(partitionData.offset, version <= 4 ? Optional.empty() : partitionData.leaderEpoch, partitionData.metadata, partitionData.error));
            }
            Map<TopicPartition, PartitionData> responseData = oldResponse.responseDataV0ToV7();
            assertEquals(expectedDataMap, responseData);
            responseData.forEach((tp, rdata) -> assertTrue(rdata.hasError()));
        } else {
            partitionDataMap.put(new TopicPartition(topicTwo, partitionTwo), new PartitionData(offset, leaderEpochTwo, metadata, Errors.GROUP_AUTHORIZATION_FAILED));
            OffsetFetchResponse latestResponse = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.NONE), Collections.singletonMap(groupOne, partitionDataMap));
            OffsetFetchResponseData data = new OffsetFetchResponseData(new ByteBufferAccessor(latestResponse.serialize(version)), version);
            OffsetFetchResponse oldResponse = new OffsetFetchResponse(data, version);
            assertEquals(Errors.NONE.code(), data.groups().get(0).errorCode());
            assertEquals(Errors.NONE, oldResponse.groupLevelError(groupOne));
            assertEquals(Utils.mkMap(Utils.mkEntry(Errors.NONE, 1), Utils.mkEntry(Errors.GROUP_AUTHORIZATION_FAILED, 1), Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1)), oldResponse.errorCounts());
            assertEquals(throttleTimeMs, oldResponse.throttleTimeMs());
            Map<TopicPartition, PartitionData> expectedDataMap = new HashMap<>();
            for (Map.Entry<TopicPartition, PartitionData> entry : partitionDataMap.entrySet()) {
                PartitionData partitionData = entry.getValue();
                expectedDataMap.put(entry.getKey(), new PartitionData(partitionData.offset, partitionData.leaderEpoch, partitionData.metadata, partitionData.error));
            }
            Map<TopicPartition, PartitionData> responseData = oldResponse.partitionDataMap(groupOne);
            assertEquals(expectedDataMap, responseData);
            responseData.forEach((tp, rdata) -> assertTrue(rdata.hasError()));
        }
    }
}
Also used : OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with OffsetFetchResponseData

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

TopicPartition (org.apache.kafka.common.TopicPartition)5 OffsetFetchResponseData (org.apache.kafka.common.message.OffsetFetchResponseData)5 PartitionData (org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData)5 Test (org.junit.jupiter.api.Test)5 OffsetFetchResponseGroup (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup)2 OffsetFetchResponsePartition (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition)2 OffsetFetchResponsePartitions (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)2 OffsetFetchResponseTopic (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic)2 OffsetFetchResponseTopics (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1