Search in sources :

Example 96 with Context

use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.

the class ControllerIT method testConfigMapModifiedWithBadData.

@Test
public void testConfigMapModifiedWithBadData(TestContext context) throws Exception {
    // create the cm
    String topicName = "test-configmap-modified-with-bad-data";
    ConfigMap cm = createCm(context, topicName);
    // now change the cm
    kubeClient.configMaps().inNamespace(NAMESPACE).withName(cm.getMetadata().getName()).edit().addToData(TopicSerialization.CM_KEY_PARTITIONS, "foo").done();
    // Wait for that to be reflected in the topic
    waitForEvent(context, cm, "ConfigMap test-configmap-modified-with-bad-data has an invalid 'data' section: " + "ConfigMap's 'data' section has invalid key 'partitions': " + "should be a strictly positive integer but was 'foo'", Controller.EventType.WARNING);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 97 with Context

use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.

the class ControllerIT method setup.

@Before
public void setup(TestContext context) throws Exception {
    LOGGER.info("Setting up test");
    Runtime.getRuntime().addShutdownHook(kafkaHook);
    kafkaCluster = new KafkaCluster();
    kafkaCluster.addBrokers(1);
    kafkaCluster.deleteDataPriorToStartup(true);
    kafkaCluster.deleteDataUponShutdown(true);
    kafkaCluster.usingDirectory(Files.createTempDirectory("controller-integration-test").toFile());
    kafkaCluster.startup();
    kubeClient = new DefaultKubernetesClient().inNamespace(NAMESPACE);
    LOGGER.info("Using namespace {}", NAMESPACE);
    Map<String, String> m = new HashMap();
    m.put(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.brokerList());
    m.put(Config.ZOOKEEPER_CONNECT.key, "localhost:" + zkPort(kafkaCluster));
    m.put(Config.NAMESPACE.key, NAMESPACE);
    session = new Session(kubeClient, new Config(m));
    Async async = context.async();
    vertx.deployVerticle(session, ar -> {
        if (ar.succeeded()) {
            deploymentId = ar.result();
            adminClient = session.adminClient;
            topicsConfigWatcher = session.topicConfigsWatcher;
            topicWatcher = session.topicWatcher;
            topicsWatcher = session.topicsWatcher;
            async.complete();
        } else {
            context.fail("Failed to deploy session");
        }
    });
    async.await();
    waitFor(context, () -> this.topicsWatcher.started(), timeout, "Topics watcher not started");
    waitFor(context, () -> this.topicsConfigWatcher.started(), timeout, "Topic configs watcher not started");
    waitFor(context, () -> this.topicWatcher.started(), timeout, "Topic watcher not started");
    // We can't delete events, so record the events which exist at the start of the test
    // and then waitForEvents() can ignore those
    preExistingEvents = kubeClient.events().inNamespace(NAMESPACE).withLabels(cmPredicate.labels()).list().getItems().stream().map(evt -> evt.getMetadata().getUid()).collect(Collectors.toSet());
    LOGGER.info("Finished setting up test");
}
Also used : KafkaCluster(io.debezium.kafka.KafkaCluster) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Before(org.junit.Before)

Example 98 with Context

use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.

the class ControllerIT method createCm.

private ConfigMap createCm(TestContext context, String topicName) {
    Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
    ConfigMap cm = TopicSerialization.toConfigMap(topic, cmPredicate);
    return createCm(context, cm);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) NewTopic(org.apache.kafka.clients.admin.NewTopic)

Example 99 with Context

use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.

the class ControllerIT method deleteTopic.

private void deleteTopic(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
    LOGGER.info("Deleting topic {} (ConfigMap {})", topicName, configMapName);
    // Now we can delete the topic
    DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName));
    dlt.all().get();
    LOGGER.info("Deleted topic {}", topicName);
    // Wait for the configmap to be deleted
    waitFor(context, () -> {
        ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
        LOGGER.info("Polled configmap {}, got {}, waiting for deletion", configMapName, cm);
        return cm == null;
    }, timeout, "Expected the configmap to have been deleted by now");
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 100 with Context

use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.

the class ControllerIT method waitForEvent.

private void waitForEvent(TestContext context, ConfigMap cm, String expectedMessage, Controller.EventType expectedType) {
    waitFor(context, () -> {
        List<Event> items = kubeClient.events().inNamespace(NAMESPACE).withLabels(cmPredicate.labels()).list().getItems();
        List<Event> filtered = items.stream().filter(evt -> !preExistingEvents.contains(evt.getMetadata().getUid()) && "ConfigMap".equals(evt.getInvolvedObject().getKind()) && cm.getMetadata().getName().equals(evt.getInvolvedObject().getName())).collect(Collectors.toList());
        LOGGER.debug("Waiting for events: {}", filtered.stream().map(evt -> evt.getMessage()).collect(Collectors.toList()));
        if (!filtered.isEmpty()) {
            assertEquals(1, filtered.size());
            Event event = filtered.get(0);
            assertEquals(expectedMessage, event.getMessage());
            assertEquals(expectedType.name, event.getType());
            assertNotNull(event.getInvolvedObject());
            assertEquals("ConfigMap", event.getInvolvedObject().getKind());
            assertEquals(cm.getMetadata().getName(), event.getInvolvedObject().getName());
            return true;
        } else {
            return false;
        }
    }, timeout, "Expected an error event");
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ZookeeperServer(io.debezium.kafka.ZookeeperServer) LoggerFactory(org.slf4j.LoggerFactory) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) BooleanSupplier(java.util.function.BooleanSupplier) Collections.singletonList(java.util.Collections.singletonList) AdminClient(org.apache.kafka.clients.admin.AdminClient) Locale(java.util.Locale) After(org.junit.After) Map(java.util.Map) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ClassRule(org.junit.ClassRule) KafkaCluster(io.debezium.kafka.KafkaCluster) AfterClass(org.junit.AfterClass) Event(io.fabric8.kubernetes.api.model.Event) Namespace(io.strimzi.test.Namespace) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) List(java.util.List) AlterConfigsResult(org.apache.kafka.clients.admin.AlterConfigsResult) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Async(io.vertx.ext.unit.Async) BeforeClass(org.junit.BeforeClass) NewPartitions(org.apache.kafka.clients.admin.NewPartitions) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) KubeClusterResource(io.strimzi.test.k8s.KubeClusterResource) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) Collections.singletonMap(java.util.Collections.singletonMap) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Vertx(io.vertx.core.Vertx) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) CreatePartitionsResult(org.apache.kafka.clients.admin.CreatePartitionsResult) Field(java.lang.reflect.Field) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ExecutionException(java.util.concurrent.ExecutionException) Ignore(org.junit.Ignore) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert.assertEquals(org.junit.Assert.assertEquals) Event(io.fabric8.kubernetes.api.model.Event)

Aggregations

Test (org.junit.Test)138 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 File (java.io.File)26 Reconciliation (io.strimzi.controller.cluster.Reconciliation)24 IOException (java.io.IOException)24 Git (org.eclipse.jgit.api.Git)23 GitContext (io.fabric8.api.GitContext)21 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)20 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)20 HashMap (java.util.HashMap)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 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