Search in sources :

Example 76 with MapBasedConfig

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) SeContainerInitializer(javax.enterprise.inject.se.SeContainerInitializer) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 77 with MapBasedConfig

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 78 with MapBasedConfig

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 79 with MapBasedConfig

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);
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectorLiteral(org.eclipse.microprofile.reactive.messaging.spi.ConnectorLiteral) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Collectors(java.util.stream.Collectors) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Message(org.eclipse.microprofile.reactive.messaging.Message) AfterEach(org.junit.jupiter.api.AfterEach) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PublisherBuilder(org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder) Weld(org.jboss.weld.environment.se.Weld) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 80 with MapBasedConfig

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");
    }
}
Also used : HashMap(java.util.HashMap) DeploymentException(javax.enterprise.inject.spi.DeploymentException) 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