Search in sources :

Example 11 with EpochEndOffset

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

the class SubscriptionStateTest method testMaybeCompleteValidationAfterPositionChange.

@Test
public void testMaybeCompleteValidationAfterPositionChange() {
    Node broker1 = new Node(1, "localhost", 9092);
    state.assignFromUser(Collections.singleton(tp0));
    int currentEpoch = 10;
    long initialOffset = 10L;
    int initialOffsetEpoch = 5;
    long updateOffset = 20L;
    int updateOffsetEpoch = 8;
    SubscriptionState.FetchPosition initialPosition = new SubscriptionState.FetchPosition(initialOffset, Optional.of(initialOffsetEpoch), new Metadata.LeaderAndEpoch(Optional.of(broker1), Optional.of(currentEpoch)));
    state.seekUnvalidated(tp0, initialPosition);
    assertTrue(state.awaitingValidation(tp0));
    SubscriptionState.FetchPosition updatePosition = new SubscriptionState.FetchPosition(updateOffset, Optional.of(updateOffsetEpoch), new Metadata.LeaderAndEpoch(Optional.of(broker1), Optional.of(currentEpoch)));
    state.seekUnvalidated(tp0, updatePosition);
    Optional<LogTruncation> truncationOpt = state.maybeCompleteValidation(tp0, initialPosition, new EpochEndOffset().setLeaderEpoch(initialOffsetEpoch).setEndOffset(initialOffset + 5));
    assertEquals(Optional.empty(), truncationOpt);
    assertTrue(state.awaitingValidation(tp0));
    assertEquals(updatePosition, state.position(tp0));
}
Also used : EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) Node(org.apache.kafka.common.Node) Metadata(org.apache.kafka.clients.Metadata) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) LogTruncation(org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation) Test(org.junit.jupiter.api.Test)

Example 12 with EpochEndOffset

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

the class SubscriptionStateTest method testMaybeCompleteValidation.

@Test
public void testMaybeCompleteValidation() {
    Node broker1 = new Node(1, "localhost", 9092);
    state.assignFromUser(Collections.singleton(tp0));
    int currentEpoch = 10;
    long initialOffset = 10L;
    int initialOffsetEpoch = 5;
    SubscriptionState.FetchPosition initialPosition = new SubscriptionState.FetchPosition(initialOffset, Optional.of(initialOffsetEpoch), new Metadata.LeaderAndEpoch(Optional.of(broker1), Optional.of(currentEpoch)));
    state.seekUnvalidated(tp0, initialPosition);
    assertTrue(state.awaitingValidation(tp0));
    Optional<LogTruncation> truncationOpt = state.maybeCompleteValidation(tp0, initialPosition, new EpochEndOffset().setLeaderEpoch(initialOffsetEpoch).setEndOffset(initialOffset + 5));
    assertEquals(Optional.empty(), truncationOpt);
    assertFalse(state.awaitingValidation(tp0));
    assertEquals(initialPosition, state.position(tp0));
}
Also used : EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) Node(org.apache.kafka.common.Node) Metadata(org.apache.kafka.clients.Metadata) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) LogTruncation(org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation) Test(org.junit.jupiter.api.Test)

Example 13 with EpochEndOffset

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

the class SubscriptionStateTest method testTruncationDetectionUnknownDivergentOffsetWithoutResetPolicy.

@Test
public void testTruncationDetectionUnknownDivergentOffsetWithoutResetPolicy() {
    Node broker1 = new Node(1, "localhost", 9092);
    state = new SubscriptionState(new LogContext(), OffsetResetStrategy.NONE);
    state.assignFromUser(Collections.singleton(tp0));
    int currentEpoch = 10;
    long initialOffset = 10L;
    int initialOffsetEpoch = 5;
    SubscriptionState.FetchPosition initialPosition = new SubscriptionState.FetchPosition(initialOffset, Optional.of(initialOffsetEpoch), new Metadata.LeaderAndEpoch(Optional.of(broker1), Optional.of(currentEpoch)));
    state.seekUnvalidated(tp0, initialPosition);
    assertTrue(state.awaitingValidation(tp0));
    Optional<LogTruncation> truncationOpt = state.maybeCompleteValidation(tp0, initialPosition, new EpochEndOffset().setLeaderEpoch(UNDEFINED_EPOCH).setEndOffset(UNDEFINED_EPOCH_OFFSET));
    assertTrue(truncationOpt.isPresent());
    LogTruncation truncation = truncationOpt.get();
    assertEquals(Optional.empty(), truncation.divergentOffsetOpt);
    assertEquals(initialPosition, truncation.fetchPosition);
    assertTrue(state.awaitingValidation(tp0));
}
Also used : EpochEndOffset(org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset) Node(org.apache.kafka.common.Node) Metadata(org.apache.kafka.clients.Metadata) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) LogContext(org.apache.kafka.common.utils.LogContext) LogTruncation(org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation) Test(org.junit.jupiter.api.Test)

Aggregations

EpochEndOffset (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.EpochEndOffset)13 Metadata (org.apache.kafka.clients.Metadata)8 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)8 Node (org.apache.kafka.common.Node)8 Test (org.junit.jupiter.api.Test)8 LogTruncation (org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation)7 OffsetForLeaderTopicResult (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData.OffsetForLeaderTopicResult)6 OffsetForLeaderEpochResponseData (org.apache.kafka.common.message.OffsetForLeaderEpochResponseData)5 LogContext (org.apache.kafka.common.utils.LogContext)4 OffsetsForLeaderEpochResponse (org.apache.kafka.common.requests.OffsetsForLeaderEpochResponse)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Errors (org.apache.kafka.common.protocol.Errors)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