aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process-monitor/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-process-monitor/src')
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaCommand.java39
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java41
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JmxConnector.java44
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java62
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/PingerThread.java60
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java79
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/RmiJmxConnector.java145
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java4
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java23
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Timeouts.java75
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/WatcherThread.java12
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/CallVerifierJmxConnector.java34
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/ImpossibleToConnectJmxConnector.java42
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaCommandTest.java17
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java3
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java106
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/RmiJmxConnectorTest.java71
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TerminationFailureRmiConnector.java27
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TimeoutsTest.java16
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java2
20 files changed, 109 insertions, 793 deletions
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaCommand.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaCommand.java
index e950c92c58c..7920581a5a2 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaCommand.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaCommand.java
@@ -37,9 +37,6 @@ public class JavaCommand {
private File workDir;
- // any available port by default
- private int jmxPort = -1;
-
// for example -Xmx1G
private final List<String> javaOptions = new ArrayList<String>();
@@ -54,6 +51,8 @@ public class JavaCommand {
private final Map<String, String> envVariables = new HashMap<String, String>(System.getenv());
+ private File tempDir = null;
+
public JavaCommand(String key) {
this.key = key;
}
@@ -71,24 +70,20 @@ public class JavaCommand {
return this;
}
- /**
- * Shortcut to set the java option -Djava.io.tmpdir
- */
- public JavaCommand setTempDir(File tempDir) {
- this.javaOptions.add("-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
- return this;
+ public File getTempDir() {
+ return tempDir;
}
- public int getJmxPort() {
- return jmxPort;
+ public JavaCommand setTempDir(File tempDir) {
+ this.tempDir = tempDir;
+ return this;
}
- /**
- * Current mandatory to be set
- */
- public JavaCommand setJmxPort(int jmxPort) {
- this.jmxPort = jmxPort;
- return this;
+ public File getReadyFile() {
+ if (tempDir == null) {
+ throw new IllegalStateException("Temp directory not set");
+ }
+ return new File(tempDir, key + ".ready");
}
public List<String> getJavaOptions() {
@@ -156,20 +151,10 @@ public class JavaCommand {
return this;
}
- public boolean isDebugMode() {
- for (String javaOption : javaOptions) {
- if (javaOption.contains("-agentlib:jdwp")) {
- return true;
- }
- }
- return false;
- }
-
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("JavaCommand{");
sb.append("workDir=").append(workDir);
- sb.append(", jmxPort=").append(jmxPort);
sb.append(", javaOptions=").append(javaOptions);
sb.append(", className='").append(className).append('\'');
sb.append(", classpath=").append(classpath);
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 ff8ef88e8f7..0fa33bc9c37 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,9 +21,9 @@ package org.sonar.process.monitor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
-import org.sonar.process.LoopbackAddress;
import org.sonar.process.ProcessEntryPoint;
import org.sonar.process.ProcessUtils;
+import org.sonar.process.SharedStatus;
import java.io.File;
import java.io.FileOutputStream;
@@ -44,20 +44,27 @@ public class JavaProcessLauncher {
ProcessRef launch(JavaCommand command) {
Process process = null;
try {
+ // cleanup existing monitor file. Child process creates it when ready.
+ // TODO fail if impossible to delete
+ SharedStatus sharedStatus = new SharedStatus(command.getReadyFile());
+ sharedStatus.prepare();
+
ProcessBuilder processBuilder = create(command);
LoggerFactory.getLogger(getClass()).info("Launch {}: {}",
command.getKey(), StringUtils.join(processBuilder.command(), " "));
+
+ long startedAt = System.currentTimeMillis();
process = processBuilder.start();
- StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), command.getKey());
StreamGobbler inputGobbler = new StreamGobbler(process.getInputStream(), command.getKey());
inputGobbler.start();
- errorGobbler.start();
- return new ProcessRef(command.getKey(), process, errorGobbler, inputGobbler);
+ ProcessRef ref = new ProcessRef(command.getKey(), sharedStatus, process, inputGobbler);
+ ref.setLaunchedAt(startedAt);
+ return ref;
} catch (Exception e) {
// just in case
- ProcessUtils.destroyQuietly(process);
+ ProcessUtils.sendKillSignal(process);
throw new IllegalStateException("Fail to launch " + command.getKey(), e);
}
}
@@ -66,17 +73,17 @@ public class JavaProcessLauncher {
List<String> commands = new ArrayList<String>();
commands.add(buildJavaPath());
commands.addAll(javaCommand.getJavaOptions());
- commands.addAll(buildJmxOptions(javaCommand));
+ // TODO warning - does it work if temp dir contains a whitespace ?
+ commands.add(String.format("-Djava.io.tmpdir=%s", javaCommand.getTempDir().getAbsolutePath()));
commands.addAll(buildClasspath(javaCommand));
commands.add(javaCommand.getClassName());
-
- // TODO warning - does it work if temp dir contains a whitespace ?
commands.add(buildPropertiesFile(javaCommand).getAbsolutePath());
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(commands);
processBuilder.directory(javaCommand.getWorkDir());
processBuilder.environment().putAll(javaCommand.getEnvVariables());
+ processBuilder.redirectErrorStream(true);
return processBuilder;
}
@@ -86,18 +93,6 @@ public class JavaProcessLauncher {
"bin" + separator + "java").getAbsolutePath();
}
- private List<String> buildJmxOptions(JavaCommand javaCommand) {
- if (javaCommand.getJmxPort() < 1) {
- throw new IllegalStateException("JMX port is not set");
- }
- return Arrays.asList(
- "-Dcom.sun.management.jmxremote",
- "-Dcom.sun.management.jmxremote.port=" + javaCommand.getJmxPort(),
- "-Dcom.sun.management.jmxremote.authenticate=false",
- "-Dcom.sun.management.jmxremote.ssl=false",
- "-Djava.rmi.server.hostname=" + LoopbackAddress.get().getHostAddress());
- }
-
private List<String> buildClasspath(JavaCommand javaCommand) {
return Arrays.asList("-cp", StringUtils.join(javaCommand.getClasspath(), System.getProperty("path.separator")));
}
@@ -105,14 +100,12 @@ public class JavaProcessLauncher {
private File buildPropertiesFile(JavaCommand javaCommand) {
File propertiesFile = null;
try {
- propertiesFile = File.createTempFile("sq-conf", "properties");
+ propertiesFile = File.createTempFile("sq-process", "properties");
Properties props = new Properties();
props.putAll(javaCommand.getArguments());
props.setProperty(ProcessEntryPoint.PROPERTY_PROCESS_KEY, javaCommand.getKey());
- props.setProperty(ProcessEntryPoint.PROPERTY_AUTOKILL_DISABLED, String.valueOf(javaCommand.isDebugMode()));
- props.setProperty(ProcessEntryPoint.PROPERTY_AUTOKILL_PING_TIMEOUT, String.valueOf(timeouts.getAutokillPingTimeout()));
- props.setProperty(ProcessEntryPoint.PROPERTY_AUTOKILL_PING_INTERVAL, String.valueOf(timeouts.getAutokillPingInterval()));
props.setProperty(ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT, String.valueOf(timeouts.getTerminationTimeout()));
+ props.setProperty(ProcessEntryPoint.PROPERTY_STATUS_PATH, javaCommand.getReadyFile().getAbsolutePath());
OutputStream out = new FileOutputStream(propertiesFile);
props.store(out, String.format("Temporary properties file for command [%s]", javaCommand.getKey()));
out.close();
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JmxConnector.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JmxConnector.java
deleted file mode 100644
index c996595ba73..00000000000
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JmxConnector.java
+++ /dev/null
@@ -1,44 +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.process.monitor;
-
-/**
- * Interactions with monitored process
- */
-public interface JmxConnector {
-
- /**
- * Throws an exception if timeout reached
- */
- void connect(JavaCommand command, ProcessRef processRef, long timeoutMs);
-
- void ping(ProcessRef process);
-
- /**
- * Throws an exception if timeout reached
- */
- boolean isReady(ProcessRef process, long timeoutMs);
-
- /**
- * Throws an exception if timeout reached
- */
- void terminate(ProcessRef process, long timeoutMs);
-
-}
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 518d2c354cd..86e47ca429e 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
@@ -21,8 +21,7 @@ package org.sonar.process.monitor;
import org.slf4j.LoggerFactory;
import org.sonar.process.Lifecycle;
-import org.sonar.process.MessageException;
-import org.sonar.process.State;
+import org.sonar.process.Lifecycle.State;
import org.sonar.process.SystemExit;
import java.util.List;
@@ -33,28 +32,23 @@ public class Monitor {
private final List<ProcessRef> processes = new CopyOnWriteArrayList<ProcessRef>();
private final TerminatorThread terminator;
private final JavaProcessLauncher launcher;
- private final JmxConnector jmxConnector;
private final Lifecycle lifecycle = new Lifecycle();
- private final Timeouts timeouts;
private final SystemExit systemExit;
private Thread shutdownHook = new Thread(new MonitorShutdownHook(), "Monitor Shutdown Hook");
- // used by awaitTermination() to block until all processes are shutdown
+ // used by awaitStop() to block until all processes are shutdown
private final List<WatcherThread> watcherThreads = new CopyOnWriteArrayList<WatcherThread>();
- Monitor(JavaProcessLauncher launcher, JmxConnector jmxConnector, Timeouts timeouts, SystemExit exit) {
+ Monitor(JavaProcessLauncher launcher, SystemExit exit) {
this.launcher = launcher;
- this.jmxConnector = jmxConnector;
- this.timeouts = timeouts;
- this.terminator = new TerminatorThread(processes, jmxConnector, timeouts);
+ this.terminator = new TerminatorThread(processes);
this.systemExit = exit;
}
public static Monitor create() {
Timeouts timeouts = new Timeouts();
- return new Monitor(new JavaProcessLauncher(timeouts), new RmiJmxConnector(),
- timeouts, new SystemExit());
+ return new Monitor(new JavaProcessLauncher(timeouts), new SystemExit());
}
/**
@@ -103,44 +97,14 @@ public class Monitor {
watcherThread.start();
watcherThreads.add(watcherThread);
- // add to list of monitored processes only when successfully connected to it
- jmxConnector.connect(command, processRef, timeouts.getJmxConnectionTimeout());
processes.add(processRef);
- // ping process on a regular basis
- processRef.setPingEnabled(!command.isDebugMode());
- if (processRef.isPingEnabled()) {
- PingerThread.startPinging(processRef, jmxConnector, timeouts);
- }
-
// wait for process to be ready (accept requests or so on)
- waitForReady(processRef);
+ processRef.waitForReady();
LoggerFactory.getLogger(getClass()).info(String.format("%s is up", processRef));
}
- private void waitForReady(ProcessRef processRef) {
- boolean ready = false;
- while (!ready) {
- if (processRef.isTerminated()) {
- throw new MessageException(String.format("%s failed to start", processRef));
- }
- try {
- ready = jmxConnector.isReady(processRef, timeouts.getMonitorIsReadyTimeout());
- } catch (Exception ignored) {
- // failed to send request, probably because RMI server is still not alive
- // trying again, as long as process is alive
- // TODO could be improved to have a STARTING timeout (to be implemented in monitor or
- // in child process ?)
- }
- try {
- Thread.sleep(300L);
- } catch (InterruptedException e) {
- throw new IllegalStateException("Interrupted while waiting for " + processRef + " to be ready", e);
- }
- }
- }
-
/**
* Blocks until all processes are terminated
*/
@@ -160,14 +124,13 @@ public class Monitor {
* Blocks until all processes are terminated.
*/
public void stop() {
- terminateAsync();
+ stopAsync();
try {
terminator.join();
} catch (InterruptedException ignored) {
- // ignore, stop blocking
+ // stop blocking and exiting
}
// safeguard if TerminatorThread is buggy
- hardKillAll();
lifecycle.tryToMoveTo(State.STOPPED);
systemExit.exit(0);
}
@@ -176,7 +139,7 @@ public class Monitor {
* Asks for processes termination and returns without blocking until termination.
* @return true if termination was requested, false if it was already being terminated
*/
- boolean terminateAsync() {
+ boolean stopAsync() {
boolean requested = false;
if (lifecycle.tryToMoveTo(State.STOPPING)) {
requested = true;
@@ -185,13 +148,6 @@ public class Monitor {
return requested;
}
- private void hardKillAll() {
- // no specific order, kill'em all!!!
- for (ProcessRef process : processes) {
- process.hardKill();
- }
- }
-
public State getState() {
return lifecycle.getState();
}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/PingerThread.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/PingerThread.java
deleted file mode 100644
index 65df8546e33..00000000000
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/PingerThread.java
+++ /dev/null
@@ -1,60 +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.process.monitor;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-/**
- * This thread pings a process - through RMI - at fixed delay
- */
-class PingerThread extends Thread {
-
- private final ProcessRef processRef;
- private final JmxConnector jmxConnector;
-
- private PingerThread(ProcessRef process, JmxConnector jmxConnector) {
- // it's important to give a name for traceability in profiling tools like visualVM
- super(String.format("Ping[%s]", process.getKey()));
- setDaemon(true);
- this.processRef = process;
- this.jmxConnector = jmxConnector;
- }
-
- @Override
- public void run() {
- if (!processRef.isTerminated() && processRef.isPingEnabled()) {
- try {
- jmxConnector.ping(processRef);
- } catch (Exception ignored) {
- // failed to ping
- }
- } else {
- interrupt();
- }
- }
-
- static void startPinging(ProcessRef processRef, JmxConnector jmxConnector, Timeouts timeouts) {
- ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
- PingerThread pinger = new PingerThread(processRef, jmxConnector);
- scheduler.scheduleAtFixedRate(pinger, 0L, timeouts.getMonitorPingInterval(), TimeUnit.MILLISECONDS);
- }
-}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
index 8d926c39d72..f49a75d79a8 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
@@ -19,21 +19,26 @@
*/
package org.sonar.process.monitor;
+import org.slf4j.LoggerFactory;
+import org.sonar.process.MessageException;
import org.sonar.process.ProcessUtils;
+import org.sonar.process.SharedStatus;
class ProcessRef {
private final String key;
+ private final SharedStatus sharedStatus;
private final Process process;
- private final StreamGobbler[] gobblers;
- private volatile boolean terminated = false;
- private volatile boolean pingEnabled = true;
+ private final StreamGobbler gobbler;
+ private long launchedAt;
+ private volatile boolean stopped = false;
- ProcessRef(String key, Process process, StreamGobbler... gobblers) {
+ ProcessRef(String key, SharedStatus sharedStatus, Process process, StreamGobbler gobbler) {
this.key = key;
+ this.sharedStatus = sharedStatus;
this.process = process;
- this.terminated = !ProcessUtils.isAlive(process);
- this.gobblers = gobblers;
+ this.stopped = !ProcessUtils.isAlive(process);
+ this.gobbler = gobbler;
}
/**
@@ -50,45 +55,53 @@ class ProcessRef {
return process;
}
- /**
- * Almost real-time status
- */
- boolean isTerminated() {
- return terminated;
+ void waitForReady() {
+ boolean ready = false;
+ while (!ready) {
+ if (isStopped()) {
+ throw new MessageException(String.format("%s failed to start", this));
+ }
+ ready = sharedStatus.wasStartedAfter(launchedAt);
+ try {
+ Thread.sleep(200L);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(String.format("Interrupted while waiting for %s to be ready", this), e);
+ }
+ }
}
- /**
- * Sending pings can be disabled when requesting for termination or when process is on debug mode (JDWP)
- */
- void setPingEnabled(boolean b) {
- this.pingEnabled = b;
+ void setLaunchedAt(long launchedAt) {
+ this.launchedAt = launchedAt;
}
- boolean isPingEnabled() {
- return pingEnabled;
+ /**
+ * Almost real-time status
+ */
+ boolean isStopped() {
+ return stopped;
}
/**
- * Destroy the process without gracefully asking it to terminate (kill -9).
- * @return true if the process was killed, false if process is already terminated
+ * Sends kill signal and awaits termination.
*/
- boolean hardKill() {
- boolean killed = false;
- terminated = true;
- pingEnabled = false;
+ void kill() {
if (ProcessUtils.isAlive(process)) {
- ProcessUtils.destroyQuietly(process);
- killed = true;
- }
- for (StreamGobbler gobbler : gobblers) {
- StreamGobbler.waitUntilFinish(gobbler);
+ LoggerFactory.getLogger(getClass()).info(String.format("%s is stopping", this));
+ ProcessUtils.sendKillSignal(process);
+ try {
+ // signal is sent, waiting for shutdown hooks to be executed
+ process.waitFor();
+ StreamGobbler.waitUntilFinish(gobbler);
+ ProcessUtils.closeStreams(process);
+ } catch (InterruptedException ignored) {
+ // can't wait for the termination of process. Let's assume it's down.
+ }
}
- ProcessUtils.closeStreams(process);
- return killed;
+ stopped = true;
}
- void setTerminated(boolean b) {
- this.terminated = b;
+ void setStopped(boolean b) {
+ this.stopped = b;
}
@Override
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/RmiJmxConnector.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/RmiJmxConnector.java
deleted file mode 100644
index 68dfc34182b..00000000000
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/RmiJmxConnector.java
+++ /dev/null
@@ -1,145 +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.process.monitor;
-
-import org.slf4j.LoggerFactory;
-import org.sonar.process.JmxUtils;
-import org.sonar.process.LoopbackAddress;
-import org.sonar.process.ProcessMXBean;
-import org.sonar.process.ProcessUtils;
-
-import javax.annotation.CheckForNull;
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-class RmiJmxConnector implements JmxConnector {
-
- static {
- /*
- * Prevents such warnings :
- *
- * WARNING: Failed to restart: java.io.IOException: Failed to get a RMI stub: javax.naming.ServiceUnavailableException [Root exception
- * is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
- * java.net.ConnectException: Connection refused]
- * Sep 11, 2014 7:32:32 PM RMIConnector RMIClientCommunicatorAdmin-doStop
- * WARNING: Failed to call the method close():java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
- * java.net.ConnectException: Connection refused
- * Sep 11, 2014 7:32:32 PM ClientCommunicatorAdmin Checker-run
- * WARNING: Failed to check connection: java.net.ConnectException: Connection refused
- * Sep 11, 2014 7:32:32 PM ClientCommunicatorAdmin Checker-run
- * WARNING: stopping
- */
- System.setProperty("sun.rmi.transport.tcp.logLevel", "SEVERE");
- }
-
- private final Map<ProcessRef, ProcessMXBean> mbeans = new IdentityHashMap<ProcessRef, ProcessMXBean>();
-
- @Override
- public synchronized void connect(final JavaCommand command, ProcessRef processRef, long timeoutMs) {
- ConnectorCallable callable = new ConnectorCallable(command, processRef.getProcess());
- ProcessMXBean mxBean = execute(callable, timeoutMs);
- if (mxBean != null) {
- register(processRef, mxBean);
- }
- }
-
- @Override
- public void ping(ProcessRef processRef) {
- mbeans.get(processRef).ping();
- }
-
- @Override
- public boolean isReady(final ProcessRef processRef, long timeoutMs) {
- return execute(new Callable<Boolean>() {
- @Override
- public Boolean call() throws Exception {
- return mbeans.get(processRef).isReady();
- }
- }, timeoutMs);
- }
-
- @Override
- public void terminate(final ProcessRef processRef, long timeoutMs) {
- execute(new Callable() {
- @Override
- public Void call() throws Exception {
- LoggerFactory.getLogger(getClass()).info("Request termination of " + processRef);
- mbeans.get(processRef).terminate();
- return null;
- }
- }, timeoutMs);
- }
-
- void register(ProcessRef processRef, ProcessMXBean mxBean) {
- mbeans.put(processRef, mxBean);
- }
-
- private <T> T execute(Callable<T> callable, long timeoutMs) {
- ExecutorService executor = Executors.newSingleThreadExecutor();
- try {
- Future<T> future = executor.submit(callable);
- return future.get(timeoutMs, TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- throw new IllegalStateException("Fail send JMX request", e);
- } finally {
- executor.shutdownNow();
- }
- }
-
- private static class ConnectorCallable implements Callable<ProcessMXBean> {
- private final JavaCommand command;
- private final Process process;
-
- private ConnectorCallable(JavaCommand command, Process process) {
- this.command = command;
- this.process = process;
- }
-
- @Override
- @CheckForNull
- public ProcessMXBean call() throws Exception {
- JMXServiceURL jmxUrl = JmxUtils.serviceUrl(LoopbackAddress.get(), command.getJmxPort());
- while (ProcessUtils.isAlive(process)) {
- try {
- JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, null);
- MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
- return JMX.newMBeanProxy(mBeanServer, JmxUtils.objectName(command.getKey()), ProcessMXBean.class);
- } catch (Exception ignored) {
- // ignored, RMI server is probably not started yet
- }
- Thread.sleep(300L);
- }
-
- // process went down, no need to connect
- return null;
- }
- }
-}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java
index cb412965f55..d5f54e33248 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java
@@ -55,8 +55,8 @@ class StreamGobbler extends Thread {
while ((line = br.readLine()) != null) {
logger.info(line);
}
- } catch (Exception e) {
- logger.error("Fail to read process logs", e);
+ } catch (Exception ignored) {
+ // ignored
} finally {
IOUtils.closeQuietly(br);
}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java
index f5b11b3148f..493be826ae7 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java
@@ -19,8 +19,6 @@
*/
package org.sonar.process.monitor;
-import org.slf4j.LoggerFactory;
-
import java.util.List;
/**
@@ -31,33 +29,18 @@ import java.util.List;
class TerminatorThread extends Thread {
private final List<ProcessRef> processes;
- private final JmxConnector jmxConnector;
- private final Timeouts timeouts;
- TerminatorThread(List<ProcessRef> processes, JmxConnector jmxConnector, Timeouts timeouts) {
+ TerminatorThread(List<ProcessRef> processes) {
super("Terminator");
this.processes = processes;
- this.jmxConnector = jmxConnector;
- this.timeouts = timeouts;
}
@Override
public void run() {
// terminate in reverse order of startup (dependency order)
for (int index = processes.size() - 1; index >= 0; index--) {
- final ProcessRef processRef = processes.get(index);
- if (!processRef.isTerminated()) {
- processRef.setPingEnabled(false);
- try {
- jmxConnector.terminate(processRef, timeouts.getTerminationTimeout());
- } catch (Exception ignored) {
- // failed to gracefully stop in a timely fashion
- LoggerFactory.getLogger(getClass()).info(String.format("Kill %s", processRef));
- } finally {
- // kill even if graceful termination was done, just to be sure that physical process is really down
- processRef.hardKill();
- }
- }
+ ProcessRef processRef = processes.get(index);
+ processRef.kill();
}
}
}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Timeouts.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Timeouts.java
index a3f7210f37f..d9b0b4f6e3e 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Timeouts.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Timeouts.java
@@ -25,81 +25,6 @@ package org.sonar.process.monitor;
class Timeouts {
private long terminationTimeout = 120000L;
- private long jmxConnectionTimeout = 15000L;
- private long monitorPingInterval = 3000L;
- private long monitorIsReadyTimeout = 10000L;
- private long autokillPingTimeout = 60000L;
- private long autokillPingInterval = 3000L;
-
- /**
- * [monitor] Timeout to get connected to RMI MXBean while process is alive
- */
- long getJmxConnectionTimeout() {
- return jmxConnectionTimeout;
- }
-
- /**
- * @see #getJmxConnectionTimeout()
- */
- void setJmxConnectionTimeout(long l) {
- this.jmxConnectionTimeout = l;
- }
-
- /**
- * [monitor] Delay between each ping request
- */
- long getMonitorPingInterval() {
- return monitorPingInterval;
- }
-
- /**
- * @see #getMonitorPingInterval()
- */
- void setMonitorPingInterval(long l) {
- this.monitorPingInterval = l;
- }
-
- /**
- * [monitor] Timeout of isReady request
- */
- long getMonitorIsReadyTimeout() {
- return monitorIsReadyTimeout;
- }
-
- /**
- * @see #getMonitorIsReadyTimeout()
- */
- void setMonitorIsReadyTimeout(long l) {
- this.monitorIsReadyTimeout = l;
- }
-
- /**
- * [monitored process] maximum age of last received ping before process autokills
- */
- long getAutokillPingTimeout() {
- return autokillPingTimeout;
- }
-
- /**
- * @see #getAutokillPingTimeout()
- */
- void setAutokillPingTimeout(long l) {
- this.autokillPingTimeout = l;
- }
-
- /**
- * [monitored process] delay between checks of freshness of received pings
- */
- long getAutokillPingInterval() {
- return autokillPingInterval;
- }
-
- /**
- * @see #getAutokillPingInterval()
- */
- void setAutokillPingInterval(long l) {
- this.autokillPingInterval = l;
- }
/**
* [both monitor and monitored process] timeout of graceful termination before hard killing
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/WatcherThread.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/WatcherThread.java
index 55880a989a7..4275b6b98a1 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/WatcherThread.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/WatcherThread.java
@@ -46,16 +46,16 @@ class WatcherThread extends Thread {
@Override
public void run() {
- boolean alive = true;
- while (alive) {
+ boolean stopped = false;
+ while (!stopped) {
try {
processRef.getProcess().waitFor();
- processRef.setTerminated(true);
- alive = false;
- LoggerFactory.getLogger(getClass()).info(String.format("%s is down", processRef));
+ processRef.setStopped(true);
+ stopped = true;
+ LoggerFactory.getLogger(getClass()).info(String.format("%s is stopped", processRef));
// terminate all other processes, but in another thread
- monitor.stop();
+ monitor.stopAsync();
} catch (InterruptedException ignored) {
// continue to watch process
}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/CallVerifierJmxConnector.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/CallVerifierJmxConnector.java
deleted file mode 100644
index 2010e19aa87..00000000000
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/CallVerifierJmxConnector.java
+++ /dev/null
@@ -1,34 +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.process.monitor;
-
-/**
- * Used to verify that pings were sent or not.
- */
-public class CallVerifierJmxConnector extends RmiJmxConnector {
-
- boolean askedPing = false;
-
- @Override
- public void ping(ProcessRef process) {
- askedPing = true;
- super.ping(process);
- }
-}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/ImpossibleToConnectJmxConnector.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/ImpossibleToConnectJmxConnector.java
deleted file mode 100644
index 055e3c8e50b..00000000000
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/ImpossibleToConnectJmxConnector.java
+++ /dev/null
@@ -1,42 +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.process.monitor;
-
-public class ImpossibleToConnectJmxConnector implements JmxConnector {
- @Override
- public void connect(JavaCommand command, ProcessRef processRef, long timeoutMs) {
- throw new IllegalStateException("Test - Impossible to connect to JMX");
- }
-
- @Override
- public void ping(ProcessRef process) {
-
- }
-
- @Override
- public boolean isReady(ProcessRef process, long timeoutMs) {
- return false;
- }
-
- @Override
- public void terminate(ProcessRef process, long timeoutMs) {
-
- }
-}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaCommandTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaCommandTest.java
index 8744fb73ff3..fbfbad11b54 100644
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaCommandTest.java
+++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaCommandTest.java
@@ -42,7 +42,6 @@ public class JavaCommandTest {
args.setProperty("second_arg", "val2");
command.setArguments(args);
- command.setJmxPort(1234);
command.setClassName("org.sonar.ElasticSearch");
command.setEnvVariable("JAVA_COMMAND_TEST", "1000");
File tempDir = temp.newFolder();
@@ -55,9 +54,9 @@ public class JavaCommandTest {
assertThat(command.toString()).isNotNull();
assertThat(command.getClasspath()).containsOnly("lib/*.jar", "conf/*.xml");
- assertThat(command.getJavaOptions()).containsOnly("-Xmx128m", "-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
+ assertThat(command.getJavaOptions()).containsOnly("-Xmx128m");
assertThat(command.getWorkDir()).isSameAs(workDir);
- assertThat(command.getJmxPort()).isEqualTo(1234);
+ assertThat(command.getTempDir()).isSameAs(tempDir);
assertThat(command.getClassName()).isEqualTo("org.sonar.ElasticSearch");
// copy current env variables
@@ -66,18 +65,6 @@ public class JavaCommandTest {
}
@Test
- public void test_debug_mode() throws Exception {
- JavaCommand command = new JavaCommand("es");
- assertThat(command.isDebugMode()).isFalse();
-
- command.addJavaOption("-Xmx512m");
- assertThat(command.isDebugMode()).isFalse();
-
- command.addJavaOption("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
- assertThat(command.isDebugMode()).isTrue();
- }
-
- @Test
public void split_java_options() throws Exception {
JavaCommand command = new JavaCommand("foo");
command.addJavaOptions("-Xmx512m -Xms256m -Dfoo");
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java
index 80a02cd39c6..80def695fb1 100644
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java
+++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java
@@ -20,7 +20,6 @@
package org.sonar.process.monitor;
import org.junit.Test;
-import org.sonar.process.NetworkUtils;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
@@ -29,7 +28,7 @@ public class JavaProcessLauncherTest {
@Test
public void fail_to_launch() throws Exception {
- JavaCommand command = new JavaCommand("test").setJmxPort(NetworkUtils.freePort());
+ JavaCommand command = new JavaCommand("test");
JavaProcessLauncher launcher = new JavaProcessLauncher(new Timeouts());
try {
// command is not correct (missing options), java.lang.ProcessBuilder#start()
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 171f5669fbc..b458254d351 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
@@ -28,7 +28,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.Timeout;
import org.sonar.process.NetworkUtils;
-import org.sonar.process.State;
+import org.sonar.process.Lifecycle.State;
import org.sonar.process.SystemExit;
import java.io.File;
@@ -159,24 +159,7 @@ public class MonitorTest {
}
@Test
- public void fail_to_connect_to_jmx() throws Exception {
- Timeouts timeouts = new Timeouts();
- monitor = new Monitor(new JavaProcessLauncher(timeouts),
- new ImpossibleToConnectJmxConnector(), timeouts, exit);
-
- HttpProcessClient p1 = new HttpProcessClient("p1");
- try {
- monitor.start(Arrays.asList(p1.newCommand()));
- fail();
- } catch (Exception e) {
- // process was correctly launched, but there was a problem with RMI
- assertThat(p1.isReady()).isFalse();
- assertThat(p1.wasGracefullyTerminated()).isFalse();
- }
- }
-
- @Test
- public void terminate_all_processes_if_monitor_shutdowns() throws Exception {
+ public void stop_all_processes_if_monitor_shutdowns() throws Exception {
monitor = newDefaultMonitor();
HttpProcessClient p1 = new HttpProcessClient("p1"), p2 = new HttpProcessClient("p2");
monitor.start(Arrays.asList(p1.newCommand(), p2.newCommand()));
@@ -192,7 +175,7 @@ public class MonitorTest {
}
@Test
- public void terminate_all_processes_if_one_monitored_process_shutdowns() throws Exception {
+ public void stop_all_processes_if_one_shutdowns() throws Exception {
monitor = newDefaultMonitor();
HttpProcessClient p1 = new HttpProcessClient("p1"), p2 = new HttpProcessClient("p2");
monitor.start(Arrays.asList(p1.newCommand(), p2.newCommand()));
@@ -210,9 +193,9 @@ public class MonitorTest {
}
@Test
- public void terminate_all_processes_if_one_fails_to_start() throws Exception {
+ public void stop_all_processes_if_one_fails_to_start() throws Exception {
monitor = newDefaultMonitor();
- HttpProcessClient p1 = new HttpProcessClient("p1"), p2 = new HttpProcessClient("p2", -1, NetworkUtils.freePort());
+ HttpProcessClient p1 = new HttpProcessClient("p1"), p2 = new HttpProcessClient("p2", -1);
try {
monitor.start(Arrays.asList(p1.newCommand(), p2.newCommand()));
fail();
@@ -226,18 +209,8 @@ public class MonitorTest {
}
@Test
- public void kill_process_if_fail_to_request_gracefully_termination() throws Exception {
- Timeouts timeouts = new Timeouts();
- timeouts.setTerminationTimeout(100L);
- monitor = new Monitor(new JavaProcessLauncher(timeouts),
- new TerminationFailureRmiConnector(), timeouts, exit);
-
- HttpProcessClient p1 = new HttpProcessClient("p1");
- monitor.start(Arrays.asList(p1.newCommand()));
- assertThat(p1.isReady()).isTrue();
-
- monitor.stop();
- assertThat(p1.isReady()).isFalse();
+ public void force_stop_if_too_long() throws Exception {
+ // TODO
}
@Test
@@ -246,7 +219,6 @@ public class MonitorTest {
JavaCommand command = new JavaCommand("test")
.addClasspath(testJar.getAbsolutePath())
.setClassName("org.sonar.process.test.Unknown")
- .setJmxPort(NetworkUtils.freePort())
.setTempDir(temp.newFolder());
try {
@@ -258,63 +230,9 @@ public class MonitorTest {
}
}
- @Test
- public void terminate_all_if_one_monitored_process_shutdowns() throws Exception {
- monitor = newDefaultMonitor();
- HttpProcessClient client = new HttpProcessClient("test");
- // blocks until started
- monitor.start(Arrays.asList(client.newCommand()));
- assertThat(client.isReady()).isTrue();
-
- client.kill();
- assertThat(client.isReady()).isFalse();
-
- // does not wait, already terminated
- monitor.awaitTermination();
-
- // TODO check logs
- }
-
- @Test
- public void fail_if_jmx_port_is_not_available() throws Exception {
- monitor = newDefaultMonitor();
- // c1 and c2 have same JMX port
- int jmxPort = NetworkUtils.freePort();
- HttpProcessClient p1 = new HttpProcessClient("p1", NetworkUtils.freePort(), jmxPort);
- HttpProcessClient p2 = new HttpProcessClient("p2", NetworkUtils.freePort(), jmxPort);
- try {
- monitor.start(Arrays.asList(p1.newCommand(), p2.newCommand()));
- fail();
- } catch (Exception expected) {
- assertThat(p1.wasReady()).isTrue();
- assertThat(p2.wasReady()).isFalse();
- assertThat(p1.isReady()).isFalse();
- assertThat(p2.isReady()).isFalse();
- }
- }
-
- @Test
- public void disable_autokill_on_jvm_debug_mode() throws Exception {
- Timeouts timeouts = new Timeouts();
- timeouts.setMonitorPingInterval(10L);
- timeouts.setAutokillPingInterval(10L);
- timeouts.setAutokillPingTimeout(10L);
- CallVerifierJmxConnector jmxConnector = new CallVerifierJmxConnector();
- monitor = new Monitor(new JavaProcessLauncher(timeouts), jmxConnector, timeouts, exit);
-
- JavaCommand command = newStandardProcessCommand()
- .addJavaOption("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + NetworkUtils.freePort());
- monitor.start(Arrays.asList(command));
-
- Thread.sleep(20L);
- assertThat(jmxConnector.askedPing).isFalse();
-
- monitor.stop();
- }
-
private Monitor newDefaultMonitor() {
Timeouts timeouts = new Timeouts();
- return new Monitor(new JavaProcessLauncher(timeouts), new RmiJmxConnector(), timeouts, exit);
+ return new Monitor(new JavaProcessLauncher(timeouts), exit);
}
/**
@@ -324,27 +242,24 @@ public class MonitorTest {
private final int httpPort;
private final String commandKey;
private final File tempDir;
- private int jmxPort;
private HttpProcessClient(String commandKey) throws IOException {
- this(commandKey, NetworkUtils.freePort(), NetworkUtils.freePort());
+ this(commandKey, NetworkUtils.freePort());
}
/**
* Use httpPort=-1 to make server fail to start
*/
- private HttpProcessClient(String commandKey, int httpPort, int jmxPort) throws IOException {
+ private HttpProcessClient(String commandKey, int httpPort) throws IOException {
this.commandKey = commandKey;
this.tempDir = temp.newFolder(commandKey);
this.httpPort = httpPort;
- this.jmxPort = jmxPort;
}
JavaCommand newCommand() throws IOException {
return new JavaCommand(commandKey)
.addClasspath(testJar.getAbsolutePath())
.setClassName("org.sonar.process.test.HttpProcess")
- .setJmxPort(jmxPort)
.setArgument("httpPort", String.valueOf(httpPort))
.setTempDir(tempDir);
}
@@ -416,7 +331,6 @@ public class MonitorTest {
return new JavaCommand("standard")
.addClasspath(testJar.getAbsolutePath())
.setClassName("org.sonar.process.test.StandardProcess")
- .setJmxPort(NetworkUtils.freePort())
.setTempDir(temp.newFolder());
}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/RmiJmxConnectorTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/RmiJmxConnectorTest.java
deleted file mode 100644
index 2289c446566..00000000000
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/RmiJmxConnectorTest.java
+++ /dev/null
@@ -1,71 +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.process.monitor;
-
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.process.NetworkUtils;
-import org.sonar.process.ProcessMXBean;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class RmiJmxConnectorTest {
-
- @Test
- public void fail_to_connect_in_timely_fashion() throws Exception {
- RmiJmxConnector connector = new RmiJmxConnector();
- ProcessRef ref = mock(ProcessRef.class);
-
- JavaCommand command = new JavaCommand("foo").setJmxPort(NetworkUtils.freePort());
- try {
- connector.connect(command, ref, 0L);
- fail();
- } catch (IllegalStateException e) {
- // ok
- }
- }
-
- @Test
- public void throw_exception_on_timeout() throws Exception {
- RmiJmxConnector connector = new RmiJmxConnector();
- ProcessRef ref = mock(ProcessRef.class);
- ProcessMXBean mxBean = mock(ProcessMXBean.class);
- connector.register(ref, mxBean);
-
- when(mxBean.isReady()).thenAnswer(new Answer<Boolean>() {
- @Override
- public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable {
- Thread.sleep(Long.MAX_VALUE);
- return null;
- }
- });
-
- try {
- connector.isReady(ref, 5L);
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Fail send JMX request");
- }
- }
-}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TerminationFailureRmiConnector.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TerminationFailureRmiConnector.java
deleted file mode 100644
index 0f9f5702666..00000000000
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TerminationFailureRmiConnector.java
+++ /dev/null
@@ -1,27 +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.process.monitor;
-
-public class TerminationFailureRmiConnector extends RmiJmxConnector {
- @Override
- public void terminate(ProcessRef processRef, long timeoutMs) {
- throw new IllegalStateException("Test - fail to send termination request");
- }
-}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TimeoutsTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TimeoutsTest.java
index 620a59929fc..dc5e63055ae 100644
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TimeoutsTest.java
+++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/TimeoutsTest.java
@@ -28,29 +28,13 @@ public class TimeoutsTest {
@Test
public void test_default_values() throws Exception {
Timeouts timeouts = new Timeouts();
- assertThat(timeouts.getMonitorPingInterval()).isGreaterThan(1000L);
- assertThat(timeouts.getAutokillPingInterval()).isGreaterThan(1000L);
- assertThat(timeouts.getAutokillPingTimeout()).isGreaterThan(1000L);
assertThat(timeouts.getTerminationTimeout()).isGreaterThan(1000L);
- assertThat(timeouts.getJmxConnectionTimeout()).isGreaterThan(1000L);
- assertThat(timeouts.getMonitorIsReadyTimeout()).isGreaterThan(1000L);
}
@Test
public void test_values() throws Exception {
Timeouts timeouts = new Timeouts();
- timeouts.setAutokillPingInterval(1L);
- timeouts.setAutokillPingTimeout(2L);
timeouts.setTerminationTimeout(3L);
- timeouts.setJmxConnectionTimeout(4L);
- timeouts.setMonitorPingInterval(5L);
- timeouts.setMonitorIsReadyTimeout(6L);
-
- assertThat(timeouts.getAutokillPingInterval()).isEqualTo(1L);
- assertThat(timeouts.getAutokillPingTimeout()).isEqualTo(2L);
assertThat(timeouts.getTerminationTimeout()).isEqualTo(3L);
- assertThat(timeouts.getJmxConnectionTimeout()).isEqualTo(4L);
- assertThat(timeouts.getMonitorPingInterval()).isEqualTo(5L);
- assertThat(timeouts.getMonitorIsReadyTimeout()).isEqualTo(6L);
}
}
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java
index 45febd53d73..2eb455f18d3 100644
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java
+++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java
@@ -34,6 +34,6 @@ public class WatcherThreadTest {
WatcherThread watcher = new WatcherThread(ref, monitor);
watcher.start();
watcher.join();
- verify(monitor).stop();
+ verify(monitor).stopAsync();
}
}