use of org.apache.kafka.common.requests.ListOffsetRequest in project apache-kafka-on-k8s by banzaicloud.
the class KafkaConsumerTest method testFetchProgressWithMissingPartitionPosition.
@Test
public void testFetchProgressWithMissingPartitionPosition() {
// Verifies that we can make progress on one partition while we are awaiting
// a reset on another partition.
Time time = new MockTime();
Cluster cluster = TestUtils.singletonCluster(topic, 2);
Node node = cluster.nodes().get(0);
Metadata metadata = createMetadata();
metadata.update(cluster, Collections.<String>emptySet(), time.milliseconds());
MockClient client = new MockClient(time, metadata);
client.setNode(node);
KafkaConsumer<String, String> consumer = newConsumerNoAutoCommit(time, client, metadata);
consumer.assign(Arrays.asList(tp0, tp1));
consumer.seekToEnd(singleton(tp0));
consumer.seekToBeginning(singleton(tp1));
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
ListOffsetRequest request = (ListOffsetRequest) body;
Map<TopicPartition, Long> expectedTimestamps = new HashMap<>();
expectedTimestamps.put(tp0, ListOffsetRequest.LATEST_TIMESTAMP);
expectedTimestamps.put(tp1, ListOffsetRequest.EARLIEST_TIMESTAMP);
return expectedTimestamps.equals(request.partitionTimestamps());
}
}, listOffsetsResponse(Collections.singletonMap(tp0, 50L), Collections.singletonMap(tp1, Errors.NOT_LEADER_FOR_PARTITION)));
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
FetchRequest request = (FetchRequest) body;
return request.fetchData().keySet().equals(singleton(tp0)) && request.fetchData().get(tp0).fetchOffset == 50L;
}
}, fetchResponse(tp0, 50L, 5));
ConsumerRecords<String, String> records = consumer.poll(5);
assertEquals(5, records.count());
assertEquals(singleton(tp0), records.partitions());
}
use of org.apache.kafka.common.requests.ListOffsetRequest in project apache-kafka-on-k8s by banzaicloud.
the class FetcherTest method testListOffsetsSendsIsolationLevel.
@Test
public void testListOffsetsSendsIsolationLevel() {
for (final IsolationLevel isolationLevel : IsolationLevel.values()) {
Fetcher<byte[], byte[]> fetcher = createFetcher(subscriptions, new Metrics(), new ByteArrayDeserializer(), new ByteArrayDeserializer(), Integer.MAX_VALUE, isolationLevel);
subscriptions.assignFromUser(singleton(tp0));
subscriptions.requestOffsetReset(tp0, OffsetResetStrategy.LATEST);
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
ListOffsetRequest request = (ListOffsetRequest) body;
return request.isolationLevel() == isolationLevel;
}
}, listOffsetResponse(Errors.NONE, 1L, 5L));
fetcher.resetOffsetsIfNeeded();
consumerClient.pollNoWakeup();
assertFalse(subscriptions.isOffsetResetNeeded(tp0));
assertTrue(subscriptions.isFetchable(tp0));
assertEquals(5, subscriptions.position(tp0).longValue());
}
}
Aggregations