Search in sources :

Example 61 with KafkaTopic

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

the class TopicOperatorTest method testReconcile_noResource_withKafka_noPrivate.

/**
 * Test reconciliation when a topic has been created while the operator wasn't running
 */
@Test
public void testReconcile_noResource_withKafka_noPrivate(VertxTestContext context) throws InterruptedException {
    Topic kubeTopic = null;
    Topic kafkaTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar"), metadata).build();
    Topic privateTopic = null;
    CountDownLatch topicCreatedInKafka = new CountDownLatch(1);
    mockTopicStore.setCreateTopicResponse(topicName, null);
    mockK8s.setCreateResponse(topicName.asKubeName(), null);
    mockKafka.setCreateTopicResponse(topicName -> Future.succeededFuture());
    mockKafka.createTopic(Reconciliation.DUMMY_RECONCILIATION, kafkaTopic).onComplete(ar -> topicCreatedInKafka.countDown());
    topicCreatedInKafka.await();
    LogContext logContext = LogContext.periodic(topicName.toString(), topicOperator.getNamespace(), topicName.toString());
    CountDownLatch async = new CountDownLatch(2);
    topicOperator.reconcile(reconciliation(logContext), logContext, null, kubeTopic, kafkaTopic, privateTopic).onComplete(reconcileResult -> {
        assertSucceeded(context, reconcileResult);
        mockTopicStore.assertExists(context, topicName);
        mockK8s.assertExists(context, topicName.asKubeName());
        mockKafka.assertExists(context, topicName);
        mockK8s.assertNoEvents(context);
        mockTopicStore.read(topicName).onComplete(readResult -> {
            assertSucceeded(context, readResult);
            context.verify(() -> assertThat(readResult.result(), is(kafkaTopic)));
            async.countDown();
        });
        mockK8s.getFromName(topicName.asKubeName()).onComplete(readResult -> {
            assertSucceeded(context, readResult);
            context.verify(() -> assertThat(TopicSerialization.fromTopicResource(readResult.result()), is(kafkaTopic)));
            async.countDown();
        });
        try {
            async.await(60, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        context.verify(() -> assertThat(mockKafka.getTopicState(topicName), is(kafkaTopic)));
        context.verify(() -> {
            MeterRegistry registry = metrics.meterRegistry();
            assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations").tag("kind", "KafkaTopic").counter().count(), is(1.0));
            assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "KafkaTopic").counter().count(), is(1.0));
            assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.failed").tag("kind", "KafkaTopic").counter().count(), is(0.0));
            assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.locked").tag("kind", "KafkaTopic").counter().count(), is(0.0));
            assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "KafkaTopic").timer().count(), is(1L));
            assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "KafkaTopic").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        });
        context.completeNow();
    });
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) CountDownLatch(java.util.concurrent.CountDownLatch) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 62 with KafkaTopic

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

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

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

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

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