Search in sources :

Example 81 with Context

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

the class AbtractReadyResourceOperatorTest method waitUntilReadyWhenDoesNotExist.

@Test
public void waitUntilReadyWhenDoesNotExist(TestContext context) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(null);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    Future<Void> fut = op.readiness(NAMESPACE, RESOURCE_NAME, 20, 100);
    fut.setHandler(ar -> {
        assertTrue(ar.failed());
        assertThat(ar.cause(), instanceOf(TimeoutException.class));
        verify(mockResource, atLeastOnce()).get();
        verify(mockResource, never()).isReady();
        async.complete();
    });
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Async(io.vertx.ext.unit.Async) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) Test(org.junit.Test)

Example 82 with Context

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

the class ControllerTest method testOnTopicDeleted_NoSuchEntityExistsException.

@Test
public void testOnTopicDeleted_NoSuchEntityExistsException(TestContext context) {
    Exception k8sException = null;
    Exception storeException = new TopicStore.NoSuchEntityExistsException();
    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 83 with Context

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

the class ControllerTest method testOnConfigMapAdded_ignorable.

/**
 * Test what happens when a non-topic config map gets created in kubernetes
 */
@Test
public void testOnConfigMapAdded_ignorable(TestContext context) {
    ConfigMap cm = new ConfigMapBuilder().withNewMetadata().withName("non-topic").endMetadata().build();
    Async async = context.async();
    controller.onConfigMapAdded(cm, ar -> {
        assertSucceeded(context, ar);
        mockKafka.assertEmpty(context);
        mockTopicStore.assertEmpty(context);
        async.complete();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 84 with Context

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

the class ControllerTest method testOnConfigMapRemoved_NoSuchEntityExistsException.

@Test
public void testOnConfigMapRemoved_NoSuchEntityExistsException(TestContext context) {
    Exception deleteTopicException = null;
    Exception storeException = new TopicStore.NoSuchEntityExistsException();
    configMapRemoved(context, deleteTopicException, storeException);
}
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 85 with Context

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

the class ControllerTest method testReconcile_withCm_withKafka_noPrivate_configsReconcilable.

/**
 * 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_configsReconcilable(TestContext context) {
    Topic kubeTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar")).build();
    Topic kafkaTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("unclean.leader.election.enable", "true")).build();
    Topic privateTopic = null;
    Topic mergedTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("unclean.leader.election.enable", "true", "cleanup.policy", "bar")).build();
    Async async0 = context.async(2);
    mockKafka.setCreateTopicResponse(topicName -> Future.succeededFuture());
    mockKafka.createTopic(kafkaTopic, ar -> async0.countDown());
    mockKafka.setUpdateTopicResponse(topicName -> Future.succeededFuture());
    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);
        mockTopicStore.assertExists(context, topicName);
        mockK8s.assertExists(context, topicName.asMapName());
        mockKafka.assertExists(context, topicName);
        mockTopicStore.read(topicName, readResult -> {
            assertSucceeded(context, readResult);
            context.assertEquals(mergedTopic, readResult.result());
            async.countDown();
        });
        mockK8s.getFromName(topicName.asMapName(), readResult -> {
            assertSucceeded(context, readResult);
            context.assertEquals(mergedTopic, TopicSerialization.fromConfigMap(readResult.result()));
            async.countDown();
        });
        context.assertEquals(mergedTopic, 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