use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection in project kafka by apache.
the class OffsetsForLeaderEpochClient method prepareRequest.
@Override
protected AbstractRequest.Builder<OffsetsForLeaderEpochRequest> prepareRequest(Node node, Map<TopicPartition, SubscriptionState.FetchPosition> requestData) {
OffsetForLeaderTopicCollection topics = new OffsetForLeaderTopicCollection(requestData.size());
requestData.forEach((topicPartition, fetchPosition) -> fetchPosition.offsetEpoch.ifPresent(fetchEpoch -> {
OffsetForLeaderTopic topic = topics.find(topicPartition.topic());
if (topic == null) {
topic = new OffsetForLeaderTopic().setTopic(topicPartition.topic());
topics.add(topic);
}
topic.partitions().add(new OffsetForLeaderPartition().setPartition(topicPartition.partition()).setLeaderEpoch(fetchEpoch).setCurrentLeaderEpoch(fetchPosition.currentLeader.epoch.orElse(RecordBatch.NO_PARTITION_LEADER_EPOCH)));
}));
return OffsetsForLeaderEpochRequest.Builder.forConsumer(topics);
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection in project kafka by apache.
the class RequestResponseTest method createOffsetForLeaderTopicCollection.
private OffsetForLeaderTopicCollection createOffsetForLeaderTopicCollection() {
OffsetForLeaderTopicCollection topics = new OffsetForLeaderTopicCollection();
topics.add(new OffsetForLeaderTopic().setTopic("topic1").setPartitions(asList(new OffsetForLeaderPartition().setPartition(0).setLeaderEpoch(1).setCurrentLeaderEpoch(0), new OffsetForLeaderPartition().setPartition(1).setLeaderEpoch(1).setCurrentLeaderEpoch(0))));
topics.add(new OffsetForLeaderTopic().setTopic("topic2").setPartitions(singletonList(new OffsetForLeaderPartition().setPartition(2).setLeaderEpoch(3).setCurrentLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH))));
return topics;
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection in project kafka by apache.
the class OffsetsForLeaderEpochRequestTest method testForConsumerRequiresVersion3.
@Test
public void testForConsumerRequiresVersion3() {
OffsetsForLeaderEpochRequest.Builder builder = OffsetsForLeaderEpochRequest.Builder.forConsumer(new OffsetForLeaderTopicCollection());
for (short version = 0; version < 3; version++) {
final short v = version;
assertThrows(UnsupportedVersionException.class, () -> builder.build(v));
}
for (short version = 3; version <= ApiKeys.OFFSET_FOR_LEADER_EPOCH.latestVersion(); version++) {
OffsetsForLeaderEpochRequest request = builder.build(version);
assertEquals(OffsetsForLeaderEpochRequest.CONSUMER_REPLICA_ID, request.replicaId());
}
}
use of org.apache.kafka.common.message.OffsetForLeaderEpochRequestData.OffsetForLeaderTopicCollection in project kafka by apache.
the class OffsetsForLeaderEpochRequestTest method testDefaultReplicaId.
@Test
public void testDefaultReplicaId() {
for (short version : ApiKeys.OFFSET_FOR_LEADER_EPOCH.allVersions()) {
int replicaId = 1;
OffsetsForLeaderEpochRequest.Builder builder = OffsetsForLeaderEpochRequest.Builder.forFollower(version, new OffsetForLeaderTopicCollection(), replicaId);
OffsetsForLeaderEpochRequest request = builder.build();
OffsetsForLeaderEpochRequest parsed = OffsetsForLeaderEpochRequest.parse(request.serialize(), version);
if (version < 3)
assertEquals(OffsetsForLeaderEpochRequest.DEBUGGING_REPLICA_ID, parsed.replicaId());
else
assertEquals(replicaId, parsed.replicaId());
}
}
Aggregations