use of io.smallrye.reactive.messaging.health.HealthReport in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkTest method testABeanProducingMessagesSentToKafka.
@Test
public void testABeanProducingMessagesSentToKafka() {
runApplication(getKafkaSinkConfigForProducingBean(), ProducingBean.class);
ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics("output", 10, Duration.ofSeconds(10));
await().until(this::isReady);
assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
HealthReport liveness = getHealth().getLiveness();
HealthReport readiness = getHealth().getReadiness();
assertThat(liveness.isOk()).isTrue();
assertThat(readiness.isOk()).isTrue();
assertThat(liveness.getChannels()).hasSize(1);
assertThat(readiness.getChannels()).hasSize(1);
assertThat(liveness.getChannels().get(0).getChannel()).isEqualTo("output");
assertThat(readiness.getChannels().get(0).getChannel()).isEqualTo("output");
KafkaClientService service = get(KafkaClientService.class);
assertThat(service.getProducer("output")).isNotNull();
assertThat(service.getProducer("missing")).isNull();
assertThatThrownBy(() -> service.getProducer(null)).isInstanceOf(NullPointerException.class);
assertThat(service.getProducerChannels()).containsExactly("output");
}
use of io.smallrye.reactive.messaging.health.HealthReport in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkWithLegacyMetadataTest method testABeanProducingMessagesSentToKafka.
@Test
public void testABeanProducingMessagesSentToKafka() {
runApplication(getKafkaSinkConfigForProducingBean(), ProducingBean.class);
ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 10, Duration.ofSeconds(10));
await().until(this::isReady);
assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
HealthReport liveness = getHealth().getLiveness();
HealthReport readiness = getHealth().getReadiness();
assertThat(liveness.isOk()).isTrue();
assertThat(readiness.isOk()).isTrue();
assertThat(liveness.getChannels()).hasSize(1);
assertThat(readiness.getChannels()).hasSize(1);
assertThat(liveness.getChannels().get(0).getChannel()).isEqualTo("output");
assertThat(readiness.getChannels().get(0).getChannel()).isEqualTo("output");
KafkaClientService service = get(KafkaClientService.class);
assertThat(service.getProducer("output")).isNotNull();
assertThat(service.getProducer("missing")).isNull();
assertThatThrownBy(() -> service.getProducer(null)).isInstanceOf(NullPointerException.class);
}
use of io.smallrye.reactive.messaging.health.HealthReport in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest method testABeanConsumingTheKafkaMessages.
@Test
public void testABeanConsumingTheKafkaMessages() {
String topic = UUID.randomUUID().toString();
String group = UUID.randomUUID().toString();
ConsumptionBean bean = run(myKafkaSourceConfig(topic, group));
List<Integer> list = bean.getResults();
assertThat(list).isEmpty();
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> list.size() >= 10);
assertThat(list).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<KafkaRecord<String, Integer>> messages = bean.getKafkaMessages();
messages.forEach(m -> {
assertThat(m.getTopic()).isEqualTo(topic);
assertThat(m.getTimestamp()).isAfter(Instant.EPOCH);
assertThat(m.getPartition()).isGreaterThan(-1);
});
HealthReport liveness = getHealth().getLiveness();
HealthReport readiness = getHealth().getReadiness();
assertThat(liveness.isOk()).isTrue();
assertThat(readiness.isOk()).isTrue();
assertThat(liveness.getChannels()).hasSize(1);
assertThat(readiness.getChannels()).hasSize(1);
assertThat(liveness.getChannels().get(0).getChannel()).isEqualTo("data");
assertThat(readiness.getChannels().get(0).getChannel()).isEqualTo("data");
KafkaClientService service = get(KafkaClientService.class);
assertThat(service.getConsumer("data")).isNotNull();
assertThat(service.getConsumer("missing")).isNull();
assertThatThrownBy(() -> service.getConsumer(null)).isInstanceOf(NullPointerException.class);
assertThat(service.getConsumerChannels()).containsExactly("data");
}
use of io.smallrye.reactive.messaging.health.HealthReport in project smallrye-reactive-messaging by smallrye.
the class BatchCommitStrategiesTest method testThrottledStrategyWithTooManyUnackedMessages.
@Test
void testThrottledStrategyWithTooManyUnackedMessages() {
MapBasedConfig config = commonConfiguration().with("client.id", UUID.randomUUID().toString()).with("commit-strategy", "throttled").with("auto.offset.reset", "earliest").with("health-enabled", true).with("throttled.unprocessed-record-max-age.ms", 1000).with("auto.commit.interval.ms", 100);
String group = UUID.randomUUID().toString();
source = new KafkaSource<>(vertx, group, new KafkaConnectorIncomingConfiguration(config), getConsumerRebalanceListeners(), CountKafkaCdiEvents.noCdiEvents, getDeserializationFailureHandlers(), -1);
injectMockConsumer(source, consumer);
List<Message<?>> list = new CopyOnWriteArrayList<>();
source.getBatchStream().subscribe().with(list::add);
TopicPartition p0 = new TopicPartition(TOPIC, 0);
TopicPartition p1 = new TopicPartition(TOPIC, 1);
Map<TopicPartition, Long> offsets = new HashMap<>();
offsets.put(p0, 0L);
offsets.put(p1, 5L);
consumer.updateBeginningOffsets(offsets);
consumer.schedulePollTask(() -> {
consumer.rebalance(offsets.keySet());
source.getCommitHandler().partitionsAssigned(offsets.keySet());
});
for (int i = 0; i < 500; i++) {
int j = i;
consumer.schedulePollTask(() -> {
consumer.addRecord(new ConsumerRecord<>(TOPIC, 0, j, "k", "v0-" + j));
consumer.addRecord(new ConsumerRecord<>(TOPIC, 1, j, "r", "v1-" + j));
});
}
// Expected number of messages: 500 messages in each partition minus the [0..5) messages from p1
int expected = 500 * 2 - 5;
await().until(() -> list.stream().map(IncomingKafkaRecordBatch.class::cast).mapToLong(r -> r.getRecords().size()).sum() == expected);
// Ack first 10 records
int count = 0;
for (Message<?> message : list) {
assertThat(message.getMetadata(IncomingKafkaRecordBatchMetadata.class)).isPresent();
if (count < 10) {
message.ack().toCompletableFuture().join();
count++;
}
}
// wait until health check is not ok
await().until(() -> {
HealthReport.HealthReportBuilder builder = HealthReport.builder();
source.isAlive(builder);
HealthReport r = builder.build();
return !r.isOk();
});
// build the health check again and get the report message
HealthReport.HealthReportBuilder builder = HealthReport.builder();
source.isAlive(builder);
String message = builder.build().getChannels().get(0).getMessage();
assertThat(message).containsAnyOf("my-topic-0", "my-topic-1");
}
use of io.smallrye.reactive.messaging.health.HealthReport in project smallrye-reactive-messaging by smallrye.
the class KafkaCommitHandlerTest method testSourceWithThrottledAndRebalance.
@Test
public void testSourceWithThrottledAndRebalance() {
companion.topics().createAndWait(topic, 2);
MapBasedConfig config1 = newCommonConfigForSource().with("client.id", UUID.randomUUID().toString()).with("group.id", "test-source-with-throttled-latest-processed-commit").with("value.deserializer", IntegerDeserializer.class.getName()).with("commit-strategy", "throttled").with("throttled.unprocessed-record-max-age.ms", 1);
MapBasedConfig config2 = newCommonConfigForSource().with("client.id", UUID.randomUUID().toString()).with("group.id", "test-source-with-throttled-latest-processed-commit").with("value.deserializer", IntegerDeserializer.class.getName()).with("commit-strategy", "throttled").with("throttled.unprocessed-record-max-age.ms", 1);
KafkaConnectorIncomingConfiguration ic1 = new KafkaConnectorIncomingConfiguration(config1);
KafkaConnectorIncomingConfiguration ic2 = new KafkaConnectorIncomingConfiguration(config2);
source = new KafkaSource<>(vertx, "test-source-with-throttled-latest-processed-commit", ic1, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
KafkaSource<String, Integer> source2 = new KafkaSource<>(vertx, "test-source-with-throttled-latest-processed-commit", ic2, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages1 = Collections.synchronizedList(new ArrayList<>());
source.getStream().subscribe().with(m -> {
m.ack();
messages1.add(m);
});
await().until(() -> source.getConsumer().getAssignments().await().indefinitely().size() == 2);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, Integer.toString(i % 2), i), 10000);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
List<Message<?>> messages2 = Collections.synchronizedList(new ArrayList<>());
source2.getStream().subscribe().with(m -> {
m.ack();
messages2.add(m);
});
await().until(() -> source2.getConsumer().getAssignments().await().indefinitely().size() == 1 && source.getConsumer().getAssignments().await().indefinitely().size() == 1);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, Integer.toString(i % 2), i), 10000);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() + messages2.size() >= 10000);
await().atMost(2, TimeUnit.MINUTES).untilAsserted(() -> {
TopicPartition tp1 = new TopicPartition(topic, 0);
TopicPartition tp2 = new TopicPartition(topic, 1);
Map<TopicPartition, OffsetAndMetadata> result = companion.consumerGroups().offsets("test-source-with-throttled-latest-processed-commit", Arrays.asList(tp1, tp2));
assertNotNull(result.get(tp1));
assertNotNull(result.get(tp2));
assertEquals(result.get(tp1).offset() + result.get(tp2).offset(), 20000);
});
await().atMost(2, TimeUnit.MINUTES).untilAsserted(() -> {
HealthReport.HealthReportBuilder healthReportBuilder = HealthReport.builder();
source.isAlive(healthReportBuilder);
HealthReport build = healthReportBuilder.build();
boolean ok = build.isOk();
if (!ok) {
build.getChannels().forEach(ci -> System.out.println(ci.getChannel() + " - " + ci.getMessage()));
}
assertTrue(ok);
});
source2.closeQuietly();
}
Aggregations