use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class PauseResumeTest method testRebalanceDuringPaused.
@Test
void testRebalanceDuringPaused() {
MapBasedConfig config = commonConfiguration().with(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 10).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);
TopicPartition tp3 = new TopicPartition(TOPIC, 3);
Map<TopicPartition, Long> beginning = new HashMap<>();
beginning.put(tp0, 0L);
beginning.put(tp1, 0L);
beginning.put(tp2, 0L);
beginning.put(tp3, 0L);
consumer.updateBeginningOffsets(beginning);
// Push 20
consumer.schedulePollTask(() -> {
consumer.rebalance(Arrays.asList(tp0, tp1, tp2, tp3));
for (int i = 0; i < 5; i++) {
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, i, "k", "v" + i));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 1, i, "k", "v" + i));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 2, i, "k", "v" + i));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 3, i, "k", "v" + i));
}
});
// Received first
await().until(() -> subscriber.getItems().size() == 1);
// Await pause
await().until(() -> !consumer.paused().isEmpty());
consumer.schedulePollTask(() -> {
consumer.rebalance(Arrays.asList(tp0, tp1));
for (int i = 5; i < 15; i++) {
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, i, "k", "v" + i));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 1, i, "k", "v" + i));
}
});
// Pull 30
subscriber.request(30);
// Await resume
await().until(() -> !resumedPartitions(consumer).isEmpty());
// Received all
await().until(() -> subscriber.getItems().size() >= 31);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class PauseResumeTest method testPauseResumeWithBlockingConsumption.
@Test
void testPauseResumeWithBlockingConsumption() {
MapBasedConfig config = commonConfiguration().with(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 2).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);
List<String> items = new ArrayList<>();
source.getStream().onItem().transformToUniAndConcatenate(item -> Uni.createFrom().item(item).onItem().delayIt().by(Duration.ofMillis(1000)).onItem().invoke(() -> items.add(item.getPayload()))).subscribe().with(item -> {
// do nothing
});
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);
// There is demand for the first item.
await().pollInterval(Duration.ofMillis(1)).until(() -> consumer.paused().isEmpty());
consumer.schedulePollTask(() -> {
consumer.rebalance(Arrays.asList(tp0, tp1, tp2));
for (int i = 0; i < 5; i++) {
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, i, "k", "v" + i));
}
});
await().until(() -> !consumer.paused().isEmpty());
// It may await until everything is consumed, but the goal is to verify it resumed.
await().pollInterval(Duration.ofMillis(1)).until(() -> consumer.paused().isEmpty());
await().until(() -> items.size() == 5);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class ReactiveKafkaBatchConsumerTest method createSource.
public KafkaSource<Integer, String> createSource() {
String groupId = UUID.randomUUID().toString();
MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic).put("batch", true);
return createSource(config, groupId);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class ReactiveKafkaConsumerTest method testThrottledAcknowledgementWithDefaultValues.
@Test
public void testThrottledAcknowledgementWithDefaultValues() throws Exception {
String groupId = UUID.randomUUID().toString();
MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
Multi<IncomingKafkaRecord<Integer, String>> stream = createSource(config, groupId).getStream().invoke(IncomingKafkaRecord::ack);
sendReceive(stream, 0, 100, 0, 100);
restartAndCheck(config, groupId, 1);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class ReactiveKafkaConsumerTest method testThatCloseReleaseTheAssignments.
@Test
public void testThatCloseReleaseTheAssignments() throws Exception {
int count = 10;
for (int i = 0; i < 2; i++) {
String groupId = UUID.randomUUID().toString();
MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
KafkaSource<Integer, String> source = createSource(config, groupId);
sendAndWaitForMessages(source.getStream().onItem().invoke(IncomingKafkaRecord::ack), count);
if (i == 0) {
waitForCommits(source, count);
}
await().until(() -> !source.getConsumer().getAssignments().await().indefinitely().isEmpty());
assertThat(source.getConsumer().getAssignments().await().indefinitely()).hasSize(partitions);
source.closeQuietly();
}
}
Aggregations