use of org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic in project kafka by apache.
the class OffsetFetchRequest method getErrorResponse.
public OffsetFetchResponse getErrorResponse(int throttleTimeMs, Errors error) {
Map<TopicPartition, OffsetFetchResponse.PartitionData> responsePartitions = new HashMap<>();
if (version() < 2) {
OffsetFetchResponse.PartitionData partitionError = new OffsetFetchResponse.PartitionData(OffsetFetchResponse.INVALID_OFFSET, Optional.empty(), OffsetFetchResponse.NO_METADATA, error);
for (OffsetFetchRequestTopic topic : this.data.topics()) {
for (int partitionIndex : topic.partitionIndexes()) {
responsePartitions.put(new TopicPartition(topic.name(), partitionIndex), partitionError);
}
}
return new OffsetFetchResponse(error, responsePartitions);
}
if (version() == 2) {
return new OffsetFetchResponse(error, responsePartitions);
}
if (version() >= 3 && version() < 8) {
return new OffsetFetchResponse(throttleTimeMs, error, responsePartitions);
}
List<String> groupIds = groupIds();
Map<String, Errors> errorsMap = new HashMap<>(groupIds.size());
Map<String, Map<TopicPartition, OffsetFetchResponse.PartitionData>> partitionMap = new HashMap<>(groupIds.size());
for (String g : groupIds) {
errorsMap.put(g, error);
partitionMap.put(g, responsePartitions);
}
return new OffsetFetchResponse(throttleTimeMs, errorsMap, partitionMap);
}
use of org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopic 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);
}
}
Aggregations