Search in sources :

Example 1 with TopicTypeService

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

the class MutationFetcherTest method shouldIngestDataWithDifferentKeyTypes.

@ParameterizedTest(name = "shouldIngestDataWithDifferentKeyTypes ({0})")
@MethodSource("provideValueArgumentsForKeys")
<K, T> void shouldIngestDataWithDifferentKeyTypes(final TestParameterBuilder<K, String, T> testParameter) throws Exception {
    final String topic = testParameter.getTopic();
    final QuickData<T> keyInfo = testParameter.getInfoType();
    final QuickTopicData<T, String> info = new QuickTopicData<>(topic, TopicWriteType.MUTABLE, keyInfo, TestTypeUtils.newStringData());
    final KafkaConfig kafkaConfig = new KafkaConfig(kafkaCluster.getBrokerList(), schemaRegistry.getUrl());
    kafkaCluster.createTopic(TopicConfig.withName(topic).useDefaults());
    final TopicTypeService typeService = topicTypeService(keyInfo.getType(), QuickTopicType.STRING, null);
    final KafkaIngestService kafkaIngestService = new KafkaIngestService(typeService, kafkaConfig);
    final DataFetcher<String> mutationFetcher = new MutationFetcher<>(topic, "id", "name", new Lazy<>(() -> info), kafkaIngestService);
    final KeyValue<K, String> keyValue = testParameter.getKeyValue();
    final DataFetchingEnvironment env = DataFetchingEnvironmentImpl.newDataFetchingEnvironment().arguments(Map.of("id", keyValue.getKey(), "name", keyValue.getValue())).build();
    final String actual = mutationFetcher.get(env);
    assertThat(actual).isEqualTo(keyValue.getValue());
    final Optional<KeyValue<String, String>> consumedRecords = kafkaCluster.read(ReadKeyValues.from(topic, String.class).with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyInfo.getSerde().deserializer().getClass()).with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class)).stream().findFirst();
    assertThat(consumedRecords).isPresent().get().hasFieldOrPropertyWithValue("key", keyValue.getKey()).hasFieldOrPropertyWithValue("value", keyValue.getValue());
}
Also used : KafkaIngestService(com.bakdata.quick.gateway.ingest.KafkaIngestService) KeyValue(net.mguenther.kafka.junit.KeyValue) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) QuickTopicData(com.bakdata.quick.common.type.QuickTopicData) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) TopicTypeService(com.bakdata.quick.common.type.TopicTypeService) TestTopicTypeService(com.bakdata.quick.common.TestTopicTypeService) KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

TestTopicTypeService (com.bakdata.quick.common.TestTopicTypeService)1 KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)1 QuickTopicData (com.bakdata.quick.common.type.QuickTopicData)1 TopicTypeService (com.bakdata.quick.common.type.TopicTypeService)1 KafkaIngestService (com.bakdata.quick.gateway.ingest.KafkaIngestService)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 KeyValue (net.mguenther.kafka.junit.KeyValue)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1