You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2020/09/21 07:53:53 UTC

[camel] branch master updated: Moved the Kafka test infrastructure from the Camel Kafka Connector to Camel Core (#4242)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 15983a6  Moved the Kafka test infrastructure from the Camel Kafka Connector to Camel Core (#4242)
15983a6 is described below

commit 15983a65cf64878c583f2c8bd57fe4c3d595f7db
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Sep 21 09:53:37 2020 +0200

    Moved the Kafka test infrastructure from the Camel Kafka Connector to Camel Core (#4242)
---
 .../camel-test-infra-common/pom.xml                |  44 +++++++++
 .../src/main/resources/META-INF/MANIFEST.MF        |   0
 .../apache/camel/test/infra/common/TestUtils.java  | 104 +++++++++++++++++++++
 .../camel-test-infra-kafka/pom.xml                 |  59 ++++++++++++
 .../src/main/resources/META-INF/MANIFEST.MF        |   0
 .../services/kafka/ContainerLocalKafkaService.java |  43 +++++++++
 .../test/infra/services/kafka/KafkaService.java    |  68 ++++++++++++++
 .../infra/services/kafka/KafkaServiceFactory.java  |  49 ++++++++++
 .../infra/services/kafka/RemoteKafkaService.java   |  40 ++++++++
 .../infra/services/kafka/StrimziContainer.java     |  68 ++++++++++++++
 .../test/infra/services/kafka/StrimziService.java  |  87 +++++++++++++++++
 .../infra/services/kafka/ZookeeperContainer.java   |  56 +++++++++++
 .../camel-test-infra-parent/pom.xml                |  84 +++++++++++++++++
 core/camel-test-infra/pom.xml                      |  41 ++++++++
 core/pom.xml                                       |   1 +
 parent/pom.xml                                     |   5 +
 16 files changed, 749 insertions(+)

diff --git a/core/camel-test-infra/camel-test-infra-common/pom.xml b/core/camel-test-infra/camel-test-infra-common/pom.xml
new file mode 100644
index 0000000..b6fa5e6
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-common/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>camel-test-infra-parent</artifactId>
+        <groupId>org.apache.camel</groupId>
+        <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+        <version>3.6.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>camel-test-infra-common</artifactId>
+
+    <name>Camel :: Test :: Infra :: Common </name>
+    <description>Common test infrastructure code for Camel</description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git a/core/camel-test-infra/camel-test-infra-common/src/main/resources/META-INF/MANIFEST.MF b/core/camel-test-infra/camel-test-infra-common/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git a/core/camel-test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java b/core/camel-test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java
new file mode 100644
index 0000000..e2d3962
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.test.infra.common;
+
+import java.util.concurrent.TimeUnit;
+import java.util.function.BooleanSupplier;
+import java.util.function.Predicate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test utilities
+ */
+public final class TestUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
+
+    private TestUtils() {
+    }
+
+    /**
+     * Wait for a given condition to be true or the retry amount (30) to expire
+     * 
+     * @param resourceCheck
+     * @param payload
+     * @param <T>
+     */
+    public static <T> boolean waitFor(Predicate<T> resourceCheck, T payload) {
+        boolean state = false;
+        int retries = 30;
+        int waitTime = 1000;
+        do {
+            try {
+                state = resourceCheck.test(payload);
+
+                if (!state) {
+                    LOG.debug("The resource is not yet available. Waiting {} seconds before retrying",
+                            TimeUnit.MILLISECONDS.toSeconds(waitTime));
+                    retries--;
+                    Thread.sleep(waitTime);
+                }
+            } catch (InterruptedException e) {
+                break;
+            }
+
+        } while (!state && retries > 0);
+
+        return state;
+    }
+
+    /**
+     * Wait for a given condition to be true or the retry amount (30) to expire
+     * 
+     * @param resourceCheck
+     */
+    public static boolean waitFor(BooleanSupplier resourceCheck) {
+        boolean state = false;
+        int retries = 30;
+        int waitTime = 1000;
+        do {
+            try {
+                state = resourceCheck.getAsBoolean();
+
+                if (!state) {
+                    LOG.debug("The resource is not yet available. Waiting {} seconds before retrying",
+                            TimeUnit.MILLISECONDS.toSeconds(waitTime));
+                    retries--;
+                    Thread.sleep(waitTime);
+                }
+            } catch (InterruptedException e) {
+                break;
+            }
+        } while (!state && retries > 0);
+
+        return state;
+    }
+
+    /**
+     * Gets a random number within range
+     * 
+     * @param  min
+     * @param  max
+     * @return
+     */
+    public static int randomWithRange(int min, int max) {
+        int range = (max - min) + 1;
+
+        return (int) (Math.random() * range) + min;
+    }
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/pom.xml b/core/camel-test-infra/camel-test-infra-kafka/pom.xml
new file mode 100644
index 0000000..6700490
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>camel-test-infra-parent</artifactId>
+        <groupId>org.apache.camel</groupId>
+        <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+        <version>3.6.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>camel-test-infra-kafka</artifactId>
+
+    <name>Camel :: Test :: Infra :: Kafka </name>
+    <description>Kafka test infrastructure for Camel</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>kafka</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/main/resources/META-INF/MANIFEST.MF b/core/camel-test-infra/camel-test-infra-kafka/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/ContainerLocalKafkaService.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/ContainerLocalKafkaService.java
new file mode 100644
index 0000000..107d2ca
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/ContainerLocalKafkaService.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.KafkaContainer;
+
+public class ContainerLocalKafkaService implements KafkaService {
+    private static final Logger LOG = LoggerFactory.getLogger(ContainerLocalKafkaService.class);
+    private KafkaContainer kafka = new KafkaContainer().withEmbeddedZookeeper();
+
+    public String getBootstrapServers() {
+        return kafka.getBootstrapServers();
+    }
+
+    @Override
+    public void initialize() {
+        kafka.start();
+
+        LOG.info("Kafka bootstrap server running at address {}", kafka.getBootstrapServers());
+    }
+
+    @Override
+    public void shutdown() {
+        kafka.stop();
+    }
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/KafkaService.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/KafkaService.java
new file mode 100644
index 0000000..1f76a24
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/KafkaService.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Provides an interface for any type of Kafka service: remote instances, local container, etc
+ */
+public interface KafkaService
+        extends BeforeAllCallback, BeforeTestExecutionCallback, AfterAllCallback, AfterTestExecutionCallback {
+
+    /**
+     * Gets the addresses of the bootstrap servers in the format host1:port,host2:port,etc
+     * 
+     * @return
+     */
+    String getBootstrapServers();
+
+    /**
+     * Perform any initialization necessary
+     */
+    void initialize();
+
+    /**
+     * Shutdown the service
+     */
+    void shutdown();
+
+    @Override
+    default void beforeAll(ExtensionContext extensionContext) throws Exception {
+        initialize();
+    }
+
+    @Override
+    default void beforeTestExecution(ExtensionContext extensionContext) throws Exception {
+        //no op
+    }
+
+    @Override
+    default void afterAll(ExtensionContext extensionContext) throws Exception {
+        shutdown();
+    }
+
+    @Override
+    default void afterTestExecution(ExtensionContext context) throws Exception {
+        //no op
+    }
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/KafkaServiceFactory.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/KafkaServiceFactory.java
new file mode 100644
index 0000000..9f544de
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/KafkaServiceFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class KafkaServiceFactory {
+    private static final Logger LOG = LoggerFactory.getLogger(KafkaServiceFactory.class);
+
+    private KafkaServiceFactory() {
+
+    }
+
+    public static KafkaService createService() {
+        String kafkaInstanceType = System.getProperty("kafka.instance.type");
+
+        if (kafkaInstanceType.equals("local-strimzi-container")) {
+            return new StrimziService();
+        }
+
+        if (kafkaInstanceType.equals("local-kafka-container")) {
+            return new ContainerLocalKafkaService();
+        }
+
+        if (kafkaInstanceType.equals("remote")) {
+            return new RemoteKafkaService();
+        }
+
+        LOG.error("Kafka instance must be one of 'local-strimzi-container', 'local-kafka-container', 'embedded' or 'remote");
+        throw new UnsupportedOperationException("Invalid Kafka instance type: " + kafkaInstanceType);
+    }
+
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/RemoteKafkaService.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/RemoteKafkaService.java
new file mode 100644
index 0000000..66cbd46
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/RemoteKafkaService.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RemoteKafkaService implements KafkaService {
+    private static final Logger LOG = LoggerFactory.getLogger(RemoteKafkaService.class);
+
+    @Override
+    public String getBootstrapServers() {
+        return System.getProperty("kafka.bootstrap.servers");
+    }
+
+    @Override
+    public void initialize() {
+        LOG.info("Kafka bootstrap server running at address {}", getBootstrapServers());
+    }
+
+    @Override
+    public void shutdown() {
+        // NO-OP
+    }
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/StrimziContainer.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/StrimziContainer.java
new file mode 100644
index 0000000..7b68038
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/StrimziContainer.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import java.util.function.Consumer;
+
+import com.github.dockerjava.api.command.CreateContainerCmd;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class StrimziContainer extends GenericContainer<StrimziContainer> {
+    private static final String STRIMZI_CONTAINER = System.getProperty("itest.strimzi.container.image");
+    private static final int KAFKA_PORT = 9092;
+
+    public StrimziContainer(Network network, String name) {
+        super(STRIMZI_CONTAINER);
+
+        withEnv("LOG_DIR", "/tmp/logs");
+        withExposedPorts(KAFKA_PORT);
+        withEnv("KAFKA_ADVERTISED_LISTENERS", String.format("PLAINTEXT://%s:9092", getContainerIpAddress()));
+        withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:9092");
+        withEnv("KAFKA_ZOOKEEPER_CONNECT", "zookeeper:2181");
+        withNetwork(network);
+
+        withCreateContainerCmdModifier(
+                new Consumer<CreateContainerCmd>() {
+                    @Override
+                    public void accept(CreateContainerCmd createContainerCmd) {
+                        createContainerCmd.withHostName(name);
+                        createContainerCmd.withName(name);
+                    }
+                });
+
+        withCommand("sh", "-c",
+                "bin/kafka-server-start.sh config/server.properties "
+                                + "--override listeners=${KAFKA_LISTENERS} "
+                                + "--override advertised.listeners=${KAFKA_ADVERTISED_LISTENERS} "
+                                + "--override zookeeper.connect=${KAFKA_ZOOKEEPER_CONNECT}");
+
+        waitingFor(Wait.forListeningPort());
+    }
+
+    public int getKafkaPort() {
+        return getMappedPort(KAFKA_PORT);
+    }
+
+    @Override
+    public void start() {
+        addFixedExposedPort(KAFKA_PORT, KAFKA_PORT);
+        super.start();
+    }
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/StrimziService.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/StrimziService.java
new file mode 100644
index 0000000..586303d
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/StrimziService.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import org.apache.camel.test.infra.common.TestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Network;
+
+public class StrimziService implements KafkaService {
+    private static final Logger LOG = LoggerFactory.getLogger(StrimziService.class);
+    private static ZookeeperContainer zookeeperContainer;
+    private static StrimziContainer strimziContainer;
+
+    public StrimziService() {
+
+        if (zookeeperContainer == null && strimziContainer == null) {
+
+            Network network = Network.newNetwork();
+
+            if (zookeeperContainer == null) {
+                zookeeperContainer = new ZookeeperContainer(network, "zookeeper");
+            }
+
+            if (strimziContainer == null) {
+                strimziContainer = new StrimziContainer(network, "strimzi");
+            }
+        }
+    }
+
+    private Integer getKafkaPort() {
+        return strimziContainer.getKafkaPort();
+    }
+
+    @Override
+    public String getBootstrapServers() {
+        return strimziContainer.getContainerIpAddress() + ":" + getKafkaPort();
+    }
+
+    @Override
+    public void initialize() {
+        if (!zookeeperContainer.isRunning()) {
+            zookeeperContainer.start();
+        }
+
+        String zookeeperConnect = "zookeeper:" + zookeeperContainer.getZookeeperPort();
+        LOG.info("Apache Zookeeper running at address {}", zookeeperConnect);
+
+        if (!strimziContainer.isRunning()) {
+            strimziContainer.start();
+        }
+
+        LOG.info("Kafka bootstrap server running at address {}", getBootstrapServers());
+    }
+
+    private boolean stopped() {
+        return !strimziContainer.isRunning() && !zookeeperContainer.isRunning();
+    }
+
+    @Override
+    public void shutdown() {
+        try {
+            LOG.info("Stopping Kafka container");
+            strimziContainer.stop();
+
+            TestUtils.waitFor(this::stopped);
+        } finally {
+            LOG.info("Stopping Zookeeper container");
+            zookeeperContainer.stop();
+        }
+    }
+}
diff --git a/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/ZookeeperContainer.java b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/ZookeeperContainer.java
new file mode 100644
index 0000000..55e109d
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/services/kafka/ZookeeperContainer.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.infra.services.kafka;
+
+import java.util.function.Consumer;
+
+import com.github.dockerjava.api.command.CreateContainerCmd;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class ZookeeperContainer extends GenericContainer<ZookeeperContainer> {
+    private static final String ZOOKEEPER_CONTAINER = System.getProperty("itest.zookeeper.container.image");
+    private static final int ZOOKEEPER_PORT = 2181;
+
+    public ZookeeperContainer(Network network, String name) {
+        super(ZOOKEEPER_CONTAINER);
+
+        withEnv("LOG_DIR", "/tmp/logs");
+        withExposedPorts(ZOOKEEPER_PORT);
+        withNetwork(network);
+        withCreateContainerCmdModifier(
+                new Consumer<CreateContainerCmd>() {
+                    @Override
+                    public void accept(CreateContainerCmd createContainerCmd) {
+                        createContainerCmd.withHostName(name);
+                        createContainerCmd.withName(name);
+                    }
+                });
+
+        withCommand("sh", "-c",
+                "bin/zookeeper-server-start.sh config/zookeeper.properties");
+
+        waitingFor(Wait.forListeningPort());
+    }
+
+    public int getZookeeperPort() {
+        return getMappedPort(ZOOKEEPER_PORT);
+    }
+
+}
diff --git a/core/camel-test-infra/camel-test-infra-parent/pom.xml b/core/camel-test-infra/camel-test-infra-parent/pom.xml
new file mode 100644
index 0000000..6cd01bc
--- /dev/null
+++ b/core/camel-test-infra/camel-test-infra-parent/pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>camel-test-core</artifactId>
+        <groupId>org.apache.camel</groupId>
+        <version>3.6.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>camel-test-infra-parent</artifactId>
+
+    <packaging>pom</packaging>
+    <name>Camel :: Test :: Infra Parent</name>
+    <description>Parent pom for the test infrastructure for Camel</description>
+
+    <dependencies>
+        <!-- JUnit 5 dependencies -->
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-params</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-jar-plugin</artifactId>
+                    <executions>
+                        <execution>
+                            <phase>test-compile</phase>
+                            <goals>
+                                <goal>test-jar</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+</project>
\ No newline at end of file
diff --git a/core/camel-test-infra/pom.xml b/core/camel-test-infra/pom.xml
new file mode 100644
index 0000000..1c988b6
--- /dev/null
+++ b/core/camel-test-infra/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>core</artifactId>
+        <groupId>org.apache.camel</groupId>
+        <version>3.6.0-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>camel-test-core</artifactId>
+
+    <packaging>pom</packaging>
+    <name>Camel :: Test :: Infra </name>
+    <description>Test infrastructure for Camel</description>
+
+    <modules>
+        <module>camel-test-infra-common</module>
+        <module>camel-test-infra-kafka</module>
+        <module>camel-test-infra-parent</module>
+    </modules>
+</project>
\ No newline at end of file
diff --git a/core/pom.xml b/core/pom.xml
index 8231fc2..1d9c4a7 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -56,6 +56,7 @@
         <module>camel-allcomponents</module>
         <module>camel-endpointdsl</module>
         <module>camel-componentdsl</module>
+        <module>camel-test-infra</module>
     </modules>
 
     <properties>
diff --git a/parent/pom.xml b/parent/pom.xml
index 6d1af75..f0343a0 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -3459,6 +3459,11 @@
                 <version>${testcontainers-version}</version>
             </dependency>
             <dependency>
+                <groupId>org.testcontainers</groupId>
+                <artifactId>kafka</artifactId>
+                <version>${testcontainers-version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
                 <version>${assertj-version}</version>