Search in sources :

Example 61 with MapBasedConfig

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

the class RabbitMQTest method testSendingMessagesToRabbitMQWithNotAnonymousDetection.

@Test
public void testSendingMessagesToRabbitMQWithNotAnonymousDetection() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(10);
    usage.consumeIntegers("sink-not-anonymous", v -> latch.countDown());
    weld.addBeanClass(ProducingBean.class);
    new MapBasedConfig().with("mp.messaging.outgoing.sink.address", "sink-not-anonymous").with("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.sink.host", host).with("mp.messaging.outgoing.sink.port", port).with("mp.messaging.outgoing.sink.durable", false).with("mp.messaging.outgoing.sink.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
    container = weld.initialize();
    await().until(() -> isAmqpConnectorReady(container));
    await().until(() -> isAmqpConnectorAlive(container));
    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 62 with MapBasedConfig

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

the class TracingAmqpToAppNoParentTest method testFromAmqpToAppWithNoParent.

@Test
public void testFromAmqpToAppWithNoParent() {
    weld.addBeanClass(MyAppReceivingData.class);
    new MapBasedConfig().put("mp.messaging.incoming.stuff.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.stuff.host", host).put("mp.messaging.incoming.stuff.port", port).put("mp.messaging.incoming.stuff.address", "no-parent-stuff").put("amqp-username", username).put("amqp-password", password).write();
    container = weld.initialize();
    MyAppReceivingData bean = container.getBeanManager().createInstance().select(MyAppReceivingData.class).get();
    await().until(() -> isAmqpConnectorReady(container));
    AtomicInteger count = new AtomicInteger();
    usage.produce("no-parent-stuff", 10, count::getAndIncrement);
    await().until(() -> bean.list().size() >= 10);
    assertThat(bean.list()).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertThat(bean.tracing()).hasSizeGreaterThanOrEqualTo(10);
    assertThat(bean.tracing()).doesNotContainNull().doesNotHaveDuplicates();
    List<String> spanIds = new ArrayList<>();
    for (TracingMetadata tracing : bean.tracing()) {
        spanIds.add(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getSpanId());
        assertThat(Span.fromContextOrNull(tracing.getPreviousContext())).isNull();
    }
    assertThat(spanIds).doesNotContainNull().doesNotHaveDuplicates().hasSizeGreaterThanOrEqualTo(10);
    for (SpanData data : testExporter.getFinishedSpanItems()) {
        assertThat(data.getSpanId()).isIn(spanIds);
        assertThat(data.getSpanId()).isNotEqualTo(data.getParentSpanId());
        assertThat(data.getKind()).isEqualByComparingTo(SpanKind.CONSUMER);
    }
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 63 with MapBasedConfig

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

the class AmqpLinkTest method doIncomingTestImpl.

private void doIncomingTestImpl(boolean durable) throws Exception {
    List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>());
    AtomicReference<ProtonConnection> connectionRef = new AtomicReference<>();
    AtomicReference<ProtonSender> senderRef = new AtomicReference<>();
    server = setupMockServer(connectionRef, senderRef, dispositionsReceived, executionHolder.vertx().getDelegate());
    Weld weld = new Weld();
    weld.addBeanClass(MyConsumer.class);
    String containerId = "myContainerId";
    String subscriptionName = "mySubName";
    String address = "people";
    MapBasedConfig config = new MapBasedConfig().put("mp.messaging.incoming.people-in.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.people-in.container-id", containerId).put("mp.messaging.incoming.people-in.address", address).put("mp.messaging.incoming.people-in.link-name", subscriptionName).put("mp.messaging.incoming.people-in.host", "localhost").put("mp.messaging.incoming.people-in.port", server.actualPort()).put("mp.messaging.incoming.people-in.tracing-enabled", false);
    if (durable) {
        config.put("mp.messaging.incoming.people-in.durable", true);
    }
    config.write();
    container = weld.initialize();
    MyConsumer consumer = container.getBeanManager().createInstance().select(MyConsumer.class).get();
    await().atMost(6, TimeUnit.SECONDS).until(() -> consumer.list().size() >= 3);
    assertThat(consumer.list()).containsExactly("Luke", "Leia", "Han");
    await().atMost(3, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= 3);
    AtomicInteger count = new AtomicInteger();
    dispositionsReceived.forEach(record -> {
        assertThat(record.getMessageNumber()).isEqualTo(count.get() + 1);
        assertThat(record.getState()).isInstanceOf(Accepted.class);
        assertThat(record.isSettled()).isTrue();
        count.incrementAndGet();
    });
    assertThat(count.get()).isEqualTo(3);
    // Verify details of the connection and link created
    ProtonConnection serverConnection = connectionRef.get();
    assertThat(serverConnection).isNotNull();
    assertThat(serverConnection.getRemoteContainer()).isEqualTo(containerId);
    ProtonSender serverSender = senderRef.get();
    assertThat(serverSender).isNotNull();
    assertThat(serverSender.getName()).isEqualTo(subscriptionName);
    Source source = (org.apache.qpid.proton.amqp.messaging.Source) serverSender.getRemoteSource();
    assertThat(source).isNotNull();
    assertThat(source.getAddress()).isEqualTo(address);
    if (durable) {
        assertThat(source.getDurable()).isEqualTo(TerminusDurability.UNSETTLED_STATE);
        assertThat(source.getExpiryPolicy()).isEqualTo(TerminusExpiryPolicy.NEVER);
    } else {
        assertThat(source.getDurable()).isEqualTo(TerminusDurability.NONE);
        assertThat(source.getExpiryPolicy()).isNotEqualTo(TerminusExpiryPolicy.NEVER);
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Source(org.apache.qpid.proton.amqp.messaging.Source) Weld(org.jboss.weld.environment.se.Weld) ProtonConnection(io.vertx.proton.ProtonConnection) ProtonSender(io.vertx.proton.ProtonSender) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 64 with MapBasedConfig

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

the class AmqpSinkCDIConfigTest method testConfigByCDIMissingBean.

@Test
public void testConfigByCDIMissingBean() {
    Weld weld = new Weld();
    weld.addBeanClass(ProducingBean.class);
    new MapBasedConfig().put("mp.messaging.outgoing.sink.address", "sink").put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.outgoing.sink.host", host).put("mp.messaging.outgoing.sink.port", port).put("amqp-username", username).put("amqp-password", password).put("mp.messaging.outgoing.sink.client-options-name", "myclientoptions").put("mp.messaging.outgoing.sink.tracing-enabled", false).write();
    assertThatThrownBy(() -> container = weld.initialize()).isInstanceOf(DeploymentException.class);
}
Also used : MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.jupiter.api.Test)

Example 65 with MapBasedConfig

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

the class AmqpSinkCDIConfigTest method testConfigGlobalOptionsByCDICorrect.

@Test
public void testConfigGlobalOptionsByCDICorrect() throws InterruptedException {
    Weld weld = new Weld();
    CountDownLatch latch = new CountDownLatch(10);
    usage.consumeIntegers("sink", v -> latch.countDown());
    weld.addBeanClass(ProducingBean.class);
    weld.addBeanClass(ClientConfigurationBean.class);
    new MapBasedConfig().put("mp.messaging.outgoing.sink.address", "sink").put("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.outgoing.sink.host", host).put("mp.messaging.outgoing.sink.port", port).put("mp.messaging.outgoing.sink.durable", false).put("mp.messaging.outgoing.sink.tracing-enabled", false).put("amqp-username", username).put("amqp-password", password).put("amqp-client-options-name", "myclientoptions").write();
    container = weld.initialize();
    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Weld(org.jboss.weld.environment.se.Weld) 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