diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-05-29 11:25:01 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-05-29 11:25:01 +0200 |
commit | 0cc7aa3e7a4f3e8a3838bbbfb970aeb4775c4e9d (patch) | |
tree | 16331cc2009b399fb7632fcb3d2661b8ebe10989 /server/sonar-process-monitor | |
parent | b0f14fa5862298c7296eb9cd61f6ca3de71b3d34 (diff) | |
download | sonarqube-0cc7aa3e7a4f3e8a3838bbbfb970aeb4775c4e9d.tar.gz sonarqube-0cc7aa3e7a4f3e8a3838bbbfb970aeb4775c4e9d.zip |
Extract an interface from org.sonar.process.ProcessCommands
Try to stabilize StopWatcherTest when machine is slow or under pressure. More than 1 second could
be spent in the creation of ProcessCommands mock.
Diffstat (limited to 'server/sonar-process-monitor')
3 files changed, 14 insertions, 14 deletions
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java index 1e3ee06648e..390746bca59 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java @@ -21,6 +21,7 @@ package org.sonar.process.monitor; import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; +import org.sonar.process.DefaultProcessCommands; import org.sonar.process.ProcessCommands; import org.sonar.process.ProcessEntryPoint; import org.sonar.process.ProcessUtils; @@ -45,7 +46,7 @@ public class JavaProcessLauncher { Process process = null; try { // cleanup existing monitor files - ProcessCommands commands = new ProcessCommands(command.getTempDir(), command.getProcessIndex()); + ProcessCommands commands = new DefaultProcessCommands(command.getTempDir(), command.getProcessIndex()); ProcessBuilder processBuilder = create(command); LoggerFactory.getLogger(getClass()).info("Launch process[{}]: {}", diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java index df3d53518ee..dd0ca58ba0a 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java @@ -19,15 +19,14 @@ */ package org.sonar.process.monitor; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import org.slf4j.LoggerFactory; import org.sonar.process.Lifecycle; import org.sonar.process.Lifecycle.State; import org.sonar.process.ProcessCommands; import org.sonar.process.SystemExit; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - public class Monitor { private final List<ProcessRef> processes = new CopyOnWriteArrayList<>(); @@ -165,8 +164,8 @@ public class Monitor { } public static int getNextProcessId() { - if (nextProcessId >= ProcessCommands.getMaxProcesses()) { - throw new IllegalStateException("The maximum number of processes launched has been reached " + ProcessCommands.getMaxProcesses()); + if (nextProcessId >= ProcessCommands.MAX_PROCESSES) { + throw new IllegalStateException("The maximum number of processes launched has been reached " + ProcessCommands.MAX_PROCESSES); } return nextProcessId++; } diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java index 57e3478162c..00ae573ed6a 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java @@ -20,6 +20,11 @@ package org.sonar.process.monitor; import com.github.kevinsawicki.http.HttpRequest; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.BeforeClass; @@ -27,17 +32,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.rules.Timeout; -import org.sonar.process.NetworkUtils; import org.sonar.process.Lifecycle.State; +import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessCommands; import org.sonar.process.SystemExit; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -211,7 +210,8 @@ public class MonitorTest { @Test public void test_too_many_processes() { - while (Monitor.getNextProcessId() < ProcessCommands.getMaxProcesses() - 1) {} + while (Monitor.getNextProcessId() < ProcessCommands.MAX_PROCESSES - 1) { + } try { newDefaultMonitor(); } catch (IllegalStateException e) { |