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