Search in sources :

Example 46 with KafkaTopicBuilder

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

Example 47 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator 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 48 with KafkaTopicBuilder

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

the class TopicOperatorBaseIT method alterTopicConfigInKube.

protected String alterTopicConfigInKube(String resourceName, String key, Function<String, String> mutator) {
    // now change the topic resource
    Object retention = operation().inNamespace(NAMESPACE).withName(resourceName).get().getSpec().getConfig().getOrDefault(key, "12341233");
    String currentValue = retention instanceof Integer ? retention.toString() : (String) retention;
    String newValue = mutator.apply(currentValue);
    KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().addToConfig(key, newValue).endSpec().build();
    operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
    return newValue;
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder)

Example 49 with KafkaTopicBuilder

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

the class TopicOperatorIT method testTopicNumPartitionsDecreased.

@Test
public void testTopicNumPartitionsDecreased() throws Exception {
    String topicName = "topic-partitions-decreased-in-kube";
    String resourceName = createTopic(topicName, new NewTopic(topicName, 2, (short) 1));
    KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().withPartitions(1).endSpec().build();
    KafkaTopic replaced = operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
    assertStatusNotReady(topicName, PartitionDecreaseException.class, "Number of partitions cannot be decreased");
    Long generation = operation().inNamespace(NAMESPACE).withName(resourceName).get().getMetadata().getGeneration();
    // Now modify Kafka-side to cause another reconciliation: We want the same status.
    alterTopicConfigInKafka(topicName, "compression.type", value -> "snappy".equals(value) ? "lz4" : "snappy");
    // Wait for a periodic reconciliation
    Thread.sleep(RECONCILIATION_INTERVAL + 10_000);
    assertStatusNotReady(topicName, PartitionDecreaseException.class, "Number of partitions cannot be decreased");
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.jupiter.api.Test)

Example 50 with KafkaTopicBuilder

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

the class TopicOperatorIT method testInvalidConfig.

@Test
public void testInvalidConfig() throws Exception {
    String topicName = "topic-invalid-config";
    String expectedMessage = "Invalid config value for resource ConfigResource(type=TOPIC, name='" + topicName + "'): Invalid value x for configuration min.insync.replicas: Not a number of type INT";
    String resourceName = createTopic(topicName, new NewTopic(topicName, 2, (short) 1));
    KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().addToConfig("min.insync.replicas", "x").endSpec().build();
    KafkaTopic replaced = operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
    assertStatusNotReady(topicName, InvalidRequestException.class, expectedMessage);
    // Now modify Kafka-side to cause another reconciliation: We want the same status.
    alterTopicConfigInKafka(topicName, "compression.type", value -> "snappy".equals(value) ? "lz4" : "snappy");
    // Wait for a periodic reconciliation
    Thread.sleep(RECONCILIATION_INTERVAL + 10_000);
    assertStatusNotReady(topicName, InvalidRequestException.class, expectedMessage);
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) NewTopic(org.apache.kafka.clients.admin.NewTopic) 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