Search in sources :

Example 31 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class ClientTestBase method createSourceSeekToOffset.

public KafkaSource<Integer, String> createSourceSeekToOffset() {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    SingletonInstance<KafkaConsumerRebalanceListener> listeners = new SingletonInstance<>(groupId, getKafkaConsumerRebalanceListenerAwaitingAssignationAndSeekToOffset());
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), listeners, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    return source;
}
Also used : KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 32 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class ClientTestBase method createSourceSeekToEnd.

public KafkaSource<Integer, String> createSourceSeekToEnd() {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    SingletonInstance<KafkaConsumerRebalanceListener> listeners = new SingletonInstance<>(groupId, getKafkaConsumerRebalanceListenerAwaitingAssignationAndSeekToEnd());
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), listeners, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    return source;
}
Also used : KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 33 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class KafkaClientReactiveStreamsPublisherTest method createSource.

public KafkaSource<String, String> createSource() {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    return source;
}
Also used : KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 34 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class PauseResumeTest method testPauseResumeWithBlockingConsumptionAndConcurrency.

@RepeatedTest(3)
void testPauseResumeWithBlockingConsumptionAndConcurrency() {
    MapBasedConfig config = commonConfiguration().with("client.id", UUID.randomUUID().toString());
    String group = UUID.randomUUID().toString();
    source = new KafkaSource<>(vertx, group, new KafkaConnectorIncomingConfiguration(config), getConsumerRebalanceListeners(), CountKafkaCdiEvents.noCdiEvents, getDeserializationFailureHandlers(), -1);
    injectMockConsumer(source, consumer);
    List<String> items = new CopyOnWriteArrayList<>();
    source.getStream().onItem().transformToUni(item -> Uni.createFrom().item(item).onItem().delayIt().by(Duration.ofMillis(1500)).onItem().invoke(() -> items.add(item.getPayload()))).merge(2).subscribe().with(item -> {
    // do nothing
    });
    TopicPartition tp0 = new TopicPartition(TOPIC, 0);
    TopicPartition tp1 = new TopicPartition(TOPIC, 1);
    TopicPartition tp2 = new TopicPartition(TOPIC, 2);
    Map<TopicPartition, Long> beginning = new HashMap<>();
    beginning.put(tp0, 0L);
    beginning.put(tp1, 0L);
    beginning.put(tp2, 0L);
    consumer.updateBeginningOffsets(beginning);
    consumer.schedulePollTask(() -> {
        consumer.rebalance(Arrays.asList(tp0, tp1, tp2));
        for (int i = 0; i < 5; i++) {
            consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, i, "k", "v" + i));
        }
    });
    await().until(() -> items.size() > 3);
    await().until(() -> consumer.paused().isEmpty());
}
Also used : Consumer(org.apache.kafka.clients.consumer.Consumer) AssertSubscriber(io.smallrye.mutiny.helpers.test.AssertSubscriber) TopicPartition(org.apache.kafka.common.TopicPartition) Awaitility.await(org.awaitility.Awaitility.await) java.util(java.util) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) OffsetResetStrategy(org.apache.kafka.clients.consumer.OffsetResetStrategy) io.smallrye.reactive.messaging.kafka(io.smallrye.reactive.messaging.kafka) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) Uni(io.smallrye.mutiny.Uni) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) MockKafkaUtils.injectMockConsumer(io.smallrye.reactive.messaging.kafka.base.MockKafkaUtils.injectMockConsumer) TypeLiteral(javax.enterprise.util.TypeLiteral) org.junit.jupiter.api(org.junit.jupiter.api) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Duration(java.time.Duration) Vertx(io.vertx.mutiny.core.Vertx) WeldTestBase(io.smallrye.reactive.messaging.kafka.base.WeldTestBase) KafkaSource(io.smallrye.reactive.messaging.kafka.impl.KafkaSource) Instance(javax.enterprise.inject.Instance) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TopicPartition(org.apache.kafka.common.TopicPartition) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 35 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class KafkaSinkTest method testInvalidTypeWithDefaultInflightMessages.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInvalidTypeWithDefaultInflightMessages() {
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 10, Duration.ofSeconds(10));
    MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0).with("retries", 0L).with("channel-name", "testInvalidTypeWithDefaultInflightMessages");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    Subscriber subscriber = sink.getSink().build();
    Multi.createFrom().range(0, 5).map(i -> {
        if (i == 3 || i == 5) {
            return Integer.toString(i);
        }
        return i;
    }).map(Message::of).subscribe(subscriber);
    await().until(() -> consumed.count() >= 3);
    // Default inflight is 5
    // 1, 2, 3, 4, 5 are sent at the same time.
    // As 3 fails, the stream is stopped, but, 1, 2, and 4 are already sent and potentially 6
    assertThat(consumed.count()).isGreaterThanOrEqualTo(3);
}
Also used : Subscriber(org.reactivestreams.Subscriber) KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Aggregations

MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)272 Test (org.junit.jupiter.api.Test)223 Message (org.eclipse.microprofile.reactive.messaging.Message)69 JsonObject (io.vertx.core.json.JsonObject)63 ArrayList (java.util.ArrayList)61 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)57 TopicPartition (org.apache.kafka.common.TopicPartition)43 Awaitility.await (org.awaitility.Awaitility.await)38 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)37 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)34 Weld (org.jboss.weld.environment.se.Weld)32 KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)31 HashMap (java.util.HashMap)29 AfterEach (org.junit.jupiter.api.AfterEach)29 Collectors (java.util.stream.Collectors)28 HealthReport (io.smallrye.reactive.messaging.health.HealthReport)26 KafkaSource (io.smallrye.reactive.messaging.kafka.impl.KafkaSource)26 IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)25 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)23 Duration (java.time.Duration)22