Search in sources :

Example 36 with KafkaTopic

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

the class TopicSerializationTest method testErrorInConfigInvalidValueWrongType.

@Test
public void testErrorInConfigInvalidValueWrongType() {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(singletonMap("foo", new Object())).endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopic's spec.config has invalid entry: The key 'foo' of the topic config is invalid: The value corresponding to the key must have a string, number or boolean value but was of type java.lang.Object"));
    }
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

Example 37 with KafkaTopic

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

the class TopicSerializationTest method testResourceSerializationRoundTripWithKubernetesLabels.

@Test
public void testResourceSerializationRoundTripWithKubernetesLabels() {
    String topicName = "tom";
    Topic.Builder builder = new Topic.Builder();
    builder.withTopicName(topicName);
    builder.withNumReplicas((short) 1);
    builder.withNumPartitions(2);
    builder.withConfigEntry("cleanup.policy", "bar");
    ObjectMeta metadata = new ObjectMeta();
    metadata.setAnnotations(new HashMap<>());
    Map<String, String> kubeLabels = new HashMap<>(3);
    kubeLabels.put("app.kubernetes.io/name", "kstreams");
    kubeLabels.put("app.kubernetes.io/instance", "fraud-detection");
    kubeLabels.put("app.kubernetes.io/managed-by", "helm");
    metadata.setLabels(kubeLabels);
    builder.withMetadata(metadata);
    Topic wroteTopic = builder.build();
    KafkaTopic kafkaTopic = TopicSerialization.toTopicResource(wroteTopic, labels);
    assertThat(kafkaTopic.getMetadata().getName(), is(wroteTopic.getTopicName().toString()));
    assertThat(kafkaTopic.getMetadata().getLabels().size(), is(4));
    assertThat(kafkaTopic.getMetadata().getLabels().get("app"), is("strimzi"));
    assertThat(kafkaTopic.getMetadata().getLabels().get("app.kubernetes.io/name"), is("kstreams"));
    assertThat(kafkaTopic.getMetadata().getLabels().get("app.kubernetes.io/instance"), is("fraud-detection"));
    assertThat(kafkaTopic.getMetadata().getLabels().get("app.kubernetes.io/managed-by"), is("helm"));
    assertThat(kafkaTopic.getSpec().getTopicName(), is(wroteTopic.getTopicName().toString()));
    assertThat(kafkaTopic.getSpec().getPartitions(), is(Integer.valueOf(2)));
    assertThat(kafkaTopic.getSpec().getReplicas(), is(Integer.valueOf(1)));
    assertThat(kafkaTopic.getSpec().getConfig(), is(singletonMap("cleanup.policy", "bar")));
    Topic readTopic = TopicSerialization.fromTopicResource(kafkaTopic);
    assertThat(readTopic, is(wroteTopic));
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HashMap(java.util.HashMap) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) 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 38 with KafkaTopic

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

the class TopicSerializationTest method testErrorInConfigInvalidValueNull.

@Test
public void testErrorInConfigInvalidValueNull() {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(singletonMap("foo", null)).endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopic's spec.config has invalid entry: The key 'foo' of the topic config is invalid: The value corresponding to the key must have a string, number or boolean value but the value was null"));
    }
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

Example 39 with KafkaTopic

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

the class TopicSerializationTest method testNoConfig.

@Test
public void testNoConfig() {
    KafkaTopicSpec spec = new KafkaTopicSpec();
    spec.setPartitions(3);
    spec.setReplicas(3);
    KafkaTopic kafkaTopic = new KafkaTopic();
    kafkaTopic.setMetadata(new ObjectMetaBuilder().withName("my-topic").build());
    kafkaTopic.setSpec(spec);
    TopicSerialization.fromTopicResource(kafkaTopic);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) KafkaTopicSpec(io.strimzi.api.kafka.model.KafkaTopicSpec) Test(org.junit.jupiter.api.Test)

Example 40 with KafkaTopic

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

the class TopicST method testCreateTopicAfterUnsupportedOperation.

@ParallelTest
@Disabled("TopicOperator allows forbidden settings - https://github.com/strimzi/strimzi-kafka-operator/issues/6884")
void testCreateTopicAfterUnsupportedOperation(ExtensionContext extensionContext) {
    String topicName = "topic-with-replication-to-change";
    String newTopicName = "another-topic";
    KafkaTopic kafkaTopic = KafkaTopicTemplates.topic(TOPIC_CLUSTER_NAME, topicName, namespace).editSpec().withReplicas(3).withPartitions(3).endSpec().build();
    resourceManager.createResource(extensionContext, kafkaTopic);
    KafkaTopicResource.replaceTopicResourceInSpecificNamespace(topicName, t -> {
        t.getSpec().setReplicas(1);
        t.getSpec().setPartitions(1);
    }, namespace);
    KafkaTopicUtils.waitForKafkaTopicNotReady(namespace, topicName);
    String exceptedMessage = "Number of partitions cannot be decreased";
    assertThat(KafkaTopicResource.kafkaTopicClient().inNamespace(namespace).withName(topicName).get().getStatus().getConditions().get(0).getMessage(), is(exceptedMessage));
    String topicCRDMessage = KafkaTopicResource.kafkaTopicClient().inNamespace(namespace).withName(topicName).get().getStatus().getConditions().get(0).getMessage();
    assertThat(topicCRDMessage, containsString(exceptedMessage));
    KafkaTopic newKafkaTopic = KafkaTopicTemplates.topic(TOPIC_CLUSTER_NAME, newTopicName, 1, 1).editMetadata().withNamespace(namespace).endMetadata().build();
    resourceManager.createResource(extensionContext, newKafkaTopic);
    assertThat("Topic exists in Kafka itself", hasTopicInKafka(topicName, TOPIC_CLUSTER_NAME));
    assertThat("Topic exists in Kafka CR (Kubernetes)", hasTopicInCRK8s(kafkaTopic, topicName));
    assertThat("Topic exists in Kafka itself", hasTopicInKafka(newTopicName, TOPIC_CLUSTER_NAME));
    assertThat("Topic exists in Kafka CR (Kubernetes)", hasTopicInCRK8s(newKafkaTopic, newTopicName));
    cmdKubeClient(namespace).deleteByName(KafkaTopic.RESOURCE_SINGULAR, topicName);
    KafkaTopicUtils.waitForKafkaTopicDeletion(namespace, topicName);
    cmdKubeClient(namespace).deleteByName(KafkaTopic.RESOURCE_SINGULAR, newTopicName);
    KafkaTopicUtils.waitForKafkaTopicDeletion(namespace, newTopicName);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest) Disabled(org.junit.jupiter.api.Disabled)

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