use of io.smallrye.reactive.messaging.kafka.companion.ProducerTask in project smallrye-reactive-messaging by smallrye.
the class MultiTopicsTest method testWithOnlyTwoTopicsReceiving.
@RepeatedTest(5)
public void testWithOnlyTwoTopicsReceiving() {
String topic1 = UUID.randomUUID().toString();
String topic2 = UUID.randomUUID().toString();
String topic3 = UUID.randomUUID().toString();
KafkaConsumer bean = runApplication(kafkaConfig("mp.messaging.incoming.kafka").with("value.deserializer", StringDeserializer.class.getName()).with("topics", topic1 + ", " + topic2 + ", " + topic3).with("graceful-shutdown", false).with("auto.offset.reset", "earliest"), KafkaConsumer.class);
await().until(this::isReady);
await().until(this::isAlive);
assertThat(bean.getMessages()).isEmpty();
ProducerTask pt1 = companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic1, Integer.toString(i), "hello"), 3);
ProducerTask pt2 = companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic3, Integer.toString(i), "bonjour"), 3);
await().until(() -> pt1.count() == 3 && pt2.count() == 3);
await().until(() -> bean.getMessages().size() >= 6);
AtomicInteger top1 = new AtomicInteger();
AtomicInteger top2 = new AtomicInteger();
AtomicInteger top3 = new AtomicInteger();
bean.getMessages().forEach(message -> {
io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordMetadata record = message.getMetadata(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordMetadata.class).orElse(null);
assertThat(record).isNotNull();
String topic = record.getTopic();
if (topic.equals(topic1)) {
top1.incrementAndGet();
assertThat(message.getPayload()).isEqualTo("hello");
} else if (topic.equals(topic2)) {
top2.incrementAndGet();
} else if (topic.equals(topic3)) {
top3.incrementAndGet();
assertThat(message.getPayload()).isEqualTo("bonjour");
}
LegacyMetadataTestUtils.tempCompareLegacyAndApiMetadata(record, message);
});
assertThat(top1).hasValue(3);
assertThat(top2).hasValue(0);
assertThat(top3).hasValue(3);
}
use of io.smallrye.reactive.messaging.kafka.companion.ProducerTask in project smallrye-reactive-messaging by smallrye.
the class KafkaWithBaseTest method testWithBase.
@Test
public void testWithBase() {
// companion is created by the base class
// produce 100 records to messages topic
ProducerTask producerTask = companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>("messages", i), 100);
long msgCount = producerTask.awaitCompletion().count();
Assertions.assertEquals(msgCount, 100);
// consume 100 records from messages topic
ConsumerTask<String, Integer> consumerTask = companion.consumeIntegers().fromTopics("messages", 100);
ConsumerRecord<String, Integer> lastRecord = consumerTask.awaitCompletion().getLastRecord();
Assertions.assertEquals(lastRecord.value(), 99);
}
use of io.smallrye.reactive.messaging.kafka.companion.ProducerTask in project smallrye-reactive-messaging by smallrye.
the class HealthCheckTest method testHealthOfApplicationWithChannel.
@Test
public void testHealthOfApplicationWithChannel() {
KafkaMapBasedConfig config = getKafkaSourceConfig(topic);
LazyConsumingBean bean = runApplication(config, LazyConsumingBean.class);
ProducerTask produced = companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "key", i), 10);
await().until(this::isStarted);
await().until(this::isReady);
await().until(this::isAlive);
produced.awaitCompletion(Duration.ofMinutes(1));
Multi<Integer> channel = bean.getChannel();
channel.select().first(10).collect().asList().await().atMost(Duration.ofSeconds(10));
HealthReport startup = getHealth().getStartup();
HealthReport liveness = getHealth().getLiveness();
HealthReport readiness = getHealth().getReadiness();
assertThat(startup.isOk()).isTrue();
assertThat(liveness.isOk()).isTrue();
assertThat(readiness.isOk()).isTrue();
assertThat(startup.getChannels()).hasSize(1);
assertThat(liveness.getChannels()).hasSize(1);
assertThat(readiness.getChannels()).hasSize(1);
}
Aggregations