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());
}
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());
}
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());
}
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()));
}
}
}
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());
}
Aggregations