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/10/18 13:23:40 UTC
[camel] branch main updated: (chores) camel-ribbon: use dynamic
ports to prevent test failures
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
The following commit(s) were added to refs/heads/main by this push:
new 281656e (chores) camel-ribbon: use dynamic ports to prevent test failures
281656e is described below
commit 281656e0ce33789ddbf9cc5cd362cac0e1b82b9f
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Mon Oct 18 13:34:13 2021 +0200
(chores) camel-ribbon: use dynamic ports to prevent test failures
---
.../cloud/RibbonServiceCallRegistryRouteTest.java | 13 ++++++------
.../cloud/RibbonServiceCallRouteDslTest.java | 20 +++++++++++--------
.../cloud/RibbonServiceCallRouteMetadataTest.java | 12 +++++++----
.../ribbon/cloud/RibbonServiceCallRouteTest.java | 23 ++++++++++++++--------
.../cloud/RibbonServiceCallUpdateRouteTest.java | 23 ++++++++++++----------
5 files changed, 55 insertions(+), 36 deletions(-)
diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRegistryRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRegistryRouteTest.java
index 2c8c65b..e96a3e8 100644
--- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRegistryRouteTest.java
+++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRegistryRouteTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.impl.cloud.StaticServiceDiscovery;
import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition;
public class RibbonServiceCallRegistryRouteTest extends RibbonServiceCallRouteTest {
+
@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@@ -30,8 +31,8 @@ public class RibbonServiceCallRegistryRouteTest extends RibbonServiceCallRouteTe
public void configure() throws Exception {
// setup a static ribbon server list with these 2 servers to start with
StaticServiceDiscovery servers = new StaticServiceDiscovery();
- servers.addServer("myService@localhost:9090");
- servers.addServer("myService@localhost:9091");
+ servers.addServer("myService@localhost:" + PORT1);
+ servers.addServer("myService@localhost:" + PORT2);
RibbonConfiguration configuration = new RibbonConfiguration();
RibbonServiceLoadBalancer loadBalancer = new RibbonServiceLoadBalancer(configuration);
@@ -50,11 +51,11 @@ public class RibbonServiceCallRegistryRouteTest extends RibbonServiceCallRouteTe
.component("http")
.end()
.to("mock:result");
- from("jetty:http://localhost:9090")
- .to("mock:9090")
+ fromF("jetty:http://localhost:%d", PORT1)
+ .to("mock:" + ROUTE_1_ID)
.transform().constant("9090");
- from("jetty:http://localhost:9091")
- .to("mock:9091")
+ fromF("jetty:http://localhost:%d", PORT2)
+ .to("mock:" + ROUTE_2_ID)
.transform().constant("9091");
}
};
diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteDslTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteDslTest.java
index 3acd72a..6fe78d9 100644
--- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteDslTest.java
+++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteDslTest.java
@@ -18,16 +18,20 @@ package org.apache.camel.component.ribbon.cloud;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RibbonServiceCallRouteDslTest extends CamelTestSupport {
+ private static final int PORT1 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT2 = AvailablePortFinder.getNextAvailable();
+
@Test
public void testServiceCall() throws Exception {
- getMockEndpoint("mock:9090").expectedMessageCount(1);
- getMockEndpoint("mock:9091").expectedMessageCount(1);
+ getMockEndpoint("mock:" + PORT1).expectedMessageCount(1);
+ getMockEndpoint("mock:" + PORT2).expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(2);
String out = template.requestBody("direct:start", null, String.class);
@@ -49,15 +53,15 @@ public class RibbonServiceCallRouteDslTest extends CamelTestSupport {
.component("http")
.ribbonLoadBalancer()
.staticServiceDiscovery()
- .servers("localhost:9090")
- .servers("localhost:9091")
+ .servers("localhost:" + PORT1)
+ .servers("localhost:" + PORT2)
.endParent()
.to("mock:result");
- from("jetty:http://localhost:9090")
- .to("mock:9090")
+ fromF("jetty:http://localhost:%d", PORT1)
+ .to("mock:" + PORT1)
.transform().constant("9090");
- from("jetty:http://localhost:9091")
- .to("mock:9091")
+ fromF("jetty:http://localhost:%d", PORT2)
+ .to("mock:" + PORT2)
.transform().constant("9091");
}
};
diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteMetadataTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteMetadataTest.java
index 7acc4c0..c905b0d 100644
--- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteMetadataTest.java
+++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteMetadataTest.java
@@ -21,12 +21,16 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.ribbon.RibbonConfiguration;
import org.apache.camel.impl.cloud.DefaultServiceDefinition;
import org.apache.camel.impl.cloud.StaticServiceDiscovery;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RibbonServiceCallRouteMetadataTest extends CamelTestSupport {
+ private static final int PORT1 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT2 = AvailablePortFinder.getNextAvailable();
+
@Test
public void testServiceCall() throws Exception {
getMockEndpoint("mock:app1").expectedMessageCount(1);
@@ -48,9 +52,9 @@ public class RibbonServiceCallRouteMetadataTest extends CamelTestSupport {
public void configure() throws Exception {
// setup a static ribbon server list with these 2 servers to start with
StaticServiceDiscovery servers = new StaticServiceDiscovery();
- servers.addServer(DefaultServiceDefinition.builder().withName("myService").withHost("localhost").withPort(9090)
+ servers.addServer(DefaultServiceDefinition.builder().withName("myService").withHost("localhost").withPort(PORT1)
.addMeta("contextPath", "app1").build());
- servers.addServer(DefaultServiceDefinition.builder().withName("myService").withHost("localhost").withPort(9090)
+ servers.addServer(DefaultServiceDefinition.builder().withName("myService").withHost("localhost").withPort(PORT2)
.addMeta("contextPath", "app2").build());
RibbonConfiguration configuration = new RibbonConfiguration();
@@ -65,10 +69,10 @@ public class RibbonServiceCallRouteMetadataTest extends CamelTestSupport {
.serviceDiscovery(servers)
.end()
.to("mock:result");
- from("jetty:http://localhost:9090/app1")
+ fromF("jetty:http://localhost:%d/app1", PORT1)
.to("mock:app1")
.transform().constant("app1");
- from("jetty:http://localhost:9090/app2")
+ fromF("jetty:http://localhost:%d/app2", PORT2)
.to("mock:app2")
.transform().constant("app2");
}
diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteTest.java
index 4acbdaf..dd94ee3 100644
--- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteTest.java
+++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallRouteTest.java
@@ -20,16 +20,23 @@ import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.ribbon.RibbonConfiguration;
import org.apache.camel.impl.cloud.StaticServiceDiscovery;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RibbonServiceCallRouteTest extends CamelTestSupport {
+ protected static final int PORT1 = AvailablePortFinder.getNextAvailable();
+ protected static final int PORT2 = AvailablePortFinder.getNextAvailable();
+
+ protected static final String ROUTE_1_ID = "srv1";
+ protected static final String ROUTE_2_ID = "srv2";
+
@Test
public void testServiceCall() throws Exception {
- getMockEndpoint("mock:9090").expectedMessageCount(1);
- getMockEndpoint("mock:9091").expectedMessageCount(1);
+ getMockEndpoint("mock:" + ROUTE_1_ID).expectedMessageCount(1);
+ getMockEndpoint("mock:" + ROUTE_2_ID).expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(2);
String out = template.requestBody("direct:start", null, String.class);
@@ -47,8 +54,8 @@ public class RibbonServiceCallRouteTest extends CamelTestSupport {
public void configure() throws Exception {
// setup a static ribbon server list with these 2 servers to start with
StaticServiceDiscovery servers = new StaticServiceDiscovery();
- servers.addServer("myService@localhost:9090");
- servers.addServer("myService@localhost:9091");
+ servers.addServer("myService@localhost:" + PORT1);
+ servers.addServer("myService@localhost:" + PORT2);
RibbonConfiguration configuration = new RibbonConfiguration();
RibbonServiceLoadBalancer loadBalancer = new RibbonServiceLoadBalancer(configuration);
@@ -61,11 +68,11 @@ public class RibbonServiceCallRouteTest extends CamelTestSupport {
.serviceDiscovery(servers)
.end()
.to("mock:result");
- from("jetty:http://localhost:9090")
- .to("mock:9090")
+ fromF("jetty:http://localhost:%d", PORT1)
+ .to("mock:" + ROUTE_1_ID)
.transform().constant("9090");
- from("jetty:http://localhost:9091")
- .to("mock:9091")
+ fromF("jetty:http://localhost:%d", PORT2)
+ .to("mock:" + ROUTE_2_ID)
.transform().constant("9091");
}
};
diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallUpdateRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallUpdateRouteTest.java
index b3ec425..1b71857 100644
--- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallUpdateRouteTest.java
+++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServiceCallUpdateRouteTest.java
@@ -20,6 +20,7 @@ import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.ribbon.RibbonConfiguration;
import org.apache.camel.impl.cloud.StaticServiceDiscovery;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.camel.util.ObjectHelper;
import org.junit.jupiter.api.BeforeEach;
@@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RibbonServiceCallUpdateRouteTest extends CamelTestSupport {
+ private static final int PORT1 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT2 = AvailablePortFinder.getNextAvailable();
private static final Logger LOG = LoggerFactory.getLogger(RibbonServiceCallUpdateRouteTest.class);
private final StaticServiceDiscovery servers = new StaticServiceDiscovery();
@@ -38,16 +41,16 @@ public class RibbonServiceCallUpdateRouteTest extends CamelTestSupport {
@BeforeEach
public void setUp() throws Exception {
// setup a static ribbon server list with these 2 servers to start with
- servers.addServer("myService@localhost:9090");
- servers.addServer("myService@localhost:9091");
+ servers.addServer("myService@localhost:" + PORT1);
+ servers.addServer("myService@localhost:" + PORT2);
super.setUp();
}
@Test
public void testServiceCall() throws Exception {
- getMockEndpoint("mock:9090").expectedMessageCount(1);
- getMockEndpoint("mock:9091").expectedMessageCount(1);
+ getMockEndpoint("mock:" + PORT1).expectedMessageCount(1);
+ getMockEndpoint("mock:" + PORT2).expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(2);
String out = template.requestBody("direct:start", null, String.class);
@@ -58,8 +61,8 @@ public class RibbonServiceCallUpdateRouteTest extends CamelTestSupport {
assertMockEndpointsSatisfied();
// stop the first server and remove it from the known list of servers
- context.getRouteController().stopRoute("9090");
- servers.removeServer(s -> ObjectHelper.equal("localhost", s.getHost()) && 9090 == s.getPort());
+ context.getRouteController().stopRoute(String.valueOf(PORT1));
+ servers.removeServer(s -> ObjectHelper.equal("localhost", s.getHost()) && PORT1 == s.getPort());
// call the other active server
String out3 = template.requestBody("direct:start", null, String.class);
@@ -93,11 +96,11 @@ public class RibbonServiceCallUpdateRouteTest extends CamelTestSupport {
.serviceDiscovery(servers)
.end()
.to("mock:result");
- from("jetty:http://localhost:9090").routeId("9090")
- .to("mock:9090")
+ fromF("jetty:http://localhost:%d", PORT1).routeId(String.valueOf(PORT1))
+ .to("mock:" + PORT1)
.transform().constant("9090");
- from("jetty:http://localhost:9091").routeId("9091")
- .to("mock:9091")
+ fromF("jetty:http://localhost:%d", PORT2).routeId(String.valueOf(PORT2))
+ .to("mock:" + PORT2)
.transform().constant("9091");
}
};