aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java5
-rw-r--r--sonar-application/src/test/java/org/sonar/application/StartServerTest.java36
2 files changed, 26 insertions, 15 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java
index c0ba7c9e033..08c3b8cd88c 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java
@@ -21,6 +21,11 @@ package org.sonar.process;
public interface ProcessMXBean {
+ public static final String IS_READY = "isReady";
+ public static final String PING = "ping";
+ public static final String TERMINATE = "terminate";
+
+
boolean isReady();
long ping();
diff --git a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
index 1f3fa455bc1..933713dcb01 100644
--- a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
@@ -7,14 +7,15 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.process.Process;
+import org.sonar.process.ProcessMXBean;
import javax.management.MBeanServer;
-import javax.management.ObjectInstance;
import javax.management.ObjectName;
import java.io.File;
import java.lang.management.ManagementFactory;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -53,22 +54,27 @@ public class StartServerTest {
ObjectName serverObjectName = Process.objectNameFor(StartServer.PROCESS_NAME);
assertThat(mbeanServer.isRegistered(serverObjectName)).isTrue();
- ObjectInstance serverMXBean = mbeanServer.getObjectInstance(serverObjectName);
+ // 2 assert that we can remotely call ping
+ Long now = System.currentTimeMillis();
+ Long ping = (Long) mbeanServer.invoke(serverObjectName, ProcessMXBean.PING, null, null);
+ assertThat(ping).isNotNull();
+ assertThat(ping - now).isLessThanOrEqualTo(3000L);
+ // 3 assert that we can remotely call isReady
+ //TODO this method is for some reason not available...
+// Boolean isReady = (Boolean) mbeanServer.invoke(serverObjectName, ProcessMXBean.IS_READY, null, null);
+// assertThat(isReady).isFalse();
- System.out.println("serverMXBean.getClassName() = " + serverMXBean.getClassName());
+ // 4 assert that we can remotely call terminate
+ mbeanServer.invoke(serverObjectName, ProcessMXBean.TERMINATE, null, null);
+
+ // 5 assert that we can remotely call terminate
+ try {
+ mbeanServer.invoke(serverObjectName, "xoxo", null, null);
+ fail();
+ } catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo("No such operation: xoxo");
+ }
-// Class<?> processClass = serverMXBean.getClassName();
-//
-// Method method =
-// Reflection.invoke(serverMXBean, "ping", Long.class);
-//
-// // 2 assert that we cannot make another Process in the same JVM
-// try {
-// process = new TestProcess(props);
-// fail();
-// } catch (IllegalStateException e) {
-// assertThat(e.getMessage()).isEqualTo("Process already exists in current JVM");
-// }
}
} \ No newline at end of file