Search in sources :

Example 6 with QuickTopicData

use of com.bakdata.quick.common.type.QuickTopicData in project quick by bakdata.

the class QuickTopicTypeService method singleToFuture.

// nothing we can do with the disposable; the value will be in the future
@SuppressWarnings("unused")
private static CompletableFuture<QuickTopicData<?, ?>> singleToFuture(final Executor executor, final Single<QuickTopicData<Object, Object>> single) {
    final CompletableFuture<QuickTopicData<?, ?>> cf = new CompletableFuture<>();
    final Disposable disposable = single.subscribeOn(Schedulers.from(executor)).subscribe(cf::complete, cf::completeExceptionally);
    return cf;
}
Also used : Disposable(io.reactivex.disposables.Disposable) CompletableFuture(java.util.concurrent.CompletableFuture) QuickTopicData(com.bakdata.quick.common.type.QuickTopicData)

Example 7 with QuickTopicData

use of com.bakdata.quick.common.type.QuickTopicData in project quick by bakdata.

the class QuickTopicTypeService method fromTopicData.

private <K, V> Single<QuickTopicData<K, V>> fromTopicData(final TopicData topicData) {
    final QuickTopicType keyType = topicData.getKeyType();
    final QuickTopicType valueType = topicData.getValueType();
    final Serde<K> keySerde = keyType.getSerde();
    final Serde<V> valueSerde = valueType.getSerde();
    final TypeResolver<K> keyResolver = keyType.getTypeResolver();
    final TypeResolver<V> valueResolver = valueType.getTypeResolver();
    final Map<String, String> configs = Map.of("schema.registry.url", this.schemaRegistryUrl);
    keySerde.configure(configs, true);
    valueSerde.configure(configs, false);
    final String topic = topicData.getName();
    // configure key and value resolver - only required if we handle avro
    final Completable configureResolver = Completable.mergeArray(this.configureResolver(keyType, KEY.asSubject(topic), keyResolver), this.configureResolver(valueType, VALUE.asSubject(topic), valueResolver));
    final QuickData<K> keyInfo = new QuickData<>(keyType, keySerde, keyResolver);
    final QuickData<V> valueInfo = new QuickData<>(valueType, valueSerde, valueResolver);
    final QuickTopicData<K, V> info = new QuickTopicData<>(topic, topicData.getWriteType(), keyInfo, valueInfo);
    // first we need to configure the resolver, then we can publish the info
    return configureResolver.andThen(Single.just(info));
}
Also used : Completable(io.reactivex.Completable) QuickData(com.bakdata.quick.common.type.QuickTopicData.QuickData) QuickTopicData(com.bakdata.quick.common.type.QuickTopicData) QuickTopicType(com.bakdata.quick.common.type.QuickTopicType)

Example 8 with QuickTopicData

use of com.bakdata.quick.common.type.QuickTopicData in project quick by bakdata.

the class SubscriptionFetcherTest method shouldFetchValuesForGivenKey.

@ParameterizedTest(name = "shouldFetchValuesForGivenKey ({0})")
@MethodSource("provideValueArgumentsForKey")
<K, V> void shouldFetchValuesForGivenKey(final String topic, final List<KeyValue<K, V>> keyValues, final QuickData<K> keyInfo, final QuickData<V> valueInfo, final K key, final List<V> expected) throws InterruptedException {
    final QuickTopicData<K, V> info = new QuickTopicData<>(topic, TopicWriteType.IMMUTABLE, keyInfo, valueInfo);
    final KafkaConfig kafkaConfig = new KafkaConfig(kafkaCluster.getBrokerList(), "http://no");
    kafkaCluster.createTopic(TopicConfig.withName(topic).useDefaults());
    final SendKeyValuesTransactional<K, V> sendRequest = SendKeyValuesTransactional.inTransaction(topic, keyValues).with(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, keyInfo.getSerde().serializer().getClass()).with(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, valueInfo.getSerde().serializer().getClass()).build();
    kafkaCluster.send(sendRequest);
    final String argumentName = "id";
    final SubscriptionFetcher<K, V> subscriptionFetcher = new SubscriptionFetcher<>(kafkaConfig, new Lazy<>(() -> info), "key-query", OffsetStrategy.EARLIEST, argumentName);
    final DataFetchingEnvironment fetchingEnvironment = DataFetchingEnvironmentImpl.newDataFetchingEnvironment().arguments(Map.of(argumentName, key)).build();
    final Publisher<V> publisher = subscriptionFetcher.get(fetchingEnvironment);
    final TestSubscriber<V> testSubscriber = TestSubscriber.create();
    publisher.subscribe(testSubscriber);
    await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> assertThat(testSubscriber.values()).containsExactlyElementsOf(expected));
}
Also used : QuickTopicData(com.bakdata.quick.common.type.QuickTopicData) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with QuickTopicData

use of com.bakdata.quick.common.type.QuickTopicData in project quick by bakdata.

the class IngestControllerTest method keyArguments.

private static Stream<TestKeyArgument<?, ?, ?>> keyArguments() {
    final QuickData<String> stringInfo = newStringData();
    final ChartRecord record = inputRecord();
    return Stream.of(new TestKeyArgument<>(new QuickTopicData<>(TOPIC, TopicWriteType.MUTABLE, stringInfo, stringInfo), "value", "value"), new TestKeyArgument<>(new QuickTopicData<>(TOPIC, TopicWriteType.MUTABLE, newIntegerData(), stringInfo), 5, 5), new TestKeyArgument<>(new QuickTopicData<>(TOPIC, TopicWriteType.MUTABLE, newDoubleData(), stringInfo), 5.0, 5.0), new TestKeyArgument<>(new QuickTopicData<>(TOPIC, TopicWriteType.MUTABLE, getAvroInfo(), stringInfo), record, outputRecord()), new TestKeyArgument<>(new QuickTopicData<>(TOPIC, TopicWriteType.MUTABLE, newLongData(), stringInfo), 5L, 5L));
}
Also used : QuickTopicData(com.bakdata.quick.common.type.QuickTopicData) ChartRecord(com.bakdata.quick.avro.ChartRecord)

Aggregations

QuickTopicData (com.bakdata.quick.common.type.QuickTopicData)9 KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)3 TopicTypeService (com.bakdata.quick.common.type.TopicTypeService)2 KafkaIngestService (com.bakdata.quick.gateway.ingest.KafkaIngestService)2 Completable (io.reactivex.Completable)2 KeyValue (net.mguenther.kafka.junit.KeyValue)2 ChartRecord (com.bakdata.quick.avro.ChartRecord)1 TestTopicTypeService (com.bakdata.quick.common.TestTopicTypeService)1 KeyValuePair (com.bakdata.quick.common.api.model.KeyValuePair)1 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)1 QuickData (com.bakdata.quick.common.type.QuickTopicData.QuickData)1 QuickTopicType (com.bakdata.quick.common.type.QuickTopicType)1 IngestFilter (com.bakdata.quick.ingest.service.IngestFilter)1 IngestLists (com.bakdata.quick.ingest.service.IngestFilter.IngestLists)1 IngestParser (com.bakdata.quick.ingest.service.IngestParser)1 IngestService (com.bakdata.quick.ingest.service.IngestService)1 Body (io.micronaut.http.annotation.Body)1