]> source.dussan.org Git - sonarqube.git/commitdiff
ServerTester don't do startup tasks by default anymore 309/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 12 May 2015 11:36:34 +0000 (13:36 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 20 May 2015 07:20:17 +0000 (09:20 +0200)
17 files changed:
server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
server/sonar-server/src/test/java/org/sonar/server/activity/ws/ActivitiesWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ServerTesterPlatform.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerMediumTest.java

index 7a85eb6731b42f6416ecd9892f4170cd70cecb7f..766a5d1ba386b990e848ca25490b3884b6a95e98 100644 (file)
@@ -83,6 +83,10 @@ public class Platform {
 
   // Platform is injected in Pico, so do not rename this method "start"
   public void doStart() {
+    doStart(Startup.ALL);
+  }
+
+  protected void doStart(Startup startup) {
     if (started && !isInSafeMode()) {
       return;
     }
@@ -94,7 +98,7 @@ public class Platform {
       started = true;
     } else {
       startLevel34Containers();
-      executeStartupTasks();
+      executeStartupTasks(startup);
       // switch current container last to avoid giving access to a partially initialized container
       currentContainer = level4Container;
       started = true;
@@ -105,6 +109,10 @@ public class Platform {
   }
 
   public void restart() {
+    restart(Startup.ALL);
+  }
+
+  protected void restart(Startup startup) {
     // switch currentContainer on level1 now to avoid exposing a container in the process of stopping
     currentContainer = level1Container;
 
@@ -115,7 +123,7 @@ public class Platform {
     // no need to initialize database connection, so level 1 is skipped
     startLevel2Container();
     startLevel34Containers();
-    executeStartupTasks();
+    executeStartupTasks(startup);
     currentContainer = level4Container;
   }
 
@@ -175,7 +183,13 @@ public class Platform {
   }
 
   public void executeStartupTasks() {
-    serverComponents.executeStartupTasks(level4Container);
+    executeStartupTasks(Startup.ALL);
+  }
+
+  private void executeStartupTasks(Startup startup) {
+    if (startup.ordinal() >= Startup.ALL.ordinal()) {
+      serverComponents.executeStartupTasks(level4Container);
+    }
   }
 
   private void startSafeModeContainer() {
@@ -256,4 +270,8 @@ public class Platform {
   public enum Status {
     BOOTING, SAFEMODE, UP;
   }
+
+  public enum Startup {
+    NO_STARTUP_TASKS, ALL
+  }
 }
index b38d7754079faf032a042d6825852432e8c3261f..25a4e53be94dfdc5e2123524236d28d904abb319 100644 (file)
@@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ActivitiesWsMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index 21bd55209481e013dc2a8f4c606baf16cc69ee0d..9c146fbba9a1774a3e489e38f19fa5a80f0fb97b 100644 (file)
@@ -41,7 +41,7 @@ import java.util.Date;
 public class HistoryActionMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index bf6b9e8a2e44a06010753f1bb1ccc1bd7ced8881..6e01a4b3c9ebc64c2593cf59137df8b41dbe84aa 100644 (file)
@@ -62,7 +62,7 @@ import static org.junit.Assert.fail;
 public class IssueBulkChangeServiceMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index f3978d66bf0e642fe48d9b067359452450e00596..7942227af2d1c169562e712595694b5ccab0339e 100644 (file)
@@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class IssueCommentServiceMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index 474954387061c431cae775879e2a4845dd152b97..24ae581f6fb93192909df69df3d3c3e9a8e90567 100644 (file)
@@ -79,7 +79,7 @@ import static org.junit.Assert.fail;
 public class IssueServiceMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index c18d372aa25ecd05307ef21896a25eb9d5d2559b..18ac9cd2a4a14ed4dac0dd2d031b3fbf508aa0c8 100644 (file)
@@ -59,7 +59,7 @@ import static com.google.common.collect.Lists.newArrayList;
 public class SearchActionComponentsMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index 714cc6b1b126e8dbb164b7329db7d09e84c6eb7a..7c429c8c139d60e6ebc95ff390ab88dce6b234e9 100644 (file)
@@ -63,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class SearchActionMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index 6023df7133eba1740cfcd44d5042d91ea15d5e51..6c369d534a992ed0c47aca772d5307c454a38586 100644 (file)
@@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class InternalPermissionServiceMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerTesterPlatform.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerTesterPlatform.java
new file mode 100644 (file)
index 0000000..786f150
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.server.platform;
+
+public class ServerTesterPlatform extends Platform {
+  /**
+   * Override to make public
+   */
+  @Override
+  public void doStart(Startup startup) {
+    super.doStart(startup);
+  }
+
+  /**
+   * Override to make public
+   */
+  @Override
+  public void restart(Startup startup) {
+    super.restart(startup);
+  }
+}
index 25ebecadd78e1c1c879deece7f5d06e9e543a6c4..b7f6ebcff4b160bbc23b6ae8dfe8c5b5263518ef 100644 (file)
@@ -54,7 +54,7 @@ import static org.junit.Assert.fail;
 public class QProfileExportersTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester().addXoo().addComponents(
+  public static ServerTester tester = new ServerTester().withStartupTasks().addXoo().addComponents(
     XooRulesDefinition.class, XooProfileDefinition.class,
     XooExporter.class, StandardExporter.class,
     XooProfileImporter.class, XooProfileImporterWithMessages.class, XooProfileImporterWithError.class);
index e635ee2d7baef82fe618abf564debbc80180ec25..98e82dafb36f8b547aa15ee96902c4122e5243c0 100644 (file)
@@ -64,7 +64,7 @@ import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P2_KEY;
 public class QProfileServiceMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester().addComponents(XooProfileImporter.class, XooExporter.class);
+  public static ServerTester tester = new ServerTester().withStartupTasks().addComponents(XooProfileImporter.class, XooExporter.class);
   @org.junit.Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
index 72f03220320892f221a58636dfeb7a1cd63f4ee0..f8891e1eb022edfd13316a4812793620640c3a31 100644 (file)
@@ -63,7 +63,7 @@ public class RegisterQualityProfilesMediumTest {
 
   @Test
   public void register_existing_profile_definitions() {
-    tester = new ServerTester().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
+    tester = new ServerTester().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
     tester.start();
     dbSession = dbClient().openSession(false);
 
@@ -106,7 +106,7 @@ public class RegisterQualityProfilesMediumTest {
 
   @Test
   public void register_profile_definitions() {
-    tester = new ServerTester().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
+    tester = new ServerTester().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
     tester.start();
     dbSession = dbClient().openSession(false);
 
@@ -164,7 +164,7 @@ public class RegisterQualityProfilesMediumTest {
 
   @Test
   public void mark_profile_as_default() {
-    tester = new ServerTester().addXoo().addComponents(new SimpleProfileDefinition("one", false), new SimpleProfileDefinition("two", true));
+    tester = new ServerTester().withStartupTasks().addXoo().addComponents(new SimpleProfileDefinition("one", false), new SimpleProfileDefinition("two", true));
 
     tester.start();
     verifyDefaultProfile("xoo", "two");
@@ -172,7 +172,7 @@ public class RegisterQualityProfilesMediumTest {
 
   @Test
   public void use_sonar_way_as_default_profile_if_none_are_marked_as_default() {
-    tester = new ServerTester().addXoo().addComponents(new SimpleProfileDefinition("Sonar way", false), new SimpleProfileDefinition("Other way", false));
+    tester = new ServerTester().withStartupTasks().addXoo().addComponents(new SimpleProfileDefinition("Sonar way", false), new SimpleProfileDefinition("Other way", false));
 
     tester.start();
     verifyDefaultProfile("xoo", "Sonar way");
@@ -180,7 +180,7 @@ public class RegisterQualityProfilesMediumTest {
 
   @Test
   public void do_not_reset_default_profile_if_still_valid() {
-    tester = new ServerTester().addXoo().addComponents(new SimpleProfileDefinition("one", true), new SimpleProfileDefinition("two", false));
+    tester = new ServerTester().withStartupTasks().addXoo().addComponents(new SimpleProfileDefinition("one", true), new SimpleProfileDefinition("two", false));
     tester.start();
 
     QualityProfileDao profileDao = dbClient().qualityProfileDao();
index d60550fb732fd5ca0fbb9b4542386f0448434a98..639548566c4cf8bc28176753b20354b4fc78f911 100644 (file)
@@ -46,7 +46,7 @@ import org.sonar.server.ws.WsTester;
 public class CompareActionMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester().addXoo()
+  public static ServerTester tester = new ServerTester().withStartupTasks().addXoo()
     .addComponents(new RulesDefinition() {
       @Override
       public void define(Context context) {
index 994cee4a07dfaff344ba7bb3e24678a32b04831a..5a137338b5ba7e5fefe15731cef77322c90901de 100644 (file)
@@ -45,7 +45,7 @@ public class CreateActionMediumTest {
 
   // TODO Replace with simpler test with DbTester / EsTester after removal of DaoV2
   @ClassRule
-  public static ServerTester tester = new ServerTester().addXoo().addComponents(
+  public static ServerTester tester = new ServerTester().withStartupTasks().addXoo().addComponents(
     XooRulesDefinition.class, XooProfileDefinition.class,
     XooExporter.class, StandardExporter.class,
     XooProfileImporter.class, XooProfileImporterWithMessages.class, XooProfileImporterWithError.class);
index 7aa97b0a5354eca5ea5e4b1855ee149498934f40..6c5506ca867a40cd5d8d055a0077fc59fb9d0f0c 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.server.tester;
 
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -26,10 +29,8 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-
 import javax.annotation.Nullable;
 import javax.servlet.ServletContext;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.junit.rules.ExternalResource;
@@ -40,14 +41,13 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.EsServerHolder;
 import org.sonar.server.platform.BackendCleanup;
-import org.sonar.server.platform.Platform;
+import org.sonar.server.platform.ServerTesterPlatform;
 import org.sonar.server.plugins.UpdateCenterClient;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.TestUtils;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
+import static org.sonar.server.platform.Platform.Startup.ALL;
+import static org.sonar.server.platform.Platform.Startup.NO_STARTUP_TASKS;
 
 /**
  * Entry point to implement medium tests of server components.
@@ -62,13 +62,19 @@ public class ServerTester extends ExternalResource {
   private static final Logger LOG = Loggers.get(ServerTester.class);
   private static final String PROP_PREFIX = "mediumTests.";
 
-  private Platform platform;
+  private ServerTesterPlatform platform;
   private EsServerHolder esServerHolder;
   private final File homeDir = TestUtils.newTempDir("tmp-sq-");
   private final List<Object> components = Lists.<Object>newArrayList(WsTester.class);
   private final Properties initialProps = new Properties();
   private final ServletContext servletContext = new AttributeHolderServletContext();
   private URL updateCenterUrl;
+  private boolean startupTasks = false;
+
+  public ServerTester withStartupTasks() {
+    this.startupTasks = true;
+    return this;
+  }
 
   /**
    * Called only when JUnit @Rule or @ClassRule is used.
@@ -105,10 +111,10 @@ public class ServerTester extends ExternalResource {
           properties.put(StringUtils.substringAfter(key, PROP_PREFIX), entry.getValue());
         }
       }
-      platform = new Platform();
+      platform = new ServerTesterPlatform();
       platform.init(properties, servletContext);
       platform.addComponents(components);
-      platform.doStart();
+      platform.doStart(startupTasks ? ALL : NO_STARTUP_TASKS);
     } catch (Exception e) {
       stop();
       Throwables.propagate(e);
index 6f9ae0d9a0ff3144673b5e36574fe0e497ec487e..54b377a9f8b5dcbb3408850aed54320a22c7d99f 100644 (file)
@@ -62,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ViewIndexerMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withStartupTasks();
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);