Search in sources :

Example 86 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerTest method testOnConfigMapRemoved_UnknownTopicOrPartitionException.

@Test
public void testOnConfigMapRemoved_UnknownTopicOrPartitionException(TestContext context) {
    Exception deleteTopicException = new UnknownTopicOrPartitionException();
    Exception storeException = null;
    configMapRemoved(context, deleteTopicException, storeException);
}
Also used : UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Test(org.junit.Test)

Example 87 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerTest method testOnConfigMapChanged.

@Test
public void testOnConfigMapChanged(TestContext context) {
    Topic kubeTopic = new Topic.Builder(topicName, mapName, 10, (short) 2, map("cleanup.policy", "baz")).build();
    Topic kafkaTopic = new Topic.Builder(topicName, mapName, 10, (short) 2, map("cleanup.policy", "bar")).build();
    Topic privateTopic = kafkaTopic;
    ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
    mockKafka.setCreateTopicResponse(topicName.toString(), null).createTopic(kafkaTopic, ar -> {
    });
    mockKafka.setTopicMetadataResponse(topicName, Utils.getTopicMetadata(kafkaTopic), null);
    mockKafka.setUpdateTopicResponse(topicName -> Future.succeededFuture());
    mockTopicStore.setCreateTopicResponse(topicName, null).create(privateTopic, ar -> {
    });
    mockTopicStore.setUpdateTopicResponse(topicName, null);
    mockK8s.setModifyResponse(mapName, null);
    Async async = context.async(3);
    controller.onConfigMapModified(cm, ar -> {
        assertSucceeded(context, ar);
        context.assertEquals("baz", mockKafka.getTopicState(topicName).getConfig().get("cleanup.policy"));
        mockTopicStore.read(topicName, ar2 -> {
            assertSucceeded(context, ar2);
            context.assertEquals("baz", ar2.result().getConfig().get("cleanup.policy"));
            async.countDown();
        });
        mockK8s.getFromName(mapName, ar2 -> {
            assertSucceeded(context, ar2);
            context.assertEquals("baz", TopicSerialization.fromConfigMap(ar2.result()).getConfig().get("cleanup.policy"));
            async.countDown();
        });
        async.countDown();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 88 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerTest method testOnTopicDeleted.

@Test
public void testOnTopicDeleted(TestContext context) {
    Exception storeException = null;
    Exception k8sException = null;
    topicDeleted(context, storeException, k8sException);
}
Also used : KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Test(org.junit.Test)

Example 89 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerTest method testOnConfigMapAdded_ClusterAuthorizationException.

/**
 * 1. controller is notified that a ConfigMap is created
 * 2. error when creating topic in kafka
 */
@Test
public void testOnConfigMapAdded_ClusterAuthorizationException(TestContext context) {
    Exception createException = new ClusterAuthorizationException("");
    Controller op = configMapAdded(context, createException, null);
// TODO check a k8s event got created
// TODO what happens when we subsequently reconcile?
}
Also used : KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) Test(org.junit.Test)

Example 90 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerTest method testReconcile_withCm_withKafka_noPrivate_irreconcilable.

/**
 * Test reconciliation when a cm has been added both in kafka and in k8s while the controller was down, and
 * the topics are irreconcilably different: Kafka wins
 */
@Test
public void testReconcile_withCm_withKafka_noPrivate_irreconcilable(TestContext context) {
    Topic kubeTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar")).build();
    Topic kafkaTopic = new Topic.Builder(topicName.toString(), 12, (short) 2, map("cleanup.policy", "baz")).build();
    Topic privateTopic = null;
    Async async0 = context.async(2);
    mockKafka.setCreateTopicResponse(topicName -> Future.succeededFuture());
    mockKafka.createTopic(kafkaTopic, ar -> async0.countDown());
    ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
    mockK8s.setCreateResponse(topicName.asMapName(), null);
    mockK8s.createConfigMap(cm, ar -> async0.countDown());
    mockK8s.setModifyResponse(topicName.asMapName(), null);
    mockTopicStore.setCreateTopicResponse(topicName, null);
    async0.await();
    Async async = context.async(2);
    controller.reconcile(cm, kubeTopic, kafkaTopic, privateTopic, reconcileResult -> {
        assertSucceeded(context, reconcileResult);
        mockK8s.assertContainsEvent(context, e -> e.getMessage().contains("ConfigMap is incompatible with the topic metadata. " + "The topic metadata will be treated as canonical."));
        mockTopicStore.assertExists(context, topicName);
        mockK8s.assertExists(context, topicName.asMapName());
        mockKafka.assertExists(context, topicName);
        mockTopicStore.read(topicName, readResult -> {
            assertSucceeded(context, readResult);
            context.assertEquals(kafkaTopic, readResult.result());
            async.countDown();
        });
        mockK8s.getFromName(topicName.asMapName(), readResult -> {
            assertSucceeded(context, readResult);
            context.assertEquals(kafkaTopic, TopicSerialization.fromConfigMap(readResult.result()));
            async.countDown();
        });
        context.assertEquals(kafkaTopic, mockKafka.getTopicState(topicName));
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)135 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)58 Async (io.vertx.ext.unit.Async)52 Expectations (mockit.Expectations)34 Probe (io.fabric8.kubernetes.api.model.Probe)33 Reconciliation (io.strimzi.controller.cluster.Reconciliation)24 File (java.io.File)23 Git (org.eclipse.jgit.api.Git)23 GitContext (io.fabric8.api.GitContext)21 IOException (java.io.IOException)21 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)20 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 HashMap (java.util.HashMap)17 LockHandle (io.fabric8.api.LockHandle)15 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)15 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (io.fabric8.kubernetes.client.dsl.Resource)14