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
This commit is contained in:
Artem Bilan
2015-12-28 18:22:07 -05:00
parent d71236ee76
commit 287173bc67
3 changed files with 6 additions and 7 deletions

View File

@@ -13,7 +13,7 @@
id="scf"
type="server"
so-timeout="60000"
port="#{tcpIpUtils.findAvailableServerSocket()}"/>
port="#{tcpIpUtils.findAvailableServerSocket(0)}"/>
<int-ip:tcp-inbound-channel-adapter
connection-factory="scf"

View File

@@ -249,7 +249,7 @@ public class FailoverClientConnectionFactoryTests {
@Test
public void testRealNet() throws Exception {
final List<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
final List<Integer> 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<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
final List<Integer> 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<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
final List<Integer> 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<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
final List<Integer> 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();
}
}
}

View File

@@ -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;