Search in sources :

Example 1 with StrimziKafkaCluster

use of io.strimzi.test.container.StrimziKafkaCluster in project strimzi by strimzi.

the class KafkaConnectApiTest method before.

@BeforeAll
public static void before() throws IOException {
    vertx = Vertx.vertx();
    final Map<String, String> kafkaClusterConfiguration = new HashMap<>();
    kafkaClusterConfiguration.put("zookeeper.connect", "zookeeper:2181");
    cluster = new StrimziKafkaCluster(3, 1, kafkaClusterConfiguration);
    cluster.start();
}
Also used : HashMap(java.util.HashMap) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with StrimziKafkaCluster

use of io.strimzi.test.container.StrimziKafkaCluster in project strimzi by strimzi.

the class TopicOperatorMockTest method setup.

@BeforeEach
public void setup(VertxTestContext context) throws Exception {
    // Create cluster in @BeforeEach instead of @BeforeAll as once the checkpoints causing premature success were fixed,
    // tests were failing due to topic "my-topic" already existing, and trying to delete the topics at the end of the test was timing out occasionally.
    // So works best when the cluster is recreated for each test to avoid shared state
    Map<String, String> config = new HashMap<>();
    config.put("zookeeper.connect", "zookeeper:2181");
    kafkaCluster = new StrimziKafkaCluster(1, 1, config);
    kafkaCluster.start();
    MockKube mockKube = new MockKube();
    mockKube.withCustomResourceDefinition(Crds.kafkaTopic(), KafkaTopic.class, KafkaTopicList.class, KafkaTopic::getStatus, KafkaTopic::setStatus);
    kubeClient = mockKube.build();
    adminClient = AdminClient.create(Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCluster.getBootstrapServers()));
    Config topicConfig = new Config(Map.of(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.getBootstrapServers(), Config.ZOOKEEPER_CONNECT.key, kafkaCluster.getZookeeper().getHost() + ":" + kafkaCluster.getZookeeper().getFirstMappedPort(), Config.ZOOKEEPER_CONNECTION_TIMEOUT_MS.key, "30000", Config.NAMESPACE.key, "myproject", Config.CLIENT_ID.key, "myproject-client-id", Config.FULL_RECONCILIATION_INTERVAL_MS.key, "10000"));
    session = new Session(kubeClient, topicConfig);
    Checkpoint async = context.checkpoint();
    vertx.deployVerticle(session, ar -> {
        if (ar.succeeded()) {
            deploymentId = ar.result();
            topicsConfigWatcher = session.topicConfigsWatcher;
            topicWatcher = session.topicWatcher;
            topicsWatcher = session.topicsWatcher;
            metrics = session.metricsRegistry;
            metrics.forEachMeter(meter -> metrics.remove(meter));
            async.flag();
        } else {
            ar.cause().printStackTrace();
            context.failNow(new Throwable("Failed to deploy session"));
        }
    });
    if (!context.awaitCompletion(60, TimeUnit.SECONDS)) {
        context.failNow(new Throwable("Test timeout"));
    }
    int timeout = 30_000;
    waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicWatcher.started());
    waitFor("Topic configs watcher not started", 1_000, timeout, () -> this.topicsConfigWatcher.started());
    waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicsWatcher.started());
}
Also used : MockKube(io.strimzi.test.mockkube.MockKube) Checkpoint(io.vertx.junit5.Checkpoint) HashMap(java.util.HashMap) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) Checkpoint(io.vertx.junit5.Checkpoint) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with StrimziKafkaCluster

use of io.strimzi.test.container.StrimziKafkaCluster in project strimzi by strimzi.

the class TopicOperatorReplicationIT method beforeAll.

@BeforeAll
public void beforeAll() throws Exception {
    kafkaCluster = new StrimziKafkaCluster(numKafkaBrokers(), numKafkaBrokers(), kafkaClusterConfig());
    kafkaCluster.start();
    setupKubeCluster();
    setup(kafkaCluster);
    startTopicOperator(kafkaCluster);
}
Also used : StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with StrimziKafkaCluster

use of io.strimzi.test.container.StrimziKafkaCluster in project strimzi-kafka-operator by strimzi.

the class KafkaConnectApiTest method before.

@BeforeAll
public static void before() throws IOException {
    vertx = Vertx.vertx();
    final Map<String, String> kafkaClusterConfiguration = new HashMap<>();
    kafkaClusterConfiguration.put("zookeeper.connect", "zookeeper:2181");
    cluster = new StrimziKafkaCluster(3, 1, kafkaClusterConfiguration);
    cluster.start();
}
Also used : HashMap(java.util.HashMap) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with StrimziKafkaCluster

use of io.strimzi.test.container.StrimziKafkaCluster in project strimzi-kafka-operator by strimzi.

the class TopicOperatorMockTest method setup.

@BeforeEach
public void setup(VertxTestContext context) throws Exception {
    // Create cluster in @BeforeEach instead of @BeforeAll as once the checkpoints causing premature success were fixed,
    // tests were failing due to topic "my-topic" already existing, and trying to delete the topics at the end of the test was timing out occasionally.
    // So works best when the cluster is recreated for each test to avoid shared state
    Map<String, String> config = new HashMap<>();
    config.put("zookeeper.connect", "zookeeper:2181");
    kafkaCluster = new StrimziKafkaCluster(1, 1, config);
    kafkaCluster.start();
    MockKube mockKube = new MockKube();
    mockKube.withCustomResourceDefinition(Crds.kafkaTopic(), KafkaTopic.class, KafkaTopicList.class, KafkaTopic::getStatus, KafkaTopic::setStatus);
    kubeClient = mockKube.build();
    adminClient = AdminClient.create(Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCluster.getBootstrapServers()));
    Config topicConfig = new Config(Map.of(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.getBootstrapServers(), Config.ZOOKEEPER_CONNECT.key, kafkaCluster.getZookeeper().getHost() + ":" + kafkaCluster.getZookeeper().getFirstMappedPort(), Config.ZOOKEEPER_CONNECTION_TIMEOUT_MS.key, "30000", Config.NAMESPACE.key, "myproject", Config.CLIENT_ID.key, "myproject-client-id", Config.FULL_RECONCILIATION_INTERVAL_MS.key, "10000"));
    session = new Session(kubeClient, topicConfig);
    Checkpoint async = context.checkpoint();
    vertx.deployVerticle(session, ar -> {
        if (ar.succeeded()) {
            deploymentId = ar.result();
            topicsConfigWatcher = session.topicConfigsWatcher;
            topicWatcher = session.topicWatcher;
            topicsWatcher = session.topicsWatcher;
            metrics = session.metricsRegistry;
            metrics.forEachMeter(meter -> metrics.remove(meter));
            async.flag();
        } else {
            ar.cause().printStackTrace();
            context.failNow(new Throwable("Failed to deploy session"));
        }
    });
    if (!context.awaitCompletion(60, TimeUnit.SECONDS)) {
        context.failNow(new Throwable("Test timeout"));
    }
    int timeout = 30_000;
    waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicWatcher.started());
    waitFor("Topic configs watcher not started", 1_000, timeout, () -> this.topicsConfigWatcher.started());
    waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicsWatcher.started());
}
Also used : MockKube(io.strimzi.test.mockkube.MockKube) Checkpoint(io.vertx.junit5.Checkpoint) HashMap(java.util.HashMap) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) Checkpoint(io.vertx.junit5.Checkpoint) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StrimziKafkaCluster (io.strimzi.test.container.StrimziKafkaCluster)14 BeforeAll (org.junit.jupiter.api.BeforeAll)12 HashMap (java.util.HashMap)8 KafkaTopic (io.strimzi.api.kafka.model.KafkaTopic)2 MockKube (io.strimzi.test.mockkube.MockKube)2 VertxOptions (io.vertx.core.VertxOptions)2 Checkpoint (io.vertx.junit5.Checkpoint)2 MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)2 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)2 LinkedHashMap (java.util.LinkedHashMap)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 AdminClientConfig (org.apache.kafka.clients.admin.AdminClientConfig)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.emptyString (org.hamcrest.Matchers.emptyString)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2