// 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;
}
started = true;
} else {
startLevel34Containers();
- executeStartupTasks();
+ executeStartupTasks(startup);
// switch current container last to avoid giving access to a partially initialized container
currentContainer = level4Container;
started = true;
}
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;
// no need to initialize database connection, so level 1 is skipped
startLevel2Container();
startLevel34Containers();
- executeStartupTasks();
+ executeStartupTasks(startup);
currentContainer = level4Container;
}
}
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() {
public enum Status {
BOOTING, SAFEMODE, UP;
}
+
+ public enum Startup {
+ NO_STARTUP_TASKS, ALL
+ }
}
public class ActivitiesWsMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class HistoryActionMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class IssueBulkChangeServiceMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class IssueCommentServiceMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class IssueServiceMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class SearchActionComponentsMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class SearchActionMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
public class InternalPermissionServiceMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
--- /dev/null
+/*
+ * 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);
+ }
+}
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);
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);
@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);
@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);
@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");
@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");
@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();
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) {
// 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);
*/
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;
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;
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.
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.
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);
public class ViewIndexerMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester().withStartupTasks();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);