[camel] branch master updated: CAMEL-14569: camel-zookeeper - Use test containers for testing

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-14569: camel-zookeeper - Use test containers for testing

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

lburgazzoli 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 8c64a52  CAMEL-14569: camel-zookeeper - Use test containers for testing
8c64a52 is described below

commit 8c64a52b93ca409fa54d4f10e9de8e57f82b9920
Author: lburgazzoli <[hidden email]>
AuthorDate: Mon Feb 17 13:03:34 2020 +0100

    CAMEL-14569: camel-zookeeper - Use test containers for testing
---
 components/camel-zookeeper/pom.xml                 |  92 +++++++--
 .../component/zookeeper/ConsumeChildrenTest.java   |   2 +-
 .../camel/component/zookeeper/ConsumeDataTest.java |   4 +-
 .../component/zookeeper/ZooKeeperContainer.java    |  94 +++++++++
 .../zookeeper/ZooKeeperManagedEndpointTest.java    |  38 +---
 .../component/zookeeper/ZooKeeperProducerTest.java |  64 +++---
 .../component/zookeeper/ZooKeeperTestSupport.java  | 219 ++-------------------
 .../zookeeper/ZookeeperConnectionManagerTest.java  |   2 +-
 .../cloud/SpringZooKeeperServiceCallRouteTest.java |  48 +++--
 .../cloud/ZooKeeperServiceCallRouteTest.java       |  18 +-
 .../cloud/ZooKeeperServiceDiscoveryTest.java       |  15 +-
 .../ZooKeeperServiceRegistrationTestBase.java      |  17 +-
 .../ZooKeeperClusteredRoutePolicyFactoryMain.java  |   2 +-
 .../ZooKeeperClusteredRoutePolicyFactoryTest.java  |  22 +--
 .../cluster/ZooKeeperClusteredRoutePolicyTest.java |  22 +--
 .../zookeeper/cluster/ZooKeeperMasterMain.java     |   2 +-
 .../zookeeper/cluster/ZooKeeperMasterTest.java     |  22 +--
 .../src/test/resources/log4j2.properties           |   2 +-
 .../cloud/SpringZooKeeperServiceCallRouteTest.xml  |   2 +-
 ...ingZooKeeperClusteredRouteConfigurationTest.xml |  13 +-
 20 files changed, 344 insertions(+), 356 deletions(-)

diff --git a/components/camel-zookeeper/pom.xml b/components/camel-zookeeper/pom.xml
index d52c3af..64c43ba 100644
--- a/components/camel-zookeeper/pom.xml
+++ b/components/camel-zookeeper/pom.xml
@@ -136,7 +136,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test-spring</artifactId>
+            <artifactId>camel-testcontainers-spring</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -157,20 +157,82 @@
 
     </dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <childDelegation>false</childDelegation>
-                    <useFile>true</useFile>
-                    <forkCount>1</forkCount>
-                    <reuseForks>true</reuseForks>
-                    <forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+
+    <profiles>
+        <profile>
+            <id>zookeeper-skip-tests</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <skipTests>true</skipTests>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <!-- activate test if the docker socket file is accessible -->
+        <profile>
+            <id>zookeeper-tests-docker-file</id>
+            <activation>
+                <file>
+                    <exists>/var/run/docker.sock</exists>
+                </file>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <skipTests>${skipTests}</skipTests>
+                            <systemPropertyVariables>
+                                <visibleassertions.silence>true</visibleassertions.silence>
+                            </systemPropertyVariables>
+                            <childDelegation>false</childDelegation>
+                            <useFile>true</useFile>
+                            <forkCount>1</forkCount>
+                            <reuseForks>true</reuseForks>
+                            <forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <!-- activate test if the DOCKER_HOST env var is set -->
+        <profile>
+            <id>zookeeper-tests-docker-env</id>
+            <activation>
+                <property>
+                    <name>env.DOCKER_HOST</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <skipTests>${skipTests}</skipTests>
+                            <systemPropertyVariables>
+                                <visibleassertions.silence>true</visibleassertions.silence>
+                            </systemPropertyVariables>
+                            <childDelegation>false</childDelegation>
+                            <useFile>true</useFile>
+                            <forkCount>1</forkCount>
+                            <reuseForks>true</reuseForks>
+                            <forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+    </profiles>
 
 
 </project>
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java
index 26ba9cc..95c3cef 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java
@@ -36,7 +36,7 @@ public class ConsumeChildrenTest extends ZooKeeperTestSupport {
     protected RouteBuilder[] createRouteBuilders() throws Exception {
         return new RouteBuilder[] {new RouteBuilder() {
             public void configure() throws Exception {
-                from("zookeeper://localhost:" + getServerPort() + "/grimm?repeat=true&listChildren=true")
+                from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/grimm?repeat=true&listChildren=true")
                     .sort(body(), new NaturalSortComparator(Order.Descending))
                     .to("mock:zookeeper-data");
             }
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java
index 727c47a..f6afc16 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java
@@ -30,7 +30,7 @@ public class ConsumeDataTest extends ZooKeeperTestSupport {
     protected RouteBuilder[] createRouteBuilders() throws Exception {
         return new RouteBuilder[] {new RouteBuilder() {
             public void configure() throws Exception {
-                from("zookeeper://localhost:" + getServerPort() + "/camel?repeat=true").to("mock:zookeeper-data");
+                from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/camel?repeat=true").to("mock:zookeeper-data");
             }
         }};
     }
@@ -89,7 +89,7 @@ public class ConsumeDataTest extends ZooKeeperTestSupport {
         // recreate and update a number of times.
         createCamelNode();
         updateNode(10);
-  
+
         MockEndpoint.assertIsSatisfied(30, TimeUnit.SECONDS);
 
         client.delete("/camel");
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperContainer.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperContainer.java
new file mode 100644
index 0000000..7b18ab6
--- /dev/null
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperContainer.java
@@ -0,0 +1,94 @@
+/*
+ * 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.component.zookeeper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class ZooKeeperContainer extends GenericContainer {
+    public static final String CONTAINER_IMAGE = "zookeeper:3.5";
+    public static final String CONTAINER_NAME = "zookeeper";
+    public static final int CLIENT_PORT = 2181;
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperContainer.class);
+
+    public ZooKeeperContainer() {
+        this(CONTAINER_NAME, -1);
+    }
+
+    public ZooKeeperContainer(int clientPort) {
+        this(CONTAINER_NAME, clientPort);
+    }
+
+    public ZooKeeperContainer(String name) {
+        this(name, -1);
+
+        setWaitStrategy(Wait.forListeningPort());
+
+        withNetworkAliases(name);
+        withExposedPorts(CLIENT_PORT);
+        withLogConsumer(new Slf4jLogConsumer(LOGGER));
+    }
+
+    public ZooKeeperContainer(String name, int clientPort) {
+        super(CONTAINER_IMAGE);
+
+        setWaitStrategy(Wait.forListeningPort());
+
+        withNetworkAliases(name);
+        withLogConsumer(new Slf4jLogConsumer(LOGGER));
+
+        if (clientPort > 0) {
+            addFixedExposedPort(clientPort, CLIENT_PORT);
+        } else {
+            withExposedPorts(CLIENT_PORT);
+        }
+    }
+
+    @Override
+    public void start() {
+        LOGGER.info("****************************************");
+        LOGGER.info("* Starting ZooKeeper container         *");
+        LOGGER.info("****************************************");
+
+        super.start();
+
+        LOGGER.info("****************************************");
+        LOGGER.info("* ZooKeeper container started          *");
+        LOGGER.info("****************************************");
+    }
+
+    @Override
+    public void stop() {
+        LOGGER.info("****************************************");
+        LOGGER.info("* Stopping ZooKeeper container         *");
+        LOGGER.info("****************************************");
+
+        super.stop();
+
+        LOGGER.info("****************************************");
+        LOGGER.info("* ZooKeeper container stopped          *");
+        LOGGER.info("****************************************");
+    }
+
+    public String getConnectionString() {
+        return getContainerIpAddress() + ":" + getMappedPort(CLIENT_PORT);
+    }
+}
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java
index ed0482e..2d775f5 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java
@@ -22,42 +22,17 @@ import java.util.Set;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.springframework.jmx.support.JmxUtils;
 
 @SuppressWarnings("all")
-public class ZooKeeperManagedEndpointTest extends CamelTestSupport {
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        ZooKeeperTestSupport.setupTestServer();
-        super.setUp();
-    }
-
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-        ZooKeeperTestSupport.shutdownServer();
-    }
-
+public class ZooKeeperManagedEndpointTest extends ZooKeeperTestSupport {
     @Override
     protected boolean useJmx() {
         return true;
     }
 
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = new DefaultCamelContext();
-        return context;
-    }
-
     protected MBeanServer getMBeanServer() {
         return context.getManagementStrategy().getManagementAgent().getMBeanServer();
     }
@@ -75,9 +50,12 @@ public class ZooKeeperManagedEndpointTest extends CamelTestSupport {
         verifyManagedAttribute(zepName, "Timeout", 1000);
         verifyManagedAttribute(zepName, "Backoff", 2000L);
 
-        getMBeanServer().invoke(zepName, "clearServers", null, JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers", null)));
-        getMBeanServer().invoke(zepName, "addServer", new Object[]{"someserver:12345"},
-                JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer", new Class[]{String.class})));
+        getMBeanServer().invoke(zepName, "clearServers",
+            null,
+            JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers", null)));
+        getMBeanServer().invoke(zepName, "addServer",
+            new Object[]{"someserver:12345"},
+            JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer", new Class[]{String.class})));
     }
 
     private void verifyManagedAttribute(ObjectName zepName, String attributeName, String attributeValue) throws Exception {
@@ -99,7 +77,7 @@ public class ZooKeeperManagedEndpointTest extends CamelTestSupport {
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("zookeeper://localhost:" + ZooKeeperTestSupport.getServerPort() + "/node?timeout=1000&backoff=2000").to("mock:test");
+                from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/node?timeout=1000&backoff=2000").to("mock:test");
             }
         };
     }
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java
index 44f6a2f..86181e2 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java
@@ -39,30 +39,46 @@ public class ZooKeeperProducerTest extends ZooKeeperTestSupport {
 
     @Override
     protected RouteBuilder[] createRouteBuilders() throws Exception {
-        return new RouteBuilder[] {new RouteBuilder() {
-            public void configure() throws Exception {
-                zookeeperUri = "zookeeper://localhost:" + getServerPort() + "/node?create=true";
-                from("direct:roundtrip").to(zookeeperUri).to("mock:producer-out");
-                from(zookeeperUri).to("mock:consumed-from-node");
+        return new RouteBuilder[] {
+            new RouteBuilder() {
+                public void configure() throws Exception {
+                    zookeeperUri = "zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/node?create=true";
+                    from("direct:roundtrip")
+                        .to(zookeeperUri)
+                        .to("mock:producer-out");
+                    from(zookeeperUri)
+                        .to("mock:consumed-from-node");
+                }
+            },
+            new RouteBuilder() {
+                public void configure() throws Exception {
+                    from("direct:no-create-fails-set")
+                        .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/doesnotexist");
+                }
+            },
+            new RouteBuilder() {
+                public void configure() throws Exception {
+                    from("direct:node-from-header")
+                        .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/notset?create=true");
+                    from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/set?create=true")
+                        .to("mock:consumed-from-set-node");
+                }
+            },
+            new RouteBuilder() {
+                public void configure() throws Exception {
+                    from("direct:create-mode")
+                        .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/persistent?create=true&createMode=PERSISTENT")
+                        .to("mock:create-mode");
+                }
+            },
+            new RouteBuilder() {
+                public void configure() throws Exception {
+                    from("direct:delete")
+                        .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/to-be-deleted")
+                        .to("mock:delete");
+                }
             }
-        }, new RouteBuilder() {
-            public void configure() throws Exception {
-                from("direct:no-create-fails-set").to("zookeeper://localhost:" + getServerPort() + "/doesnotexist");
-            }
-        }, new RouteBuilder() {
-            public void configure() throws Exception {
-                from("direct:node-from-header").to("zookeeper://localhost:" + getServerPort() + "/notset?create=true");
-                from("zookeeper://localhost:" + getServerPort() + "/set?create=true").to("mock:consumed-from-set-node");
-            }
-        }, new RouteBuilder() {
-            public void configure() throws Exception {
-                from("direct:create-mode").to("zookeeper://localhost:" + getServerPort() + "/persistent?create=true&createMode=PERSISTENT").to("mock:create-mode");
-            }
-        }, new RouteBuilder() {
-            public void configure() throws Exception {
-                from("direct:delete").to("zookeeper://localhost:39913/to-be-deleted").to("mock:delete");
-            }
-        }};
+        };
     }
 
     @Test
@@ -143,7 +159,7 @@ public class ZooKeeperProducerTest extends ZooKeeperTestSupport {
         Exchange exchange = createExchangeWithBody(testPayload);
         exchange.getIn().setHeader(ZOOKEEPER_NODE, "/set-listing/firstborn");
         exchange.setPattern(ExchangePattern.InOut);
-        template.send("zookeeper://localhost:" + getServerPort() + "/set-listing?create=true&listChildren=true", exchange);
+        template.send("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/set-listing?create=true&listChildren=true", exchange);
         List<?> children = exchange.getMessage().getMandatoryBody(List.class);
         assertEquals(1, children.size());
         assertEquals("firstborn", children.get(0));
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java
index cbc2bb2..7e620d7 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java
@@ -16,26 +16,14 @@
  */
 package org.apache.camel.component.zookeeper;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.InetSocketAddress;
-import java.net.Socket;
 import java.util.Arrays;
-import java.util.Deque;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.util.FileUtil;
-import org.apache.camel.util.IOHelper;
+import org.apache.camel.test.testcontainers.ContainerAwareTestSupport;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
@@ -44,112 +32,50 @@ import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
 
-public class ZooKeeperTestSupport extends CamelTestSupport {
-
-    protected static TestZookeeperServer server;
-    protected static TestZookeeperClient client;
-
-    private static volatile int port;
-    private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperTestSupport.class);
-
+public class ZooKeeperTestSupport extends ContainerAwareTestSupport {
     protected String testPayload = "This is a test";
     protected byte[] testPayloadBytes = testPayload.getBytes();
-        
-    @BeforeClass
-    public static void setupTestServer() throws Exception {
-        port = AvailablePortFinder.getNextAvailable();
-        
-        LOG.info("Starting Zookeeper Test Infrastructure");
-        server = new TestZookeeperServer(getServerPort(), clearServerData());
-        waitForServerUp("localhost:" + getServerPort(), 1000);
-        client = new TestZookeeperClient(getServerPort(), getTestClientSessionTimeout());
-        LOG.info("Started Zookeeper Test Infrastructure on port " + getServerPort());
+    protected TestZookeeperClient client;
+
+    @Override
+    protected GenericContainer<?> createContainer() {
+        return new ZooKeeperContainer();
     }
 
-    public ZooKeeper getConnection() {
-        return client.getConnection();
+    @Override
+    public void doPreSetup() throws Exception {
+        client = new TestZookeeperClient(getConnectionString(), getTestClientSessionTimeout());
     }
 
-    @AfterClass
-    public static void shutdownServer() throws Exception {
-        LOG.info("Stopping Zookeeper Test Infrastructure");
+    @Override
+    protected void doPostTearDown() throws Exception {
         client.shutdown();
-        server.shutdown();
-        waitForServerDown("localhost:" + getServerPort(), 1000);
-        LOG.info("Stopped Zookeeper Test Infrastructure");
     }
 
-    protected static int getServerPort() {
-        return port;
+    public String getConnectionString() {
+        return getContainerHost(ZooKeeperContainer.CONTAINER_NAME) + ":" + getContainerPort(ZooKeeperContainer.CONTAINER_NAME, ZooKeeperContainer.CLIENT_PORT);
     }
 
-    protected static int getTestClientSessionTimeout() {
-        return 100000;
-    }
-
-    protected static boolean clearServerData() {
-        return true;
+    public ZooKeeper getConnection() {
+        return client.getConnection();
     }
 
-    public static class TestZookeeperServer {
-        private static int count;
-        private NIOServerCnxnFactory connectionFactory;
-        private ZooKeeperServer zkServer;
-        private File zookeeperBaseDir;
-        
-        public TestZookeeperServer(int clientPort, boolean clearServerData) throws Exception {
-            // TODO This is necessary as zookeeper does not delete the log dir when it shuts down. Remove as soon as zookeeper shutdown works
-            zookeeperBaseDir = new File("./target/zookeeper" + count++);
-            if (clearServerData) {
-                cleanZookeeperDir();
-            }
-            zkServer = new ZooKeeperServer();
-            File dataDir = new File(zookeeperBaseDir, "log");
-            File snapDir = new File(zookeeperBaseDir, "data");
-            FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir);
-            zkServer.setTxnLogFactory(ftxn);
-            zkServer.setTickTime(1000);
-            connectionFactory = new NIOServerCnxnFactory();
-            connectionFactory.configure(new InetSocketAddress("localhost", clientPort), 0);
-            connectionFactory.startup(zkServer);
-        }
-        
-        private void cleanZookeeperDir() throws Exception {
-            File working = zookeeperBaseDir;
-            deleteDir(working);
-        }
-
-        public void shutdown() throws Exception {
-            connectionFactory.shutdown();
-            connectionFactory.join();
-            zkServer.shutdown();
-            while (zkServer.isRunning()) {
-                zkServer.shutdown();
-                Thread.sleep(100);
-            }
-            cleanZookeeperDir();
-        }
+    protected static int getTestClientSessionTimeout() {
+        return 100000;
     }
 
     public static class TestZookeeperClient implements Watcher {
-
-        public static int x;
-
         private final Logger log = LoggerFactory.getLogger(getClass());
         private ZooKeeper zk;
         private CountDownLatch connected = new CountDownLatch(1);
 
 
-        public TestZookeeperClient(int port, int timeout) throws Exception {
-            zk = new ZooKeeper("localhost:" + port, timeout, this);
+        public TestZookeeperClient(String connectString, int timeout) throws Exception {
+            zk = new ZooKeeper(connectString, timeout, this);
             connected.await();
         }
 
@@ -221,109 +147,6 @@ public class ZooKeeperTestSupport extends CamelTestSupport {
         }
     }
 
-    // Wait methods are taken directly from the Zookeeper tests. A tests jar
-    // would be nice! Another good reason the keeper folks should move to maven.
-    public static boolean waitForServerUp(String hp, long timeout) {
-        long start = System.currentTimeMillis();
-        while (true) {
-            try {
-                // if there are multiple hostports, just take the first one
-                hp = hp.split(",")[0];
-                String result = send4LetterWord(hp, "stat");
-                if (result.startsWith("Zookeeper version:")) {
-                    return true;
-                }
-            } catch (IOException e) {
-                LOG.info("server {} not up {}", hp, e);
-            }
-
-            if (System.currentTimeMillis() > start + timeout) {
-                break;
-            }
-            try {
-                Thread.sleep(250);
-            } catch (InterruptedException e) {
-                // ignore
-            }
-        }
-        return false;
-    }
-
-    private static String send4LetterWord(String hp, String cmd) throws IOException {
-        String split[] = hp.split(":");
-        String host = split[0];
-        int port;
-        try {
-            port = Integer.parseInt(split[1]);
-        } catch (RuntimeException e) {
-            throw new RuntimeException("Problem parsing " + hp + e.toString());
-        }
-
-        Socket sock = new Socket(host, port);
-        BufferedReader reader = null;
-        try {
-            OutputStream outstream = sock.getOutputStream();
-            outstream.write(cmd.getBytes());
-            outstream.flush();
-
-            reader = IOHelper.buffered(new InputStreamReader(sock.getInputStream()));
-            StringBuilder sb = new StringBuilder();
-            String line;
-            while ((line = reader.readLine()) != null) {
-                sb.append(line + "\n");
-            }
-            return sb.toString();
-        } finally {
-            sock.close();
-            if (reader != null) {
-                reader.close();
-            }
-        }
-    }
-
-    private static boolean waitForServerDown(String hp, long timeout) {
-        long start = System.currentTimeMillis();
-        while (true) {
-            try {
-                send4LetterWord(hp, "stat");
-            } catch (IOException e) {
-                return true;
-            }
-
-            if (System.currentTimeMillis() > start + timeout) {
-                break;
-            }
-            try {
-                Thread.sleep(250);
-            } catch (InterruptedException e) {
-                // ignore
-            }
-        }
-        return false;
-    }
-
-    public static void deleteDir(File f) {
-        LinkedList<File> deleteStack = new LinkedList<>();
-        deleteStack.addLast(f);
-        deleteDir(deleteStack);
-    }
-
-    private static void deleteDir(Deque<File> deleteStack) {
-        File f = deleteStack.pollLast();
-        if (f != null) {
-            if (f.isDirectory()) {
-                File[] files = f.listFiles();
-                if (files != null) {
-                    for (File child : files) {
-                        deleteStack.addLast(child);
-                    }
-                }
-            }
-            deleteDir(deleteStack);
-            FileUtil.deleteFile(f);
-        }
-    }
-
     public static void delay(int wait) throws InterruptedException {
         Thread.sleep(wait);
     }
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZookeeperConnectionManagerTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZookeeperConnectionManagerTest.java
index 8815fa9..bee0fd6 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZookeeperConnectionManagerTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZookeeperConnectionManagerTest.java
@@ -25,7 +25,7 @@ public class ZookeeperConnectionManagerTest extends ZooKeeperTestSupport {
     @Test
     public void shouldWaitForConnection() {
         ZooKeeperConfiguration config = new ZooKeeperConfiguration();
-        config.addZookeeperServer("localhost:" + getServerPort());
+        config.addZookeeperServer(getConnectionString());
 
         ZooKeeperComponent component = new ZooKeeperComponent(config);
         component.setConfiguration(config);
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java
index 38cc21a..54795c0 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.component.zookeeper.cloud;
 
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
-import org.apache.camel.test.spring.CamelSpringTestSupport;
+import java.util.Collections;
+
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
+import org.apache.camel.test.testcontainers.ContainerPropertiesFunction;
+import org.apache.camel.test.testcontainers.spring.ContainerAwareSpringTestSupport;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -26,17 +29,17 @@ import org.apache.curator.x.discovery.ServiceDiscovery;
 import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
 import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
-import org.junit.After;
 import org.junit.Test;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.support.AbstractApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.testcontainers.containers.GenericContainer;
 
-public class SpringZooKeeperServiceCallRouteTest extends CamelSpringTestSupport {
-    private static final int SERVER_PORT = 9001;
+public class SpringZooKeeperServiceCallRouteTest extends ContainerAwareSpringTestSupport {
     private static final String SERVICE_NAME = "http-service";
     private static final String SERVICE_PATH = "/camel";
 
-    private ZooKeeperTestSupport.TestZookeeperServer server;
     private CuratorFramework curator;
     private ServiceDiscovery<ZooKeeperServiceDiscovery.MetaData> discovery;
 
@@ -45,14 +48,16 @@ public class SpringZooKeeperServiceCallRouteTest extends CamelSpringTestSupport
     // ***********************
 
     @Override
+    public GenericContainer createContainer() {
+        return new ZooKeeperContainer();
+    }
+
+    @Override
     public void doPreSetup() throws Exception {
         super.doPreSetup();
 
-        server = new ZooKeeperTestSupport.TestZookeeperServer(SERVER_PORT, true);
-        ZooKeeperTestSupport.waitForServerUp("127.0.0.1:" + SERVER_PORT, 1000);
-
         curator = CuratorFrameworkFactory.builder()
-            .connectString("127.0.0.1:" + SERVER_PORT)
+            .connectString(getContainerHost(ZooKeeperContainer.CONTAINER_NAME) + ":" + getContainerPort(ZooKeeperContainer.CONTAINER_NAME, ZooKeeperContainer.CLIENT_PORT))
             .retryPolicy(new ExponentialBackoffRetry(1000, 3))
             .build();
 
@@ -91,16 +96,11 @@ public class SpringZooKeeperServiceCallRouteTest extends CamelSpringTestSupport
     }
 
     @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
+    public void doPostTearDown() throws Exception {
+        super.doPostTearDown();
 
         CloseableUtils.closeQuietly(discovery);
         CloseableUtils.closeQuietly(curator);
-
-        if (server != null) {
-            server.shutdown();
-        }
     }
 
     // ***********************
@@ -125,6 +125,16 @@ public class SpringZooKeeperServiceCallRouteTest extends CamelSpringTestSupport
 
     @Override
     protected AbstractApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml");
+        GenericApplicationContext applicationContext = new GenericApplicationContext();
+        applicationContext.getBeanFactory().registerSingleton(
+            "zkProperties",
+            new ContainerPropertiesFunction(Collections.singletonList(getContainer(ZooKeeperContainer.CONTAINER_NAME))));
+
+        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext);
+        xmlReader.loadBeanDefinitions(new ClassPathResource("org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml"));
+
+        applicationContext.refresh();
+
+        return applicationContext;
     }
 }
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java
index b990a7b..671e364 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java
@@ -21,7 +21,7 @@ import java.util.List;
 
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.curator.framework.CuratorFramework;
@@ -32,7 +32,6 @@ import org.apache.curator.x.discovery.ServiceDiscovery;
 import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
 import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
-import org.junit.After;
 import org.junit.Test;
 
 public class ZooKeeperServiceCallRouteTest extends CamelTestSupport {
@@ -41,7 +40,7 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport {
     private static final int SERVICE_COUNT = 5;
     private static final String SERVICE_PATH = "/camel";
 
-    private ZooKeeperTestSupport.TestZookeeperServer server;
+    protected ZooKeeperContainer container;
     private CuratorFramework curator;
     private ServiceDiscovery<ZooKeeperServiceDiscovery.MetaData> discovery;
     private List<ServiceInstance<ZooKeeperServiceDiscovery.MetaData>> instances;
@@ -55,11 +54,11 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport {
     protected void doPreSetup() throws Exception {
         super.doPreSetup();
 
-        server = new ZooKeeperTestSupport.TestZookeeperServer(SERVER_PORT, true);
-        ZooKeeperTestSupport.waitForServerUp("127.0.0.1:" + SERVER_PORT, 1000);
+        container = new ZooKeeperContainer();
+        container.start();
 
         curator = CuratorFrameworkFactory.builder()
-            .connectString("127.0.0.1:" + SERVER_PORT)
+            .connectString(container.getConnectionString())
             .retryPolicy(new ExponentialBackoffRetry(1000, 3))
             .build();
 
@@ -90,7 +89,6 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport {
     }
 
     @Override
-    @After
     public void tearDown() throws Exception {
         super.tearDown();
 
@@ -105,7 +103,9 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport {
         CloseableUtils.closeQuietly(discovery);
         CloseableUtils.closeQuietly(curator);
 
-        server.shutdown();
+        if (container != null) {
+            container.stop();
+        }
     }
 
     // *************************************************************************
@@ -136,7 +136,7 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport {
                         .name(SERVICE_NAME)
                         .component("http")
                         .defaultLoadBalancer()
-                        .zookeeperServiceDiscovery("127.0.0.1:" + SERVER_PORT, SERVICE_PATH)
+                        .zookeeperServiceDiscovery(container.getConnectionString(), SERVICE_PATH)
                         .end()
                     .to("log:org.apache.camel.component.zookeeper.cloud?level=INFO&showAll=true&multiline=true")
                     .to("mock:result");
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java
index f615620..a61b92c 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java
@@ -20,9 +20,9 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
 import org.apache.camel.component.zookeeper.ZooKeeperCuratorConfiguration;
 import org.apache.camel.component.zookeeper.ZooKeeperCuratorHelper;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -41,16 +41,15 @@ public class ZooKeeperServiceDiscoveryTest {
     public void testServiceDiscovery() throws Exception {
         ZooKeeperCuratorConfiguration configuration  = new ZooKeeperCuratorConfiguration();
         ServiceDiscovery<ZooKeeperServiceDiscovery.MetaData> zkDiscovery = null;
-        ZooKeeperTestSupport.TestZookeeperServer server = null;
-        int port = AvailablePortFinder.getNextAvailable();
+        ZooKeeperContainer container = null;
 
         try {
-            server = new ZooKeeperTestSupport.TestZookeeperServer(port, true);
-            ZooKeeperTestSupport.waitForServerUp("localhost:" + port, 1000);
+            container = new ZooKeeperContainer();
+            container.start();
 
             configuration.setBasePath("/camel");
             configuration.setCuratorFramework(CuratorFrameworkFactory.builder()
-                .connectString("localhost:" + port)
+                .connectString(container.getConnectionString())
                 .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                 .build()
             );
@@ -103,8 +102,8 @@ public class ZooKeeperServiceDiscoveryTest {
             CloseableUtils.closeQuietly(zkDiscovery);
             CloseableUtils.closeQuietly(configuration.getCuratorFramework());
 
-            if (server != null) {
-                server.shutdown();
+            if (container != null) {
+                container.stop();
             }
         }
     }
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java
index d9fd966..2dd5851 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java
@@ -23,7 +23,7 @@ import java.util.UUID;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.cloud.ServiceDefinition;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.curator.framework.CuratorFramework;
@@ -43,9 +43,8 @@ public abstract class ZooKeeperServiceRegistrationTestBase extends CamelTestSupp
     protected static final String SERVICE_HOST = "localhost";
     protected static final String SERVICE_PATH = "/camel";
     protected static final int SERVICE_PORT = AvailablePortFinder.getNextAvailable();
-    protected static final int SERVER_PORT = AvailablePortFinder.getNextAvailable();
 
-    protected ZooKeeperTestSupport.TestZookeeperServer server;
+    protected ZooKeeperContainer container;
     protected CuratorFramework curator;
     protected ServiceDiscovery<ZooKeeperServiceRegistry.MetaData> discovery;
 
@@ -57,11 +56,11 @@ public abstract class ZooKeeperServiceRegistrationTestBase extends CamelTestSupp
     protected void doPreSetup() throws Exception {
         super.doPreSetup();
 
-        server = new ZooKeeperTestSupport.TestZookeeperServer(SERVER_PORT, true);
-        ZooKeeperTestSupport.waitForServerUp("127.0.0.1:" + SERVER_PORT, 1000);
+        container = new ZooKeeperContainer();
+        container.start();
 
         curator = CuratorFrameworkFactory.builder()
-            .connectString("127.0.0.1:" + SERVER_PORT)
+            .connectString(container.getConnectionString())
             .retryPolicy(new ExponentialBackoffRetry(1000, 3))
             .build();
 
@@ -83,7 +82,9 @@ public abstract class ZooKeeperServiceRegistrationTestBase extends CamelTestSupp
         CloseableUtils.closeQuietly(discovery);
         CloseableUtils.closeQuietly(curator);
 
-        server.shutdown();
+        if (container != null) {
+            container.stop();
+        }
     }
 
 
@@ -98,7 +99,7 @@ public abstract class ZooKeeperServiceRegistrationTestBase extends CamelTestSupp
         ZooKeeperServiceRegistry registry = new ZooKeeperServiceRegistry();
         registry.setId(context.getUuidGenerator().generateUuid());
         registry.setCamelContext(context());
-        registry.setNodes("localhost:" + SERVER_PORT);
+        registry.setNodes(container.getConnectionString());
         registry.setBasePath(SERVICE_PATH);
         registry.setServiceHost(SERVICE_HOST);
         registry.setOverrideServiceHost(true);
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryMain.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryMain.java
index b7dc143..afa68ec 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryMain.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryMain.java
@@ -51,7 +51,7 @@ public final class ZooKeeperClusteredRoutePolicyFactoryMain {
             }
         });
 
-        main.addRouteBuilder(new RouteBuilder() {
+        main.addRoutesBuilder(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
                 from("timer:clustered?delay=1s&period=1s")
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java
index 3540b3f..b3289c3 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java
@@ -27,18 +27,15 @@ import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport.TestZookeeperServer;
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.cluster.ClusteredRoutePolicyFactory;
-import org.apache.camel.test.AvailablePortFinder;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class ZooKeeperClusteredRoutePolicyFactoryTest {
-    private static final int PORT = AvailablePortFinder.getNextAvailable();
     private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperClusteredRoutePolicyFactoryTest.class);
     private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
     private static final List<String> RESULTS = new ArrayList<>();
@@ -51,14 +48,15 @@ public final class ZooKeeperClusteredRoutePolicyFactoryTest {
 
     @Test
     public void test() throws Exception {
-        TestZookeeperServer server = null;
+        ZooKeeperContainer container = null;
 
         try {
-            server = new TestZookeeperServer(PORT, true);
-            ZooKeeperTestSupport.waitForServerUp("localhost:" + PORT, 1000);
+            container = new ZooKeeperContainer();
+            container.start();
 
+            String connectString = container.getConnectionString();
             for (String id : CLIENTS) {
-                SCHEDULER.submit(() -> run(id));
+                SCHEDULER.submit(() -> run(connectString, id));
             }
 
             LATCH.await(1, TimeUnit.MINUTES);
@@ -67,8 +65,8 @@ public final class ZooKeeperClusteredRoutePolicyFactoryTest {
             Assert.assertEquals(CLIENTS.size(), RESULTS.size());
             Assert.assertTrue(RESULTS.containsAll(CLIENTS));
         } finally {
-            if (server != null) {
-                server.shutdown();
+            if (container != null) {
+                container.stop();
             }
         }
     }
@@ -77,14 +75,14 @@ public final class ZooKeeperClusteredRoutePolicyFactoryTest {
     // Run a Camel node
     // ************************************
 
-    private static void run(String id) {
+    private static void run(String connectString, String id) {
         try {
             int events = ThreadLocalRandom.current().nextInt(2, 6);
             CountDownLatch contextLatch = new CountDownLatch(events);
 
             ZooKeeperClusterService service = new ZooKeeperClusterService();
             service.setId("node-" + id);
-            service.setNodes("localhost:" + PORT);
+            service.setNodes(connectString);
             service.setBasePath("/camel");
 
             DefaultCamelContext context = new DefaultCamelContext();
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java
index 33908a1..b686f74 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java
@@ -27,18 +27,15 @@ import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport.TestZookeeperServer;
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.cluster.ClusteredRoutePolicy;
-import org.apache.camel.test.AvailablePortFinder;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class ZooKeeperClusteredRoutePolicyTest {
-    private static final int PORT = AvailablePortFinder.getNextAvailable();
     private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperClusteredRoutePolicyTest.class);
     private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
     private static final List<String> RESULTS = new ArrayList<>();
@@ -51,14 +48,15 @@ public final class ZooKeeperClusteredRoutePolicyTest {
 
     @Test
     public void test() throws Exception {
-        TestZookeeperServer server = null;
+        ZooKeeperContainer container = null;
 
         try {
-            server = new TestZookeeperServer(PORT, true);
-            ZooKeeperTestSupport.waitForServerUp("localhost:" + PORT, 1000);
+            container = new ZooKeeperContainer();
+            container.start();
 
+            String connectString = container.getConnectionString();
             for (String id : CLIENTS) {
-                SCHEDULER.submit(() -> run(id));
+                SCHEDULER.submit(() -> run(connectString, id));
             }
 
             LATCH.await(1, TimeUnit.MINUTES);
@@ -67,8 +65,8 @@ public final class ZooKeeperClusteredRoutePolicyTest {
             Assert.assertEquals(CLIENTS.size(), RESULTS.size());
             Assert.assertTrue(RESULTS.containsAll(CLIENTS));
         } finally {
-            if (server != null) {
-                server.shutdown();
+            if (container != null) {
+                container.stop();
             }
         }
     }
@@ -77,14 +75,14 @@ public final class ZooKeeperClusteredRoutePolicyTest {
     // Run a Camel node
     // ************************************
 
-    private static void run(String id) {
+    private static void run(String connectString, String id) {
         try {
             int events = ThreadLocalRandom.current().nextInt(2, 6);
             CountDownLatch contextLatch = new CountDownLatch(events);
 
             ZooKeeperClusterService service = new ZooKeeperClusterService();
             service.setId("node-" + id);
-            service.setNodes("localhost:" + PORT);
+            service.setNodes(connectString);
             service.setBasePath("/camel");
 
             DefaultCamelContext context = new DefaultCamelContext();
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterMain.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterMain.java
index 0361531..5a9ea9d 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterMain.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterMain.java
@@ -51,7 +51,7 @@ public final class ZooKeeperMasterMain {
             }
         });
 
-        main.addRouteBuilder(new RouteBuilder() {
+        main.addRoutesBuilder(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
                 final int delay = 1 + ThreadLocalRandom.current().nextInt(10);
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java
index 139372f..a2f29c5 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java
@@ -27,17 +27,14 @@ import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
-import org.apache.camel.component.zookeeper.ZooKeeperTestSupport.TestZookeeperServer;
+import org.apache.camel.component.zookeeper.ZooKeeperContainer;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.test.AvailablePortFinder;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class ZooKeeperMasterTest {
-    private static final int PORT = AvailablePortFinder.getNextAvailable();
     private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperMasterTest.class);
     private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
     private static final List<String> RESULTS = new ArrayList<>();
@@ -50,14 +47,15 @@ public final class ZooKeeperMasterTest {
 
     @Test
     public void test() throws Exception {
-        TestZookeeperServer server = null;
+        ZooKeeperContainer container = null;
 
         try {
-            server = new TestZookeeperServer(PORT, true);
-            ZooKeeperTestSupport.waitForServerUp("localhost:" + PORT, 1000);
+            container = new ZooKeeperContainer();
+            container.start();
 
+            String connectString = container.getConnectionString();
             for (String id : CLIENTS) {
-                SCHEDULER.submit(() -> run(id));
+                SCHEDULER.submit(() -> run(connectString, id));
             }
 
             LATCH.await(1, TimeUnit.MINUTES);
@@ -66,8 +64,8 @@ public final class ZooKeeperMasterTest {
             Assert.assertEquals(CLIENTS.size(), RESULTS.size());
             Assert.assertTrue(RESULTS.containsAll(CLIENTS));
         } finally {
-            if (server != null) {
-                server.shutdown();
+            if (container != null) {
+                container.stop();
             }
         }
     }
@@ -76,14 +74,14 @@ public final class ZooKeeperMasterTest {
     // Run a Camel node
     // ************************************
 
-    private static void run(String id) {
+    private static void run(String connectString, String id) {
         try {
             int events = ThreadLocalRandom.current().nextInt(2, 6);
             CountDownLatch contextLatch = new CountDownLatch(events);
 
             ZooKeeperClusterService service = new ZooKeeperClusterService();
             service.setId("node-" + id);
-            service.setNodes("localhost:" + PORT);
+            service.setNodes(connectString);
             service.setBasePath("/camel/master");
 
             DefaultCamelContext context = new DefaultCamelContext();
diff --git a/components/camel-zookeeper/src/test/resources/log4j2.properties b/components/camel-zookeeper/src/test/resources/log4j2.properties
index 98db0e3..8041ed2 100644
--- a/components/camel-zookeeper/src/test/resources/log4j2.properties
+++ b/components/camel-zookeeper/src/test/resources/log4j2.properties
@@ -48,5 +48,5 @@ logger.springframework.name = org.springframework
 logger.springframework.level = WARN
 
 rootLogger.level = INFO
-//rootLogger.appenderRef.stdout.ref = out
+rootLogger.appenderRef.stdout.ref = out
 rootLogger.appenderRef.file.ref = file
diff --git a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml
index d5b4fd4..6345443 100644
--- a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml
+++ b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml
@@ -34,7 +34,7 @@
     <route id="scall">
       <from uri="direct:start"/>
       <serviceCall name="http-service" component="http">
-        <zookeeperServiceDiscovery nodes="localhost:9001" basePath="/camel"/>
+        <zookeeperServiceDiscovery nodes="{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}" basePath="/camel"/>
       </serviceCall>
       <to uri="mock:result"/>
     </route>
diff --git a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml
index c0ba63e..2b91015 100644
--- a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml
+++ b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml
@@ -25,11 +25,22 @@
          http://camel.apache.org/schema/spring
          http://camel.apache.org/schema/spring/camel-spring.xsd">
 
+  <bean id="zkContainer" class="org.apache.camel.component.zookeeper.ZooKeeperContainer" init-method="start" destroy-method="start">
+    <constructor-arg>
+      <value>zookeeper</value>
+    </constructor-arg>
+  </bean>
+
+  <bean id="zkConnectString" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <property name="targetObject" ref="zkContainer"/>
+    <property name="targetMethod" value="getConnectionString">
+    </property>
+  </bean>
 
   <bean id="cluster-service" class="org.apache.camel.component.zookeeper.cluster.ZooKeeperClusterService">
     <property name="id" value="node-1"/>
     <property name="basePath" value="/camel/cluster"/>
-    <property name="nodes" value="localhost:2181"/>
+    <property name="nodes" ref="zkConnectString"/>
   </bean>
 
   <bean id="cluster-policy" class="org.apache.camel.impl.cluster.ClusteredRoutePolicyFactory" factory-method="forNamespace">