use of io.kestra.runner.kafka.services.KafkaConsumerService in project kestra by kestra-io.
the class KafkaElasticIndexerTest method run.
@Test
void run() throws IOException, InterruptedException {
String topic = this.topicsConfig.stream().filter(indicesConfig -> indicesConfig.getCls() == Execution.class).findFirst().orElseThrow().getName();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestHighLevelClient elasticClientSpy = spy(elasticClient);
doAnswer(invocation -> {
countDownLatch.countDown();
return invocation.callRealMethod();
}).when(elasticClientSpy).bulk(any(), any());
KafkaConsumerService kafkaConsumerServiceSpy = mock(KafkaConsumerService.class);
MockConsumer<String, String> mockConsumer = mockConsumer(topic);
doReturn(mockConsumer).when(kafkaConsumerServiceSpy).of(any(), any(), any());
ConsumerRecord<String, String> first = buildExecutionRecord(topic, 0);
mockConsumer.addRecord(first);
mockConsumer.addRecord(buildExecutionRecord(topic, 1));
mockConsumer.addRecord(buildExecutionRecord(topic, 2));
mockConsumer.addRecord(buildExecutionRecord(topic, 3));
mockConsumer.addRecord(buildExecutionRecord(topic, 4));
mockConsumer.addRecord(buildRecord(topic, first.key(), null, 5));
KafkaElasticIndexer indexer = new KafkaElasticIndexer(metricRegistry, elasticClientSpy, indexerConfig, topicsConfig, indicesConfigs, elasticSearchIndicesService, kafkaConsumerServiceSpy, executorsUtils);
Thread thread = new Thread(indexer);
thread.start();
countDownLatch.await();
assertThat(countDownLatch.getCount(), is(0L));
}
Aggregations