Search in sources :

Example 1 with ExecutionHolder

use of io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder in project smallrye-reactive-messaging by smallrye.

the class KafkaSourceWithLegacyMetadataTest method testBroadcastWithPartitions.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBroadcastWithPartitions() {
    companion.topics().create(topic, 2);
    MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("broadcast", true).with("partitions", 2);
    connector = new KafkaConnector();
    connector.executionHolder = new ExecutionHolder(vertx);
    connector.configurations = UnsatisfiedInstance.instance();
    connector.consumerRebalanceListeners = UnsatisfiedInstance.instance();
    connector.kafkaCDIEvents = new CountKafkaCdiEvents();
    connector.init();
    PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector.getPublisherBuilder(config);
    List<KafkaRecord> messages1 = new ArrayList<>();
    List<KafkaRecord> messages2 = new ArrayList<>();
    builder.forEach(messages1::add).run();
    builder.forEach(messages2::add).run();
    companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
    assertThat(messages1.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactlyInAnyOrder(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertThat(messages2.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactlyInAnyOrder(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
Also used : IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) PublisherBuilder(org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) Test(org.junit.jupiter.api.Test)

Example 2 with ExecutionHolder

use of io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder in project smallrye-reactive-messaging by smallrye.

the class KafkaSourceWithLegacyMetadataTest method testBroadcast.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBroadcast() {
    MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("broadcast", true);
    CountKafkaCdiEvents testEvents = new CountKafkaCdiEvents();
    connector = new KafkaConnector();
    connector.executionHolder = new ExecutionHolder(vertx);
    connector.configurations = UnsatisfiedInstance.instance();
    connector.consumerRebalanceListeners = UnsatisfiedInstance.instance();
    connector.kafkaCDIEvents = testEvents;
    connector.init();
    PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector.getPublisherBuilder(config);
    List<KafkaRecord> messages1 = new ArrayList<>();
    List<KafkaRecord> messages2 = new ArrayList<>();
    builder.forEach(messages1::add).run();
    builder.forEach(messages2::add).run();
    companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
    assertThat(messages1.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertThat(messages2.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertThat(testEvents.firedConsumerEvents.sum()).isEqualTo(1);
    assertThat(testEvents.firedProducerEvents.sum()).isEqualTo(0);
}
Also used : PublisherBuilder(org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) Test(org.junit.jupiter.api.Test)

Example 3 with ExecutionHolder

use of io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder in project smallrye-reactive-messaging by smallrye.

the class AmqpBrokerTestBase method setup.

@BeforeEach
public void setup() {
    executionHolder = new ExecutionHolder(Vertx.vertx());
    usage = new AmqpUsage(executionHolder.vertx(), host, port, username, password);
    SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig());
    MapBasedConfig.cleanup();
}
Also used : ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ExecutionHolder

use of io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder in project smallrye-reactive-messaging by smallrye.

the class RabbitMQBrokerTestBase method setup.

@BeforeEach
public void setup() {
    executionHolder = new ExecutionHolder(Vertx.vertx());
    usage = new RabbitMQUsage(executionHolder.vertx(), host, port, managementPort, username, password);
    SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig());
    MapBasedConfig.cleanup();
}
Also used : ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ExecutionHolder

use of io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder in project smallrye-reactive-messaging by smallrye.

the class AmqpTestBase method setup.

@BeforeEach
public void setup(TestInfo testInfo) {
    logger.infof("========== start %s.%s ==========", getClass().getSimpleName(), testInfo.getDisplayName());
    executionHolder = new ExecutionHolder(Vertx.vertx());
    SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig());
    MapBasedConfig.cleanup();
}
Also used : ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder)

Aggregations

ExecutionHolder (io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder)9 KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)4 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)4 ArrayList (java.util.ArrayList)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 PublisherBuilder (org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4 IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)2