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

janbednar pushed a commit to branch CAMEL-13853
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/CAMEL-13853 by this push:
     new 65e2582  CAMEL-13853: AvailablePortFinder now delegates the port 
selection to OS
65e2582 is described below

commit 65e25820f9a8496a7494ac4d974f514deff413a2
Author: Jan Bednář <m...@janbednar.eu>
AuthorDate: Tue Aug 13 09:41:36 2019 +0200

    CAMEL-13853: AvailablePortFinder now delegates the port selection to OS
---
 .../camel/component/netty4/http/BaseNettyTest.java | 32 +++-------------------
 .../http/NettyHttpGetWithInvalidMessageTest.java   |  2 +-
 .../netty4/http/NettyHttpProducerHeadersTest.java  |  2 +-
 .../camel/component/netty4/BaseNettyTest.java      | 32 +++-------------------
 .../camel/itest/cxf/CamelCxfBeanInjectTest.java    |  2 +-
 5 files changed, 11 insertions(+), 59 deletions(-)

diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
index d129005..2342ecc 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
@@ -31,6 +31,7 @@ import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.logging.log4j.core.LogEvent;
 import org.junit.AfterClass;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,34 +44,9 @@ public class BaseNettyTest extends CamelTestSupport {
 
     private static volatile int port;
 
-    @BeforeClass
+    @Before
     public static void initPort() throws Exception {
-        File file = new File("target/nettyport.txt");
-
-        if (!file.exists()) {
-            // start from somewhere in the 26xxx range
-            port = AvailablePortFinder.getNextAvailable(26000);
-        } else {
-            // read port number from file
-            String s = IOConverter.toString(file, null);
-            port = Integer.parseInt(s);
-            // use next free port
-            port = AvailablePortFinder.getNextAvailable(port + 1);
-        }
-
-    }
-
-    @AfterClass
-    public static void savePort() throws Exception {
-        File file = new File("target/nettyport.txt");
-
-        // save to file, do not append
-        FileOutputStream fos = new FileOutputStream(file, false);
-        try {
-            fos.write(String.valueOf(port).getBytes());
-        } finally {
-            fos.close();
-        }
+        port = AvailablePortFinder.getNextAvailable();
     }
 
     @BeforeClass
@@ -115,7 +91,7 @@ public class BaseNettyTest extends CamelTestSupport {
     }
 
     protected int getNextPort() {
-        port = AvailablePortFinder.getNextAvailable(port + 1);
+        port = AvailablePortFinder.getNextAvailable();
         return port;
     }
 
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
index 8e5c307..135d0bf 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpGetWithInvalidMessageTest.java
@@ -92,7 +92,7 @@ public class NettyHttpGetWithInvalidMessageTest extends 
CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                port1 = AvailablePortFinder.getNextAvailable(8100);
+                port1 = AvailablePortFinder.getNextAvailable();
                 
                // set up a netty http proxy
                 from("netty-http:http://localhost:"; + port1 + "/test")
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerHeadersTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerHeadersTest.java
index a1fc167..9e26098 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerHeadersTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerHeadersTest.java
@@ -74,7 +74,7 @@ public class NettyHttpProducerHeadersTest extends 
CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                port = AvailablePortFinder.getNextAvailable(8000);
+                port = AvailablePortFinder.getNextAvailable();
 
                 from("netty-http:http://localhost:"; + port + 
"?matchOnUriPrefix=true")
                     .setBody(simple("${header." + Exchange.HTTP_URI + "}"));
diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty4/BaseNettyTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty4/BaseNettyTest.java
index e9feb3b..7453ba6 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty4/BaseNettyTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty4/BaseNettyTest.java
@@ -32,6 +32,7 @@ import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.logging.log4j.core.LogEvent;
 import org.junit.AfterClass;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,34 +45,9 @@ public class BaseNettyTest extends CamelTestSupport {
 
     private static volatile int port;
 
-    @BeforeClass
+    @Before
     public static void initPort() throws Exception {
-        File file = new File("target/nettyport.txt");
-
-        if (!file.exists()) {
-            // start from somewhere in the 25xxx range
-            port = AvailablePortFinder.getNextAvailable(25000);
-        } else {
-            // read port number from file
-            String s = IOConverter.toString(file, null);
-            port = Integer.parseInt(s);
-            // use next free port
-            port = AvailablePortFinder.getNextAvailable(port + 1);
-        }
-
-    }
-
-    @AfterClass
-    public static void savePort() throws Exception {
-        File file = new File("target/nettyport.txt");
-
-        // save to file, do not append
-        FileOutputStream fos = new FileOutputStream(file, false);
-        try {
-            fos.write(String.valueOf(port).getBytes());
-        } finally {
-            fos.close();
-        }
+        port = AvailablePortFinder.getNextAvailable();
     }
 
     @BeforeClass
@@ -116,7 +92,7 @@ public class BaseNettyTest extends CamelTestSupport {
     }
 
     protected int getNextPort() {
-        port = AvailablePortFinder.getNextAvailable(port + 1);
+        port = AvailablePortFinder.getNextAvailable();
         return port;
     }
 
diff --git 
a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/cxf/CamelCxfBeanInjectTest.java
 
b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/cxf/CamelCxfBeanInjectTest.java
index b752bfb..373d0d0 100644
--- 
a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/cxf/CamelCxfBeanInjectTest.java
+++ 
b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/cxf/CamelCxfBeanInjectTest.java
@@ -47,7 +47,7 @@ import org.osgi.framework.Constants;
 @Ignore("Flaky on CI server")
 public class CamelCxfBeanInjectTest extends AbstractFeatureTest {
 
-    private static final int PORT = 
AvailablePortFinder.getNextAvailable(30000);
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
     private static final String ENDPOINT_ADDRESS = String.format(
         "http://localhost:%s/CamelCxfBeanInjectTest/router";, PORT);
 

Reply via email to