aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2015-09-14 09:15:42 +0200
committerDavid Gageot <david@gageot.net>2015-09-14 09:15:42 +0200
commitfd64661844eadbce52506f169ad8d396905da15b (patch)
treefec6f4e84cb35521cab69844386c29535d2a2d34 /it
parentea1a6ab2144921a880d3d347a95c43aa415a5d10 (diff)
downloadsonarqube-fd64661844eadbce52506f169ad8d396905da15b.tar.gz
sonarqube-fd64661844eadbce52506f169ad8d396905da15b.zip
Cleanup code
Diffstat (limited to 'it')
-rw-r--r--it/it-tests/src/test/java/com/sonar/orchestrator/util/NetworkUtils.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/it/it-tests/src/test/java/com/sonar/orchestrator/util/NetworkUtils.java b/it/it-tests/src/test/java/com/sonar/orchestrator/util/NetworkUtils.java
index 9274dab3483..ebe398646d0 100644
--- a/it/it-tests/src/test/java/com/sonar/orchestrator/util/NetworkUtils.java
+++ b/it/it-tests/src/test/java/com/sonar/orchestrator/util/NetworkUtils.java
@@ -25,28 +25,27 @@ import java.net.ServerSocket;
import java.util.concurrent.atomic.AtomicInteger;
public final class NetworkUtils {
+ private static final int MAX_TRY = 10;
private static final AtomicInteger nextPort = new AtomicInteger(20000);
private NetworkUtils() {
}
public static int getNextAvailablePort() {
- System.out.println("=== Override method provided by orchestrator");
-
- if ("true".equals(System.getenv("TRAVIS"))) {
- for (int i = 0; i < 10; i++) {
+ if (isOnTravisCI()) {
+ for (int i = 0; i < MAX_TRY; i++) {
int port = nextPort.getAndIncrement();
+ // Check that the port is really available.
+ // (On Travis, if the build is single threaded, it should be)
+ //
try {
- System.out.println("=== Trying port " + port);
Process process = new ProcessBuilder("nc", "-z", "localhost", Integer.toString(port)).start();
if (process.waitFor() == 1) {
- System.out.println("=== Using port " + port);
return port;
}
} catch (Exception e) {
- // Ignore. will try again
- System.out.println(e);
+ throw new IllegalStateException("Can't test that a network port is available", e);
}
}
@@ -60,4 +59,8 @@ public final class NetworkUtils {
throw new IllegalStateException("Can't find a free network port", e);
}
}
+
+ private static boolean isOnTravisCI() {
+ return "true".equals(System.getenv("TRAVIS"));
+ }
}