diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-08-25 17:38:56 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-08-25 17:39:13 +0200 |
commit | 242b94658b9764556bf7227de40f3e34058422e9 (patch) | |
tree | 28874435a6082109c96bb1028edc6c9f6074e5b5 /server/process | |
parent | ae5852574593c9fff61567bb9526542bad0319e3 (diff) | |
download | sonarqube-242b94658b9764556bf7227de40f3e34058422e9.tar.gz sonarqube-242b94658b9764556bf7227de40f3e34058422e9.zip |
Disable process monitoring when in debug with agentlib:jdwt
Diffstat (limited to 'server/process')
-rw-r--r-- | server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java | 2 | ||||
-rw-r--r-- | server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java | 81 |
2 files changed, 58 insertions, 25 deletions
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java index 6d75bece303..4a6c3ec5e51 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java @@ -32,7 +32,7 @@ public abstract class MonitoredProcess implements ProcessMXBean { private final static Logger LOGGER = LoggerFactory.getLogger(MonitoredProcess.class); - private static final String DEBUG_AGENT = "-agentlib:jdwp"; + public static final String DEBUG_AGENT = "-agentlib:jdwp"; private static final long AUTOKILL_TIMEOUT_MS = 30000L; private static final long AUTOKILL_CHECK_DELAY_MS = 2000L; public static final String NAME_PROPERTY = "pName"; diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java index f3e4d2a78db..e8f87147654 100644 --- a/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java +++ b/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java @@ -78,18 +78,12 @@ public class MonitoredProcessTest { dummyProcess.start(); } }); - assertThat(dummyProcess.isReady()).isFalse(); - assertThat(dummyProcess.isTerminated()).isFalse(); + assertProcessNotYetRunning(dummyProcess); process.start(); Thread.sleep(100); - assertThat(dummyProcess.isReady()).isTrue(); - assertThat(dummyProcess.isTerminated()).isFalse(); - process.join(); - assertThat(dummyProcess.isReady()).isTrue(); - assertThat(dummyProcess.isTerminated()).isTrue(); - assertThat(dummyProcess.getCheckFile()).isNotNull(); - assertThat(dummyProcess.getCheckFile().getName()).isEqualTo(DummyProcess.CHECKFILE_NAME); + assertProcessRunning(dummyProcess); + assertJoinAndTerminate(dummyProcess, process); } @Test(timeout = 3000L) @@ -105,30 +99,23 @@ public class MonitoredProcessTest { dummyProcess.start(); } }); - assertThat(dummyProcess.isReady()).isFalse(); - assertThat(dummyProcess.isTerminated()).isFalse(); + assertProcessNotYetRunning(dummyProcess); process.start(); Thread.sleep(100); int count = 0; for (int i = 0; i < 3; i++) { dummyProcess.ping(); - assertThat(dummyProcess.isReady()).isTrue(); - assertThat(dummyProcess.isTerminated()).isFalse(); + assertProcessRunning(dummyProcess); Thread.sleep(300); count++; } assertThat(count).isEqualTo(3); - process.join(); - assertThat(dummyProcess.isReady()).isTrue(); - assertThat(dummyProcess.isTerminated()).isTrue(); - - assertThat(dummyProcess.getCheckFile()).isNotNull(); - assertThat(dummyProcess.getCheckFile().getName()).isEqualTo(DummyProcess.CHECKFILE_NAME); + assertJoinAndTerminate(dummyProcess, process); } @Test(timeout = 3000L) - public void monitor_explicitely_shutdown() throws Exception { + public void monitor_explicitly_shutdown() throws Exception { Properties properties = new Properties(); properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME); final DummyProcess dummyProcess = new DummyProcess(new Props(properties), true); @@ -139,17 +126,63 @@ public class MonitoredProcessTest { dummyProcess.start(); } }); - assertThat(dummyProcess.isReady()).isFalse(); - assertThat(dummyProcess.isTerminated()).isFalse(); + assertProcessNotYetRunning(dummyProcess); process.start(); Thread.sleep(100); - assertThat(dummyProcess.isReady()).isTrue(); - assertThat(dummyProcess.isTerminated()).isFalse(); + assertProcessRunning(dummyProcess); dummyProcess.terminate(); Thread.sleep(100); + assertProcessTerminated(dummyProcess); + } + + @Test(timeout = 1000L) + public void process_does_not_die_when_debugged() throws Exception { + Properties properties = new Properties(); + properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME); + properties.setProperty("sonar.search.javaOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); + + final DummyProcess dummyProcess = new DummyProcess(new Props(properties)); + assertThat(dummyProcess.isMonitored()).isFalse(); + + dummyProcess.setTimeout(100L).setCheckDelay(100L); + Thread process = new Thread(new Runnable() { + @Override + public void run() { + dummyProcess.start(); + } + }); + process.start(); + Thread.sleep(600); + + assertProcessRunning(dummyProcess); + dummyProcess.terminate(); + assertProcessTerminated(dummyProcess); + } + + + private void assertJoinAndTerminate(DummyProcess dummyProcess, Thread process) throws InterruptedException { + process.join(); + assertProcessTerminated(dummyProcess); + } + + private void assertProcessTerminated(DummyProcess dummyProcess) { assertThat(dummyProcess.isReady()).isTrue(); assertThat(dummyProcess.isTerminated()).isTrue(); + assertProcessCreatedFile(dummyProcess); + } + + private void assertProcessNotYetRunning(DummyProcess dummyProcess) { + assertThat(dummyProcess.isReady()).isFalse(); + assertThat(dummyProcess.isTerminated()).isFalse(); + } + + private void assertProcessRunning(DummyProcess dummyProcess) throws InterruptedException { + assertThat(dummyProcess.isReady()).isTrue(); + assertThat(dummyProcess.isTerminated()).isFalse(); + } + + private void assertProcessCreatedFile(DummyProcess dummyProcess) { assertThat(dummyProcess.getCheckFile()).isNotNull(); assertThat(dummyProcess.getCheckFile().getName()).isEqualTo(DummyProcess.CHECKFILE_NAME); } |