use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project kafka by apache.
the class FetcherTest method testUpdateFetchPositionToCommitted.
@Test
public void testUpdateFetchPositionToCommitted() {
// unless a specific reset is expected, the default behavior is to reset to the committed
// position if one is present
subscriptions.assignFromUser(singleton(tp));
subscriptions.committed(tp, new OffsetAndMetadata(5));
fetcher.updateFetchPositions(singleton(tp));
assertTrue(subscriptions.isFetchable(tp));
assertEquals(5, subscriptions.position(tp).longValue());
}
use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project kafka by apache.
the class FetcherTest method testUpdateFetchPositionOfPausedPartitionsRequiringOffsetReset.
@Test
public void testUpdateFetchPositionOfPausedPartitionsRequiringOffsetReset() {
subscriptions.assignFromUser(singleton(tp));
subscriptions.committed(tp, new OffsetAndMetadata(0));
// paused partition does not have a valid position
subscriptions.pause(tp);
subscriptions.needOffsetReset(tp, OffsetResetStrategy.LATEST);
client.prepareResponse(listOffsetRequestMatcher(ListOffsetRequest.LATEST_TIMESTAMP), listOffsetResponse(Errors.NONE, 1L, 10L));
fetcher.updateFetchPositions(singleton(tp));
assertFalse(subscriptions.isOffsetResetNeeded(tp));
// because tp is paused
assertFalse(subscriptions.isFetchable(tp));
assertTrue(subscriptions.hasValidPosition(tp));
assertEquals(10, subscriptions.position(tp).longValue());
}
use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project kafka by apache.
the class FetcherTest method testUpdateFetchPositionOfPausedPartitionsWithoutAValidPosition.
@Test
public void testUpdateFetchPositionOfPausedPartitionsWithoutAValidPosition() {
subscriptions.assignFromUser(singleton(tp));
subscriptions.committed(tp, new OffsetAndMetadata(0));
// paused partition does not have a valid position
subscriptions.pause(tp);
subscriptions.seek(tp, 10);
fetcher.updateFetchPositions(singleton(tp));
assertFalse(subscriptions.isOffsetResetNeeded(tp));
// because tp is paused
assertFalse(subscriptions.isFetchable(tp));
assertTrue(subscriptions.hasValidPosition(tp));
assertEquals(10, subscriptions.position(tp).longValue());
}
use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project kafka by apache.
the class ConsumerCoordinatorTest method testCommitOffsetOnly.
@Test
public void testCommitOffsetOnly() {
subscriptions.assignFromUser(singleton(t1p));
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady();
client.prepareResponse(offsetCommitResponse(Collections.singletonMap(t1p, Errors.NONE)));
AtomicBoolean success = new AtomicBoolean(false);
coordinator.commitOffsetsAsync(Collections.singletonMap(t1p, new OffsetAndMetadata(100L)), callback(success));
coordinator.invokeCompletedOffsetCommitCallbacks();
assertTrue(success.get());
assertEquals(100L, subscriptions.committed(t1p).offset());
}
use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project kafka by apache.
the class ConsumerInterceptorsTest method testOnCommitChain.
@Test
public void testOnCommitChain() {
List<ConsumerInterceptor<Integer, Integer>> interceptorList = new ArrayList<>();
// we are testing two different interceptors by configuring the same interceptor differently, which is not
// how it would be done in KafkaConsumer, but ok for testing interceptor callbacks
FilterConsumerInterceptor<Integer, Integer> interceptor1 = new FilterConsumerInterceptor<>(filterPartition1);
FilterConsumerInterceptor<Integer, Integer> interceptor2 = new FilterConsumerInterceptor<>(filterPartition2);
interceptorList.add(interceptor1);
interceptorList.add(interceptor2);
ConsumerInterceptors<Integer, Integer> interceptors = new ConsumerInterceptors<>(interceptorList);
// verify that onCommit is called for all interceptors in the chain
Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
offsets.put(tp, new OffsetAndMetadata(0));
interceptors.onCommit(offsets);
assertEquals(2, onCommitCount);
// verify that even if one of the interceptors throws an exception, all interceptors' onCommit are called
interceptor1.injectOnCommitError(true);
interceptors.onCommit(offsets);
assertEquals(4, onCommitCount);
interceptors.close();
}
Aggregations