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;
}
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));
}
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));
}
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));
}
Aggregations