From 0d049321178a98f46a1739f1c2817098064f1475 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Thu, 21 Sep 2017 09:53:43 +0200 Subject: [PATCH] SONAR-9802 Fix quality flaws --- .../container/ComputeEngineContainerImpl.java | 6 ++--- .../ComputeEngineContainerImplTest.java | 6 ++--- .../org/sonar/application/AppStateImpl.java | 4 ++-- .../cluster/ClusterAppStateImpl.java | 11 ++++++---- .../config/AppSettingsLoaderImpl.java | 4 ++-- .../application/AppStateFactoryTest.java | 4 ++-- .../org/sonar/application/TestAppState.java | 4 ++-- .../cluster/ClusterAppStateImplTest.java | 4 ++-- .../config/ClusterSettingsLoopbackTest.java | 3 ++- .../config/ClusterSettingsTest.java | 3 ++- .../java/org/sonar/process/NetworkUtils.java | 1 - .../org/sonar/process/NetworkUtilsImpl.java | 1 + .../org/sonar/process/ProcessProperties.java | 2 +- .../process/cluster/hz/DistributedAnswer.java | 6 +++-- .../process/cluster/hz/HazelcastMember.java | 22 ++++++++++++++----- .../cluster/hz/HazelcastMemberBuilder.java | 12 +++++----- .../cluster/hz/HazelcastMemberSelectors.java | 3 ++- .../process/cluster/hz/HazelcastObjects.java | 3 --- .../cluster/hz/DistributedAnswerTest.java | 3 ++- .../hz/HazelcastMemberBuilderTest.java | 4 ++-- .../cluster/hz/HazelcastMemberImplTest.java | 8 +++---- .../hz/HazelcastMemberSelectorsTest.java | 12 +++++----- .../sonar/server/platform/ServerLogging.java | 8 +++---- .../monitoring/OfficialDistribution.java | 10 ++++----- .../cluster/AppNodesInfoLoaderImpl.java | 7 ++++-- .../cluster/ProcessInfoProvider.java | 8 +++---- .../platformlevel/PlatformLevel1.java | 4 ++-- .../sonar/server/app/EmbeddedTomcatTest.java | 4 ++-- .../cluster/StartableHazelcastMemberTest.java | 3 ++- .../platform/db/EmbeddedDatabaseTest.java | 8 +++---- .../monitoring/OfficialDistributionTest.java | 10 ++++----- .../java/org/sonarqube/tests/Byteman.java | 4 ++-- .../settings/ElasticsearchSettingsTest.java | 4 ++-- 33 files changed, 108 insertions(+), 88 deletions(-) diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index b62dca5b430..c5e45edfa25 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -73,7 +73,7 @@ import org.sonar.db.DatabaseChecker; import org.sonar.db.DbClient; import org.sonar.db.DefaultDatabase; import org.sonar.db.purge.PurgeProfiler; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import org.sonar.process.logging.LogbackHelper; @@ -127,8 +127,8 @@ import org.sonar.server.platform.WebServerImpl; import org.sonar.server.platform.db.migration.MigrationConfigurationModule; import org.sonar.server.platform.db.migration.version.DatabaseVersion; import org.sonar.server.platform.monitoring.DatabaseSection; -import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider; import org.sonar.server.platform.monitoring.cluster.LoggingSection; +import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider; import org.sonar.server.plugins.InstalledPluginReferentialFactory; import org.sonar.server.plugins.ServerExtensionInstaller; import org.sonar.server.plugins.privileged.PrivilegedPluginsBootstraper; @@ -238,7 +238,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.COMPUTE_ENGINE), CeProcessLogging.class, UuidFactoryImpl.INSTANCE, - NetworkUtils.INSTANCE, + NetworkUtilsImpl.INSTANCE, WebServerImpl.class, LogbackHelper.class, DefaultDatabase.class, diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 4cf1cac4434..c10b6f94c6d 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -42,7 +42,7 @@ import org.sonar.ce.CeDistributedInformationImpl; import org.sonar.ce.StandaloneCeDistributedInformation; import org.sonar.db.DbTester; import org.sonar.db.property.PropertyDto; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; @@ -87,7 +87,7 @@ public class ComputeEngineContainerImplTest { @Test public void real_start_with_cluster() throws IOException { - Optional localhost = NetworkUtils.INSTANCE.getLocalNonLoopbackIpv4Address(); + Optional localhost = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address(); // test is ignored if offline assumeThat(localhost.isPresent(), CoreMatchers.is(true)); @@ -96,7 +96,7 @@ public class ComputeEngineContainerImplTest { properties.setProperty(CLUSTER_ENABLED, "true"); properties.setProperty(CLUSTER_NODE_TYPE, "application"); properties.setProperty(CLUSTER_NODE_HOST, localhost.get().getHostAddress()); - properties.setProperty(CLUSTER_NODE_PORT, "" + NetworkUtils.INSTANCE.getNextAvailablePort(localhost.get())); + properties.setProperty(CLUSTER_NODE_PORT, "" + NetworkUtilsImpl.INSTANCE.getNextAvailablePort(localhost.get())); // required persisted properties insertProperty(CoreProperties.SERVER_ID, "a_startup_id"); 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 942abe0bc8a..d1f3936a6da 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 @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; public class AppStateImpl implements AppState { @@ -74,7 +74,7 @@ public class AppStateImpl implements AppState { @Override public Optional getLeaderHostName() { - return Optional.of(NetworkUtils.INSTANCE.getHostname()); + return Optional.of(NetworkUtilsImpl.INSTANCE.getHostname()); } @Override diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java index 3c23a5501eb..2876b2eccbc 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterAppStateImpl.java @@ -45,12 +45,15 @@ import org.sonar.application.cluster.health.SearchNodeHealthProvider; import org.sonar.application.config.AppSettings; import org.sonar.application.config.ClusterSettings; import org.sonar.process.MessageException; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.cluster.NodeType; import org.sonar.process.cluster.hz.HazelcastMember; import static java.lang.String.format; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.HOSTNAME; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.IP_ADDRESSES; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_TYPE; import static org.sonar.process.cluster.hz.HazelcastObjects.CLUSTER_NAME; import static org.sonar.process.cluster.hz.HazelcastObjects.LEADER; import static org.sonar.process.cluster.hz.HazelcastObjects.OPERATIONAL_PROCESSES; @@ -77,7 +80,7 @@ public class ClusterAppStateImpl implements ClusterAppState { nodeDisconnectedListenerUUID = hzMember.getCluster().addMembershipListener(new NodeDisconnectedListener()); if (ClusterSettings.isLocalElasticsearchEnabled(settings)) { - this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtils.INSTANCE)); + this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtilsImpl.INSTANCE)); this.healthStateSharing.start(); } } @@ -187,7 +190,7 @@ public class ClusterAppStateImpl implements ClusterAppState { Optional leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst(); if (leader.isPresent()) { return Optional.of( - format("%s (%s)", leader.get().getStringAttribute(HazelcastMember.Attribute.HOSTNAME), leader.get().getStringAttribute(HazelcastMember.Attribute.IP_ADDRESSES))); + format("%s (%s)", leader.get().getStringAttribute(HOSTNAME.getKey()), leader.get().getStringAttribute(IP_ADDRESSES.getKey()))); } } return Optional.empty(); @@ -278,7 +281,7 @@ public class ClusterAppStateImpl implements ClusterAppState { } private boolean isAppNode(Member member) { - return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(HazelcastMember.Attribute.NODE_TYPE)); + return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(NODE_TYPE.getKey())); } private void removeOperationalProcess(String uuid) { diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java b/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java index 801e61410ac..006c512b7bc 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java @@ -30,7 +30,7 @@ import java.util.Properties; import java.util.function.Consumer; import org.slf4j.LoggerFactory; import org.sonar.process.ConfigurationUtils; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; @@ -44,7 +44,7 @@ public class AppSettingsLoaderImpl implements AppSettingsLoader { public AppSettingsLoaderImpl(String[] cliArguments) { this(cliArguments, detectHomeDir(), - new FileSystemSettings(), new JdbcSettings(), new ClusterSettings(NetworkUtils.INSTANCE)); + new FileSystemSettings(), new JdbcSettings(), new ClusterSettings(NetworkUtilsImpl.INSTANCE)); } AppSettingsLoaderImpl(String[] cliArguments, File homeDir, Consumer... consumers) { diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java index 8919ed84c75..86080ff87da 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java @@ -25,7 +25,7 @@ import org.hamcrest.CoreMatchers; import org.junit.Test; import org.sonar.application.cluster.ClusterAppStateImpl; import org.sonar.application.config.TestAppSettings; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeThat; @@ -42,7 +42,7 @@ public class AppStateFactoryTest { @Test public void create_cluster_implementation_if_cluster_is_enabled() { - Optional ip = NetworkUtils.INSTANCE.getLocalNonLoopbackIpv4Address(); + Optional ip = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address(); assumeThat(ip.isPresent(), CoreMatchers.is(true)); settings.set(CLUSTER_ENABLED, "true"); 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 ee6e3e9cfa1..b0b94642619 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 @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; public class TestAppState implements AppState { @@ -84,7 +84,7 @@ public class TestAppState implements AppState { @Override public Optional getLeaderHostName() { - return Optional.of(NetworkUtils.INSTANCE.getHostname()); + return Optional.of(NetworkUtilsImpl.INSTANCE.getHostname()); } @Override diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java index bf93a7b88c5..ba85353df39 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java @@ -29,7 +29,7 @@ import org.junit.rules.Timeout; import org.sonar.application.AppStateListener; import org.sonar.application.config.TestAppSettings; import org.sonar.process.MessageException; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.cluster.NodeType; import org.sonar.process.cluster.hz.HazelcastMember; @@ -143,7 +143,7 @@ public class ClusterAppStateImplTest { .setProcessId(ProcessId.COMPUTE_ENGINE) .setClusterName("foo") .setNodeName("bar") - .setPort(NetworkUtils.INSTANCE.getNextAvailablePort(loopback)) + .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback)) .setNetworkInterface(loopback.getHostAddress()) .build(); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java index 245b935d5a8..4895083944c 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java @@ -30,6 +30,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.process.MessageException; import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessProperties; import static org.junit.Assume.assumeThat; @@ -49,7 +50,7 @@ public class ClusterSettingsLoopbackTest { private InetAddress loopback = InetAddress.getLoopbackAddress(); private InetAddress nonLoopbackLocal; - private NetworkUtils network = spy(NetworkUtils.INSTANCE); + private NetworkUtils network = spy(NetworkUtilsImpl.INSTANCE); @Before public void setUp() throws Exception { diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java index f3f528da701..c7088c507ec 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.process.MessageException; import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -49,7 +50,7 @@ public class ClusterSettingsTest { public ExpectedException expectedException = ExpectedException.none(); private InetAddress nonLoopbackLocal = InetAddress.getLoopbackAddress(); - private NetworkUtils network = spy(NetworkUtils.INSTANCE); + private NetworkUtils network = spy(NetworkUtilsImpl.INSTANCE); @Before public void setUp() throws Exception { diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java index 7d4fc4d51f3..234b930d241 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java +++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java @@ -27,7 +27,6 @@ import java.util.Optional; import java.util.function.Predicate; public interface NetworkUtils { - NetworkUtils INSTANCE = new NetworkUtilsImpl(); int getNextAvailablePort(InetAddress address); diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java index 9da928a7c9d..3f7d6892f35 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java +++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java @@ -40,6 +40,7 @@ import static org.apache.commons.lang.StringUtils.isBlank; public class NetworkUtilsImpl implements NetworkUtils { + public static final NetworkUtils INSTANCE = new NetworkUtilsImpl(); private static final Set PORTS_ALREADY_ALLOCATED = new HashSet<>(); private static final int PORT_MAX_TRIES = 50; diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java index 5d90670108a..012474d50d7 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java @@ -135,7 +135,7 @@ public class ProcessProperties { if ("0".equals(port)) { String address = props.nonNullValue(addressPropertyKey); try { - props.set(portPropertyKey, String.valueOf(NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getByName(address)))); + props.set(portPropertyKey, String.valueOf(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getByName(address)))); } catch (UnknownHostException e) { throw new IllegalStateException("Cannot resolve address [" + address + "] set by property [" + addressPropertyKey + "]", e); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java index f5a0bc920c8..526b17ee183 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedAnswer.java @@ -30,6 +30,8 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME; + /** * Answer of {@link DistributedCall}, aggregating the answers from * all the target members. @@ -75,7 +77,7 @@ public class DistributedAnswer { public void propagateExceptions() { if (!failedMembers.isEmpty()) { String failedMemberNames = failedMembers.keySet().stream() - .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)) + .map(m -> m.getStringAttribute(NODE_NAME.getKey())) .collect(Collectors.joining(", ")); throw new IllegalStateException("Distributed cluster action in cluster nodes " + failedMemberNames + " (other nodes may have timed out)", failedMembers.values().iterator().next()); @@ -83,7 +85,7 @@ public class DistributedAnswer { if (!timedOutMembers.isEmpty()) { String timedOutMemberNames = timedOutMembers.stream() - .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)) + .map(m -> m.getStringAttribute(NODE_NAME.getKey())) .collect(Collectors.joining(", ")); throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java index 0a70741d020..d2e081d4443 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java @@ -31,28 +31,38 @@ import org.sonar.process.cluster.NodeType; public interface HazelcastMember extends AutoCloseable { - interface Attribute { + enum Attribute { /** * The key of the hostname attribute of a member */ - String HOSTNAME = "HOSTNAME"; + HOSTNAME("HOSTNAME"), /** * The key of the ips list attribute of a member */ - String IP_ADDRESSES = "IP_ADDRESSES"; + IP_ADDRESSES("IP_ADDRESSES"), /** * The key of the node name attribute of a member */ - String NODE_NAME = "NODE_NAME"; + NODE_NAME("NODE_NAME"), /** * The role of the sonar-application inside the SonarQube cluster * {@link NodeType} */ - String NODE_TYPE = "NODE_TYPE"; + NODE_TYPE("NODE_TYPE"), /** * Key of process as defined by {@link ProcessId#getKey()} */ - String PROCESS_KEY = "PROCESS_KEY"; + PROCESS_KEY("PROCESS_KEY"); + + private final String key; + + Attribute(String key) { + this.key = key; + } + + public String getKey() { + return key; + } } IAtomicReference getAtomicReference(String name); diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java index 806b0d7cf8e..55a5dd0a4ed 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberBuilder.java @@ -29,7 +29,7 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import javax.annotation.CheckForNull; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; import org.sonar.process.cluster.NodeType; @@ -130,11 +130,11 @@ public class HazelcastMemberBuilder { .setProperty("hazelcast.logging.type", "slf4j"); MemberAttributeConfig attributes = config.getMemberAttributeConfig(); - attributes.setStringAttribute(Attribute.HOSTNAME, NetworkUtils.INSTANCE.getHostname()); - attributes.setStringAttribute(Attribute.IP_ADDRESSES, NetworkUtils.INSTANCE.getIPAddresses()); - attributes.setStringAttribute(Attribute.NODE_NAME, requireNonNull(nodeName, "Node name is missing")); - attributes.setStringAttribute(Attribute.NODE_TYPE, requireNonNull(nodeType, "Node type is missing").getValue()); - attributes.setStringAttribute(Attribute.PROCESS_KEY, requireNonNull(processId, "Process key is missing").getKey()); + attributes.setStringAttribute(Attribute.HOSTNAME.getKey(), NetworkUtilsImpl.INSTANCE.getHostname()); + attributes.setStringAttribute(Attribute.IP_ADDRESSES.getKey(), NetworkUtilsImpl.INSTANCE.getIPAddresses()); + attributes.setStringAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing")); + attributes.setStringAttribute(Attribute.NODE_TYPE.getKey(), requireNonNull(nodeType, "Node type is missing").getValue()); + attributes.setStringAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey()); return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config)); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java index 3b7abe59f89..222ea28e7f9 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberSelectors.java @@ -25,6 +25,7 @@ import org.sonar.process.ProcessId; import static java.util.Arrays.asList; import static org.sonar.process.ProcessId.fromKey; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY; public class HazelcastMemberSelectors { @@ -34,7 +35,7 @@ public class HazelcastMemberSelectors { public static MemberSelector selectorForProcessIds(ProcessId... processIds) { List processIdList = asList(processIds); return member -> { - ProcessId memberProcessId = fromKey(member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY)); + ProcessId memberProcessId = fromKey(member.getStringAttribute(PROCESS_KEY.getKey())); return processIdList.contains(memberProcessId); }; } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java index 97e5952b8d7..ddcf39bc126 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastObjects.java @@ -20,9 +20,6 @@ package org.sonar.process.cluster.hz; -import org.sonar.process.ProcessId; -import org.sonar.process.cluster.NodeType; - /** * This class holds all object keys accessible via Hazelcast */ diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java index 2cdf3d5dd75..5b45fc8a6a8 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/DistributedAnswerTest.java @@ -28,6 +28,7 @@ import org.junit.rules.ExpectedException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME; public class DistributedAnswerTest { @@ -133,7 +134,7 @@ public class DistributedAnswerTest { private static Member newMember(String uuid) { Member member = mock(Member.class); when(member.getUuid()).thenReturn(uuid); - when(member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)).thenReturn(uuid); + when(member.getStringAttribute(NODE_NAME.getKey())).thenReturn(uuid); return member; } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java index 9316ad6d3e0..6a4973b8d13 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberBuilderTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; import org.sonar.process.cluster.NodeType; @@ -49,7 +49,7 @@ public class HazelcastMemberBuilderTest { .setProcessId(ProcessId.COMPUTE_ENGINE) .setClusterName("foo") .setNodeName("bar") - .setPort(NetworkUtils.INSTANCE.getNextAvailablePort(loopback)) + .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback)) .setNetworkInterface(loopback.getHostAddress()) .build(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java index 72087914a8e..4d83a82f233 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberImplTest.java @@ -35,7 +35,7 @@ import org.junit.rules.DisableOnDebug; import org.junit.rules.ExpectedException; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.ProcessId; import org.sonar.process.cluster.NodeType; @@ -56,9 +56,9 @@ public class HazelcastMemberImplTest { @BeforeClass public static void setUp() throws Exception { - int port1 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback); - int port2 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback); - int port3 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback); + int port1 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback); + int port2 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback); + int port3 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback); member1 = newHzMember(port1, port2, port3); member2 = newHzMember(port2, port1, port3); member3 = newHzMember(port3, port1, port2); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java index 309e3463a32..ce5c36de367 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/hz/HazelcastMemberSelectorsTest.java @@ -38,13 +38,13 @@ public class HazelcastMemberSelectorsTest { Member member = mock(Member.class); MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE); - when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey()); + when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey()); assertThat(underTest.select(member)).isTrue(); - when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey()); + when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey()); assertThat(underTest.select(member)).isFalse(); - when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey()); + when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey()); assertThat(underTest.select(member)).isFalse(); } @@ -53,13 +53,13 @@ public class HazelcastMemberSelectorsTest { Member member = mock(Member.class); MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP); - when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey()); + when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey()); assertThat(underTest.select(member)).isFalse(); - when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey()); + when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey()); assertThat(underTest.select(member)).isTrue(); - when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey()); + when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey()); assertThat(underTest.select(member)).isTrue(); } } \ No newline at end of file diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java index c7da8f50085..5075fff884c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerLogging.java @@ -42,7 +42,7 @@ import static org.sonar.api.utils.log.LoggerLevel.TRACE; public class ServerLogging implements Startable { /** Used for Hazelcast's distributed queries in cluster mode */ - private static ServerLogging INSTANCE; + private static ServerLogging instance; private final LogbackHelper helper; private final Configuration config; private final ServerProcessLogging serverProcessLogging; @@ -62,16 +62,16 @@ public class ServerLogging implements Startable { @Override public void start() { - INSTANCE = this; + instance = this; } @Override public void stop() { - INSTANCE = null; + instance = null; } public static void changeLevelFromHazelcastDistributedQuery(LoggerLevel level) { - INSTANCE.changeLevel(level); + instance.changeLevel(level); } public void changeLevel(LoggerLevel level) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/OfficialDistribution.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/OfficialDistribution.java index 4120fcda0f4..5d90aadf749 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/OfficialDistribution.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/OfficialDistribution.java @@ -20,23 +20,23 @@ package org.sonar.server.platform.monitoring; import java.io.File; -import org.sonar.api.platform.Server; import org.sonar.api.server.ServerSide; +import org.sonar.server.platform.ServerFileSystem; @ServerSide public class OfficialDistribution { static final String BRANDING_FILE_PATH = "web/WEB-INF/classes/com/sonarsource/branding"; - private final Server server; + private final ServerFileSystem serverFileSystem; - public OfficialDistribution(Server server) { - this.server = server; + public OfficialDistribution(ServerFileSystem serverFileSystem) { + this.serverFileSystem = serverFileSystem; } public boolean check() { // the dependency com.sonarsource:sonarsource-branding is shaded to webapp // during release (see sonar-web pom) - File brandingFile = new File(server.getRootDir(), BRANDING_FILE_PATH); + File brandingFile = new File(serverFileSystem.getHomeDir(), BRANDING_FILE_PATH); // no need to check that the file exists. java.io.File#length() returns zero in this case. return brandingFile.length() > 0L; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java index 67c943028f0..bb545a764eb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java @@ -31,6 +31,9 @@ import org.sonar.process.cluster.hz.DistributedAnswer; import org.sonar.process.cluster.hz.HazelcastMember; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME; +import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY; + @ServerSide public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader { @@ -45,7 +48,7 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader { Map nodesByName = new HashMap<>(); DistributedAnswer distributedAnswer = hzMember.call(ProcessInfoProvider::provide, new CeWebMemberSelector(), 15_000L); for (Member member : distributedAnswer.getMembers()) { - String nodeName = member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME); + String nodeName = member.getStringAttribute(NODE_NAME.getKey()); NodeInfo nodeInfo = nodesByName.get(nodeName); if (nodeInfo == null) { nodeInfo = new NodeInfo(nodeName); @@ -76,7 +79,7 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader { private static class CeWebMemberSelector implements MemberSelector { @Override public boolean select(Member member) { - String processKey = member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY); + String processKey = member.getStringAttribute(PROCESS_KEY.getKey()); return processKey.equals(ProcessId.WEB_SERVER.getKey()) || processKey.equals(ProcessId.COMPUTE_ENGINE.getKey()); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/ProcessInfoProvider.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/ProcessInfoProvider.java index 3f4350c6619..a2f106b5a4f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/ProcessInfoProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/ProcessInfoProvider.java @@ -34,7 +34,7 @@ import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; public class ProcessInfoProvider implements Startable { /** Used for Hazelcast's distributed queries in cluster mode */ - private static ProcessInfoProvider INSTANCE; + private static ProcessInfoProvider instance; private final List sections; public ProcessInfoProvider(SystemInfoSection[] sections) { @@ -45,17 +45,17 @@ public class ProcessInfoProvider implements Startable { @Override public void start() { - INSTANCE = this; + instance = this; } @Override public void stop() { - INSTANCE = null; + instance = null; } public static ProtobufSystemInfo.SystemInfo provide() { ProtobufSystemInfo.SystemInfo.Builder protobuf = ProtobufSystemInfo.SystemInfo.newBuilder(); - INSTANCE.sections.forEach(section -> protobuf.addSections(section.toProtobuf())); + instance.sections.forEach(section -> protobuf.addSections(section.toProtobuf())); return protobuf.build(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index 56e31290229..87bfb90d1e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -22,7 +22,6 @@ package org.sonar.server.platform.platformlevel; import java.time.Clock; import java.util.Properties; import javax.annotation.Nullable; -import org.sonar.process.NetworkUtils; import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarQubeVersion; import org.sonar.api.internal.ApiVersion; @@ -40,6 +39,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DefaultDatabase; import org.sonar.db.purge.PurgeProfiler; import org.sonar.db.semaphore.SemaphoresImpl; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.logging.LogbackHelper; import org.sonar.server.app.ProcessCommandWrapperImpl; import org.sonar.server.app.RestartFlagHolderImpl; @@ -86,7 +86,7 @@ public class PlatformLevel1 extends PlatformLevel { ProcessCommandWrapperImpl.class, RestartFlagHolderImpl.class, UuidFactoryImpl.INSTANCE, - NetworkUtils.INSTANCE, + NetworkUtilsImpl.INSTANCE, UrlSettings.class, EmbeddedDatabaseFactory.class, LogbackHelper.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java index 2840cba3b45..5162e13d240 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java @@ -28,7 +28,7 @@ import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; @@ -55,7 +55,7 @@ public class EmbeddedTomcatTest { // start server on a random port InetAddress address = InetAddress.getLoopbackAddress(); - int httpPort = NetworkUtils.INSTANCE.getNextAvailablePort(address); + int httpPort = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(address); props.set("sonar.web.host", address.getHostAddress()); props.set("sonar.web.port", String.valueOf(httpPort)); EmbeddedTomcat tomcat = new EmbeddedTomcat(props); diff --git a/server/sonar-server/src/test/java/org/sonar/server/cluster/StartableHazelcastMemberTest.java b/server/sonar-server/src/test/java/org/sonar/server/cluster/StartableHazelcastMemberTest.java index 475079444ec..84e82d23386 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/cluster/StartableHazelcastMemberTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/cluster/StartableHazelcastMemberTest.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.config.internal.MapSettings; import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -45,7 +46,7 @@ public class StartableHazelcastMemberTest { @Test public void start_initializes_hazelcast() { completeValidSettings(); - StartableHazelcastMember underTest = new StartableHazelcastMember(settings.asConfig(), NetworkUtils.INSTANCE); + StartableHazelcastMember underTest = new StartableHazelcastMember(settings.asConfig(), NetworkUtilsImpl.INSTANCE); verifyStopped(underTest); underTest.start(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java index 416524560f1..5306c9d4051 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java @@ -34,7 +34,7 @@ import org.junit.rules.Timeout; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.System2; import org.sonar.api.utils.log.LogTester; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import static junit.framework.Assert.fail; import static org.mockito.Mockito.mock; @@ -113,7 +113,7 @@ public class EmbeddedDatabaseTest { @Test public void start_ignores_URL_to_create_database_and_uses_default_username_and_password_when_then_are_not_set() throws IOException { - int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); + int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); settings .setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath()) .setProperty(PROP_URL, "jdbc url") @@ -126,7 +126,7 @@ public class EmbeddedDatabaseTest { @Test public void start_creates_db_and_adds_tcp_listener() throws IOException { - int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); + int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); settings .setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath()) .setProperty(PROP_URL, "jdbc url") @@ -144,7 +144,7 @@ public class EmbeddedDatabaseTest { @Test public void start_supports_in_memory_H2_JDBC_URL() throws IOException { - int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); + int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); settings .setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath()) .setProperty(PROP_URL, "jdbc:h2:mem:sonar") diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/OfficialDistributionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/OfficialDistributionTest.java index 3f6a1cdb80a..dc68af71716 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/OfficialDistributionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/OfficialDistributionTest.java @@ -24,7 +24,7 @@ import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.platform.Server; +import org.sonar.server.platform.ServerFileSystem; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -36,14 +36,14 @@ public class OfficialDistributionTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - private Server server = mock(Server.class); - private OfficialDistribution underTest = new OfficialDistribution(server); + private ServerFileSystem serverFileSystem = mock(ServerFileSystem.class); + private OfficialDistribution underTest = new OfficialDistribution(serverFileSystem); @Test public void official_distribution() throws Exception { File rootDir = temp.newFolder(); FileUtils.write(new File(rootDir, OfficialDistribution.BRANDING_FILE_PATH), "1.2"); - when(server.getRootDir()).thenReturn(rootDir); + when(serverFileSystem.getHomeDir()).thenReturn(rootDir); assertThat(underTest.check()).isTrue(); } @@ -52,7 +52,7 @@ public class OfficialDistributionTest { public void not_an_official_distribution() throws Exception { File rootDir = temp.newFolder(); // branding file is missing - when(server.getRootDir()).thenReturn(rootDir); + when(serverFileSystem.getHomeDir()).thenReturn(rootDir); assertThat(underTest.check()).isFalse(); } diff --git a/tests/src/test/java/org/sonarqube/tests/Byteman.java b/tests/src/test/java/org/sonarqube/tests/Byteman.java index 23a0b0161c8..2e84c5aa1a9 100644 --- a/tests/src/test/java/org/sonarqube/tests/Byteman.java +++ b/tests/src/test/java/org/sonarqube/tests/Byteman.java @@ -24,7 +24,7 @@ import java.io.File; import java.net.InetAddress; import java.util.Collections; import org.jboss.byteman.agent.submit.Submit; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import static java.lang.String.format; @@ -50,7 +50,7 @@ public class Byteman { public Byteman(OrchestratorBuilder builder, Process process) { this.builder = builder; String jar = findBytemanJar(); - port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); + port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); String bytemanArg = format("-javaagent:%s=boot:%s,port:%d", jar, jar, port); builder.setServerProperty(process.argument, bytemanArg); } diff --git a/tests/src/test/java/org/sonarqube/tests/settings/ElasticsearchSettingsTest.java b/tests/src/test/java/org/sonarqube/tests/settings/ElasticsearchSettingsTest.java index 0c046076021..7a2bb9eec16 100644 --- a/tests/src/test/java/org/sonarqube/tests/settings/ElasticsearchSettingsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/settings/ElasticsearchSettingsTest.java @@ -25,7 +25,7 @@ import com.sonar.orchestrator.http.HttpResponse; import java.net.InetAddress; import okhttp3.HttpUrl; import org.junit.Test; -import org.sonar.process.NetworkUtils; +import org.sonar.process.NetworkUtilsImpl; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +33,7 @@ public class ElasticsearchSettingsTest { @Test public void set_http_port_through_sonar_properties() throws Exception { - int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); + int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress()); Orchestrator orchestrator = Orchestrator .builderEnv() .setServerProperty("sonar.search.httpPort", "" + port) -- 2.39.5