Search in sources :

Example 1 with OffsetForLeaderEpochResponseData

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

the class OffsetsForLeaderEpochRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Errors error = Errors.forException(e);
    OffsetForLeaderEpochResponseData responseData = new OffsetForLeaderEpochResponseData();
    data.topics().forEach(topic -> {
        OffsetForLeaderTopicResult topicData = new OffsetForLeaderTopicResult().setTopic(topic.topic());
        topic.partitions().forEach(partition -> topicData.partitions().add(new EpochEndOffset().setPartition(partition.partition()).setErrorCode(error.code()).setLeaderEpoch(UNDEFINED_EPOCH).setEndOffset(UNDEFINED_EPOCH_OFFSET)));
        responseData.topics().add(topicData);
    });
    return new OffsetsForLeaderEpochResponse(responseData);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) OffsetForLeaderTopicResult(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult) OffsetForLeaderEpochResponseData(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData)

Example 2 with OffsetForLeaderEpochResponseData

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

the class RequestResponseTest method createLeaderEpochResponse.

private OffsetsForLeaderEpochResponse createLeaderEpochResponse() {
    OffsetForLeaderEpochResponseData data = new OffsetForLeaderEpochResponseData();
    data.topics().add(new OffsetForLeaderTopicResult().setTopic("topic1").setPartitions(asList(new EpochEndOffset().setPartition(0).setErrorCode(Errors.NONE.code()).setLeaderEpoch(1).setEndOffset(0), new EpochEndOffset().setPartition(1).setErrorCode(Errors.NONE.code()).setLeaderEpoch(1).setEndOffset(1))));
    data.topics().add(new OffsetForLeaderTopicResult().setTopic("topic2").setPartitions(singletonList(new EpochEndOffset().setPartition(2).setErrorCode(Errors.NONE.code()).setLeaderEpoch(1).setEndOffset(1))));
    return new OffsetsForLeaderEpochResponse(data);
}
Also used : EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) OffsetForLeaderTopicResult(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult) OffsetForLeaderEpochResponseData(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData)

Example 3 with OffsetForLeaderEpochResponseData

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

the class OffsetForLeaderEpochClientTest method prepareOffsetForLeaderEpochResponse.

private static OffsetsForLeaderEpochResponse prepareOffsetForLeaderEpochResponse(TopicPartition tp, Errors error, int leaderEpoch, long endOffset) {
    OffsetForLeaderEpochResponseData data = new OffsetForLeaderEpochResponseData();
    OffsetForLeaderTopicResult topic = new OffsetForLeaderTopicResult().setTopic(tp.topic());
    data.topics().add(topic);
    topic.partitions().add(new EpochEndOffset().setPartition(tp.partition()).setErrorCode(error.code()).setLeaderEpoch(leaderEpoch).setEndOffset(endOffset));
    return new OffsetsForLeaderEpochResponse(data);
}
Also used : EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) OffsetForLeaderTopicResult(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult) OffsetForLeaderEpochResponseData(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData) OffsetsForLeaderEpochResponse(org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse)

Example 4 with OffsetForLeaderEpochResponseData

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

the class OffsetForLeaderEpochClientTest method testUnexpectedEmptyResponse.

@Test
public void testUnexpectedEmptyResponse() {
    Map<TopicPartition, SubscriptionState.FetchPosition> positionMap = new HashMap<>();
    positionMap.put(tp0, new SubscriptionState.FetchPosition(0, Optional.of(1), new Metadata.LeaderAndEpoch(Optional.empty(), Optional.of(1))));
    OffsetsForLeaderEpochClient offsetClient = newOffsetClient();
    RequestFuture<OffsetsForLeaderEpochClient.OffsetForEpochResult> future = offsetClient.sendAsyncRequest(Node.noNode(), positionMap);
    OffsetsForLeaderEpochResponse resp = new OffsetsForLeaderEpochResponse(new OffsetForLeaderEpochResponseData());
    client.prepareResponse(resp);
    consumerClient.pollNoWakeup();
    OffsetsForLeaderEpochClient.OffsetForEpochResult result = future.value();
    assertFalse(result.partitionsToRetry().isEmpty());
    assertTrue(result.endOffsets().isEmpty());
}
Also used : HashMap(java.util.HashMap) OffsetForLeaderEpochResponseData(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetsForLeaderEpochResponse(org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse) Test(org.junit.jupiter.api.Test)

Example 5 with OffsetForLeaderEpochResponseData

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

the class OffsetForLeaderEpochClientTest method testEmptyResponse.

@Test
public void testEmptyResponse() {
    OffsetsForLeaderEpochClient offsetClient = newOffsetClient();
    RequestFuture<OffsetsForLeaderEpochClient.OffsetForEpochResult> future = offsetClient.sendAsyncRequest(Node.noNode(), Collections.emptyMap());
    OffsetsForLeaderEpochResponse resp = new OffsetsForLeaderEpochResponse(new OffsetForLeaderEpochResponseData());
    client.prepareResponse(resp);
    consumerClient.pollNoWakeup();
    OffsetsForLeaderEpochClient.OffsetForEpochResult result = future.value();
    assertTrue(result.partitionsToRetry().isEmpty());
    assertTrue(result.endOffsets().isEmpty());
}
Also used : OffsetsForLeaderEpochResponse(org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse) OffsetForLeaderEpochResponseData(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetForLeaderEpochResponseData (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData)7 EpochEndOffset (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset)5 OffsetForLeaderTopicResult (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult)5 OffsetsForLeaderEpochResponse (org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse)5 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 DataOutputStream (java.io.DataOutputStream)1 Field (java.lang.reflect.Field)1 ByteBuffer (java.nio.ByteBuffer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1