use of org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation in project kafka by apache.
the class SubscriptionStateTest method testTruncationDetectionWithResetPolicy.
@Test
public void testTruncationDetectionWithResetPolicy() {
Node broker1 = new Node(1, "localhost", 9092);
state.assignFromUser(Collections.singleton(tp0));
int currentEpoch = 10;
long initialOffset = 10L;
int initialOffsetEpoch = 5;
long divergentOffset = 5L;
int divergentOffsetEpoch = 7;
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(divergentOffsetEpoch).setEndOffset(divergentOffset));
assertEquals(Optional.empty(), truncationOpt);
assertFalse(state.awaitingValidation(tp0));
SubscriptionState.FetchPosition updatedPosition = new SubscriptionState.FetchPosition(divergentOffset, Optional.of(divergentOffsetEpoch), new Metadata.LeaderAndEpoch(Optional.of(broker1), Optional.of(currentEpoch)));
assertEquals(updatedPosition, state.position(tp0));
}
use of org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation in project kafka by apache.
the class SubscriptionStateTest method testMaybeCompleteValidationAfterOffsetReset.
@Test
public void testMaybeCompleteValidationAfterOffsetReset() {
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));
state.requestOffsetReset(tp0);
Optional<LogTruncation> truncationOpt = state.maybeCompleteValidation(tp0, initialPosition, new EpochEndOffset().setLeaderEpoch(initialOffsetEpoch).setEndOffset(initialOffset + 5));
assertEquals(Optional.empty(), truncationOpt);
assertFalse(state.awaitingValidation(tp0));
assertTrue(state.isOffsetResetNeeded(tp0));
assertNull(state.position(tp0));
}
use of org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation in project kafka by apache.
the class SubscriptionStateTest method testTruncationDetectionWithoutResetPolicy.
@Test
public void testTruncationDetectionWithoutResetPolicy() {
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;
long divergentOffset = 5L;
int divergentOffsetEpoch = 7;
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(divergentOffsetEpoch).setEndOffset(divergentOffset));
assertTrue(truncationOpt.isPresent());
LogTruncation truncation = truncationOpt.get();
assertEquals(Optional.of(new OffsetAndMetadata(divergentOffset, Optional.of(divergentOffsetEpoch), "")), truncation.divergentOffsetOpt);
assertEquals(initialPosition, truncation.fetchPosition);
assertTrue(state.awaitingValidation(tp0));
}
use of org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation in project kafka by apache.
the class SubscriptionStateTest method testTruncationDetectionUnknownDivergentOffsetWithResetPolicy.
@Test
public void testTruncationDetectionUnknownDivergentOffsetWithResetPolicy() {
Node broker1 = new Node(1, "localhost", 9092);
state = new SubscriptionState(new LogContext(), OffsetResetStrategy.EARLIEST);
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));
assertEquals(Optional.empty(), truncationOpt);
assertFalse(state.awaitingValidation(tp0));
assertTrue(state.isOffsetResetNeeded(tp0));
assertEquals(OffsetResetStrategy.EARLIEST, state.resetStrategy(tp0));
}
use of org.apache.kafka.clients.consumer.internals.SubscriptionState.LogTruncation 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));
}
Aggregations