Repository: flink
Updated Branches:
refs/heads/master d760bbc96 -> 8696e799f
[FLINK-4052] [runtime] Improve test stability for ConnectionUtilsTest
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/8696e799
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/8696e799
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/8696e799
Branch: refs/heads/master
Commit: 8696e799faf18027cd9f2479b24520cdcbca8bdb
Parents: d760bbc
Author: Stephan Ewen <sewen@apache.org>
Authored: Thu Jun 9 21:32:45 2016 +0200
Committer: Stephan Ewen <sewen@apache.org>
Committed: Thu Jun 9 21:32:45 2016 +0200
----------------------------------------------------------------------
.../flink/runtime/net/ConnectionUtilsTest.java | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/8696e799/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java
index 57360ff..7d615bd 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java
@@ -24,6 +24,7 @@ import org.junit.Test;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.ServerSocket;
/**
* Tests for the network utilities.
@@ -32,20 +33,11 @@ public class ConnectionUtilsTest {
@Test
public void testReturnLocalHostAddressUsingHeuristics() {
- int unusedPort;
- try {
- unusedPort = org.apache.flink.util.NetUtils.getAvailablePort();
- }
- catch (Throwable t) {
- // if this system cannot find an available port,
- // skip this test
- return;
- }
-
- try {
- // create an unreachable target address
- InetSocketAddress unreachable = new InetSocketAddress("localhost", unusedPort);
-
+ try (ServerSocket blocker = new ServerSocket(0, 1, InetAddress.getLocalHost())) {
+ // the "blocker" server socket simply does not accept connections
+ // this address is consequently "unreachable"
+ InetSocketAddress unreachable = new InetSocketAddress("localhost", blocker.getLocalPort());
+
final long start = System.currentTimeMillis();
InetAddress add = ConnectionUtils.findConnectingAddress(unreachable, 2000, 400);
|