use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class AmqpWithConverterTest method testAckWithConverter.
@Test
@Timeout(30)
public void testAckWithConverter() throws Exception {
String address = UUID.randomUUID().toString();
int msgCount = 10;
List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
server = setupMockServer(msgCount, dispositionsReceived, executionHolder.vertx().getDelegate());
SeContainerInitializer weld = Weld.newInstance();
new MapBasedConfig().with("mp.messaging.incoming.in.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.in.host", "localhost").with("mp.messaging.incoming.in.port", server.actualPort()).with("mp.messaging.incoming.in.address", address).with("mp.messaging.incoming.in.tracing-enabled", false).write();
weld.addBeanClasses(DummyConverter.class, MyApp.class);
container = weld.initialize();
MyApp app = container.getBeanManager().createInstance().select(MyApp.class).get();
List<DummyData> appList = app.list();
await().atMost(5, TimeUnit.SECONDS).until(() -> appList.size() >= msgCount);
AtomicInteger count = new AtomicInteger();
appList.forEach(dummy -> {
assertThat(dummy).isInstanceOf(DummyData.class);
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
await().atMost(2, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= msgCount);
count.set(0);
dispositionsReceived.forEach(record -> {
int messageNum = count.get() + 1;
assertThat(messageNum).isLessThanOrEqualTo(msgCount);
assertThat(record.getMessageNumber()).isEqualTo(messageNum);
assertThat(record.getState()).isInstanceOf(Accepted.class);
assertThat(record.isSettled()).isTrue();
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class MqttSinkTest method testSinkUsingString.
@SuppressWarnings("unchecked")
@Test
public void testSinkUsingString() throws InterruptedException {
String topic = UUID.randomUUID().toString();
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger expected = new AtomicInteger(0);
usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS, latch::countDown, v -> expected.getAndIncrement());
Map<String, Object> config = new HashMap<>();
config.put("topic", topic);
config.put("host", address);
config.put("port", port);
MqttSink sink = new MqttSink(vertx, new MqttConnectorOutgoingConfiguration(new MapBasedConfig(config)));
Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Multi.createFrom().range(0, 10).map(i -> Integer.toString(i)).map(Message::of).subscribe((Subscriber<? super Message<String>>) subscriber);
assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
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 MqttSinkTest method testSinkUsingChannelName.
@SuppressWarnings("unchecked")
@Test
public void testSinkUsingChannelName() throws InterruptedException {
String topic = UUID.randomUUID().toString();
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger expected = new AtomicInteger(0);
usage.consumeIntegers(topic, 10, 10, TimeUnit.SECONDS, latch::countDown, v -> expected.getAndIncrement());
Map<String, Object> config = new HashMap<>();
config.put("channel-name", topic);
config.put("host", address);
config.put("port", port);
MqttSink sink = new MqttSink(vertx, new MqttConnectorOutgoingConfiguration(new MapBasedConfig(config)));
Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Multi.createFrom().range(0, 10).map(Message::of).subscribe((Subscriber<? super Message<Integer>>) subscriber);
assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
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 MqttSourceTest method testBroadcast.
@Test
public void testBroadcast() {
String topic = UUID.randomUUID().toString();
Map<String, Object> config = new HashMap<>();
config.put("topic", topic);
config.put("host", address);
config.put("port", port);
config.put("channel-name", topic);
config.put("broadcast", true);
MqttSource source = new MqttSource(vertx, new MqttConnectorIncomingConfiguration(new MapBasedConfig(config)));
List<MqttMessage<?>> messages1 = new ArrayList<>();
List<MqttMessage<?>> messages2 = new ArrayList<>();
PublisherBuilder<MqttMessage<?>> stream = source.getSource();
stream.forEach(messages1::add).run();
stream.forEach(messages2::add).run();
await().until(source::isReady);
AtomicInteger counter = new AtomicInteger();
new Thread(() -> usage.produceIntegers(topic, 10, 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(Message::getPayload).map(x -> (byte[]) x).map(bytes -> Integer.valueOf(new String(bytes))).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(messages2.stream().map(Message::getPayload).map(x -> (byte[]) x).map(bytes -> Integer.valueOf(new String(bytes))).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 DeprecatedNamedFactoryTest method testWithNonMatchingConnectionFactory.
@Test
public void testWithNonMatchingConnectionFactory() {
initWithoutConnectionFactory().addBeanClasses(FooConnectionFactoryBean.class);
Map<String, Object> map = new HashMap<>();
map.put("mp.messaging.connector." + JmsConnector.CONNECTOR_NAME + ".connection-factory-name", "bar");
map.put("mp.messaging.outgoing.queue-one.connector", JmsConnector.CONNECTOR_NAME);
map.put("mp.messaging.incoming.jms.connector", JmsConnector.CONNECTOR_NAME);
map.put("mp.messaging.incoming.jms.destination", "queue-one");
MapBasedConfig config = new MapBasedConfig(map);
addConfig(config);
try {
deploy(PayloadConsumerBean.class, ProducerBean.class);
} catch (DeploymentException de) {
assertThat(de).hasCauseInstanceOf(IllegalStateException.class).hasMessageContaining("javax.jms.ConnectionFactory bean named");
}
}
Aggregations