use of org.apache.kafka.streams.integration.utils.IntegrationTestUtils.DEFAULT_TIMEOUT in project kafka by apache.
the class SuppressionIntegrationTest method waitForAnyRecord.
private static boolean waitForAnyRecord(final String topic) {
final Properties properties = new Properties();
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
try (final Consumer<Object, Object> consumer = new KafkaConsumer<>(properties)) {
final List<TopicPartition> partitions = consumer.partitionsFor(topic).stream().map(pi -> new TopicPartition(pi.topic(), pi.partition())).collect(Collectors.toList());
consumer.assign(partitions);
consumer.seekToBeginning(partitions);
final long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < DEFAULT_TIMEOUT) {
final ConsumerRecords<Object, Object> records = consumer.poll(ofMillis(500));
if (!records.isEmpty()) {
return true;
}
}
return false;
}
}
Aggregations