Search in sources :

Example 1 with TopicCreationData

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

the class TopicControllerTest method testCreateTopicWhenQueryIsSet.

@Test
void testCreateTopicWhenQueryIsSet() {
    when(this.service.createTopic(anyString(), any(), any(), any())).thenReturn(Completable.complete());
    final String uri = UriBuilder.of(baseUri).queryParam("keyType", QuickTopicType.STRING).queryParam("valueType", QuickTopicType.DOUBLE).build().toString();
    final TopicCreationData creationData = new TopicCreationData(TopicWriteType.MUTABLE, null, null, null);
    this.client.toBlocking().exchange(POST(uri, creationData));
    verify(this.service).createTopic(NAME, QuickTopicType.STRING, QuickTopicType.DOUBLE, creationData);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 2 with TopicCreationData

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

the class KafkaTopicServiceTest method shouldRegisterTopic.

@Test
void shouldRegisterTopic() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, null, null, null);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.DOUBLE, requestData);
    final TopicData expectedTopicData = new TopicData(topicName, TopicWriteType.MUTABLE, QuickTopicType.DOUBLE, QuickTopicType.DOUBLE, null);
    assertThat(completable.blockingGet()).isNull();
    assertThat(this.topicRegistryClient.getTopicData(topicName).blockingGet()).usingRecursiveComparison().isEqualTo(expectedTopicData);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) TopicData(com.bakdata.quick.common.api.model.TopicData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with TopicCreationData

use of com.bakdata.quick.common.api.model.manager.creation.TopicCreationData 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 4 with TopicCreationData

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

the class KafkaTopicServiceTest method shouldRetrieveAllTopics.

@Test
void shouldRetrieveAllTopics() {
    final int numberOfTopics = 10;
    for (int i = 0; i < numberOfTopics; i++) {
        final String topicName = UUID.randomUUID().toString();
        this.successfulMock();
        final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, null, null, null);
        this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.DOUBLE, requestData).blockingAwait();
    }
    final Single<List<TopicData>> allTopics = this.topicRegistryClient.getAllTopics();
    assertThat(allTopics.blockingGet().size()).isEqualTo(numberOfTopics);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with TopicCreationData

use of com.bakdata.quick.common.api.model.manager.creation.TopicCreationData 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)

Aggregations

TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)15 Test (org.junit.jupiter.api.Test)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 Completable (io.reactivex.Completable)8 GatewayDescription (com.bakdata.quick.common.api.model.manager.GatewayDescription)5 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)5 TopicData (com.bakdata.quick.common.api.model.TopicData)4 SchemaData (com.bakdata.quick.common.api.model.gateway.SchemaData)4 GatewaySchema (com.bakdata.quick.common.api.model.manager.GatewaySchema)3 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)2 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)2 Duration (java.time.Duration)2 List (java.util.List)2 Schema (org.apache.avro.Schema)2 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)1 TopicRegistryClient (com.bakdata.quick.common.api.client.TopicRegistryClient)1 KeyValueEnum (com.bakdata.quick.common.api.model.KeyValueEnum)1 KEY (com.bakdata.quick.common.api.model.KeyValueEnum.KEY)1 VALUE (com.bakdata.quick.common.api.model.KeyValueEnum.VALUE)1