From: Sébastien Lesaint Date: Fri, 8 Jan 2016 17:11:09 +0000 (+0100) Subject: SONAR-7168 support restart in prod mode in ITs X-Git-Tag: 5.4-M5~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=454932613ec7810bce21d53abee0bcc98fa72d04;p=sonarqube.git SONAR-7168 support restart in prod mode in ITs in addition, rename IT DevModeTest to RestartTest --- diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java index f95e3e0a94f..389a3db0314 100644 --- a/it/it-tests/src/test/java/it/Category4Suite.java +++ b/it/it-tests/src/test/java/it/Category4Suite.java @@ -28,7 +28,7 @@ import it.dbCleaner.PurgeTest; import it.duplication.CrossProjectDuplicationsOnRemoveFileTest; import it.duplication.CrossProjectDuplicationsTest; import it.duplication.DuplicationsTest; -import it.serverSystem.DevModeTest; +import it.serverSystem.RestartTest; import it.serverSystem.HttpsTest; import it.serverSystem.ServerSystemRestartingOrchestrator; import it.serverSystem.ServerSystemTest; @@ -44,7 +44,7 @@ import static util.ItUtils.xooPlugin; @RunWith(Suite.class) @Suite.SuiteClasses({ // server system - DevModeTest.class, + RestartTest.class, HttpsTest.class, ServerSystemTest.class, ServerSystemRestartingOrchestrator.class, diff --git a/it/it-tests/src/test/java/it/serverSystem/DevModeTest.java b/it/it-tests/src/test/java/it/serverSystem/DevModeTest.java deleted file mode 100644 index d48f269adf6..00000000000 --- a/it/it-tests/src/test/java/it/serverSystem/DevModeTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube Integration Tests :: Tests - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 it.serverSystem; - -import com.sonar.orchestrator.Orchestrator; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.SystemUtils; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -/** - * This class start a new orchestrator on each test case - */ -public class DevModeTest { - - Orchestrator orchestrator; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @After - public void stop() { - if (orchestrator != null) { - orchestrator.stop(); - } - } - - /** - * SONAR-4843 - */ - @Test - public void restart_forbidden_if_not_dev_mode() throws Exception { - // server classloader locks Jar files on Windows - if (!SystemUtils.IS_OS_WINDOWS) { - orchestrator = Orchestrator.builderEnv() - .build(); - orchestrator.start(); - try { - orchestrator.getServer().adminWsClient().systemClient().restart(); - fail(); - } catch (Exception e) { - assertThat(e.getMessage()).contains("403"); - } - } - } - - /** - * SONAR-4843 - */ - @Test - public void restart_on_dev_mode() throws Exception { - // server classloader locks Jar files on Windows - if (!SystemUtils.IS_OS_WINDOWS) { - orchestrator = Orchestrator.builderEnv() - .setServerProperty("sonar.web.dev", "true") - .build(); - orchestrator.start(); - - orchestrator.getServer().adminWsClient().systemClient().restart(); - assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())) - .contains("Restart server") - .contains("Server restarted"); - } - } -} diff --git a/it/it-tests/src/test/java/it/serverSystem/RestartTest.java b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java new file mode 100644 index 00000000000..d52215d3776 --- /dev/null +++ b/it/it-tests/src/test/java/it/serverSystem/RestartTest.java @@ -0,0 +1,99 @@ +/* + * SonarQube Integration Tests :: Tests + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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 it.serverSystem; + +import com.sonar.orchestrator.Orchestrator; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.SystemUtils; +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.ExpectedException; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + +/** + * This class starts a new orchestrator on each test case + */ +public class RestartTest { + + Orchestrator orchestrator; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Rule + public TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(120)); + + @After + public void stop() { + if (orchestrator != null) { + orchestrator.stop(); + } + } + + @Test + public void restart_in_prod_mode_requires_admin_privileges_and_restarts_WebServer_and_ES() throws Exception { + // server classloader locks Jar files on Windows + if (!SystemUtils.IS_OS_WINDOWS) { + orchestrator = Orchestrator.builderEnv() + .setOrchestratorProperty("orchestrator.keepWorkspace", "true") + .build(); + orchestrator.start(); + + try { + orchestrator.getServer().wsClient().systemClient().restart(); + fail(); + } catch (Exception e) { + assertThat(e.getMessage()).contains("403"); + } + + orchestrator.getServer().adminWsClient().systemClient().restart(); + + // we just wait five seconds, for a lack of a better approach to waiting for the restart process to start in SQ + Thread.sleep(5000); + + assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())) + .contains("Requesting SonarQube restart"); + } + } + + /** + * SONAR-4843 + */ + @Test + public void restart_on_dev_mode() throws Exception { + // server classloader locks Jar files on Windows + if (!SystemUtils.IS_OS_WINDOWS) { + orchestrator = Orchestrator.builderEnv() + .setServerProperty("sonar.web.dev", "true") + .build(); + orchestrator.start(); + + orchestrator.getServer().adminWsClient().systemClient().restart(); + assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())) + .contains("Fast restarting WebServer...") + .contains("WebServer restarted"); + } + } +}