Search in sources :

Example 1 with GatewayDescription

use of com.bakdata.quick.common.api.model.manager.GatewayDescription in project quick by bakdata.

the class KafkaTopicServiceTest method shouldSetRetentionTime.

@Test
void shouldSetRetentionTime() {
    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 Duration retentionTime = Duration.ofMinutes(30);
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, retentionTime);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.DOUBLE, requestData);
    assertThat(completable.blockingGet()).isNull();
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(topicName, topicName, 1, null, retentionTime);
    verify(this.mirrorService).createMirror(mirrorCreationData);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) Duration(java.time.Duration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) Test(org.junit.jupiter.api.Test)

Example 2 with GatewayDescription

use of com.bakdata.quick.common.api.model.manager.GatewayDescription in project quick by bakdata.

the class KafkaTopicServiceTest method shouldNotCreateTopicWithInvalidGraphQLSchema.

@Test
void shouldNotCreateTopicWithInvalidGraphQLSchema() {
    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.error(new BadArgumentException("Type OopsNotHere does not exist")));
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, null);
    final Throwable throwable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData).blockingGet();
    assertThat(throwable).isNotNull().isExactlyInstanceOf(BadArgumentException.class).extracting(Throwable::getMessage).asString().startsWith("Type OopsNotHere does not exist");
}
Also used : BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with GatewayDescription

use of com.bakdata.quick.common.api.model.manager.GatewayDescription in project quick by bakdata.

the class KafkaTopicServiceTest method shouldNotCreateTopicIfSubjectExists.

@Test
@Disabled("Compatibility test not supported in SR mock yet")
void shouldNotCreateTopicIfSubjectExists() throws RestClientException, IOException {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    this.schemaRegistry.registerValueSchema(topicName, this.graphQLToAvroConverter.convertToSchema(SCHEMA));
    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 Throwable throwable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData).blockingGet();
    assertThat(throwable).isNotNull().isExactlyInstanceOf(BadArgumentException.class).extracting(Throwable::getMessage).asString().endsWith("already exists");
    assertThat(kafkaCluster.exists(topicName)).isFalse();
    assertThat(this.topicRegistryClient.topicDataExists(topicName).blockingGet()).isFalse();
    assertThat(this.schemaRegistry.getSchemaRegistryClient().getAllSubjects()).isEmpty();
}
Also used : BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with GatewayDescription

use of com.bakdata.quick.common.api.model.manager.GatewayDescription in project quick by bakdata.

the class GatewayControllerTest method shouldGetGatewayAvroSchema.

@Test
void shouldGetGatewayAvroSchema() throws IOException {
    final Path workingDirectory = Path.of("src", "test", "resources", "schema", "avro");
    final String avroSchema = new Schema.Parser().parse(Files.readString(workingDirectory.resolve("test.avsc"))).toString();
    final SchemaData schemaData = new SchemaData(avroSchema);
    final GatewayDescription gatewayDescription = new GatewayDescription(GATEWAY_NAME, 1, null);
    when(this.gatewayService.getGateway(GATEWAY_NAME)).thenReturn(Single.just(gatewayDescription));
    when(this.gatewayService.getGatewayWriteSchema(GATEWAY_NAME, "Test", SchemaFormat.AVRO)).thenReturn(Single.just(schemaData));
    final String uri = UriBuilder.of(BASE_PATH + "/schema/{type}/avro").expand(Map.of("name", GATEWAY_NAME, "type", "Test")).toString();
    assertEquals("/gateway/test-gateway/schema/Test/avro", uri);
    final SchemaData retrievedAvroSchema = this.client.toBlocking().retrieve(GET(uri), SchemaData.class);
    assertThat(retrievedAvroSchema).isEqualTo(schemaData);
}
Also used : Path(java.nio.file.Path) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 5 with GatewayDescription

use of com.bakdata.quick.common.api.model.manager.GatewayDescription in project quick by bakdata.

the class GatewayControllerTest method shouldGetGatewayList.

@Test
void shouldGetGatewayList() {
    when(this.gatewayService.getGatewayList()).thenReturn(Single.just(List.of(new GatewayDescription(GATEWAY_NAME, 1, TAG))));
    this.client.toBlocking().exchange(GET("/gateways"));
    verify(this.gatewayService).getGatewayList();
}
Also used : GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Aggregations

GatewayDescription (com.bakdata.quick.common.api.model.manager.GatewayDescription)9 Test (org.junit.jupiter.api.Test)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 SchemaData (com.bakdata.quick.common.api.model.gateway.SchemaData)6 TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)5 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)3 Completable (io.reactivex.Completable)3 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)2 TopicData (com.bakdata.quick.common.api.model.TopicData)1 GatewaySchema (com.bakdata.quick.common.api.model.manager.GatewaySchema)1 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)1 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Schema (org.apache.avro.Schema)1 Disabled (org.junit.jupiter.api.Disabled)1