use of com.bakdata.quick.common.api.model.TopicData in project quick by bakdata.
the class TopicDataClientTest method shouldReturnGetAllTopicData.
@Test
void shouldReturnGetAllTopicData() throws JsonProcessingException {
final TopicData topicData = createTopicData("dummy");
final TopicData topicData2 = createTopicData("dummy2");
final String body = this.generateBody(List.of(topicData, topicData2));
this.server.enqueue(new MockResponse().setBody(body));
final List<TopicData> topic = this.topicDataClient.fetchAll();
assertThat(topic).hasSize(2).extracting(TopicData::getName).containsExactly("dummy", "dummy2");
}
use of com.bakdata.quick.common.api.model.TopicData in project quick by bakdata.
the class TopicDataClientTest method shouldReturnListOfTopicsData.
@Test
void shouldReturnListOfTopicsData() throws JsonProcessingException {
final TopicData topicData = createTopicData("dummy");
final TopicData topicData2 = createTopicData("dummy2");
final String body = this.generateBody(List.of(topicData, topicData2));
this.server.enqueue(new MockResponse().setBody(body));
final List<TopicData> topic = this.topicDataClient.fetchValues(List.of("dummy", "dummy2"));
assertThat(topic).hasSize(2).extracting(TopicData::getName).containsExactly("dummy", "dummy2");
}
use of com.bakdata.quick.common.api.model.TopicData in project quick by bakdata.
the class KafkaTopicService method createTopic.
@SuppressWarnings("RxReturnValueIgnored")
@Override
public Completable createTopic(final String name, final QuickTopicType keyType, final QuickTopicType valueType, final TopicCreationData requestData) {
log.info("Create new topic {} with data {}", name, requestData);
// we don't need the cache, so make sure we get the current information
this.schemaRegistryClient.reset();
// first, check if topic might already exist in topic registry or kafka itself and then make also sure there
final Completable kafkaStateCheck = Completable.mergeArray(this.checkKafka(name), this.checkTopicRegistry(name));
final Single<Optional<QuickSchemas>> keySchema = this.getQuickSchemas(requestData.getKeySchema()).cache();
final Single<Optional<QuickSchemas>> valueSchema = this.getQuickSchemas(requestData.getValueSchema()).cache();
final Completable schemaRegistryCheck = Completable.defer(() -> Completable.mergeArray(keySchema.flatMapCompletable(schema -> this.checkSchemaRegistry(name + "-key", schema)), valueSchema.flatMapCompletable(schema -> this.checkSchemaRegistry(name + "-value", schema))));
final Completable stateCheck = kafkaStateCheck.andThen(schemaRegistryCheck);
// create topic in kafka and deploy a mirror application
final Completable kafkaTopicCreation = this.createKafkaTopic(name);
final Completable mirrorCreation = this.createMirror(name, requestData.getRetentionTime());
// default to mutable topic write type
final TopicWriteType writeType = Objects.requireNonNullElse(requestData.getWriteType(), TopicWriteType.MUTABLE);
// register at topic registry (value schema can be nullable)
// todo evaluate whether the schema should be part of the topic registry
final Completable topicRegister = Completable.defer(() -> {
log.debug("Register subject '{}' with topic registry", name);
return valueSchema.flatMapCompletable(schema -> {
final String graphQLSchema = schema.map(QuickSchemas::getGraphQLSchema).orElse(null);
final TopicData topicData = new TopicData(name, writeType, keyType, valueType, graphQLSchema);
return this.topicRegistryClient.register(name, topicData);
});
});
// register potential avro schema with the schema registry
final Completable keyRegister = keySchema.flatMapCompletable(schemas -> this.registerSchema(name, schemas, KEY));
final Completable valueRegister = valueSchema.flatMapCompletable(schemas -> this.registerSchema(name, schemas, VALUE));
final Completable creationOperations = Completable.mergeArray(kafkaTopicCreation, mirrorCreation, topicRegister, keyRegister, valueRegister);
return stateCheck.andThen(creationOperations.doOnError(ignored -> this.deleteTopic(name)));
}
use of com.bakdata.quick.common.api.model.TopicData in project quick by bakdata.
the class KafkaTopicServiceTest method shouldRegisterTopicGraphQLSchema.
@Test
void shouldRegisterTopicGraphQLSchema() {
final String topicName = UUID.randomUUID().toString();
this.successfulMock();
when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.just(new GatewayDescription("test", 1, "latest")));
when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.just(new SchemaData(SCHEMA)));
final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, null);
final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData);
assertThat(completable.blockingGet()).isNull();
final TopicData expected = new TopicData(topicName, TopicWriteType.MUTABLE, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, SCHEMA);
assertThat(this.topicRegistryClient.getTopicData(topicName).blockingGet()).usingRecursiveComparison().isEqualTo(expected);
}
use of com.bakdata.quick.common.api.model.TopicData in project quick by bakdata.
the class ControllerReturnSchemaTest method setUp.
@BeforeEach
void setUp() throws IOException {
this.registryClient.register("purchase-topic", new TopicData("purchase-topic", TopicWriteType.MUTABLE, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, "")).blockingAwait();
this.registryClient.register("product-topic", new TopicData("product-topic", TopicWriteType.MUTABLE, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, "")).blockingAwait();
final Path schemaPath = workingDirectory.resolve("schema.graphql");
this.context.updateFromSchemaString(Files.readString(schemaPath));
}
Aggregations