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 2021/01/13 06:24:46 UTC

[camel] branch master updated: CAMEL-16023: ensure resources are released after the test execution (#4867)

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 0184108  CAMEL-16023: ensure resources are released after the test execution (#4867)
0184108 is described below

commit 01841086f3cf0978318bb101c1a1e8011f1853af
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Wed Jan 13 07:24:16 2021 +0100

    CAMEL-16023: ensure resources are released after the test execution (#4867)
---
 .../test/infra/kafka/services/StrimziService.java  | 60 +++++++---------------
 1 file changed, 19 insertions(+), 41 deletions(-)

diff --git a/test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/kafka/services/StrimziService.java b/test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/kafka/services/StrimziService.java
index cb4f8b3..d646ab7 100644
--- a/test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/kafka/services/StrimziService.java
+++ b/test-infra/camel-test-infra-kafka/src/test/java/org/apache/camel/test/infra/kafka/services/StrimziService.java
@@ -27,30 +27,25 @@ import org.testcontainers.containers.Network;
 public class StrimziService implements KafkaService, ContainerService<StrimziContainer> {
     private static final Logger LOG = LoggerFactory.getLogger(StrimziService.class);
 
-    private static ZookeeperContainer zookeeperContainer;
-    private static StrimziContainer strimziContainer;
-    private static String zookeeperInstanceName;
-    private static String strimziInstanceName;
+    private final ZookeeperContainer zookeeperContainer;
+    private final StrimziContainer strimziContainer;
 
     public StrimziService() {
+        Network network = Network.newNetwork();
 
-        if (zookeeperContainer == null && strimziContainer == null) {
+        String zookeeperInstanceName = "zookeeper-" + TestUtils.randomWithRange(1, 100);
+        zookeeperContainer = new ZookeeperContainer(network, zookeeperInstanceName);
 
-            Network network = Network.newNetwork();
-
-            if (zookeeperContainer == null) {
-                zookeeperInstanceName = "zookeeper-" + TestUtils.randomWithRange(1, 100);
-                zookeeperContainer = new ZookeeperContainer(network, zookeeperInstanceName);
-            }
+        String strimziInstanceName = "strimzi-" + TestUtils.randomWithRange(1, 100);
+        strimziContainer = new StrimziContainer(network, strimziInstanceName, zookeeperInstanceName);
+    }
 
-            if (strimziContainer == null) {
-                strimziInstanceName = "strimzi-" + TestUtils.randomWithRange(1, 100);
-                strimziContainer = new StrimziContainer(network, strimziInstanceName, zookeeperInstanceName);
-            }
-        }
+    public StrimziService(ZookeeperContainer zookeeperContainer, StrimziContainer strimziContainer) {
+        this.zookeeperContainer = zookeeperContainer;
+        this.strimziContainer = strimziContainer;
     }
 
-    private Integer getKafkaPort() {
+    protected Integer getKafkaPort() {
         return strimziContainer.getKafkaPort();
     }
 
@@ -66,38 +61,17 @@ public class StrimziService implements KafkaService, ContainerService<StrimziCon
 
     @Override
     public void initialize() {
-        if (!zookeeperContainer.isRunning()) {
-            /*
-             When running multiple tests at once, this throttles the startup to give
-             time for docker to fully shutdown previously running instances (which
-             happens asynchronously). This prevents problems with false positive errors
-             such as docker complaining of multiple containers with the same name or
-             trying to reuse port numbers too quickly.
-             */
-            throttle();
-            zookeeperContainer.start();
-        }
+        zookeeperContainer.start();
 
-        String zookeeperConnect = zookeeperInstanceName + ":" + zookeeperContainer.getZookeeperPort();
+        String zookeeperConnect = zookeeperContainer.getContainerIpAddress() + ":" + zookeeperContainer.getZookeeperPort();
         LOG.info("Apache Zookeeper running at address {}", zookeeperConnect);
 
-        if (!strimziContainer.isRunning()) {
-            strimziContainer.start();
-        }
+        strimziContainer.start();
 
         registerProperties();
         LOG.info("Kafka bootstrap server running at address {}", getBootstrapServers());
     }
 
-    private void throttle() {
-        try {
-            String throttleDelay = System.getProperty("itest.strimzi.throttle.delay", "10000");
-            Thread.sleep(Integer.parseInt(throttleDelay));
-        } catch (InterruptedException e) {
-            LOG.warn("Strimzi startup interrupted");
-        }
-    }
-
     private boolean stopped() {
         return !strimziContainer.isRunning() && !zookeeperContainer.isRunning();
     }
@@ -119,4 +93,8 @@ public class StrimziService implements KafkaService, ContainerService<StrimziCon
     public StrimziContainer getContainer() {
         return strimziContainer;
     }
+
+    protected ZookeeperContainer getZookeeperContainer() {
+        return zookeeperContainer;
+    }
 }