Search in sources :

Example 71 with KafkaTopic

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

the class TopicOperatorBaseIT method createKafkaTopicResource.

protected KafkaTopic createKafkaTopicResource(String topicName) throws InterruptedException, ExecutionException, TimeoutException {
    Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
    KafkaTopic topicResource = TopicSerialization.toTopicResource(topic, labels);
    return createKafkaTopicResource(topicResource);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) NewTopic(org.apache.kafka.clients.admin.NewTopic) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic)

Example 72 with KafkaTopic

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

the class TopicOperatorIT method testKafkaTopicAddedWithBadData.

@Test
public void testKafkaTopicAddedWithBadData() {
    String topicName = "test-resource-created-with-bad-data";
    Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
    KafkaTopic kafkaTopic = TopicSerialization.toTopicResource(topic, labels);
    kafkaTopic.getSpec().setPartitions(-1);
    // Create a Topic Resource
    try {
        operation().inNamespace(NAMESPACE).create(kafkaTopic);
        fail();
    } 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) NewTopic(org.apache.kafka.clients.admin.NewTopic) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Test(org.junit.jupiter.api.Test)

Example 73 with KafkaTopic

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

the class TopicOperatorIT method testKafkaTopicModifiedNameChanged.

@Test
public void testKafkaTopicModifiedNameChanged() throws Exception {
    // create the topicResource
    String topicName = "test-kafkatopic-modified-name-changed";
    KafkaTopic topicResource = createKafkaTopicResource(topicName);
    // now change the topicResource
    String changedName = topicName.toUpperCase(Locale.ENGLISH);
    LOGGER.info("Changing Topic Resource spec.topicName from {} to {}", topicName, changedName);
    KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).get()).editOrNewSpec().withTopicName(changedName).endSpec().build();
    operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).replace(changedTopic);
    // We expect this to cause a warning event
    waitForEvent(topicResource, "Kafka topics cannot be renamed, but KafkaTopic's spec.topicName has changed.", TopicOperator.EventType.WARNING);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) Test(org.junit.jupiter.api.Test)

Example 74 with KafkaTopic

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

the class TopicOperatorIT method testReconcile.

@Test
public void testReconcile() throws InterruptedException, ExecutionException, TimeoutException {
    String topicName = "test-reconcile";
    Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
    KafkaTopic topicResource = TopicSerialization.toTopicResource(topic, labels);
    String resourceName = topicResource.getMetadata().getName();
    operation().inNamespace(NAMESPACE).create(topicResource);
    // Wait for the resource to be created
    waitFor(() -> {
        KafkaTopic createdResource = operation().inNamespace(NAMESPACE).withName(resourceName).get();
        LOGGER.info("Polled kafkatopic {} waiting for creation", resourceName);
        // modify resource
        if (createdResource != null) {
            createdResource.getSpec().setPartitions(2);
            operation().inNamespace(NAMESPACE).withName(resourceName).patch(createdResource);
        }
        return createdResource != null;
    }, "Expected the kafkatopic to have been created by now");
    // trigger an immediate reconcile, while topic operator is dealing with resource modification
    session.topicOperator.reconcileAllTopics("periodic");
    // Wait for the topic to be created
    waitForTopicInKafka(topicName);
    assertStatusReady(topicName);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) NewTopic(org.apache.kafka.clients.admin.NewTopic) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Test(org.junit.jupiter.api.Test)

Example 75 with KafkaTopic

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

the class TopicOperatorIT method testCreateTwoResourcesManagingOneTopic.

@Test
public void testCreateTwoResourcesManagingOneTopic() throws InterruptedException, ExecutionException, TimeoutException {
    String topicName = "two-resources-one-topic";
    Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
    KafkaTopic topicResource = TopicSerialization.toTopicResource(topic, labels);
    KafkaTopic topicResource2 = new KafkaTopicBuilder(topicResource).withMetadata(new ObjectMetaBuilder(topicResource.getMetadata()).withName(topicName + "-1").build()).build();
    // create one
    createKafkaTopicResource(topicResource2);
    // create another
    operation().inNamespace(NAMESPACE).create(topicResource);
    waitForEvent(topicResource, "Failure processing KafkaTopic watch event ADDED on resource two-resources-one-topic with labels \\{.*\\}: " + "Topic 'two-resources-one-topic' is already managed via KafkaTopic 'two-resources-one-topic-1' it cannot also be managed via the KafkaTopic 'two-resources-one-topic'", TopicOperator.EventType.WARNING);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) NewTopic(org.apache.kafka.clients.admin.NewTopic) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

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