diff --git a/components/camel-thrift/src/main/java/org/apache/camel/component/thrift/ThriftConsumer.java b/components/camel-thrift/src/main/java/org/apache/camel/component/thrift/ThriftConsumer.java index 11e8e2cff6019..0845099cabff5 100644 --- a/components/camel-thrift/src/main/java/org/apache/camel/component/thrift/ThriftConsumer.java +++ b/components/camel-thrift/src/main/java/org/apache/camel/component/thrift/ThriftConsumer.java @@ -85,6 +85,16 @@ protected void doStart() throws Exception { } } + public int getLocalPort() { + if (asyncServerTransport != null) { + return asyncServerTransport.getPort(); + } + if (syncServerTransport != null) { + return syncServerTransport.getServerSocket().getLocalPort(); + } + return -1; + } + @Override protected void doStop() throws Exception { if (server != null) { diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerAsyncTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerAsyncTest.java index b07eab4434936..7fc8205d9e4b2 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerAsyncTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerAsyncTest.java @@ -29,7 +29,6 @@ import org.apache.camel.component.thrift.generated.Calculator; import org.apache.camel.component.thrift.generated.Operation; import org.apache.camel.component.thrift.generated.Work; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.async.TAsyncClientManager; @@ -40,7 +39,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,8 +48,7 @@ public class ThriftConsumerAsyncTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(ThriftConsumerAsyncTest.class); - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; private Calculator.AsyncClient thriftClient; @@ -63,11 +60,16 @@ public class ThriftConsumerAsyncTest extends CamelTestSupport { private int allTypesResult; private Work echoResult; + private int getActualPort() { + return ((ThriftConsumer) context.getRoutes().get(0).getConsumer()).getLocalPort(); + } + @BeforeEach public void startThriftClient() throws IOException, TTransportException { if (transport == null) { - LOG.info("Connecting to the Thrift server on port: {}", thriftTestPort.getPort()); - transport = new TNonblockingSocket("localhost", thriftTestPort.getPort()); + int thriftTestPort = getActualPort(); + LOG.info("Connecting to the Thrift server on port: {}", thriftTestPort); + transport = new TNonblockingSocket("localhost", thriftTestPort); thriftClient = (new Calculator.AsyncClient.Factory(new TAsyncClientManager(), new TBinaryProtocol.Factory())) .getAsyncClient(transport); } @@ -243,8 +245,7 @@ protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override public void configure() { - from("thrift://localhost:" + thriftTestPort.getPort() - + "/org.apache.camel.component.thrift.generated.Calculator") + from("thrift://localhost:0/org.apache.camel.component.thrift.generated.Calculator") .to("mock:thrift-service").choice() .when(header(ThriftConstants.THRIFT_METHOD_NAME_HEADER).isEqualTo("calculate")) .setBody(simple(Integer.valueOf(THRIFT_TEST_NUM1 * THRIFT_TEST_NUM2).toString())) diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerConcurrentTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerConcurrentTest.java index 12ba89471b339..b743ded59022a 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerConcurrentTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerConcurrentTest.java @@ -27,7 +27,6 @@ import org.apache.camel.component.thrift.generated.Calculator; import org.apache.camel.component.thrift.generated.Operation; import org.apache.camel.component.thrift.generated.Work; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; @@ -41,7 +40,6 @@ import org.apache.thrift.transport.TTransportException; import org.apache.thrift.transport.layered.TFramedTransport; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,16 +49,16 @@ public class ThriftConsumerConcurrentTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(ThriftConsumerConcurrentTest.class); - @RegisterExtension - AvailablePortFinder.Port thriftSyncPort = AvailablePortFinder.find(); - @RegisterExtension - AvailablePortFinder.Port thriftAsyncPort = AvailablePortFinder.find(); private static final int THRIFT_TEST_NUM1 = 12; private static final int CONCURRENT_THREAD_COUNT = 30; private static final int ROUNDS_PER_THREAD_COUNT = 10; private static AtomicInteger idCounter = new AtomicInteger(); + private int getPortForRoute(int index) { + return ((ThriftConsumer) context.getRoutes().get(index).getConsumer()).getLocalPort(); + } + public static Integer createId() { return idCounter.getAndIncrement(); } @@ -75,7 +73,7 @@ public void testSyncWithConcurrentThreads() { @Override public void run() throws TTransportException { - TTransport transport = new TSocket("localhost", thriftSyncPort.getPort()); + TTransport transport = new TSocket("localhost", getPortForRoute(0)); transport.open(); TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport)); Calculator.Client client = (new Calculator.Client.Factory()).getClient(protocol); @@ -108,7 +106,7 @@ public void testAsyncWithConcurrentThreads() { public void run() throws TTransportException, IOException, InterruptedException { final CountDownLatch latch = new CountDownLatch(1); - TNonblockingTransport transport = new TNonblockingSocket("localhost", thriftAsyncPort.getPort()); + TNonblockingTransport transport = new TNonblockingSocket("localhost", getPortForRoute(1)); Calculator.AsyncClient client = (new Calculator.AsyncClient.Factory(new TAsyncClientManager(), new TBinaryProtocol.Factory())) .getAsyncClient(transport); @@ -165,12 +163,10 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { - from("thrift://localhost:" + thriftSyncPort.getPort() - + "/org.apache.camel.component.thrift.generated.Calculator?synchronous=true") + from("thrift://localhost:0/org.apache.camel.component.thrift.generated.Calculator?synchronous=true") .setBody(simple("${body[1]}")).bean(new CalculatorMessageBuilder(), "multiply"); - from("thrift://localhost:" + thriftAsyncPort.getPort() - + "/org.apache.camel.component.thrift.generated.Calculator") + from("thrift://localhost:0/org.apache.camel.component.thrift.generated.Calculator") .setBody(simple("${body[1]}")).bean(new CalculatorMessageBuilder(), "multiply"); } }; diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSecurityTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSecurityTest.java index f7cdd3fdd0481..3f1f6fe4b7290 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSecurityTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSecurityTest.java @@ -25,7 +25,6 @@ import org.apache.camel.support.jsse.KeyManagersParameters; import org.apache.camel.support.jsse.KeyStoreParameters; import org.apache.camel.support.jsse.SSLContextParameters; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; @@ -35,7 +34,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,8 +43,7 @@ public class ThriftConsumerSecurityTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(ThriftConsumerSecurityTest.class); - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; private static final String TRUST_STORE_RESOURCE = "file:src/test/resources/certs/truststore.jks"; @@ -59,15 +56,20 @@ public class ThriftConsumerSecurityTest extends CamelTestSupport { private TProtocol protocol; private TTransport transport; + private int getActualPort() { + return ((ThriftConsumer) context.getRoutes().get(0).getConsumer()).getLocalPort(); + } + @BeforeEach public void startThriftSecureClient() throws TTransportException { if (transport == null) { - LOG.info("Connecting to the secured Thrift server on port: {}", thriftTestPort.getPort()); + int thriftTestPort = getActualPort(); + LOG.info("Connecting to the secured Thrift server on port: {}", thriftTestPort); TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters(); sslParams.setTrustStore(TRUST_STORE_RESOURCE, SECURITY_STORE_PASSWORD); - transport = TSSLTransportFactory.getClientSocket("localhost", thriftTestPort.getPort(), THRIFT_CLIENT_TIMEOUT, + transport = TSSLTransportFactory.getClientSocket("localhost", thriftTestPort, THRIFT_CLIENT_TIMEOUT, sslParams); protocol = new TBinaryProtocol(transport); @@ -140,8 +142,7 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { - from("thrift://localhost:" + thriftTestPort.getPort() - + "/org.apache.camel.component.thrift.generated.Calculator?negotiationType=SSL&sslParameters=#sslParams&synchronous=true") + from("thrift://localhost:0/org.apache.camel.component.thrift.generated.Calculator?negotiationType=SSL&sslParameters=#sslParams&synchronous=true") .to("mock:thrift-secure-service").choice() .when(header(ThriftConstants.THRIFT_METHOD_NAME_HEADER).isEqualTo("calculate")) .setBody(simple(Integer.valueOf(THRIFT_TEST_NUM1 * THRIFT_TEST_NUM2).toString())) diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSyncTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSyncTest.java index 3dd5d4575c2d6..80fdf74b120e8 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSyncTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerSyncTest.java @@ -21,7 +21,6 @@ import org.apache.camel.component.thrift.generated.Calculator; import org.apache.camel.component.thrift.generated.Operation; import org.apache.camel.component.thrift.generated.Work; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; @@ -32,7 +31,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,8 +40,7 @@ public class ThriftConsumerSyncTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(ThriftConsumerSyncTest.class); - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; private Calculator.Client thriftClient; @@ -51,11 +48,16 @@ public class ThriftConsumerSyncTest extends CamelTestSupport { private TProtocol protocol; private TTransport transport; + private int getActualPort() { + return ((ThriftConsumer) context.getRoutes().get(0).getConsumer()).getLocalPort(); + } + @BeforeEach public void startThriftClient() throws TTransportException { if (transport == null) { - LOG.info("Connecting to the Thrift server on port: {}", thriftTestPort.getPort()); - transport = new TSocket("localhost", thriftTestPort.getPort()); + int thriftTestPort = getActualPort(); + LOG.info("Connecting to the Thrift server on port: {}", thriftTestPort); + transport = new TSocket("localhost", thriftTestPort); transport.open(); protocol = new TBinaryProtocol(new TFramedTransport(transport)); thriftClient = (new Calculator.Client.Factory()).getClient(protocol); @@ -106,8 +108,7 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { - from("thrift://localhost:" + thriftTestPort.getPort() - + "/org.apache.camel.component.thrift.generated.Calculator?synchronous=true") + from("thrift://localhost:0/org.apache.camel.component.thrift.generated.Calculator?synchronous=true") .to("mock:thrift-service").choice() .when(header(ThriftConstants.THRIFT_METHOD_NAME_HEADER).isEqualTo("calculate")) .setBody(simple(Integer.valueOf(THRIFT_TEST_NUM1 * THRIFT_TEST_NUM2).toString())) diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerZlibCompressionTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerZlibCompressionTest.java index 4db3c343583f7..2d4f74c78aa15 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerZlibCompressionTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftConsumerZlibCompressionTest.java @@ -21,7 +21,6 @@ import org.apache.camel.component.thrift.generated.Calculator; import org.apache.camel.component.thrift.generated.Operation; import org.apache.camel.component.thrift.generated.Work; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.TConfiguration; import org.apache.thrift.protocol.TBinaryProtocol; @@ -33,7 +32,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,8 +41,7 @@ public class ThriftConsumerZlibCompressionTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(ThriftConsumerZlibCompressionTest.class); - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; private static final int THRIFT_CLIENT_TIMEOUT = 2000; @@ -54,12 +51,17 @@ public class ThriftConsumerZlibCompressionTest extends CamelTestSupport { private TProtocol protocol; private TTransport transport; + private int getActualPort() { + return ((ThriftConsumer) context.getRoutes().get(0).getConsumer()).getLocalPort(); + } + @BeforeEach public void startThriftZlibClient() throws TTransportException { if (transport == null) { - LOG.info("Connecting to the Thrift server with zlib compression on port: {}", thriftTestPort.getPort()); + int thriftTestPort = getActualPort(); + LOG.info("Connecting to the Thrift server with zlib compression on port: {}", thriftTestPort); - transport = new TSocket(new TConfiguration(), "localhost", thriftTestPort.getPort(), THRIFT_CLIENT_TIMEOUT); + transport = new TSocket(new TConfiguration(), "localhost", thriftTestPort, THRIFT_CLIENT_TIMEOUT); protocol = new TBinaryProtocol(new TZlibTransport(transport)); thriftClient = new Calculator.Client(protocol); transport.open(); @@ -115,8 +117,7 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { - from("thrift://localhost:" + thriftTestPort.getPort() - + "/org.apache.camel.component.thrift.generated.Calculator?compressionType=ZLIB&synchronous=true") + from("thrift://localhost:0/org.apache.camel.component.thrift.generated.Calculator?compressionType=ZLIB&synchronous=true") .to("mock:thrift-secure-service").choice() .when(header(ThriftConstants.THRIFT_METHOD_NAME_HEADER).isEqualTo("calculate")) .setBody(simple(Integer.valueOf(THRIFT_TEST_NUM1 * THRIFT_TEST_NUM2).toString())) diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerBaseTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerBaseTest.java index 6b4b12942b958..1be6d84f3333c 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerBaseTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerBaseTest.java @@ -18,19 +18,16 @@ import org.apache.camel.component.thrift.generated.Calculator; import org.apache.camel.component.thrift.impl.CalculatorSyncServerImpl; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.server.THsHaServer; import org.apache.thrift.server.THsHaServer.Args; import org.apache.thrift.server.TServer; import org.apache.thrift.transport.TNonblockingServerSocket; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class ThriftProducerBaseTest extends CamelTestSupport { - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + protected int thriftTestPort; protected static final int THRIFT_TEST_NUM1 = 12; protected static final int THRIFT_TEST_NUM2 = 13; @SuppressWarnings({ "rawtypes" }) @@ -42,13 +39,14 @@ public abstract class ThriftProducerBaseTest extends CamelTestSupport { @Override @SuppressWarnings({ "unchecked", "rawtypes" }) - protected void setupResources() throws Exception { + public void doPreSetup() throws Exception { processor = new Calculator.Processor(new CalculatorSyncServerImpl()); - serverTransport = new TNonblockingServerSocket(thriftTestPort.getPort()); + serverTransport = new TNonblockingServerSocket(0); + thriftTestPort = serverTransport.getPort(); server = new THsHaServer(new Args(serverTransport).processor(processor)); Runnable simple = new Runnable() { public void run() { - LOG.info("Thrift server started on port: {}", thriftTestPort.getPort()); + LOG.info("Thrift server started on port: {}", thriftTestPort); server.serve(); } }; diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java index 1a4cad0a5cd14..3427bc0843d9c 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java @@ -34,14 +34,12 @@ import org.apache.camel.support.jsse.KeyStoreParameters; import org.apache.camel.support.jsse.SSLContextParameters; import org.apache.camel.support.jsse.TrustManagersParameters; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.transport.TSSLTransportFactory; import org.apache.thrift.transport.TServerSocket; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,8 +57,7 @@ public class ThriftProducerSecurityTest extends CamelTestSupport { @SuppressWarnings({ "rawtypes" }) private Calculator.Processor processor; - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private int thriftTestPort; private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; @@ -71,21 +68,22 @@ public class ThriftProducerSecurityTest extends CamelTestSupport { @Override @SuppressWarnings({ "unchecked", "rawtypes" }) - protected void setupResources() throws Exception { + public void doPreSetup() throws Exception { processor = new Calculator.Processor(new CalculatorSyncServerImpl()); TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters(); sslParams.setKeyStore(KEY_STORE_SOURCE, SECURITY_STORE_PASSWORD); - serverTransport = TSSLTransportFactory.getServerSocket(thriftTestPort.getPort(), THRIFT_CLIENT_TIMEOUT, + serverTransport = TSSLTransportFactory.getServerSocket(0, THRIFT_CLIENT_TIMEOUT, InetAddress.getByName("localhost"), sslParams); + thriftTestPort = serverTransport.getServerSocket().getLocalPort(); TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport); args.processor(processor); server = new TThreadPoolServer(args); Runnable simple = new Runnable() { public void run() { - LOG.info("Thrift secured server started on port: {}", thriftTestPort.getPort()); + LOG.info("Thrift secured server started on port: {}", thriftTestPort); server.serve(); } }; @@ -201,23 +199,23 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { from("direct:thrift-secured-calculate") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?" + "method=calculate&negotiationType=SSL&sslParameters=#sslParams&synchronous=true"); from("direct:thrift-secured-add") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?" + "method=add&negotiationType=SSL&sslParameters=#sslParams&synchronous=true"); from("direct:thrift-secured-ping") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?" + "method=ping&negotiationType=SSL&sslParameters=#sslParams&synchronous=true"); from("direct:thrift-secured-zip") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?" + "method=zip&negotiationType=SSL&sslParameters=#sslParams&synchronous=true"); from("direct:thrift-secured-alltypes") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?" + "method=alltypes&negotiationType=SSL&sslParameters=#sslParams&synchronous=true"); } diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java index 0d04cc18db12e..d01ce11f646da 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java @@ -158,22 +158,22 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { from("direct:thrift-calculate") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=calculate&synchronous=true"); from("direct:thrift-add") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=add&synchronous=true"); from("direct:thrift-ping") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=ping&synchronous=true"); from("direct:thrift-zip") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=zip&synchronous=true"); from("direct:thrift-alltypes") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=alltypes&synchronous=true"); from("direct:thrift-echo") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=echo&synchronous=true"); } }; diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java index 20c2125de9e64..cbf3ea2ee036a 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java @@ -26,7 +26,6 @@ import org.apache.camel.component.thrift.generated.Operation; import org.apache.camel.component.thrift.generated.Work; import org.apache.camel.component.thrift.impl.CalculatorSyncServerImpl; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.server.TServer; @@ -34,7 +33,6 @@ import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TZlibTransport; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,19 +49,19 @@ public class ThriftProducerZlibCompressionTest extends CamelTestSupport { @SuppressWarnings({ "rawtypes" }) private Calculator.Processor processor; - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private int thriftTestPort; private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; private static final int THRIFT_CLIENT_TIMEOUT = 2000; @Override @SuppressWarnings({ "unchecked", "rawtypes" }) - protected void setupResources() throws Exception { + public void doPreSetup() throws Exception { processor = new Calculator.Processor(new CalculatorSyncServerImpl()); serverTransport = new TServerSocket( - new InetSocketAddress(InetAddress.getByName("localhost"), thriftTestPort.getPort()), THRIFT_CLIENT_TIMEOUT); + new InetSocketAddress(InetAddress.getByName("localhost"), 0), THRIFT_CLIENT_TIMEOUT); + thriftTestPort = serverTransport.getServerSocket().getLocalPort(); TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport); args.processor(processor); args.protocolFactory(new TBinaryProtocol.Factory()); @@ -72,7 +70,7 @@ protected void setupResources() throws Exception { Runnable simple = new Runnable() { public void run() { - LOG.info("Thrift server with zlib compression started on port: {}", thriftTestPort.getPort()); + LOG.info("Thrift server with zlib compression started on port: {}", thriftTestPort); server.serve(); } }; @@ -120,10 +118,10 @@ protected RouteBuilder createRouteBuilder() { @Override public void configure() { from("direct:thrift-zlib-calculate") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=calculate&compressionType=ZLIB&synchronous=true"); from("direct:thrift-zlib-ping") - .to("thrift://localhost:" + thriftTestPort.getPort() + .to("thrift://localhost:" + thriftTestPort + "/org.apache.camel.component.thrift.generated.Calculator?method=ping&compressionType=ZLIB&synchronous=true"); } }; diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java index 3b221c914562c..bdb8b01ab4d4e 100644 --- a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java +++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java @@ -22,7 +22,6 @@ import org.apache.camel.component.thrift.generated.Calculator; import org.apache.camel.component.thrift.impl.CalculatorSyncServerImpl; import org.apache.camel.component.thrift.server.ThriftThreadPoolServer; -import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit6.CamelTestSupport; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; @@ -34,7 +33,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,8 +44,7 @@ public class ThriftThreadPoolServerTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(ThriftProducerSecurityTest.class); - @RegisterExtension - AvailablePortFinder.Port thriftTestPort = AvailablePortFinder.find(); + private int thriftTestPort; private static final int THRIFT_TEST_NUM1 = 12; private static final int THRIFT_TEST_NUM2 = 13; @@ -71,8 +68,9 @@ public void startThriftServer() throws Exception { TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters(); sslParams.setKeyStore(KEY_STORE_PATH, SECURITY_STORE_PASSWORD); - serverTransport = TSSLTransportFactory.getServerSocket(thriftTestPort.getPort(), THRIFT_CLIENT_TIMEOUT, + serverTransport = TSSLTransportFactory.getServerSocket(0, THRIFT_CLIENT_TIMEOUT, InetAddress.getByName("localhost"), sslParams); + thriftTestPort = serverTransport.getServerSocket().getLocalPort(); ThriftThreadPoolServer.Args args = new ThriftThreadPoolServer.Args(serverTransport); args.processor(processor); @@ -82,7 +80,7 @@ public void startThriftServer() throws Exception { server = new ThriftThreadPoolServer(args); server.serve(); - LOG.info("Thrift secured server started on port: {}", thriftTestPort.getPort()); + LOG.info("Thrift secured server started on port: {}", thriftTestPort); } @AfterEach @@ -98,7 +96,7 @@ public void stopThriftServer() { public void clientConnectionTest() throws TException { TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters(); sslParams.setTrustStore(TRUST_STORE_PATH, SECURITY_STORE_PASSWORD); - clientTransport = TSSLTransportFactory.getClientSocket("localhost", thriftTestPort.getPort(), 1000, sslParams); + clientTransport = TSSLTransportFactory.getClientSocket("localhost", thriftTestPort, 1000, sslParams); protocol = new TBinaryProtocol(clientTransport); Calculator.Client client = new Calculator.Client(protocol);