use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkWithLegacyMetadataTest method testInvalidTypeWithDefaultInflightMessages.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInvalidTypeWithDefaultInflightMessages() {
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("retries", 0L).with("channel-name", "testInvalidTypeWithDefaultInflightMessages");
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
Subscriber subscriber = sink.getSink().build();
Multi.createFrom().range(0, 5).map(i -> {
if (i == 3 || i == 5) {
return Integer.toString(i);
}
return i;
}).map(Message::of).subscribe(subscriber);
await().until(() -> consumed.count() >= 3);
// Default inflight is 5
// 1, 2, 3, 4, 5 are sent at the same time.
// As 3 fails, the stream is stopped, but, 1, 2, and 4 are already sent and potentially 6
assertThat(consumed.count()).isGreaterThanOrEqualTo(3);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest 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, Duration.ofMinutes(1));
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);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest 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 KafkaSourceTest method testSourceWithEmptyOptionalConfiguration.
@SuppressWarnings("unchecked")
@Test
public void testSourceWithEmptyOptionalConfiguration() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("sasl.jaas.config", // optional configuration
"").with("sasl.mechanism", // optional configuration
"");
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), 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 PauseResumeTest method testPauseResumeWithRequests.
@Test
void testPauseResumeWithRequests() {
MapBasedConfig config = commonConfiguration().with(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1).with("client.id", UUID.randomUUID().toString());
String group = UUID.randomUUID().toString();
source = new KafkaSource<>(vertx, group, new KafkaConnectorIncomingConfiguration(config), getConsumerRebalanceListeners(), CountKafkaCdiEvents.noCdiEvents, getDeserializationFailureHandlers(), -1);
injectMockConsumer(source, consumer);
AssertSubscriber<IncomingKafkaRecord<String, String>> subscriber = source.getStream().subscribe().withSubscriber(AssertSubscriber.create(1));
TopicPartition tp0 = new TopicPartition(TOPIC, 0);
TopicPartition tp1 = new TopicPartition(TOPIC, 1);
TopicPartition tp2 = new TopicPartition(TOPIC, 2);
Map<TopicPartition, Long> beginning = new HashMap<>();
beginning.put(tp0, 0L);
beginning.put(tp1, 0L);
beginning.put(tp2, 0L);
consumer.updateBeginningOffsets(beginning);
consumer.schedulePollTask(() -> {
consumer.rebalance(Arrays.asList(tp0, tp1, tp2));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, 0, "k", "v0"));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, 1, "k", "v1"));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, 2, "k", "v2"));
});
// two messages in the buffer, first one is delivered
await().until(() -> subscriber.getItems().size() == 1);
// request 1, delivered one more record
subscriber.request(1);
await().until(() -> subscriber.getItems().size() == 2);
// 1 <= 1 (halfBufferSize) -> resumed
await().until(() -> consumer.paused().isEmpty());
// request 1, delivered last record
subscriber.request(1);
await().until(() -> subscriber.getItems().size() == 3);
consumer.schedulePollTask(() -> {
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, 3, "k", "v0"));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, 4, "k", "v1"));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, 5, "k", "v2"));
});
// 2 messages in the buffer
// 2 >= 2 (maxBufferSize) -> paused
await().until(() -> !consumer.paused().isEmpty());
subscriber.request(2);
await().until(() -> subscriber.getItems().size() == 5);
// 1 <= 1 (halfBufferSize) -> resumed
await().until(() -> consumer.paused().isEmpty());
}
Aggregations