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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations