Search in sources :

Example 36 with KafkaTopicBuilder

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

the class TopicOperatorTest method testOnKafkaTopicAdded_ignorable.

/**
 * Test what happens when a non-topic KafkaTopic gets created in kubernetes
 */
@Test
public void testOnKafkaTopicAdded_ignorable(VertxTestContext context) {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("non-topic").build()).build();
    Checkpoint async = context.checkpoint();
    K8sTopicWatcher w = new K8sTopicWatcher(topicOperator, Future.succeededFuture(), () -> {
    });
    w.eventReceived(ADDED, kafkaTopic);
    mockKafka.assertEmpty(context);
    mockTopicStore.assertEmpty(context);
    async.flag();
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint) 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 KafkaTopicBuilder

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

the class TopicSerializationTest method testErrorInReplicas.

@Test
public void testErrorInReplicas() {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(-1).withPartitions(1).withConfig(emptyMap()).endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopic's spec.replicas should be between 1 and 32767 inclusive"));
    }
}
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 38 with KafkaTopicBuilder

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

the class TopicSerializationTest method testErrorInDefaultTopicName.

@Test
public void testErrorInDefaultTopicName() {
    // The problem with this resource name is it's too long to be a legal topic name
    String illegalAsATopicName = "012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789";
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName(illegalAsATopicName).build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(emptyMap()).endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopics's spec.topicName property is absent and KafkaTopics's metadata.name is invalid as a topic name: " + "Topic name is illegal, it can't be longer than 249 characters, Topic name: " + illegalAsATopicName));
    }
}
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 KafkaTopicBuilder

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

the class TopicSerializationTest method testErrorInPartitions.

@Test
public void testErrorInPartitions() {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(-1).withConfig(emptyMap()).endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopic's spec.partitions should be strictly greater than 0"));
    }
}
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 40 with KafkaTopicBuilder

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

the class TopicSerializationTest method testErrorInTopicName.

@Test
public void testErrorInTopicName() {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("foo").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(emptyMap()).withTopicName("An invalid topic name!").endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopics's spec.topicName property is invalid as a topic name: Topic name \"An invalid topic name!\" is illegal, it contains a character other than ASCII alphanumerics, '.', '_' and '-'"));
    }
}
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)

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