Search in sources :

Example 76 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorIT method testKafkaTopicModifiedRetentionChanged.

@Test
public void testKafkaTopicModifiedRetentionChanged() throws Exception {
    // create the topic
    String topicName = "test-kafkatopic-modified-retention-changed";
    KafkaTopic topicResource = createKafkaTopicResource(topicName);
    String expectedValue = alterTopicConfigInKube(topicResource.getMetadata().getName(), "retention.ms", currentValue -> Integer.toString(Integer.parseInt(currentValue) + 1));
    awaitTopicConfigInKafka(topicName, "retention.ms", expectedValue);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Test(org.junit.jupiter.api.Test)

Example 77 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorIT method testKafkaTopicDeleted.

@Test
public void testKafkaTopicDeleted() throws InterruptedException, ExecutionException, TimeoutException {
    // create the Topic Resource
    String topicName = "test-kafkatopic-deleted";
    KafkaTopic topicResource = createKafkaTopicResource(topicName);
    deleteInKubeAndAwaitReconciliation(topicName, topicResource);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Test(org.junit.jupiter.api.Test)

Example 78 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorIT method testKafkaTopicModifiedWithBadData.

@Test
public void testKafkaTopicModifiedWithBadData() throws Exception {
    // create the topicResource
    String topicName = "test-kafkatopic-modified-with-bad-data";
    KafkaTopic topicResource = createKafkaTopicResource(topicName);
    // now change the topicResource
    KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).get()).editOrNewSpec().withPartitions(-1).endSpec().build();
    try {
        operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).replace(changedTopic);
    } catch (KubernetesClientException e) {
        assertThat(e.getMessage().contains("spec.partitions in body should be greater than or equal to 1"), is(true));
    }
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Test(org.junit.jupiter.api.Test)

Example 79 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator 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)

Example 80 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator 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)

Aggregations

KafkaTopic (io.strimzi.api.kafka.model.KafkaTopic)187 Test (org.junit.jupiter.api.Test)92 KafkaTopicBuilder (io.strimzi.api.kafka.model.KafkaTopicBuilder)80 Checkpoint (io.vertx.junit5.Checkpoint)46 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)38 HashMap (java.util.HashMap)32 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)30 CountDownLatch (java.util.concurrent.CountDownLatch)28 NewTopic (org.apache.kafka.clients.admin.NewTopic)28 List (java.util.List)26 Map (java.util.Map)26 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)22 KafkaTopicStatus (io.strimzi.api.kafka.model.status.KafkaTopicStatus)22 AsyncResult (io.vertx.core.AsyncResult)22 MaxAttemptsExceededException (io.strimzi.operator.common.MaxAttemptsExceededException)20 Vertx (io.vertx.core.Vertx)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 Watcher (io.fabric8.kubernetes.client.Watcher)18 KafkaClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients)18 KafkaClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder)18