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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations