Search in sources :

Example 31 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.

the class TopicOperatorMockTest method testNotCreatedInKube.

void testNotCreatedInKube(VertxTestContext context, KafkaTopic kt) throws InterruptedException, ExecutionException {
    String kubeName = kt.getMetadata().getName();
    String kafkaName = kt.getSpec().getTopicName() != null ? kt.getSpec().getTopicName() : kubeName;
    int retention = (Integer) kt.getSpec().getConfig().get("retention.bytes");
    createInKube(kt);
    Thread.sleep(2000);
    LOGGER.info("Topic has not been created");
    Topic fromKafka = getFromKafka(kafkaName);
    context.verify(() -> assertThat(fromKafka, is(nullValue())));
    // Reconcile after no changes
    reconcile(context);
    // Check things still the same
    context.verify(() -> assertThat(fromKafka, is(nullValue())));
    // Config change + reconcile
    updateInKube(new KafkaTopicBuilder(kt).editSpec().addToConfig("retention.bytes", retention + 1).endSpec().build());
    // Another reconciliation
    reconcile(context);
    // Check things still the same
    context.verify(() -> {
        assertThat(getFromKafka(kafkaName), is(nullValue()));
        context.completeNow();
    });
}
Also used : KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Checkpoint(io.vertx.junit5.Checkpoint)

Example 32 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.

the class TopicOperatorMockTest method testCreatedWithDifferentTopicNameInKube.

@Test
public void testCreatedWithDifferentTopicNameInKube(VertxTestContext context) throws InterruptedException, ExecutionException {
    int retention = 100_000_000;
    KafkaTopic kt = new KafkaTopicBuilder().withNewMetadata().withName("my-topic").withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_KIND_LABEL, "topic").endMetadata().withNewSpec().withTopicName(// different to metadata.name
    "DIFFERENT").withPartitions(1).withReplicas(1).addToConfig("retention.bytes", retention).endSpec().build();
    testCreatedInKube(context, kt);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 33 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.

the class TopicOperatorMockTest method testCreatedInKube.

void testCreatedInKube(VertxTestContext context, KafkaTopic kt) throws InterruptedException, ExecutionException {
    String kubeName = kt.getMetadata().getName();
    String kafkaName = kt.getSpec().getTopicName() != null ? kt.getSpec().getTopicName() : kubeName;
    int retention = (Integer) kt.getSpec().getConfig().get("retention.bytes");
    createInKube(kt);
    // Check created in Kafka
    waitUntilTopicExistsInKafka(kafkaName);
    LOGGER.info("Topic has been created");
    Topic fromKafka = getFromKafka(kafkaName);
    context.verify(() -> assertThat(fromKafka.getTopicName().toString(), is(kafkaName)));
    // Reconcile after no changes
    reconcile(context);
    // Check things still the same
    context.verify(() -> assertThat(fromKafka, is(getFromKafka(kafkaName))));
    // Config change + reconcile
    updateInKube(new KafkaTopicBuilder(kt).editSpec().addToConfig("retention.bytes", retention + 1).endSpec().build());
    waitUntilTopicInKafka(kafkaName, config -> Integer.toString(retention + 1).equals(config.get("retention.bytes").value()));
    // Another reconciliation
    reconcile(context);
    // Check things still the same
    context.verify(() -> {
        assertThat(getFromKafka(kafkaName), is(new Topic.Builder(fromKafka).withConfigEntry("retention.bytes", Integer.toString(retention + 1)).build()));
        context.completeNow();
    });
}
Also used : KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Checkpoint(io.vertx.junit5.Checkpoint)

Example 34 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.

the class TopicOperatorMockTest method testCreatedWithSameTopicNameInKube.

@Test
public void testCreatedWithSameTopicNameInKube(VertxTestContext context) throws InterruptedException, ExecutionException {
    int retention = 100_000_000;
    KafkaTopic kt = new KafkaTopicBuilder().withNewMetadata().withName("my-topic").withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_KIND_LABEL, "topic").endMetadata().withNewSpec().withTopicName(// the same as metadata.name
    "my-topic").withPartitions(1).withReplicas(1).addToConfig("retention.bytes", retention).endSpec().build();
    testCreatedInKube(context, kt);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 35 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.

the class TopicOperatorMockTest method testReconciliationPaused.

@Test
public void testReconciliationPaused(VertxTestContext context) throws InterruptedException, ExecutionException {
    LOGGER.info("Test started");
    int retention = 100_000_000;
    KafkaTopic kt = new KafkaTopicBuilder().withNewMetadata().withName("my-topic").withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_KIND_LABEL, "topic").addToLabels(Labels.KUBERNETES_NAME_LABEL, "topic-operator").withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "true")).endMetadata().withNewSpec().withPartitions(1).withReplicas(1).addToConfig("retention.bytes", retention).endSpec().build();
    testNotCreatedInKube(context, kt);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaTopicBuilder (io.strimzi.api.kafka.model.KafkaTopicBuilder)56 KafkaTopic (io.strimzi.api.kafka.model.KafkaTopic)54 Test (org.junit.jupiter.api.Test)40 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)22 Checkpoint (io.vertx.junit5.Checkpoint)22 NewTopic (org.apache.kafka.clients.admin.NewTopic)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 KafkaTopicList (io.strimzi.api.kafka.KafkaTopicList)2 KafkaTopicStatusBuilder (io.strimzi.api.kafka.model.status.KafkaTopicStatusBuilder)2 Vertx (io.vertx.core.Vertx)2 VertxExtension (io.vertx.junit5.VertxExtension)2 VertxTestContext (io.vertx.junit5.VertxTestContext)2 File (java.io.File)2