diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-08-25 11:54:26 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:49 +0200 |
commit | 80269a5d22553335f22f3e8a8a5840724fb154f9 (patch) | |
tree | df2a88bb4ae61251040499ec77f2d217246512a1 /server/sonar-process/src/test/java | |
parent | 904cd8b327790c31d1abe0bceb0007015e74dfdf (diff) | |
download | sonarqube-80269a5d22553335f22f3e8a8a5840724fb154f9.tar.gz sonarqube-80269a5d22553335f22f3e8a8a5840724fb154f9.zip |
SONAR-9741 move shared cluster related classes to sonar-cluster
Diffstat (limited to 'server/sonar-process/src/test/java')
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java | 91 | ||||
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java | 23 |
2 files changed, 13 insertions, 101 deletions
diff --git a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java deleted file mode 100644 index 6450790490d..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.process; - -import java.net.InetAddress; -import java.util.HashSet; -import java.util.Set; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static java.net.InetAddress.getLoopbackAddress; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.sonar.process.NetworkUtils.getNextAvailablePort; - -public class NetworkUtilsTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void getNextAvailablePort_never_returns_the_same_port_in_current_jvm() { - Set<Integer> ports = new HashSet<>(); - for (int i = 0; i < 100; i++) { - int port = getNextAvailablePort(getLoopbackAddress()); - assertThat(port).isGreaterThan(1_023); - ports.add(port); - } - assertThat(ports).hasSize(100); - } - - @Test - public void getNextAvailablePort_retries_to_get_available_port_when_port_has_already_been_allocated() { - NetworkUtils.PortAllocator portAllocator = mock(NetworkUtils.PortAllocator.class); - when(portAllocator.getAvailable(any(InetAddress.class))).thenReturn(9_000, 9_000, 9_000, 9_100); - - InetAddress address = getLoopbackAddress(); - assertThat(getNextAvailablePort(address, portAllocator)).isEqualTo(9_000); - assertThat(getNextAvailablePort(address, portAllocator)).isEqualTo(9_100); - } - - @Test - public void getNextAvailablePort_does_not_return_special_ports() { - NetworkUtils.PortAllocator portAllocator = mock(NetworkUtils.PortAllocator.class); - when(portAllocator.getAvailable(any(InetAddress.class))).thenReturn(900, 903, 1_059); - - // the two first ports are banned because < 1023, so 1_059 is returned - assertThat(getNextAvailablePort(getLoopbackAddress(), portAllocator)).isEqualTo(1_059); - } - - @Test - public void getNextAvailablePort_throws_ISE_if_too_many_attempts() { - NetworkUtils.PortAllocator portAllocator = mock(NetworkUtils.PortAllocator.class); - when(portAllocator.getAvailable(any(InetAddress.class))).thenReturn(900); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to find an available port on "); - - getNextAvailablePort(getLoopbackAddress(), portAllocator); - } - - @Test - public void getHostname_must_return_a_value() { - assertThat(NetworkUtils.getHostname()).containsPattern(".+"); - } - - @Test - public void getIPAddresses_must_return_a_value() { - assertThat(NetworkUtils.getIPAddresses()).matches("(\\d+\\.\\d+\\.\\d+\\.\\d+,?)+"); - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java b/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java index 643e80c859f..c11fc2589a0 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java @@ -28,12 +28,15 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.sonar.cluster.ClusterProperties; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; +import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; public class EsSettingsTest { @@ -55,7 +58,7 @@ public class EsSettingsTest { props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); + props.set(CLUSTER_NAME, "sonarqube"); EsSettings esSettings = new EsSettings(props, new EsFileSystem(props)); @@ -91,9 +94,9 @@ public class EsSettingsTest { props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube-1"); - props.set(ProcessProperties.CLUSTER_ENABLED, "true"); - props.set(ProcessProperties.CLUSTER_NODE_NAME, "node-1"); + props.set(ClusterProperties.CLUSTER_NAME, "sonarqube-1"); + props.set(ClusterProperties.CLUSTER_ENABLED, "true"); + props.set(ClusterProperties.CLUSTER_NODE_NAME, "node-1"); EsSettings esSettings = new EsSettings(props, new EsFileSystem(props)); @@ -106,8 +109,8 @@ public class EsSettingsTest { public void test_node_name_default_for_cluster_mode() throws Exception { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - props.set(ProcessProperties.CLUSTER_ENABLED, "true"); + props.set(ClusterProperties.CLUSTER_NAME, "sonarqube"); + props.set(ClusterProperties.CLUSTER_ENABLED, "true"); props.set(ProcessProperties.SEARCH_PORT, "1234"); props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); @@ -122,8 +125,8 @@ public class EsSettingsTest { public void test_node_name_default_for_standalone_mode() throws Exception { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - props.set(ProcessProperties.CLUSTER_ENABLED, "false"); + props.set(ClusterProperties.CLUSTER_NAME, "sonarqube"); + props.set(ClusterProperties.CLUSTER_ENABLED, "false"); props.set(ProcessProperties.SEARCH_PORT, "1234"); props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); @@ -153,7 +156,7 @@ public class EsSettingsTest { @Test public void set_discovery_settings_if_cluster_is_enabled() throws Exception { Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.CLUSTER_SEARCH_HOSTS, "1.2.3.4:9000,1.2.3.5:8080"); + props.set(CLUSTER_SEARCH_HOSTS, "1.2.3.4:9000,1.2.3.5:8080"); Map<String, String> settings = new EsSettings(props, new EsFileSystem(props)).build(); assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080"); @@ -246,7 +249,7 @@ public class EsSettingsTest { Props props = new Props(new Properties()); ProcessProperties.completeDefaults(props); props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.CLUSTER_ENABLED, Boolean.toString(cluster)); + props.set(ClusterProperties.CLUSTER_ENABLED, Boolean.toString(cluster)); return props; } } |