diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-21 21:22:59 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-21 21:27:19 +0200 |
commit | bbca1b8de515423e6fd0d7e93e0d2f49e82dd7ba (patch) | |
tree | e07194d1fa98865db4ffff2cc86e5a552ad74f53 /server/sonar-process-monitor/src/test/java | |
parent | 9999a96f4b0cbb345cd4690ebc37452ff624e1d5 (diff) | |
download | sonarqube-bbca1b8de515423e6fd0d7e93e0d2f49e82dd7ba.tar.gz sonarqube-bbca1b8de515423e6fd0d7e93e0d2f49e82dd7ba.zip |
SONAR-4898 drop RMI and autokill
Diffstat (limited to 'server/sonar-process-monitor/src/test/java')
9 files changed, 14 insertions, 304 deletions
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(); } } |