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