Search in sources :

Example 36 with MapBasedConfig

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

the class KafkaSinkTest method testSinkUsingInteger.

@SuppressWarnings("unchecked")
@Test
public void testSinkUsingInteger() {
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 10, Duration.ofSeconds(10));
    MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0).with("channel-name", "testSinkUsingInteger");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
    Multi.createFrom().range(0, 10).map(Message::of).subscribe((Subscriber<? super Message<Integer>>) subscriber);
    assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
}
Also used : KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) Test(org.junit.jupiter.api.Test)

Example 37 with MapBasedConfig

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

the class SourceCloseTest method testNoLostMessagesOnClose.

@Test
public void testNoLostMessagesOnClose() {
    companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, null, i), 1000).awaitCompletion();
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config1 = new MapBasedConfig().with("channel-name", "data1").with("bootstrap.servers", companion.getBootstrapServers()).with("topic", topic).with("value.deserializer", IntegerDeserializer.class.getName()).with("max.poll.records", 4).with(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest").with(ConsumerConfig.GROUP_ID_CONFIG, groupId).with(ConsumerConfig.CLIENT_ID_CONFIG, "A");
    MapBasedConfig config2 = new MapBasedConfig().with("channel-name", "data2").with("bootstrap.servers", companion.getBootstrapServers()).with("topic", topic).with("value.deserializer", IntegerDeserializer.class.getName()).with("max.poll.records", 4).with(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest").with(ConsumerConfig.GROUP_ID_CONFIG, groupId).with(ConsumerConfig.CLIENT_ID_CONFIG, "B");
    List<Integer> list = new ArrayList<>();
    KafkaSource<String, Integer> source1 = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config1), UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    KafkaSource<String, Integer> source2 = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config2), UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    source1.getStream().subscribe().with(l -> {
        list.add(l.getPayload());
        CompletableFuture.runAsync(l::ack);
    });
    source2.getStream().subscribe().with(l -> {
        list.add(l.getPayload());
        CompletableFuture.runAsync(l::ack);
    });
    await().until(() -> list.size() >= 100);
    source1.closeQuietly();
    await().until(() -> list.size() == 1000);
    source2.closeQuietly();
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) KafkaCompanionTestBase(io.smallrye.reactive.messaging.kafka.base.KafkaCompanionTestBase) CompletableFuture(java.util.concurrent.CompletableFuture) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) UUID(java.util.UUID) UnsatisfiedInstance(io.smallrye.reactive.messaging.kafka.base.UnsatisfiedInstance) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) KafkaSource(io.smallrye.reactive.messaging.kafka.impl.KafkaSource) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) KafkaSource(io.smallrye.reactive.messaging.kafka.impl.KafkaSource) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ArrayList(java.util.ArrayList) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 38 with MapBasedConfig

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

the class AmqpCapabilitiesConfigTest method testConsumeWithCapabilities.

/**
 * see {@code ProtonServerReceiverContext} for receiver capabilities
 */
@Test
public void testConsumeWithCapabilities() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("amqp-username", username).with("amqp-password", password).with("mp.messaging.incoming.data.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.data.address", address).with("mp.messaging.incoming.data.host", host).with("mp.messaging.incoming.data.port", port).with("mp.messaging.incoming.data.capabilities", "topic").with("mp.messaging.incoming.data.tracing-enabled", false).write();
    weld.addBeanClass(ConsumptionBean.class);
    container = weld.initialize();
    await().until(() -> isAmqpConnectorReady(container));
    ConsumptionBean bean = container.getBeanManager().createInstance().select(ConsumptionBean.class).get();
    AtomicInteger counter = new AtomicInteger();
    usage.produceTenIntegers(address, counter::incrementAndGet);
    await().until(() -> bean.getResults().size() == 10);
    ActiveMQServer activeMQServer = broker.getServer().getActiveMQServer();
    AddressInfo addressInfo = activeMQServer.getAddressInfo(SimpleString.toSimpleString(address));
    assertThat(addressInfo).isNotNull();
    assertThat(addressInfo.getRoutingType()).isEqualTo(RoutingType.MULTICAST);
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.jupiter.api.Test)

Example 39 with MapBasedConfig

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

the class AmqpCapabilitiesConfigTest method testProduceWithCapabilities.

/**
 * see {@code ProtonServerSenderContext} for sender capabilities
 */
@Test
public void testProduceWithCapabilities() {
    String address = UUID.randomUUID().toString();
    List<Integer> messages = new ArrayList<>();
    usage.consumeIntegers(address, messages::add);
    new MapBasedConfig().with("amqp-username", username).with("amqp-password", password).with("mp.messaging.outgoing.sink.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.sink.address", address).with("mp.messaging.outgoing.sink.host", host).with("mp.messaging.outgoing.sink.port", port).with("mp.messaging.outgoing.sink.use-anonymous-sender", false).with("mp.messaging.outgoing.sink.capabilities", "shared,global,some-random-capability").with("mp.messaging.outgoing.sink.tracing-enabled", false).write();
    weld.addBeanClass(ProducingBean.class);
    container = weld.initialize();
    await().until(() -> isAmqpConnectorReady(container));
    await().until(() -> messages.size() >= 10);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 40 with MapBasedConfig

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

the class AmqpConnectionTest method testVirtualhostOptionSetsOpenHostname.

@Test
public void testVirtualhostOptionSetsOpenHostname() throws Exception {
    // NOTE: this only tests the Open hostname aspect, not the further TLS SNI aspect the option also sets.
    List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>());
    AtomicReference<ProtonConnection> connectionRef = new AtomicReference<>();
    server = setupMockServerForVirtualhostOption(connectionRef, dispositionsReceived, executionHolder.vertx().getDelegate());
    Weld weld = new Weld();
    weld.addBeanClass(MyConsumer.class);
    String serverDnsHost = "localhost";
    String virtualHostname = "some-other-virtual-hostname";
    assertThat(serverDnsHost).isNotEqualTo(virtualHostname);
    MapBasedConfig config = new MapBasedConfig().put("mp.messaging.incoming.messages-in.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.messages-in.host", serverDnsHost).put("mp.messaging.incoming.messages-in.port", server.actualPort()).put("mp.messaging.incoming.messages-in.virtual-host", virtualHostname).put("mp.messaging.incoming.messages-in.tracing-enabled", false);
    config.write();
    container = weld.initialize();
    MyConsumer consumer = container.getBeanManager().createInstance().select(MyConsumer.class).get();
    await().atMost(6, TimeUnit.SECONDS).until(() -> consumer.list().size() >= 1);
    assertThat(consumer.list()).containsExactly("Virtual");
    await().atMost(3, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= 1);
    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(1);
    // Verify details of the connection created
    ProtonConnection serverConnection = connectionRef.get();
    assertThat(serverConnection).isNotNull();
    assertThat(serverConnection.getRemoteHostname()).isEqualTo(virtualHostname);
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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