use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testSource.
@SuppressWarnings("unchecked")
@Test
public void testSource() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "hello", i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 10);
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testBroadcast.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBroadcast() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("broadcast", true);
CountKafkaCdiEvents testEvents = new CountKafkaCdiEvents();
connector = new KafkaConnector();
connector.executionHolder = new ExecutionHolder(vertx);
connector.configurations = UnsatisfiedInstance.instance();
connector.consumerRebalanceListeners = UnsatisfiedInstance.instance();
connector.kafkaCDIEvents = testEvents;
connector.init();
PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector.getPublisherBuilder(config);
List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
assertThat(messages1.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(messages2.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(testEvents.firedConsumerEvents.sum()).isEqualTo(1);
assertThat(testEvents.firedProducerEvents.sum()).isEqualTo(0);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testRetry.
@SuppressWarnings({ "rawtypes" })
@Test
@Tag(TestTags.SLOW)
public void testRetry() {
// This test need an individual Kafka container
try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
kafka.start();
await().until(kafka::isRunning);
MapBasedConfig config = newCommonConfigForSource().with("bootstrap.servers", kafka.getBootstrapServers()).with("value.deserializer", IntegerDeserializer.class.getName()).with("retry", true).with("retry-attempts", 100).with("retry-max-wait", 30);
KafkaCompanion kafkaCompanion = new KafkaCompanion(kafka.getBootstrapServers());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<KafkaRecord> messages1 = new ArrayList<>();
source.getStream().subscribe().with(messages1::add);
kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
try (@SuppressWarnings("unused") StrimziKafkaContainer container = restart(kafka, 2)) {
kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, 10), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 20);
assertThat(messages1.size()).isGreaterThanOrEqualTo(20);
}
}
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkTest method testSinkUsingIntegerAndChannelName.
@Test
@SuppressWarnings("unchecked")
public void testSinkUsingIntegerAndChannelName() {
ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 10, Duration.ofSeconds(10));
MapBasedConfig config = getBaseConfig().with("channel-name", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0);
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Multi.createFrom().range(0, 10).map(Message::of).subscribe((Subscriber<? super Message<Integer>>) subscriber);
assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkTest method testInvalidPayloadType.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInvalidPayloadType() {
ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 4, Duration.ofSeconds(10));
MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0).with("max-inflight-messages", 1L).with("channel-name", "my-channel").with("retries", // disable retry.
0L);
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
CountKafkaCdiEvents testCdiEvents = new CountKafkaCdiEvents();
sink = new KafkaSink(oc, testCdiEvents, UnsatisfiedInstance.instance());
await().until(() -> {
HealthReport.HealthReportBuilder builder = HealthReport.builder();
sink.isReady(builder);
return builder.build().isOk();
});
List<Object> acked = new CopyOnWriteArrayList<>();
List<Object> nacked = new CopyOnWriteArrayList<>();
Subscriber subscriber = sink.getSink().build();
Multi.createFrom().range(0, 6).map(i -> {
if (i == 3 || i == 5) {
return Integer.toString(i);
}
return i;
}).map(i -> Message.of(i, () -> {
acked.add(i);
return CompletableFuture.completedFuture(null);
}, t -> {
nacked.add(i);
return CompletableFuture.completedFuture(null);
})).subscribe(subscriber);
assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(4);
await().until(() -> nacked.size() >= 2);
assertThat(acked).containsExactly(0, 1, 2, 4);
assertThat(nacked).contains("3", "5");
assertThat(testCdiEvents.firedConsumerEvents.sum()).isEqualTo(0);
assertThat(testCdiEvents.firedProducerEvents.sum()).isEqualTo(1);
}
Aggregations