use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class MirrorResourceLoaderTest method shouldCreateMirrorService.
@Test
void shouldCreateMirrorService() {
final MirrorCreationData mirrorCreationData = new MirrorCreationData(DEFAULT_NAME, DEFAULT_TOPIC_NAME, 3, "snapshot", null);
final MirrorResources mirrorResources = this.loader.forCreation(mirrorCreationData, ResourcePrefix.MIRROR);
final Optional<HasMetadata> hasMetadata = findResource(mirrorResources, ResourceKind.SERVICE);
final Map<String, String> labels = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/managed-by", "quick", "app.kubernetes.io/component", "mirror");
final Map<String, String> selectors = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/component", "mirror");
assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Service.class)).satisfies(service -> {
assertThat(service.getMetadata()).hasFieldOrPropertyWithValue("name", DEFAULT_DEPLOYMENT_NAME).extracting(ObjectMeta::getLabels, MAP).isNotNull().containsExactlyInAnyOrderEntriesOf(labels);
final ServiceSpec serviceSpec = service.getSpec();
assertThat(serviceSpec.getSelector()).containsExactlyInAnyOrderEntriesOf(selectors);
assertThat(serviceSpec.getPorts()).hasSize(1).first().hasFieldOrPropertyWithValue("protocol", "TCP").hasFieldOrPropertyWithValue("port", KubernetesResources.SERVICE_PORT).hasFieldOrPropertyWithValue("targetPort", new IntOrString(KubernetesResources.CONTAINER_PORT));
});
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData 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);
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class KafkaTopicService method createMirror.
private Completable createMirror(final String name, final Duration retentionTime) {
return Completable.defer(() -> {
log.debug("Create mirror for topic {}", name);
final MirrorCreationData mirrorCreationData = new MirrorCreationData(name, name, 1, // use default tag
null, retentionTime);
return this.mirrorService.createMirror(mirrorCreationData);
});
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class TopicRegistryInitializerTest method shouldCreateMirror.
@Test
void shouldCreateMirror() {
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 MirrorCreationData mirrorCreationData = new MirrorCreationData(TEST_NAME, topicName, 1, null, null);
verify(this.mock).createInternalMirror(mirrorCreationData);
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class ImageUpdaterTest method shouldUpdateMultipleMirrors.
@Test
void shouldUpdateMultipleMirrors() {
final MirrorResourceLoader loader = new MirrorResourceLoader(new KubernetesResources(), this.getDeploymentConfig(), this.getResourceConfig());
final MirrorService mirrorService = new KubernetesMirrorService(new KubernetesResources(), this.getManagerClient(), this.getDeploymentConfig(), loader);
final MirrorCreationData mirrorCreationData1 = new MirrorCreationData("topic", "service", 1, // use default tag
null, null);
mirrorService.createMirror(mirrorCreationData1).blockingAwait();
final MirrorCreationData mirrorCreationData2 = new MirrorCreationData("topic2", "service2", 1, // use default tag
null, null);
mirrorService.createMirror(mirrorCreationData2).blockingAwait();
assertThat(this.getDeployments()).hasSize(2).extracting(ImageUpdaterTest::getContainerImage).allMatch(name -> name.equals(String.format("%s/%s:%s", DOCKER_REGISTRY, MIRROR_IMAGE, DEFAULT_IMAGE_TAG)));
final DeploymentConfig newDeploymentConfig = this.createNewDeploymentConfig();
final ImageUpdater imageUpdater = new ImageUpdater(this.client, newDeploymentConfig);
imageUpdater.updateManagedDeployments();
assertThat(this.getDeployments()).hasSize(2).extracting(ImageUpdaterTest::getContainerImage).allMatch(name -> name.equals(String.format("%s/%s:%s", DOCKER_REGISTRY, MIRROR_IMAGE, NEW_TAG)));
}
Aggregations