Search in sources :

Example 11 with KafkaConfig

use of com.bakdata.quick.common.config.KafkaConfig in project quick by bakdata.

the class TopicRegistryInitializerTest method shouldCreateSchema.

@Test
void shouldCreateSchema() throws IOException, RestClientException {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    final KafkaConfig kafkaConfig = new KafkaConfig(kafkaCluster.getBrokerList(), this.schemaRegistry.getUrl());
    final TopicRegistryConfig registryConfig = new TopicRegistryConfig(topicName, TEST_NAME, 3, (short) 1);
    final TopicRegistryInitializer topicRegistryInitializer = new TopicRegistryInitializer(kafkaConfig, registryConfig, this.mock);
    topicRegistryInitializer.onStartUp(new StartupEvent(this.applicationContext));
    final SchemaRegistryClient registryClient = this.schemaRegistry.getSchemaRegistryClient();
    final String subject = topicName + "-value";
    assertThat(registryClient.getAllSubjects()).containsExactly(subject);
    assertThat(registryClient.getBySubjectAndId(subject, 1)).isEqualTo(AvroTopicData.getClassSchema());
}
Also used : StartupEvent(io.micronaut.context.event.StartupEvent) TopicRegistryConfig(com.bakdata.quick.common.config.TopicRegistryConfig) KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Example 12 with KafkaConfig

use of com.bakdata.quick.common.config.KafkaConfig in project quick by bakdata.

the class TopicRegistryInitializerTest method shouldNotFailIfSchemaExists.

@Test
void shouldNotFailIfSchemaExists() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    final KafkaConfig kafkaConfig = new KafkaConfig(kafkaCluster.getBrokerList(), this.schemaRegistry.getUrl());
    final TopicRegistryConfig registryConfig = new TopicRegistryConfig(topicName, TEST_NAME, 3, (short) 1);
    final TopicRegistryInitializer topicRegistryInitializer = new TopicRegistryInitializer(kafkaConfig, registryConfig, this.mock);
    assertThatCode(() -> {
        topicRegistryInitializer.onStartUp(new StartupEvent(this.applicationContext));
    }).doesNotThrowAnyException();
}
Also used : StartupEvent(io.micronaut.context.event.StartupEvent) TopicRegistryConfig(com.bakdata.quick.common.config.TopicRegistryConfig) KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) Test(org.junit.jupiter.api.Test)

Example 13 with KafkaConfig

use of com.bakdata.quick.common.config.KafkaConfig in project quick by bakdata.

the class MirrorApplication method addKafkaConfigToArgs.

/**
 * Adds Kafka specific configurations to CLI args
 *
 * <p>
 * {@link KafkaStreamsApplication} handles reading common settings like bootstrap server and schema registry url for
 * us. With this, we enable it to properly populate these.
 *
 * @param context current context
 * @param args    existing CLI args
 */
private static String[] addKafkaConfigToArgs(final ApplicationContext context, final String[] args) {
    final KafkaConfig kafkaConfig = context.getBean(KafkaConfig.class);
    final List<String> allArgs = CliArgHandler.convertArgs(kafkaConfig);
    allArgs.addAll(Arrays.asList(args));
    return allArgs.toArray(String[]::new);
}
Also used : KafkaConfig(com.bakdata.quick.common.config.KafkaConfig)

Example 14 with KafkaConfig

use of com.bakdata.quick.common.config.KafkaConfig 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 15 with KafkaConfig

use of com.bakdata.quick.common.config.KafkaConfig in project quick by bakdata.

the class KafkaIngestServiceTest method setUp.

@BeforeEach
void setUp() {
    this.schemaRegistry.start();
    this.kafkaCluster = provisionWith(EmbeddedKafkaClusterConfig.defaultClusterConfig());
    this.kafkaCluster.start();
    this.kafkaCluster.createTopic(TopicConfig.withName(TOPIC).useDefaults());
    final KafkaConfig kafkaConfig = new KafkaConfig(this.kafkaCluster.getBrokerList(), this.schemaRegistry.getUrl());
    this.service = new KafkaIngestService(this.typeService, kafkaConfig);
}
Also used : KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)15 TopicRegistryConfig (com.bakdata.quick.common.config.TopicRegistryConfig)8 StartupEvent (io.micronaut.context.event.StartupEvent)8 Test (org.junit.jupiter.api.Test)8 QuickTopicData (com.bakdata.quick.common.type.QuickTopicData)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)3 InternalErrorException (com.bakdata.quick.common.exception.InternalErrorException)2 KafkaIngestService (com.bakdata.quick.gateway.ingest.KafkaIngestService)2 KeyValue (net.mguenther.kafka.junit.KeyValue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TestTopicTypeService (com.bakdata.quick.common.TestTopicTypeService)1 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)1 TopicTypeService (com.bakdata.quick.common.type.TopicTypeService)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1