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 2023/07/17 14:46:58 UTC

[camel] 02/02: CAMEL-19609: fixed a cyclic dependency issue with camel-test-infra-hdfs

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

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

commit 947d2ef9b545e05082be8b42b837a61842255cb5
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jul 17 15:21:34 2023 +0200

    CAMEL-19609: fixed a cyclic dependency issue with camel-test-infra-hdfs
---
 .../camel/component/hdfs/integration/HdfsAppendIT.java    |  3 ++-
 .../hdfs/integration/HdfsConsumerIntegrationIT.java       |  3 ++-
 .../integration/HdfsProducerConsumerIntegrationIT.java    |  3 ++-
 test-infra/camel-test-infra-hdfs/pom.xml                  |  6 ------
 .../test/infra/hdfs/v2/services/EmbeddedHDFSService.java  |  4 ++--
 .../camel/test/infra/hdfs/v2/services/HDFSContainer.java  |  7 +++++--
 .../test/infra/hdfs/v2/services/HDFSServiceFactory.java   | 15 +++++++--------
 7 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsAppendIT.java b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsAppendIT.java
index c75b7a3f916..e2770f8d127 100644
--- a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsAppendIT.java
+++ b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsAppendIT.java
@@ -20,6 +20,7 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
 import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
 import org.apache.camel.test.junit5.CamelTestSupport;
@@ -40,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class HdfsAppendIT extends CamelTestSupport {
     @RegisterExtension
-    public static HDFSService service = HDFSServiceFactory.createSingletonService();
+    public static HDFSService service = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());
 
     private static final Logger LOG = LoggerFactory.getLogger(HdfsAppendIT.class);
 
diff --git a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsConsumerIntegrationIT.java b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsConsumerIntegrationIT.java
index 6ca0840873a..770fc8acbf2 100644
--- a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsConsumerIntegrationIT.java
+++ b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsConsumerIntegrationIT.java
@@ -30,6 +30,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultScheduledPollConsumerScheduler;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
 import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
 import org.apache.camel.test.junit5.CamelTestSupport;
@@ -58,7 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class HdfsConsumerIntegrationIT extends CamelTestSupport {
     @RegisterExtension
-    public static HDFSService service = HDFSServiceFactory.createSingletonService();
+    public static HDFSService service = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());
 
     private static final int ITERATIONS = 200;
 
diff --git a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsProducerConsumerIntegrationIT.java b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsProducerConsumerIntegrationIT.java
index 3c24cdf0c58..8ff7f86b3c7 100644
--- a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsProducerConsumerIntegrationIT.java
+++ b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/integration/HdfsProducerConsumerIntegrationIT.java
@@ -26,6 +26,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
 import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
 import org.apache.camel.test.junit5.CamelTestSupport;
@@ -42,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class HdfsProducerConsumerIntegrationIT extends CamelTestSupport {
     @RegisterExtension
-    public static HDFSService service = HDFSServiceFactory.createSingletonService();
+    public static HDFSService service = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());
 
     private static final int ITERATIONS = 400;
 
diff --git a/test-infra/camel-test-infra-hdfs/pom.xml b/test-infra/camel-test-infra-hdfs/pom.xml
index 98f6eb14b85..0061c0a6831 100644
--- a/test-infra/camel-test-infra-hdfs/pom.xml
+++ b/test-infra/camel-test-infra-hdfs/pom.xml
@@ -38,12 +38,6 @@
             <type>test-jar</type>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test-junit5</artifactId>
-            <scope>test</scope>
-        </dependency>
-
         <dependency>
             <groupId>org.apache.hadoop</groupId>
             <artifactId>hadoop-minicluster</artifactId>
diff --git a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/EmbeddedHDFSService.java b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/EmbeddedHDFSService.java
index b6d81275b0c..75dc0bbb497 100644
--- a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/EmbeddedHDFSService.java
+++ b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/EmbeddedHDFSService.java
@@ -24,8 +24,8 @@ public class EmbeddedHDFSService implements HDFSService {
     private static final Logger LOG = LoggerFactory.getLogger(EmbeddedHDFSService.class);
     private final HDFSContainer container;
 
-    public EmbeddedHDFSService() {
-        container = new HDFSContainer();
+    public EmbeddedHDFSService(int port) {
+        container = new HDFSContainer(port);
     }
 
     @Override
diff --git a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSContainer.java b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSContainer.java
index a5d5091786a..ed3d13ab2e6 100644
--- a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSContainer.java
+++ b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSContainer.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.test.infra.hdfs.v2.services;
 
-import org.apache.camel.test.AvailablePortFinder;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.slf4j.Logger;
@@ -25,15 +24,19 @@ import org.slf4j.LoggerFactory;
 public class HDFSContainer {
     private static final Logger LOG = LoggerFactory.getLogger(HDFSContainer.class);
 
+    private final int port;
     private MiniDFSCluster cluster;
 
+    public HDFSContainer(int port) {
+        this.port = port;
+    }
 
     public void start() {
         try {
             Configuration conf = new Configuration();
             conf.set("dfs.namenode.fs-limits.max-directory-items", "1048576");
             cluster = new MiniDFSCluster.Builder(conf)
-                    .nameNodePort(AvailablePortFinder.getNextAvailable())
+                    .nameNodePort(port)
                     .numDataNodes(3)
                     .format(true)
                     .build();
diff --git a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSServiceFactory.java b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSServiceFactory.java
index 0433b19ce2f..db0e202a047 100644
--- a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSServiceFactory.java
+++ b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HDFSServiceFactory.java
@@ -38,6 +38,8 @@ public final class HDFSServiceFactory {
         }
     }
 
+    private static HDFSService INSTANCE;
+
     private HDFSServiceFactory() {
 
     }
@@ -46,16 +48,13 @@ public final class HDFSServiceFactory {
         return new SimpleTestServiceBuilder<>("hdfs");
     }
 
-    public static HDFSService createSingletonService() {
-        return SingletonServiceHolder.INSTANCE;
-    }
-
-    private static class SingletonServiceHolder {
-        static final HDFSService INSTANCE;
-        static {
+    public static HDFSService createSingletonService(int port) {
+        if (INSTANCE == null) {
             SimpleTestServiceBuilder<HDFSService> instance = builder();
-            instance.addLocalMapping(() -> new SingletonHDFSService(new EmbeddedHDFSService(), "hdfs"));
+            instance.addLocalMapping(() -> new SingletonHDFSService(new EmbeddedHDFSService(port), "hdfs"));
             INSTANCE = instance.build();
         }
+
+        return INSTANCE;
     }
 }