use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest method testSource.
@SuppressWarnings("unchecked")
@Test
public void testSource() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "hello", i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 10);
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest method testRetry.
@SuppressWarnings({ "rawtypes" })
@Test
@Tag(TestTags.SLOW)
public void testRetry() {
// This test need an individual Kafka container
try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
kafka.start();
await().until(kafka::isRunning);
MapBasedConfig config = newCommonConfigForSource().with("bootstrap.servers", kafka.getBootstrapServers()).with("value.deserializer", IntegerDeserializer.class.getName()).with("retry", true).with("retry-attempts", 100).with("retry-max-wait", 30);
KafkaCompanion kafkaCompanion = new KafkaCompanion(kafka.getBootstrapServers());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<KafkaRecord> messages1 = new ArrayList<>();
source.getStream().subscribe().with(messages1::add);
AtomicInteger counter = new AtomicInteger();
kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
try (@SuppressWarnings("unused") StrimziKafkaContainer container = KafkaBrokerExtension.restart(kafka, 2)) {
kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 20);
assertThat(messages1.size()).isGreaterThanOrEqualTo(20);
}
}
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig 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);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testInvalidIncomingType.
@SuppressWarnings("unchecked")
@Test
public void testInvalidIncomingType() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 2);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 2);
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1);
companion.produceStrings().fromRecords(new ProducerRecord<>(topic, "hello"));
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 2);
// no other message received
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testSourceWithPartitions.
@SuppressWarnings("unchecked")
@Test
public void testSourceWithPartitions() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("partitions", 4);
companion.topics().createAndWait(topic, 3);
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 1000);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 1000);
List<Integer> expected = IntStream.range(0, 1000).boxed().collect(Collectors.toList());
// Because of partitions we cannot enforce the order.
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(expected);
}
Aggregations