diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-11 00:56:41 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-11 00:56:41 +0200 |
commit | 5176c669e21dbb2de66c8c984b4f4de4a9347bcc (patch) | |
tree | a68deb4c409df1764513a90d2552c64ca827762b /server/sonar-search | |
parent | c6e9206b43e5e95a2b09109e77068842667d80d5 (diff) | |
download | sonarqube-5176c669e21dbb2de66c8c984b4f4de4a9347bcc.tar.gz sonarqube-5176c669e21dbb2de66c8c984b4f4de4a9347bcc.zip |
SONAR-4898 - Using NetworkUtils for ES port selection
Diffstat (limited to 'server/sonar-search')
-rw-r--r-- | server/sonar-search/src/main/java/org/sonar/search/NetworkUtils.java | 38 | ||||
-rw-r--r-- | server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java | 5 |
2 files changed, 3 insertions, 40 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/NetworkUtils.java b/server/sonar-search/src/main/java/org/sonar/search/NetworkUtils.java deleted file mode 100644 index 6a78006c299..00000000000 --- a/server/sonar-search/src/main/java/org/sonar/search/NetworkUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.search; - -import java.io.IOException; -import java.net.ServerSocket; - -class NetworkUtils { - - static int freePort() { - try { - return new ServerSocket(0).getLocalPort(); - } catch (IOException e) { - throw new IllegalStateException("Can not find an open network port", e); - } - } - - private static boolean isValidPort(int port) { - return port > 1023; - } -} diff --git a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java index e48b95b6683..ece2083ae38 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; +import java.net.SocketException; import java.util.Properties; import static org.fest.assertions.Assertions.assertThat; @@ -82,9 +83,9 @@ public class ElasticSearchTest { } @Test - public void can_connect() { + public void can_connect() throws SocketException { - int port = NetworkUtils.freePort(); + int port = new DatagramSocket(0).getLocalPort(); Properties properties = new Properties(); properties.setProperty(Process.NAME_PROPERTY, "ES"); |