diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-06 14:38:25 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:50 +0200 |
commit | 0d06d27d3c0f1a35384b40926e34dc0020de998d (patch) | |
tree | 1246636c4acf1d1c5d9c00de23dfada6646f17bd /server/sonar-main | |
parent | 893b3d2f8d5e5d2789cd5c954d8016742bfc18e5 (diff) | |
download | sonarqube-0d06d27d3c0f1a35384b40926e34dc0020de998d.tar.gz sonarqube-0d06d27d3c0f1a35384b40926e34dc0020de998d.zip |
SONAR-9741 make NetworkUtils an interface
to allow unit testing
Diffstat (limited to 'server/sonar-main')
4 files changed, 6 insertions, 7 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java b/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java index b571f2c19dc..1e9d9cf3580 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java @@ -74,7 +74,7 @@ public class AppStateImpl implements AppState { @Override public Optional<String> getLeaderHostName() { - return Optional.of(NetworkUtils.getHostname()); + return Optional.of(NetworkUtils.INSTANCE.getHostname()); } @Override diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java index 4769a8a1d95..cea75088e0a 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java @@ -45,6 +45,7 @@ import java.util.Map; import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.NetworkUtils; import org.sonar.application.AppStateListener; import org.sonar.process.MessageException; import org.sonar.process.NodeType; @@ -52,8 +53,6 @@ import org.sonar.process.ProcessId; import static java.lang.String.format; import static java.util.stream.Collectors.toList; -import static org.sonar.NetworkUtils.getHostname; -import static org.sonar.NetworkUtils.getIPAddresses; import static org.sonar.application.cluster.ClusterProperties.HAZELCAST_CLUSTER_NAME; import static org.sonar.cluster.ClusterObjectKeys.CLIENT_UUIDS; import static org.sonar.cluster.ClusterObjectKeys.CLUSTER_NAME; @@ -250,9 +249,9 @@ public class HazelcastCluster implements AutoCloseable { hzConfig.getMemberAttributeConfig() .setStringAttribute(NODE_NAME, clusterProperties.getNodeName()); hzConfig.getMemberAttributeConfig() - .setStringAttribute(HOSTNAME, getHostname()); + .setStringAttribute(HOSTNAME, NetworkUtils.INSTANCE.getHostname()); hzConfig.getMemberAttributeConfig() - .setStringAttribute(IP_ADDRESSES, getIPAddresses()); + .setStringAttribute(IP_ADDRESSES, NetworkUtils.INSTANCE.getIPAddresses()); hzConfig.getMemberAttributeConfig() .setStringAttribute(NODE_TYPE, clusterProperties.getNodeType().getValue()); diff --git a/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java b/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java index b590e5937d8..27f6c4d5fb0 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java +++ b/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java @@ -84,7 +84,7 @@ public class TestAppState implements AppState { @Override public Optional<String> getLeaderHostName() { - return Optional.of(NetworkUtils.getHostname()); + return Optional.of(NetworkUtils.INSTANCE.getHostname()); } @Override diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java index 4f2dfe53a2a..702359aa2ee 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java @@ -111,7 +111,7 @@ public class HazelcastClusterTest { try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { assertThat(hzCluster.tryToLockWebLeader()).isTrue(); assertThat(hzCluster.getLeaderHostName().get()).isEqualTo( - format("%s (%s)", NetworkUtils.getHostname(), NetworkUtils.getIPAddresses())); + format("%s (%s)", NetworkUtils.INSTANCE.getHostname(), NetworkUtils.INSTANCE.getIPAddresses())); } } |