Search in sources :

Example 96 with MapBasedConfig

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

the class EventBusSinkTest method testSinkUsingString.

@SuppressWarnings("unchecked")
@Test
public void testSinkUsingString() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS, v -> expected.getAndIncrement());
    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    EventBusSink sink = new EventBusSink(vertx, new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));
    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10).map(i -> Integer.toString(i)).map(Message::of).subscribe((Subscriber<Message<?>>) subscriber.build());
    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 97 with MapBasedConfig

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

the class EventBusSinkTest method testSinkUsingInteger.

@SuppressWarnings("unchecked")
@Test
public void testSinkUsingInteger() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeIntegers(topic, 10, 10, TimeUnit.SECONDS, v -> expected.getAndIncrement());
    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    EventBusSink sink = new EventBusSink(vertx, new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));
    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10).map(v -> (Message<?>) Message.of(v)).subscribe((Subscriber<Message<?>>) subscriber.build());
    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Multi(io.smallrye.mutiny.Multi) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) ArrayList(java.util.ArrayList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) NoSuchElementException(java.util.NoSuchElementException) Subscriber(org.reactivestreams.Subscriber) Weld(org.jboss.weld.environment.se.Weld) Awaitility.await(org.awaitility.Awaitility.await) PersonCodec(io.smallrye.reactive.messaging.eventbus.codec.PersonCodec) SubscriberBuilder(org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder) UUID(java.util.UUID) WeldContainer(org.jboss.weld.environment.se.WeldContainer) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Message(org.eclipse.microprofile.reactive.messaging.Message) AfterEach(org.junit.jupiter.api.AfterEach) Person(io.smallrye.reactive.messaging.eventbus.codec.Person) Collections(java.util.Collections) Message(org.eclipse.microprofile.reactive.messaging.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 98 with MapBasedConfig

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

the class EventBusSinkTest method testPublish.

@SuppressWarnings("unchecked")
@Test
public void testPublish() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected1 = new AtomicInteger(0);
    usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS, v -> expected1.getAndIncrement());
    AtomicInteger expected2 = new AtomicInteger(0);
    usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS, v -> expected2.getAndIncrement());
    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("publish", true);
    EventBusSink sink = new EventBusSink(vertx, new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));
    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10).map(i -> Integer.toString(i)).map(Message::of).subscribe((Subscriber<Message<?>>) subscriber.build());
    await().untilAtomic(expected1, is(10));
    assertThat(expected1).hasValue(10);
    assertThat(expected2).hasValue(10);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 99 with MapBasedConfig

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

the class EventBusSourceTest method testAcknowledgement.

@Test
public void testAcknowledgement() {
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("use-reply-as-ack", true);
    EventBusSource source = new EventBusSource(vertx, new VertxEventBusConnectorIncomingConfiguration(new MapBasedConfig(config)));
    Multi<? extends EventBusMessage<?>> multi = Multi.createFrom().publisher(source.source().buildRs()).onItem().transform(x -> (EventBusMessage<?>) x).onItem().transformToUniAndConcatenate(m -> Uni.createFrom().completionStage(m.ack().toCompletableFuture().thenApply(x -> m)));
    List<EventBusMessage<?>> messages = new ArrayList<>();
    multi.subscribe().with(messages::add);
    AtomicBoolean acked = new AtomicBoolean();
    vertx.eventBus().request(topic, 1).onItem().invoke(rep -> acked.set(true)).await().indefinitely();
    await().untilTrue(acked);
    assertThat(messages).isNotEmpty();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 100 with MapBasedConfig

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

the class EventBusSourceTest method testBroadcast.

@SuppressWarnings("unchecked")
@Test
public void testBroadcast() {
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("broadcast", true);
    EventBusSource source = new EventBusSource(vertx, new VertxEventBusConnectorIncomingConfiguration(new MapBasedConfig(config)));
    List<EventBusMessage<Integer>> messages1 = new ArrayList<>();
    List<EventBusMessage<Integer>> messages2 = new ArrayList<>();
    Multi<EventBusMessage<Integer>> multi = Multi.createFrom().publisher(source.source().buildRs()).onItem().transform(x -> (EventBusMessage<Integer>) x);
    multi.subscribe().with(messages1::add);
    multi.subscribe().with(messages2::add);
    AtomicInteger counter = new AtomicInteger();
    new Thread(() -> usage.produceIntegers(topic, 10, true, null, counter::getAndIncrement)).start();
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
    assertThat(messages1.stream().map(EventBusMessage::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertThat(messages2.stream().map(EventBusMessage::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) 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