Search in sources :

Example 71 with MapBasedConfig

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

the class CloudEventProductionTest method testSendingBinaryCloudEventsWithConfiguredTypeAndSource.

@Test
public void testSendingBinaryCloudEventsWithConfiguredTypeAndSource() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("mp.messaging.outgoing.amqp.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.amqp.address", address).with("mp.messaging.outgoing.amqp.host", host).with("mp.messaging.outgoing.amqp.port", port).with("mp.messaging.outgoing.amqp.cloud-events-type", "my type").with("mp.messaging.outgoing.amqp.cloud-events-source", "http://acme.org").with("amqp-username", username).with("amqp-password", password).write();
    weld.addBeanClass(AmqpSender.class);
    container = weld.initialize();
    AmqpSender bean = container.getBeanManager().createInstance().select(AmqpSender.class).get();
    Emitter<JsonObject> emitter = bean.get();
    List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
    usage.consume(address, list::add);
    Message<JsonObject> msg = Message.of(new JsonObject().put("message", "hello")).addMetadata(OutgoingCloudEventMetadata.builder().withDataContentType("application/json+neo").withId("some id").build());
    emitter.send(msg);
    await().until(() -> list.size() == 1);
    AmqpMessage message = list.get(0);
    assertThat(message.address()).isEqualTo(address);
    assertThat(message.contentType()).isEqualTo("application/json+neo");
    JsonObject app = message.applicationProperties();
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_SPEC_VERSION)).isEqualTo("1.0");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_TYPE)).isEqualTo("my type");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_SOURCE)).isEqualTo("http://acme.org");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_ID)).isEqualTo("some id");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_CONTENT_TYPE)).isEqualTo("application/json+neo");
    JsonObject body = message.bodyAsJsonObject();
    assertThat(body.getString("message")).isEqualTo("hello");
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) Test(org.junit.jupiter.api.Test)

Example 72 with MapBasedConfig

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

the class AmqpSourceTest method doSourceTestImpl.

private void doSourceTestImpl(boolean useChannelName) throws Exception {
    int msgCount = 10;
    List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
    server = setupMockServer(msgCount, dispositionsReceived, executionHolder.vertx().getDelegate());
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config;
    if (useChannelName) {
        config = getConfigUsingChannelName(topic, server.actualPort());
    } else {
        config = getConfig(topic, server.actualPort());
    }
    provider = new AmqpConnector();
    provider.setup(executionHolder);
    PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
    List<Message<Integer>> messages = new ArrayList<>();
    builder.buildRs().subscribe(createSubscriber(messages, new AtomicBoolean()));
    await().atMost(5, TimeUnit.SECONDS).until(() -> messages.size() >= 10);
    assertThat(messages.stream().peek(m -> m.ack().toCompletableFuture().join()).map(Message::getPayload).collect(Collectors.toList())).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    await().atMost(2, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= msgCount);
    AtomicInteger count = new AtomicInteger();
    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 : Message(org.eclipse.microprofile.reactive.messaging.Message) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JsonObject(io.vertx.core.json.JsonObject) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 73 with MapBasedConfig

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

the class AmqpSourceTest method doDataContentTestImpl.

private void doDataContentTestImpl(boolean setContentType) throws Exception {
    List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>());
    final org.apache.qpid.proton.message.Message msg = Proton.message();
    msg.setBody(new Data(new Binary("foo".getBytes(StandardCharsets.UTF_8))));
    if (setContentType) {
        msg.setContentType("application/octet-stream");
    }
    server = setupMockServerForTypeTest(msg, dispositionsReceived, executionHolder.vertx().getDelegate());
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config = getConfig(topic, server.actualPort());
    provider = new AmqpConnector();
    provider.setup(executionHolder);
    List<Message<byte[]>> messages = new ArrayList<>();
    PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
    builder.to(createSubscriber(messages, new AtomicBoolean())).run();
    await().atMost(6, TimeUnit.SECONDS).until(() -> !messages.isEmpty());
    assertThat(messages.stream().peek(m -> m.ack().toCompletableFuture().join()).map(Message::getPayload).collect(Collectors.toList())).containsExactly("foo".getBytes(StandardCharsets.UTF_8));
    await().atMost(2, TimeUnit.SECONDS).until(() -> !dispositionsReceived.isEmpty());
    AtomicInteger count = new AtomicInteger();
    dispositionsReceived.forEach(record -> {
        assertThat(record.getMessageNumber()).isEqualTo(1);
        assertThat(record.getState()).isInstanceOf(Accepted.class);
        assertThat(record.isSettled()).isTrue();
        count.incrementAndGet();
    });
    assertThat(count.get()).isEqualTo(1);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) Data(org.apache.qpid.proton.amqp.messaging.Data) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JsonObject(io.vertx.core.json.JsonObject) Binary(org.apache.qpid.proton.amqp.Binary) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 74 with MapBasedConfig

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

the class AmqpSourceTest method testSourceWithBinaryContent.

@Test
@Timeout(30)
public void testSourceWithBinaryContent() throws Exception {
    List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>());
    final org.apache.qpid.proton.message.Message msg = Proton.message();
    msg.setBody(new AmqpValue(new Binary("foo".getBytes(StandardCharsets.UTF_8))));
    server = setupMockServerForTypeTest(msg, dispositionsReceived, executionHolder.vertx().getDelegate());
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config = getConfig(topic, server.actualPort());
    provider = new AmqpConnector();
    provider.setup(executionHolder);
    List<Message<byte[]>> messages = new ArrayList<>();
    PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
    builder.to(createSubscriber(messages, new AtomicBoolean())).run();
    await().atMost(6, TimeUnit.SECONDS).until(() -> !messages.isEmpty());
    assertThat(messages.stream().peek(m -> m.ack().toCompletableFuture().join()).map(Message::getPayload).collect(Collectors.toList())).containsExactly("foo".getBytes(StandardCharsets.UTF_8));
    await().atMost(2, TimeUnit.SECONDS).until(() -> !dispositionsReceived.isEmpty());
    AtomicInteger count = new AtomicInteger();
    dispositionsReceived.forEach(record -> {
        assertThat(record.getMessageNumber()).isEqualTo(1);
        assertThat(record.getState()).isInstanceOf(Accepted.class);
        assertThat(record.isSettled()).isTrue();
        count.incrementAndGet();
    });
    assertThat(count.get()).isEqualTo(1);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JsonObject(io.vertx.core.json.JsonObject) Binary(org.apache.qpid.proton.amqp.Binary) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 75 with MapBasedConfig

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

the class AmqpSourceTest method testABeanConsumingTheAMQPMessages.

@Test
@Timeout(30)
public void testABeanConsumingTheAMQPMessages() throws Exception {
    int msgCount = 10;
    List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
    server = setupMockServer(msgCount, dispositionsReceived, executionHolder.vertx().getDelegate());
    new MapBasedConfig().put("mp.messaging.incoming.data.address", "data").put("mp.messaging.incoming.data.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.data.host", "localhost").put("mp.messaging.incoming.data.port", server.actualPort()).put("mp.messaging.incoming.data.tracing-enabled", false).write();
    ConsumptionBean bean = deploy();
    List<Integer> list = bean.getResults();
    await().atMost(5, TimeUnit.SECONDS).until(() -> list.size() >= 10);
    // ConsumptionBean adds 1, thus shifting original values by 1
    assertThat(list).containsExactly(2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
    await().atMost(2, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= msgCount);
    AtomicInteger count = new AtomicInteger();
    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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

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