<commit_before>/*
 * Copyright 2018, Strimzi authors.
 * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
 */
package io.strimzi.systemtest;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.strimzi.test.JUnitGroup;
import io.strimzi.test.Namespace;
import io.strimzi.test.OpenShiftOnly;
import io.strimzi.test.Resources;
import io.strimzi.test.StrimziRunner;
import io.strimzi.test.k8s.KubeClusterResource;
import io.strimzi.test.k8s.Oc;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.Map;

import static io.strimzi.test.TestUtils.map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * Basic tests for the OpenShift templates.
 * This only tests that the template create the appropriate resource,
 * not that the created resource is processed by operator(s) in the appropriate way.
 */
@RunWith(StrimziRunner.class)
@OpenShiftOnly
@Namespace(OpenShiftTemplatesIT.NAMESPACE)
@Resources(value = "../examples/templates/cluster-operator", asAdmin = true)
@Resources(value = "../examples/templates/topic-operator", asAdmin = true)
public class OpenShiftTemplatesIT {

    public static final String NAMESPACE = "template-test";

    @ClassRule
    public static KubeClusterResource cluster = new KubeClusterResource();

    private ObjectMapper mapper = new ObjectMapper();
    private Oc oc = (Oc) cluster.client();
    private KubernetesClient client = new DefaultKubernetesClient();

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziEphemeral() throws IOException {
        String clusterName = "foo";
        oc.newApp("strimzi-ephemeral", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_NODE_COUNT", "1",
                "KAFKA_NODE_COUNT", "1"));

        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("1", cmData.get("kafka-nodes"));
        assertEquals("1", cmData.get("zookeeper-nodes"));
        assertEquals("ephemeral", mapper.readTree(cmData.get("kafka-storage")).get("type").asText());
        assertEquals("ephemeral", mapper.readTree(cmData.get("zookeeper-storage")).get("type").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziPersistent() throws IOException {
        String clusterName = "bar";
        oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_NODE_COUNT", "1",
                "KAFKA_NODE_COUNT", "1"));

        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("1", cmData.get("kafka-nodes"));
        assertEquals("1", cmData.get("zookeeper-nodes"));
        assertEquals("persistent-claim", mapper.readTree(cmData.get("kafka-storage")).get("type").asText());
        assertEquals("persistent-claim", mapper.readTree(cmData.get("zookeeper-storage")).get("type").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziEphemeralWithCustomParameters() {
        String clusterName = "test-ephemeral-with-custom-parameters";
        oc.newApp("strimzi-ephemeral", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_HEALTHCHECK_DELAY", "30",
                "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_HEALTHCHECK_DELAY", "30",
                "KAFKA_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_DEFAULT_REPLICATION_FACTOR", "2",
                "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5",
                "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5"));

        //TODO Add assertions to check that Kafka brokers have a custom configuration
        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
        assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
        assertEquals("30", cmData.get("kafka-healthcheck-delay"));
        assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
        assertEquals("2", cmData.get("KAFKA_DEFAULT_REPLICATION_FACTOR"));
        assertEquals("5", cmData.get("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR"));
        assertEquals("5", cmData.get("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR"));
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziPersistentWithCustomParameters() throws IOException {
        String clusterName = "test-persistent-with-custom-parameters";
        oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_HEALTHCHECK_DELAY", "30",
                "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_HEALTHCHECK_DELAY", "30",
                "KAFKA_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_DEFAULT_REPLICATION_FACTOR", "2",
                "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5",
                "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5",
                "ZOOKEEPER_VOLUME_CAPACITY", "2Gi",
                "KAFKA_VOLUME_CAPACITY", "2Gi"));

        //TODO Add assertions to check that Kafka brokers have a custom configuration
        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
        assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
        assertEquals("30", cmData.get("kafka-healthcheck-delay"));
        assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
        assertEquals("2", cmData.get("KAFKA_DEFAULT_REPLICATION_FACTOR"));
        assertEquals("5", cmData.get("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR"));
        assertEquals("5", cmData.get("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR"));
        assertEquals("2Gi", mapper.readTree(cmData.get("kafka-storage")).get("size").asText());
        assertEquals("2Gi", mapper.readTree(cmData.get("zookeeper-storage")).get("size").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testConnect() {<commit_msg>Updated asserts for replication factor because the structure of JSON was changed (#442)<commit_after>/*
 * Copyright 2018, Strimzi authors.
 * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
 */
package io.strimzi.systemtest;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.strimzi.test.JUnitGroup;
import io.strimzi.test.Namespace;
import io.strimzi.test.OpenShiftOnly;
import io.strimzi.test.Resources;
import io.strimzi.test.StrimziRunner;
import io.strimzi.test.k8s.KubeClusterResource;
import io.strimzi.test.k8s.Oc;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.Map;

import static io.strimzi.test.TestUtils.map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * Basic tests for the OpenShift templates.
 * This only tests that the template create the appropriate resource,
 * not that the created resource is processed by operator(s) in the appropriate way.
 */
@RunWith(StrimziRunner.class)
@OpenShiftOnly
@Namespace(OpenShiftTemplatesIT.NAMESPACE)
@Resources(value = "../examples/templates/cluster-operator", asAdmin = true)
@Resources(value = "../examples/templates/topic-operator", asAdmin = true)
public class OpenShiftTemplatesIT {

    public static final String NAMESPACE = "template-test";

    @ClassRule
    public static KubeClusterResource cluster = new KubeClusterResource();

    private ObjectMapper mapper = new ObjectMapper();
    private Oc oc = (Oc) cluster.client();
    private KubernetesClient client = new DefaultKubernetesClient();

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziEphemeral() throws IOException {
        String clusterName = "foo";
        oc.newApp("strimzi-ephemeral", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_NODE_COUNT", "1",
                "KAFKA_NODE_COUNT", "1"));

        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("1", cmData.get("kafka-nodes"));
        assertEquals("1", cmData.get("zookeeper-nodes"));
        assertEquals("ephemeral", mapper.readTree(cmData.get("kafka-storage")).get("type").asText());
        assertEquals("ephemeral", mapper.readTree(cmData.get("zookeeper-storage")).get("type").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziPersistent() throws IOException {
        String clusterName = "bar";
        oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_NODE_COUNT", "1",
                "KAFKA_NODE_COUNT", "1"));

        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("1", cmData.get("kafka-nodes"));
        assertEquals("1", cmData.get("zookeeper-nodes"));
        assertEquals("persistent-claim", mapper.readTree(cmData.get("kafka-storage")).get("type").asText());
        assertEquals("persistent-claim", mapper.readTree(cmData.get("zookeeper-storage")).get("type").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziEphemeralWithCustomParameters() throws IOException {
        String clusterName = "test-ephemeral-with-custom-parameters";
        oc.newApp("strimzi-ephemeral", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_HEALTHCHECK_DELAY", "30",
                "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_HEALTHCHECK_DELAY", "30",
                "KAFKA_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_DEFAULT_REPLICATION_FACTOR", "2",
                "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5",
                "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5"));

        //TODO Add assertions to check that Kafka brokers have a custom configuration
        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
        assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
        assertEquals("30", cmData.get("kafka-healthcheck-delay"));
        assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
        assertEquals("2", mapper.readTree(cmData.get("kafka-config")).get("default.replication.factor").asText());
        assertEquals("5", mapper.readTree(cmData.get("kafka-config")).get("offsets.topic.replication.factor").asText());
        assertEquals("5", mapper.readTree(cmData.get("kafka-config")).get("transaction.state.log.replication.factor").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testStrimziPersistentWithCustomParameters() throws IOException {
        String clusterName = "test-persistent-with-custom-parameters";
        oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName,
                "ZOOKEEPER_HEALTHCHECK_DELAY", "30",
                "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_HEALTHCHECK_DELAY", "30",
                "KAFKA_HEALTHCHECK_TIMEOUT", "10",
                "KAFKA_DEFAULT_REPLICATION_FACTOR", "2",
                "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5",
                "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5",
                "ZOOKEEPER_VOLUME_CAPACITY", "2Gi",
                "KAFKA_VOLUME_CAPACITY", "2Gi"));

        //TODO Add assertions to check that Kafka brokers have a custom configuration
        ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
        assertNotNull(cm);
        Map<String, String> cmData = cm.getData();
        assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
        assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
        assertEquals("30", cmData.get("kafka-healthcheck-delay"));
        assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
        assertEquals("2", mapper.readTree(cmData.get("kafka-config")).get("default.replication.factor").asText());
        assertEquals("5", mapper.readTree(cmData.get("kafka-config")).get("offsets.topic.replication.factor").asText());
        assertEquals("5", mapper.readTree(cmData.get("kafka-config")).get("transaction.state.log.replication.factor").asText());
        assertEquals("2Gi", mapper.readTree(cmData.get("kafka-storage")).get("size").asText());
        assertEquals("2Gi", mapper.readTree(cmData.get("zookeeper-storage")).get("size").asText());
    }

    @Test
    @JUnitGroup(name = "acceptance")
    public void testConnect() {
{'fraction_non_alphanumeric': 0.13804467228121567, 'fraction_numerical': 0.01032588795313072, 'mean_word_length': 3.803376714737953, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7322784', 'n_tokens_mistral': 4336, 'n_tokens_neox': 4113, 'n_words': 680}