From 287173bc670b2de8175a9940e9289e5c50ad5908 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 28 Dec 2015 18:22:07 -0500 Subject: [PATCH] Fix TCP tests to use `0 port` https://build.spring.io/browse/INT-MJATS41-495 https://build.spring.io/browse/INT-AT42SIO-16 Can be backported to `4.2.x` on demand --- .../CachingClientConnectionFactoryTests-context.xml | 2 +- .../connection/FailoverClientConnectionFactoryTests.java | 9 ++++----- .../integration/test/util/SocketUtils.java | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests-context.xml b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests-context.xml index 522674071d..afd654519f 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests-context.xml +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests-context.xml @@ -13,7 +13,7 @@ id="scf" type="server" so-timeout="60000" - port="#{tcpIpUtils.findAvailableServerSocket()}"/> + port="#{tcpIpUtils.findAvailableServerSocket(0)}"/> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2); + final List openPorts = SocketUtils.findAvailableServerSockets(0, 2); int port1 = openPorts.get(0); int port2 = openPorts.get(1); @@ -263,7 +263,7 @@ public class FailoverClientConnectionFactoryTests { @Test public void testRealNio() throws Exception { - final List openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2); + final List openPorts = SocketUtils.findAvailableServerSockets(0, 2); int port1 = openPorts.get(0); int port2 = openPorts.get(1); @@ -278,7 +278,7 @@ public class FailoverClientConnectionFactoryTests { @Test public void testRealNetSingleUse() throws Exception { - final List openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2); + final List openPorts = SocketUtils.findAvailableServerSockets(0, 2); int port1 = openPorts.get(0); int port2 = openPorts.get(1); @@ -295,7 +295,7 @@ public class FailoverClientConnectionFactoryTests { @Test public void testRealNioSingleUse() throws Exception { - final List openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2); + final List openPorts = SocketUtils.findAvailableServerSockets(0, 2); int port1 = openPorts.get(0); int port2 = openPorts.get(1); @@ -591,7 +591,6 @@ public class FailoverClientConnectionFactoryTests { else { return TestUtils.getPropertyValue(client.getConnection(), "socketChannel", SocketChannel.class).socket(); } - } } diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/util/SocketUtils.java b/spring-integration-test/src/main/java/org/springframework/integration/test/util/SocketUtils.java index 412204a339..363b54889b 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/util/SocketUtils.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/util/SocketUtils.java @@ -99,7 +99,7 @@ public final class SocketUtils { ServerSocket sock = ServerSocketFactory.getDefault() .createServerSocket(i, 1, InetAddress.getByName("localhost")); sock.close(); - openPorts.add(i); + openPorts.add(i == 0 ? sock.getLocalPort() : i); if (openPorts.size() == numberOfRequestedPorts) { return openPorts;