]> source.dussan.org Git - sonarqube.git/commitdiff
Disable process monitoring when in debug with agentlib:jdwt
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 25 Aug 2014 15:38:56 +0000 (17:38 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 25 Aug 2014 15:39:13 +0000 (17:39 +0200)
debug.sh [new file with mode: 0755]
server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
sonar-application/src/main/java/org/sonar/application/App.java

diff --git a/debug.sh b/debug.sh
new file mode 100755 (executable)
index 0000000..5dadb3b
--- /dev/null
+++ b/debug.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+
+cd sonar-application/target/
+if ! ls sonarqube-*/bin/sonar-application*.jar &> /dev/null; then
+  unzip sonarqube-*.zip
+fi
+
+cd sonarqube-*
+java -jar ./lib/sonar-application*.jar -Dsonar.web.javaOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
\ No newline at end of file
index 6d75bece303599bdf4383c1008c96c2ffbb8e142..4a6c3ec5e51e880439ab27d8fc318d5b199008fd 100644 (file)
@@ -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";
index f3e4d2a78db40b8ee4cef964e84a4fa42700b4f7..e8f871476542a40156e212e2d4e67285d799b2fd 100644 (file)
@@ -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);
   }
index 11196971a7460f7ad3e54cb14e3509a7a076fae5..873e8b95ab057f9e1ecbbfd1d275d0362d144fb5 100644 (file)
@@ -74,7 +74,7 @@ public class SearchServer extends MonitoredProcess {
 
   public SearchServer(Props props) {
     super(props);
-    this.isBlocking = false;
+    this.isBlocking = true;
     new MinimumViableSystem().check();
 
     String esNodesInets = props.of(ES_CLUSTER_INET);
index 72e7e229e7aeb2cc93a46ab2502b66ec0b8eb000..67efece6734a16aa47a70c479d5e34408dfb149e 100644 (file)
@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
 import org.sonar.process.JmxUtils;
 import org.sonar.process.MinimumViableSystem;
 import org.sonar.process.Monitor;
+import org.sonar.process.MonitoredProcess;
 import org.sonar.process.ProcessLogging;
 import org.sonar.process.ProcessMXBean;
 import org.sonar.process.ProcessUtils;
@@ -56,6 +57,12 @@ public class App implements ProcessMXBean {
   public void start(Props props) throws InterruptedException {
     try {
       Logger logger = LoggerFactory.getLogger(getClass());
+
+      if (props.containsValue(MonitoredProcess.DEBUG_AGENT)) {
+        logger.info("**********************************************************");
+        logger.info("*   sonarQube is running in debug mode. No monitoring    *");
+        logger.info("**********************************************************");
+      }
       monitor.start();
 
       File homeDir = props.fileOf("sonar.path.home");