From: Sébastien Lesaint Date: Thu, 7 Jun 2018 14:50:08 +0000 (+0200) Subject: SONAR-10690 make fake-governance-plugin a core extension X-Git-Tag: 7.5~997 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bf6c9991631f6303fb5905c1a0061f4bf8a9e2ee;p=sonarqube.git SONAR-10690 make fake-governance-plugin a core extension --- diff --git a/run-integration-tests.sh b/run-integration-tests.sh index 476782962c4..938cd9bd6f7 100755 --- a/run-integration-tests.sh +++ b/run-integration-tests.sh @@ -16,7 +16,8 @@ CATEGORY=$1 ORCHESTRATOR_CONFIG_URL=$2 shift 2 -./gradlew --no-daemon --console plain \ +./gradlew \ + :tests:clean \ :tests:integrationTest \ -Dcategory="$CATEGORY" \ -Dorchestrator.configUrl=$ORCHESTRATOR_CONFIG_URL \ diff --git a/settings.gradle b/settings.gradle index d15f0d6f31c..10d2f730941 100644 --- a/settings.gradle +++ b/settings.gradle @@ -41,7 +41,7 @@ include 'tests:plugins:blue-green-plugin-v1' include 'tests:plugins:blue-green-plugin-v2' include 'tests:plugins:extension-lifecycle-plugin' include 'tests:plugins:fake-billing-plugin' -include 'tests:plugins:fake-governance-plugin' +include 'tests:plugins:core-extension-it-tests' include 'tests:plugins:foo-plugin-v1' include 'tests:plugins:foo-plugin-v2' include 'tests:plugins:foo-plugin-v3' diff --git a/tests/build.gradle b/tests/build.gradle index 3b357654511..da55a4f03cf 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -20,7 +20,7 @@ def pluginsForITs = [ ':tests:plugins:blue-green-plugin-v2', ':tests:plugins:extension-lifecycle-plugin', ':tests:plugins:fake-billing-plugin', - ':tests:plugins:fake-governance-plugin', + ':tests:plugins:core-extension-it-tests', ':tests:plugins:foo-plugin-v1', ':tests:plugins:foo-plugin-v2', ':tests:plugins:foo-plugin-v3', diff --git a/tests/plugins/core-extension-it-tests/build.gradle b/tests/plugins/core-extension-it-tests/build.gradle new file mode 100644 index 00000000000..3dc8a9030bb --- /dev/null +++ b/tests/plugins/core-extension-it-tests/build.gradle @@ -0,0 +1,4 @@ +dependencies { + compileOnly project(path: ':sonar-plugin-api', configuration: 'shadow') + compileOnly project(':server:sonar-server') +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ItTestsCoreExtension.java b/tests/plugins/core-extension-it-tests/src/main/java/ItTestsCoreExtension.java new file mode 100644 index 00000000000..f38bf272205 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ItTestsCoreExtension.java @@ -0,0 +1,73 @@ + +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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. + */ +import ce.BombConfig; +import ce.ComponentBombReportAnalysisComponentProvider; +import ce.IseTaskProcessor; +import ce.OkTaskProcessor; +import ce.OomTaskProcessor; +import ce.ws.BombActivatorAction; +import ce.ws.FakeGovWs; +import ce.ws.SubmitAction; +import org.sonar.api.SonarQubeSide; +import org.sonar.core.extension.CoreExtension; +import systemPasscode.SystemPasscodeWebService; +import workerCount.FakeWorkerCountProviderImpl; +import workerCount.RefreshWorkerCountAction; +import workerlatch.LatchControllerWorkerMeasureComputer; +import workerlatch.WorkerLatchMetrics; + +import static org.sonar.api.SonarQubeSide.COMPUTE_ENGINE; +import static org.sonar.api.SonarQubeSide.SERVER; + +public class ItTestsCoreExtension implements CoreExtension { + @Override + public String getName() { + return "it-tests"; + } + + @Override + public void load(Context context) { + // Nothing should be loaded when the plugin is running within by the scanner + SonarQubeSide sonarQubeSide = context.getRuntime().getSonarQubeSide(); + if (sonarQubeSide == COMPUTE_ENGINE || sonarQubeSide == SERVER) { + context.addExtension(FakeWorkerCountProviderImpl.class); + context.addExtension(WorkerLatchMetrics.class); + context.addExtension(LatchControllerWorkerMeasureComputer.class); + context.addExtension(RefreshWorkerCountAction.class); + context.addExtension(SystemPasscodeWebService.class); + + // WS api/fake_gov + context.addExtension(FakeGovWs.class); + + // failing CE tasks + context.addExtension(SubmitAction.class); + context.addExtension(OomTaskProcessor.class); + context.addExtension(IseTaskProcessor.class); + context.addExtension(OkTaskProcessor.class); + + // component bombs injection into the Report Analysis processing container in the CE + context.addExtension(BombConfig.class); + context.addExtension(ComponentBombReportAnalysisComponentProvider.class); + context.addExtension(BombActivatorAction.class); + } + } + +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/BombConfig.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/BombConfig.java new file mode 100644 index 00000000000..d6fdd5d5e49 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/BombConfig.java @@ -0,0 +1,102 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce; + +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.server.ServerSide; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; + +@ServerSide +@ComputeEngineSide +public class BombConfig { + private static final String OOM_START_BOMB_KEY = "oomStartBomb"; + private static final String ISE_START_BOMB_KEY = "iseStartBomb"; + private static final String OOM_STOP_BOMB_KEY = "oomStopBomb"; + private static final String ISE_STOP_BOMB_KEY = "iseStopBomb"; + + private final DbClient dbClient; + + public BombConfig(DbClient dbClient) { + this.dbClient = dbClient; + } + + public void reset() { + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.internalPropertiesDao().save(dbSession, OOM_START_BOMB_KEY, String.valueOf(false)); + dbClient.internalPropertiesDao().save(dbSession, ISE_START_BOMB_KEY, String.valueOf(false)); + dbClient.internalPropertiesDao().save(dbSession, OOM_STOP_BOMB_KEY, String.valueOf(false)); + dbClient.internalPropertiesDao().save(dbSession, ISE_STOP_BOMB_KEY, String.valueOf(false)); + dbSession.commit(); + } + } + + public boolean isOomStartBomb() { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.internalPropertiesDao().selectByKey(dbSession, OOM_START_BOMB_KEY).map(Boolean::valueOf).orElse(false); + } + } + + public void setOomStartBomb(boolean oomStartBomb) { + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.internalPropertiesDao().save(dbSession, OOM_START_BOMB_KEY, String.valueOf(oomStartBomb)); + dbSession.commit(); + } + } + + public boolean isIseStartBomb() { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.internalPropertiesDao().selectByKey(dbSession, ISE_START_BOMB_KEY).map(Boolean::valueOf).orElse(false); + } + } + + public void setIseStartBomb(boolean iseStartBomb) { + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.internalPropertiesDao().save(dbSession, ISE_START_BOMB_KEY, String.valueOf(iseStartBomb)); + dbSession.commit(); + } + } + + public boolean isOomStopBomb() { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.internalPropertiesDao().selectByKey(dbSession, OOM_STOP_BOMB_KEY).map(Boolean::valueOf).orElse(false); + } + } + + public void setOomStopBomb(boolean oomStopBomb) { + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.internalPropertiesDao().save(dbSession, OOM_STOP_BOMB_KEY, String.valueOf(oomStopBomb)); + dbSession.commit(); + } + } + + public boolean isIseStopBomb() { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.internalPropertiesDao().selectByKey(dbSession, ISE_STOP_BOMB_KEY).map(Boolean::valueOf).orElse(false); + } + } + + public void setIseStopBomb(boolean iseStopBomb) { + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.internalPropertiesDao().save(dbSession, ISE_STOP_BOMB_KEY, String.valueOf(iseStopBomb)); + dbSession.commit(); + } + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/ComponentBombReportAnalysisComponentProvider.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/ComponentBombReportAnalysisComponentProvider.java new file mode 100644 index 00000000000..2b2ea4eee9b --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/ComponentBombReportAnalysisComponentProvider.java @@ -0,0 +1,109 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce; + +import java.util.List; +import org.picocontainer.Startable; +import org.sonar.plugin.ce.ReportAnalysisComponentProvider; +import org.sonar.server.computation.task.container.EagerStart; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + +public class ComponentBombReportAnalysisComponentProvider implements ReportAnalysisComponentProvider { + private final BombConfig bombConfig; + + public ComponentBombReportAnalysisComponentProvider(BombConfig bombConfig) { + this.bombConfig = bombConfig; + } + + @Override + public List getComponents() { + if (bombConfig.isOomStartBomb()) { + return singletonList(OOMFailingStartComponent.class); + } + if (bombConfig.isIseStartBomb()) { + return singletonList(ISEFailingStartComponent.class); + } + if (bombConfig.isOomStopBomb()) { + return singletonList(OOMFailingStopComponent.class); + } + if (bombConfig.isIseStopBomb()) { + return singletonList(ISEFailingStopComponent.class); + } + return emptyList(); + } + + @EagerStart + public static final class OOMFailingStartComponent implements Startable { + + @Override + public void start() { + OOMGenerator.consumeAvailableMemory(); + } + + @Override + public void stop() { + // nothing to do + } + } + + @EagerStart + public static final class ISEFailingStartComponent implements Startable { + + @Override + public void start() { + throw new IllegalStateException("Faking an IllegalStateException thrown by a startable component in the Analysis Report processing container"); + } + + @Override + public void stop() { + // nothing to do + } + } + + @EagerStart + public static final class OOMFailingStopComponent implements Startable { + + @Override + public void start() { + // nothing to do + } + + @Override + public void stop() { + OOMGenerator.consumeAvailableMemory(); + } + } + + @EagerStart + public static final class ISEFailingStopComponent implements Startable { + + @Override + public void start() { + // nothing to do + } + + @Override + public void stop() { + throw new IllegalStateException("Faking an IllegalStateException thrown by a stoppable component in the Analysis Report processing container"); + } + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/IseTaskProcessor.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/IseTaskProcessor.java new file mode 100644 index 00000000000..40b11ec079d --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/IseTaskProcessor.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce; + +import java.util.Collections; +import java.util.Set; +import org.sonar.ce.queue.CeTask; +import org.sonar.ce.queue.CeTaskResult; +import org.sonar.ce.taskprocessor.CeTaskProcessor; + +public class IseTaskProcessor implements CeTaskProcessor { + @Override + public Set getHandledCeTaskTypes() { + return Collections.singleton("ISE"); + } + + @Override + public CeTaskResult process(CeTask task) { + throw new IllegalStateException("Faking an IllegalStateException thrown processing a task"); + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/OOMGenerator.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/OOMGenerator.java new file mode 100644 index 00000000000..e8673412fc2 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/OOMGenerator.java @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce; + +import java.util.ArrayList; +import java.util.List; + +public final class OOMGenerator { + private OOMGenerator() { + // prevents instantiation + } + + public static List consumeAvailableMemory() { + List holder = new ArrayList<>(); + while (true) { + holder.add(new byte[128 * 1024]); + } + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/OkTaskProcessor.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/OkTaskProcessor.java new file mode 100644 index 00000000000..88d9abaf013 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/OkTaskProcessor.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce; + +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import org.sonar.ce.queue.CeTask; +import org.sonar.ce.queue.CeTaskResult; +import org.sonar.ce.taskprocessor.CeTaskProcessor; + +public class OkTaskProcessor implements CeTaskProcessor { + @Override + public Set getHandledCeTaskTypes() { + return Collections.singleton("OK"); + } + + @Override + public CeTaskResult process(CeTask task) { + return Optional::empty; + } + + +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/OomTaskProcessor.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/OomTaskProcessor.java new file mode 100644 index 00000000000..a79c71f0ec7 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/OomTaskProcessor.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce; + +import java.util.Collections; +import java.util.Set; +import org.sonar.ce.queue.CeTask; +import org.sonar.ce.queue.CeTaskResult; +import org.sonar.ce.taskprocessor.CeTaskProcessor; + +public class OomTaskProcessor implements CeTaskProcessor { + @Override + public Set getHandledCeTaskTypes() { + return Collections.singleton("OOM"); + } + + @Override + public CeTaskResult process(CeTask task) { + OOMGenerator.consumeAvailableMemory(); + return null; + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/BombActivatorAction.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/BombActivatorAction.java new file mode 100644 index 00000000000..31be2ce3bc1 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/BombActivatorAction.java @@ -0,0 +1,82 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce.ws; + +import ce.BombConfig; +import java.util.Arrays; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static java.util.stream.Collectors.toList; + +public class BombActivatorAction implements FakeGoVWsAction { + + private static final String PARAM_BOMB_TYPE = "type"; + + private final BombConfig bombConfig; + + public BombActivatorAction(BombConfig bombConfig) { + this.bombConfig = bombConfig; + } + + @Override + public void define(WebService.NewController controller) { + WebService.NewAction action = controller.createAction("activate_bomb") + .setPost(true) + .setHandler(this); + action.createParam(PARAM_BOMB_TYPE) + .setRequired(true) + .setPossibleValues(Arrays.stream(BombType.values()).map(Enum::toString).collect(toList())); + } + + @Override + public void handle(Request request, Response response) { + BombType bombType = BombType.valueOf(request.mandatoryParam(PARAM_BOMB_TYPE)); + + bombConfig.reset(); + switch (bombType) { + case ISE_START: + bombConfig.setIseStartBomb(true); + break; + case OOM_START: + bombConfig.setOomStartBomb(true); + break; + case ISE_STOP: + bombConfig.setIseStopBomb(true); + break; + case OOM_STOP: + bombConfig.setOomStopBomb(true); + break; + case NONE: + break; + default: + throw new IllegalArgumentException("Unsupported bomb type " + bombType); + } + + response.noContent(); + } + + enum BombType { + NONE, OOM_START, ISE_START, OOM_STOP, ISE_STOP + + } + +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/FakeGoVWsAction.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/FakeGoVWsAction.java new file mode 100644 index 00000000000..58fb69a8b72 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/FakeGoVWsAction.java @@ -0,0 +1,25 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce.ws; + +import org.sonar.server.ws.WsAction; + +public interface FakeGoVWsAction extends WsAction { +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/FakeGovWs.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/FakeGovWs.java new file mode 100644 index 00000000000..41a49841088 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/FakeGovWs.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce.ws; + +import java.util.Arrays; +import org.sonar.api.server.ws.WebService; + +public class FakeGovWs implements WebService { + private final FakeGoVWsAction[] actions; + + public FakeGovWs(FakeGoVWsAction[] actions) { + this.actions = actions; + } + + @Override + public void define(Context context) { + NewController controller = context.createController("api/fake_gov"); + Arrays.stream(actions).forEach(action -> action.define(controller)); + controller.done(); + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/SubmitAction.java b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/SubmitAction.java new file mode 100644 index 00000000000..fb47686044e --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/ce/ws/SubmitAction.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 ce.ws; + +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; +import org.sonar.ce.queue.CeQueue; +import org.sonar.ce.queue.CeTaskSubmit; + +public class SubmitAction implements FakeGoVWsAction { + + private static final String PARAM_TYPE = "type"; + + private final CeQueue ceQueue; + + public SubmitAction(CeQueue ceQueue) { + this.ceQueue = ceQueue; + } + + @Override + public void define(WebService.NewController controller) { + WebService.NewAction action = controller.createAction("submit") + .setPost(true) + .setHandler(this); + action.createParam(PARAM_TYPE) + .setRequired(true) + .setPossibleValues("OOM", "OK", "ISE"); + } + + @Override + public void handle(Request request, Response response) { + String type = request.mandatoryParam(PARAM_TYPE); + + CeTaskSubmit.Builder submit = ceQueue.prepareSubmit(); + submit.setType(type); + + ceQueue.submit(submit.build()); + response.noContent(); + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/systemPasscode/SystemPasscodeWebService.java b/tests/plugins/core-extension-it-tests/src/main/java/systemPasscode/SystemPasscodeWebService.java new file mode 100644 index 00000000000..b1682ae6656 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/systemPasscode/SystemPasscodeWebService.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 systemPasscode; + +import java.net.HttpURLConnection; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.RequestHandler; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.user.SystemPasscode; + +public class SystemPasscodeWebService implements WebService, RequestHandler { + private final SystemPasscode passcode; + + public SystemPasscodeWebService(SystemPasscode passcode) { + this.passcode = passcode; + } + + @Override + public void define(Context context) { + NewController controller = context.createController("api/system_passcode"); + controller.createAction("check").setHandler(this); + controller.done(); + } + + @Override + public void handle(Request request, Response response) { + if (!passcode.isValid(request)) { + response.stream().setStatus(HttpURLConnection.HTTP_UNAUTHORIZED); + } + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/workerCount/FakeWorkerCountProviderImpl.java b/tests/plugins/core-extension-it-tests/src/main/java/workerCount/FakeWorkerCountProviderImpl.java new file mode 100644 index 00000000000..4e05ecda89d --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/workerCount/FakeWorkerCountProviderImpl.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 workerCount; +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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. + */ + +import org.sonar.api.config.Configuration; +import org.sonar.ce.configuration.WorkerCountProvider; + +public class FakeWorkerCountProviderImpl implements WorkerCountProvider { + + static final String PROPERTY_WORKER_COUNT = "fakeGovernance.workerCount"; + + private final Configuration configuration; + + public FakeWorkerCountProviderImpl(Configuration configuration) { + this.configuration = configuration; + } + + @Override + public int get() { + return configuration.get(PROPERTY_WORKER_COUNT).map(Integer::valueOf).orElse(1); + } + +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/workerCount/RefreshWorkerCountAction.java b/tests/plugins/core-extension-it-tests/src/main/java/workerCount/RefreshWorkerCountAction.java new file mode 100644 index 00000000000..df37590a2ab --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/workerCount/RefreshWorkerCountAction.java @@ -0,0 +1,67 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 workerCount; + +import org.sonar.api.server.ServerSide; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; +import org.sonar.ce.http.CeHttpClient; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.property.PropertyDto; +import org.sonar.server.ce.ws.CeWsAction; + +import static workerCount.FakeWorkerCountProviderImpl.PROPERTY_WORKER_COUNT; + +@ServerSide +public class RefreshWorkerCountAction implements CeWsAction { + private static final String PARAM_COUNT = "count"; + + private final CeHttpClient ceHttpClient; + private final DbClient dbClient; + + public RefreshWorkerCountAction(CeHttpClient ceHttpClient, DbClient dbClient) { + this.ceHttpClient = ceHttpClient; + this.dbClient = dbClient; + } + + @Override + public void define(WebService.NewController controller) { + controller.createAction("refreshWorkerCount") + .setPost(true) + .setHandler(this) + .createParam(PARAM_COUNT) + .setPossibleValues("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") + .setRequired(true); + } + + @Override + public void handle(Request request, Response response) { + String count = request.getParam(PARAM_COUNT).getValue(); + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.propertiesDao().saveProperty(new PropertyDto() + .setKey(PROPERTY_WORKER_COUNT) + .setValue(count)); + dbSession.commit(); + } + ceHttpClient.refreshCeWorkerCount(); + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/workerlatch/LatchControllerWorkerMeasureComputer.java b/tests/plugins/core-extension-it-tests/src/main/java/workerlatch/LatchControllerWorkerMeasureComputer.java new file mode 100644 index 00000000000..65297544391 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/workerlatch/LatchControllerWorkerMeasureComputer.java @@ -0,0 +1,120 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 workerlatch; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import org.sonar.api.ce.measure.Component; +import org.sonar.api.ce.measure.MeasureComputer; +import org.sonar.api.config.Configuration; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; + +public class LatchControllerWorkerMeasureComputer implements MeasureComputer { + private static final Logger LOG = Loggers.get(LatchControllerWorkerMeasureComputer.class); + private static final String WORKER_LATCH_SHARED_MEMORY_FILE_PATH = "itTests.workerLatch.sharedMemoryFile"; + + private static final int WAIT = 200; // ms + private static final int MAX_WAIT_ROUND = 5 * 60 * 2; // 2 minutes + + private static final int MAX_SHARED_MEMORY = 1; + private static final byte UNLATCHED = (byte) 0x01; + + private final File sharedMemory; + + public LatchControllerWorkerMeasureComputer(Configuration configuration) { + this.sharedMemory = configuration.get(WORKER_LATCH_SHARED_MEMORY_FILE_PATH) + .map(path -> { + File file = new File(path); + if (file.exists() && file.isFile()) { + return file; + } + LOG.info("Latch sharedMemory file {} is not a file or does not exist", path); + return null; + }) + .orElse(null); + } + + private boolean isLatchEnabled() { + return sharedMemory != null; + } + + @Override + public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) { + return defContext.newDefinitionBuilder() + .setOutputMetrics(WorkerLatchMetrics.METRIC_KEY) + .build(); + } + + @Override + public void compute(MeasureComputerContext context) { + Component component = context.getComponent(); + if (isLatchEnabled() && component.getType() == Component.Type.PROJECT) { + context.addMeasure(WorkerLatchMetrics.METRIC_KEY, waitForUnlatched(component.getKey())); + } else { + context.addMeasure(WorkerLatchMetrics.METRIC_KEY, false); + } + } + + private boolean waitForUnlatched(String key) { + RandomAccessFile randomAccessFile = null; + try { + randomAccessFile = new RandomAccessFile(sharedMemory, "rw"); + MappedByteBuffer mappedByteBuffer = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, MAX_SHARED_MEMORY); + int i = 0; + boolean unlatched = isUnlatched(mappedByteBuffer); + while (!unlatched && i < MAX_WAIT_ROUND) { + waitInterruptedly(); + i++; + unlatched = isUnlatched(mappedByteBuffer); + } + LOG.info("Project {} unlatched={} i={}", key, unlatched, i); + + return true; + } catch (IOException e) { + LOG.error("Failed to read or write to shared memory", e); + return false; + } finally { + if (randomAccessFile != null) { + try { + randomAccessFile.close(); + } catch (IOException e) { + LOG.error("Failed to close randomAccessFile", e); + } + } + } + } + + private static void waitInterruptedly() { + try { + Thread.sleep(WAIT); + } catch (InterruptedException e) { + LOG.error("Wait was interrupted"); + } + } + + private boolean isUnlatched(MappedByteBuffer mappedByteBuffer) { + return mappedByteBuffer.get(0) == UNLATCHED; + } + +} diff --git a/tests/plugins/core-extension-it-tests/src/main/java/workerlatch/WorkerLatchMetrics.java b/tests/plugins/core-extension-it-tests/src/main/java/workerlatch/WorkerLatchMetrics.java new file mode 100644 index 00000000000..7b31a6c666a --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/java/workerlatch/WorkerLatchMetrics.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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 workerlatch; + +import java.util.Collections; +import java.util.List; +import org.sonar.api.measures.Metric; +import org.sonar.api.measures.Metrics; + +public class WorkerLatchMetrics implements Metrics { + static final String METRIC_KEY = "WORKER_LATCH"; + + @Override + public List getMetrics() { + return Collections.singletonList( + new Metric.Builder(METRIC_KEY, "Worker latch", Metric.ValueType.BOOL) + .setHidden(true) + .create()); + } +} diff --git a/tests/plugins/core-extension-it-tests/src/main/resources/META-INF/services/org.sonar.core.extension.CoreExtension b/tests/plugins/core-extension-it-tests/src/main/resources/META-INF/services/org.sonar.core.extension.CoreExtension new file mode 100644 index 00000000000..058722722b9 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/resources/META-INF/services/org.sonar.core.extension.CoreExtension @@ -0,0 +1 @@ +ItTestsCoreExtension diff --git a/tests/plugins/core-extension-it-tests/src/main/resources/org/sonar/l10n/billing.properties b/tests/plugins/core-extension-it-tests/src/main/resources/org/sonar/l10n/billing.properties new file mode 100644 index 00000000000..f8ac8fcaef5 --- /dev/null +++ b/tests/plugins/core-extension-it-tests/src/main/resources/org/sonar/l10n/billing.properties @@ -0,0 +1,2 @@ +billing.upgrade_box.header=The fake billing plugin is installed +billing.upgrade_box.text=It shows how to change the wording and hide the "Upgrade" button. \ No newline at end of file diff --git a/tests/plugins/fake-governance-plugin/build.gradle b/tests/plugins/fake-governance-plugin/build.gradle deleted file mode 100644 index 77e1a9d4d95..00000000000 --- a/tests/plugins/fake-governance-plugin/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -dependencies { - compileOnly project(path: ':sonar-plugin-api', configuration: 'shadow') - compileOnly project(':server:sonar-server') -} - -jar { - manifest { - attributes( - 'Plugin-Key': 'governance', - 'Plugin-Version': version, - 'Plugin-Class': 'FakeGovernancePlugin', - 'Plugin-ChildFirstClassLoader': 'false', - 'Sonar-Version': version, - 'SonarLint-Supported': 'false', - 'Plugin-Name': 'Plugins :: Fake Governance Plugin', - 'Plugin-License': 'GNU LGPL 3' - ) - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java deleted file mode 100644 index df27964476e..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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. - */ -import ce.BombConfig; -import ce.ComponentBombReportAnalysisComponentProvider; -import ce.IseTaskProcessor; -import ce.OkTaskProcessor; -import ce.OomTaskProcessor; -import ce.ws.BombActivatorAction; -import ce.ws.FakeGovWs; -import ce.ws.SubmitAction; -import org.sonar.api.Plugin; -import systemPasscode.SystemPasscodeWebService; -import workerCount.FakeWorkerCountProviderImpl; -import workerCount.RefreshWorkerCountAction; -import workerlatch.LatchControllerWorkerMeasureComputer; -import workerlatch.WorkerLatchMetrics; - -public class FakeGovernancePlugin implements Plugin { - - @Override - public void define(Context context) { - // Nothing should be loaded when the plugin is running within by the scanner - if (isRunningInSQ()) { - context.addExtension(FakeWorkerCountProviderImpl.class); - context.addExtension(WorkerLatchMetrics.class); - context.addExtension(LatchControllerWorkerMeasureComputer.class); - context.addExtension(RefreshWorkerCountAction.class); - context.addExtension(SystemPasscodeWebService.class); - - // WS api/fake_gov - context.addExtension(FakeGovWs.class); - - // failing CE tasks - context.addExtension(SubmitAction.class); - context.addExtension(OomTaskProcessor.class); - context.addExtension(IseTaskProcessor.class); - context.addExtension(OkTaskProcessor.class); - - // component bombs injection into the Report Analysis processing container in the CE - context.addExtension(BombConfig.class); - context.addExtension(ComponentBombReportAnalysisComponentProvider.class); - context.addExtension(BombActivatorAction.class); - } - } - - private static boolean isRunningInSQ() { - try { - Class.forName("org.sonar.server.plugins.privileged.CoreExtensionBridge"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/BombConfig.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/BombConfig.java deleted file mode 100644 index d6fdd5d5e49..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/BombConfig.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce; - -import org.sonar.api.ce.ComputeEngineSide; -import org.sonar.api.server.ServerSide; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; - -@ServerSide -@ComputeEngineSide -public class BombConfig { - private static final String OOM_START_BOMB_KEY = "oomStartBomb"; - private static final String ISE_START_BOMB_KEY = "iseStartBomb"; - private static final String OOM_STOP_BOMB_KEY = "oomStopBomb"; - private static final String ISE_STOP_BOMB_KEY = "iseStopBomb"; - - private final DbClient dbClient; - - public BombConfig(DbClient dbClient) { - this.dbClient = dbClient; - } - - public void reset() { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.internalPropertiesDao().save(dbSession, OOM_START_BOMB_KEY, String.valueOf(false)); - dbClient.internalPropertiesDao().save(dbSession, ISE_START_BOMB_KEY, String.valueOf(false)); - dbClient.internalPropertiesDao().save(dbSession, OOM_STOP_BOMB_KEY, String.valueOf(false)); - dbClient.internalPropertiesDao().save(dbSession, ISE_STOP_BOMB_KEY, String.valueOf(false)); - dbSession.commit(); - } - } - - public boolean isOomStartBomb() { - try (DbSession dbSession = dbClient.openSession(false)) { - return dbClient.internalPropertiesDao().selectByKey(dbSession, OOM_START_BOMB_KEY).map(Boolean::valueOf).orElse(false); - } - } - - public void setOomStartBomb(boolean oomStartBomb) { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.internalPropertiesDao().save(dbSession, OOM_START_BOMB_KEY, String.valueOf(oomStartBomb)); - dbSession.commit(); - } - } - - public boolean isIseStartBomb() { - try (DbSession dbSession = dbClient.openSession(false)) { - return dbClient.internalPropertiesDao().selectByKey(dbSession, ISE_START_BOMB_KEY).map(Boolean::valueOf).orElse(false); - } - } - - public void setIseStartBomb(boolean iseStartBomb) { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.internalPropertiesDao().save(dbSession, ISE_START_BOMB_KEY, String.valueOf(iseStartBomb)); - dbSession.commit(); - } - } - - public boolean isOomStopBomb() { - try (DbSession dbSession = dbClient.openSession(false)) { - return dbClient.internalPropertiesDao().selectByKey(dbSession, OOM_STOP_BOMB_KEY).map(Boolean::valueOf).orElse(false); - } - } - - public void setOomStopBomb(boolean oomStopBomb) { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.internalPropertiesDao().save(dbSession, OOM_STOP_BOMB_KEY, String.valueOf(oomStopBomb)); - dbSession.commit(); - } - } - - public boolean isIseStopBomb() { - try (DbSession dbSession = dbClient.openSession(false)) { - return dbClient.internalPropertiesDao().selectByKey(dbSession, ISE_STOP_BOMB_KEY).map(Boolean::valueOf).orElse(false); - } - } - - public void setIseStopBomb(boolean iseStopBomb) { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.internalPropertiesDao().save(dbSession, ISE_STOP_BOMB_KEY, String.valueOf(iseStopBomb)); - dbSession.commit(); - } - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/ComponentBombReportAnalysisComponentProvider.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/ComponentBombReportAnalysisComponentProvider.java deleted file mode 100644 index 2b2ea4eee9b..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/ComponentBombReportAnalysisComponentProvider.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce; - -import java.util.List; -import org.picocontainer.Startable; -import org.sonar.plugin.ce.ReportAnalysisComponentProvider; -import org.sonar.server.computation.task.container.EagerStart; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - -public class ComponentBombReportAnalysisComponentProvider implements ReportAnalysisComponentProvider { - private final BombConfig bombConfig; - - public ComponentBombReportAnalysisComponentProvider(BombConfig bombConfig) { - this.bombConfig = bombConfig; - } - - @Override - public List getComponents() { - if (bombConfig.isOomStartBomb()) { - return singletonList(OOMFailingStartComponent.class); - } - if (bombConfig.isIseStartBomb()) { - return singletonList(ISEFailingStartComponent.class); - } - if (bombConfig.isOomStopBomb()) { - return singletonList(OOMFailingStopComponent.class); - } - if (bombConfig.isIseStopBomb()) { - return singletonList(ISEFailingStopComponent.class); - } - return emptyList(); - } - - @EagerStart - public static final class OOMFailingStartComponent implements Startable { - - @Override - public void start() { - OOMGenerator.consumeAvailableMemory(); - } - - @Override - public void stop() { - // nothing to do - } - } - - @EagerStart - public static final class ISEFailingStartComponent implements Startable { - - @Override - public void start() { - throw new IllegalStateException("Faking an IllegalStateException thrown by a startable component in the Analysis Report processing container"); - } - - @Override - public void stop() { - // nothing to do - } - } - - @EagerStart - public static final class OOMFailingStopComponent implements Startable { - - @Override - public void start() { - // nothing to do - } - - @Override - public void stop() { - OOMGenerator.consumeAvailableMemory(); - } - } - - @EagerStart - public static final class ISEFailingStopComponent implements Startable { - - @Override - public void start() { - // nothing to do - } - - @Override - public void stop() { - throw new IllegalStateException("Faking an IllegalStateException thrown by a stoppable component in the Analysis Report processing container"); - } - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/IseTaskProcessor.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/IseTaskProcessor.java deleted file mode 100644 index 40b11ec079d..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/IseTaskProcessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce; - -import java.util.Collections; -import java.util.Set; -import org.sonar.ce.queue.CeTask; -import org.sonar.ce.queue.CeTaskResult; -import org.sonar.ce.taskprocessor.CeTaskProcessor; - -public class IseTaskProcessor implements CeTaskProcessor { - @Override - public Set getHandledCeTaskTypes() { - return Collections.singleton("ISE"); - } - - @Override - public CeTaskResult process(CeTask task) { - throw new IllegalStateException("Faking an IllegalStateException thrown processing a task"); - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/OOMGenerator.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/OOMGenerator.java deleted file mode 100644 index e8673412fc2..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/OOMGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce; - -import java.util.ArrayList; -import java.util.List; - -public final class OOMGenerator { - private OOMGenerator() { - // prevents instantiation - } - - public static List consumeAvailableMemory() { - List holder = new ArrayList<>(); - while (true) { - holder.add(new byte[128 * 1024]); - } - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/OkTaskProcessor.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/OkTaskProcessor.java deleted file mode 100644 index 88d9abaf013..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/OkTaskProcessor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce; - -import java.util.Collections; -import java.util.Optional; -import java.util.Set; -import org.sonar.ce.queue.CeTask; -import org.sonar.ce.queue.CeTaskResult; -import org.sonar.ce.taskprocessor.CeTaskProcessor; - -public class OkTaskProcessor implements CeTaskProcessor { - @Override - public Set getHandledCeTaskTypes() { - return Collections.singleton("OK"); - } - - @Override - public CeTaskResult process(CeTask task) { - return Optional::empty; - } - - -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/OomTaskProcessor.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/OomTaskProcessor.java deleted file mode 100644 index a79c71f0ec7..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/OomTaskProcessor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce; - -import java.util.Collections; -import java.util.Set; -import org.sonar.ce.queue.CeTask; -import org.sonar.ce.queue.CeTaskResult; -import org.sonar.ce.taskprocessor.CeTaskProcessor; - -public class OomTaskProcessor implements CeTaskProcessor { - @Override - public Set getHandledCeTaskTypes() { - return Collections.singleton("OOM"); - } - - @Override - public CeTaskResult process(CeTask task) { - OOMGenerator.consumeAvailableMemory(); - return null; - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/BombActivatorAction.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/BombActivatorAction.java deleted file mode 100644 index 31be2ce3bc1..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/BombActivatorAction.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce.ws; - -import ce.BombConfig; -import java.util.Arrays; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; - -import static java.util.stream.Collectors.toList; - -public class BombActivatorAction implements FakeGoVWsAction { - - private static final String PARAM_BOMB_TYPE = "type"; - - private final BombConfig bombConfig; - - public BombActivatorAction(BombConfig bombConfig) { - this.bombConfig = bombConfig; - } - - @Override - public void define(WebService.NewController controller) { - WebService.NewAction action = controller.createAction("activate_bomb") - .setPost(true) - .setHandler(this); - action.createParam(PARAM_BOMB_TYPE) - .setRequired(true) - .setPossibleValues(Arrays.stream(BombType.values()).map(Enum::toString).collect(toList())); - } - - @Override - public void handle(Request request, Response response) { - BombType bombType = BombType.valueOf(request.mandatoryParam(PARAM_BOMB_TYPE)); - - bombConfig.reset(); - switch (bombType) { - case ISE_START: - bombConfig.setIseStartBomb(true); - break; - case OOM_START: - bombConfig.setOomStartBomb(true); - break; - case ISE_STOP: - bombConfig.setIseStopBomb(true); - break; - case OOM_STOP: - bombConfig.setOomStopBomb(true); - break; - case NONE: - break; - default: - throw new IllegalArgumentException("Unsupported bomb type " + bombType); - } - - response.noContent(); - } - - enum BombType { - NONE, OOM_START, ISE_START, OOM_STOP, ISE_STOP - - } - -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/FakeGoVWsAction.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/FakeGoVWsAction.java deleted file mode 100644 index 58fb69a8b72..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/FakeGoVWsAction.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce.ws; - -import org.sonar.server.ws.WsAction; - -public interface FakeGoVWsAction extends WsAction { -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/FakeGovWs.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/FakeGovWs.java deleted file mode 100644 index 41a49841088..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/FakeGovWs.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce.ws; - -import java.util.Arrays; -import org.sonar.api.server.ws.WebService; - -public class FakeGovWs implements WebService { - private final FakeGoVWsAction[] actions; - - public FakeGovWs(FakeGoVWsAction[] actions) { - this.actions = actions; - } - - @Override - public void define(Context context) { - NewController controller = context.createController("api/fake_gov"); - Arrays.stream(actions).forEach(action -> action.define(controller)); - controller.done(); - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/SubmitAction.java b/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/SubmitAction.java deleted file mode 100644 index fb47686044e..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/ce/ws/SubmitAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 ce.ws; - -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.ce.queue.CeQueue; -import org.sonar.ce.queue.CeTaskSubmit; - -public class SubmitAction implements FakeGoVWsAction { - - private static final String PARAM_TYPE = "type"; - - private final CeQueue ceQueue; - - public SubmitAction(CeQueue ceQueue) { - this.ceQueue = ceQueue; - } - - @Override - public void define(WebService.NewController controller) { - WebService.NewAction action = controller.createAction("submit") - .setPost(true) - .setHandler(this); - action.createParam(PARAM_TYPE) - .setRequired(true) - .setPossibleValues("OOM", "OK", "ISE"); - } - - @Override - public void handle(Request request, Response response) { - String type = request.mandatoryParam(PARAM_TYPE); - - CeTaskSubmit.Builder submit = ceQueue.prepareSubmit(); - submit.setType(type); - - ceQueue.submit(submit.build()); - response.noContent(); - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java b/tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java deleted file mode 100644 index b1682ae6656..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 systemPasscode; - -import java.net.HttpURLConnection; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.RequestHandler; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.server.user.SystemPasscode; - -public class SystemPasscodeWebService implements WebService, RequestHandler { - private final SystemPasscode passcode; - - public SystemPasscodeWebService(SystemPasscode passcode) { - this.passcode = passcode; - } - - @Override - public void define(Context context) { - NewController controller = context.createController("api/system_passcode"); - controller.createAction("check").setHandler(this); - controller.done(); - } - - @Override - public void handle(Request request, Response response) { - if (!passcode.isValid(request)) { - response.stream().setStatus(HttpURLConnection.HTTP_UNAUTHORIZED); - } - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/workerCount/FakeWorkerCountProviderImpl.java b/tests/plugins/fake-governance-plugin/src/main/java/workerCount/FakeWorkerCountProviderImpl.java deleted file mode 100644 index 4e05ecda89d..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/workerCount/FakeWorkerCountProviderImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 workerCount; -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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. - */ - -import org.sonar.api.config.Configuration; -import org.sonar.ce.configuration.WorkerCountProvider; - -public class FakeWorkerCountProviderImpl implements WorkerCountProvider { - - static final String PROPERTY_WORKER_COUNT = "fakeGovernance.workerCount"; - - private final Configuration configuration; - - public FakeWorkerCountProviderImpl(Configuration configuration) { - this.configuration = configuration; - } - - @Override - public int get() { - return configuration.get(PROPERTY_WORKER_COUNT).map(Integer::valueOf).orElse(1); - } - -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java b/tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java deleted file mode 100644 index df37590a2ab..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 workerCount; - -import org.sonar.api.server.ServerSide; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.ce.http.CeHttpClient; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.property.PropertyDto; -import org.sonar.server.ce.ws.CeWsAction; - -import static workerCount.FakeWorkerCountProviderImpl.PROPERTY_WORKER_COUNT; - -@ServerSide -public class RefreshWorkerCountAction implements CeWsAction { - private static final String PARAM_COUNT = "count"; - - private final CeHttpClient ceHttpClient; - private final DbClient dbClient; - - public RefreshWorkerCountAction(CeHttpClient ceHttpClient, DbClient dbClient) { - this.ceHttpClient = ceHttpClient; - this.dbClient = dbClient; - } - - @Override - public void define(WebService.NewController controller) { - controller.createAction("refreshWorkerCount") - .setPost(true) - .setHandler(this) - .createParam(PARAM_COUNT) - .setPossibleValues("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") - .setRequired(true); - } - - @Override - public void handle(Request request, Response response) { - String count = request.getParam(PARAM_COUNT).getValue(); - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.propertiesDao().saveProperty(new PropertyDto() - .setKey(PROPERTY_WORKER_COUNT) - .setValue(count)); - dbSession.commit(); - } - ceHttpClient.refreshCeWorkerCount(); - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/workerlatch/LatchControllerWorkerMeasureComputer.java b/tests/plugins/fake-governance-plugin/src/main/java/workerlatch/LatchControllerWorkerMeasureComputer.java deleted file mode 100644 index c6d2391f9f0..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/workerlatch/LatchControllerWorkerMeasureComputer.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 workerlatch; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import org.sonar.api.ce.measure.Component; -import org.sonar.api.ce.measure.MeasureComputer; -import org.sonar.api.config.Configuration; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -public class LatchControllerWorkerMeasureComputer implements MeasureComputer { - private static final Logger LOG = Loggers.get(LatchControllerWorkerMeasureComputer.class); - private static final String WORKER_LATCH_SHARED_MEMORY_FILE_PATH = "fakeGoverance.workerLatch.sharedMemoryFile"; - - private static final int WAIT = 200; // ms - private static final int MAX_WAIT_ROUND = 5 * 60 * 2; // 2 minutes - - private static final int MAX_SHARED_MEMORY = 1; - private static final byte UNLATCHED = (byte) 0x01; - - private final File sharedMemory; - - public LatchControllerWorkerMeasureComputer(Configuration configuration) { - this.sharedMemory = configuration.get(WORKER_LATCH_SHARED_MEMORY_FILE_PATH) - .map(path -> { - File file = new File(path); - if (file.exists() && file.isFile()) { - return file; - } - LOG.info("Latch sharedMemory file {} is not a file or does not exist", path); - return null; - }) - .orElse(null); - } - - private boolean isLatchEnabled() { - return sharedMemory != null; - } - - @Override - public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) { - return defContext.newDefinitionBuilder() - .setOutputMetrics(WorkerLatchMetrics.METRIC_KEY) - .build(); - } - - @Override - public void compute(MeasureComputerContext context) { - Component component = context.getComponent(); - if (isLatchEnabled() && component.getType() == Component.Type.PROJECT) { - context.addMeasure(WorkerLatchMetrics.METRIC_KEY, waitForUnlatched(component.getKey())); - } else { - context.addMeasure(WorkerLatchMetrics.METRIC_KEY, false); - } - } - - private boolean waitForUnlatched(String key) { - RandomAccessFile randomAccessFile = null; - try { - randomAccessFile = new RandomAccessFile(sharedMemory, "rw"); - MappedByteBuffer mappedByteBuffer = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, MAX_SHARED_MEMORY); - int i = 0; - boolean unlatched = isUnlatched(mappedByteBuffer); - while (!unlatched && i < MAX_WAIT_ROUND) { - waitInterruptedly(); - i++; - unlatched = isUnlatched(mappedByteBuffer); - } - LOG.info("Project {} unlatched={} i={}", key, unlatched, i); - - return true; - } catch (IOException e) { - LOG.error("Failed to read or write to shared memory", e); - return false; - } finally { - if (randomAccessFile != null) { - try { - randomAccessFile.close(); - } catch (IOException e) { - LOG.error("Failed to close randomAccessFile", e); - } - } - } - } - - private static void waitInterruptedly() { - try { - Thread.sleep(WAIT); - } catch (InterruptedException e) { - LOG.error("Wait was interrupted"); - } - } - - private boolean isUnlatched(MappedByteBuffer mappedByteBuffer) { - return mappedByteBuffer.get(0) == UNLATCHED; - } - -} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/workerlatch/WorkerLatchMetrics.java b/tests/plugins/fake-governance-plugin/src/main/java/workerlatch/WorkerLatchMetrics.java deleted file mode 100644 index 7b31a6c666a..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/java/workerlatch/WorkerLatchMetrics.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 workerlatch; - -import java.util.Collections; -import java.util.List; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metrics; - -public class WorkerLatchMetrics implements Metrics { - static final String METRIC_KEY = "WORKER_LATCH"; - - @Override - public List getMetrics() { - return Collections.singletonList( - new Metric.Builder(METRIC_KEY, "Worker latch", Metric.ValueType.BOOL) - .setHidden(true) - .create()); - } -} diff --git a/tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties b/tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties deleted file mode 100644 index f8ac8fcaef5..00000000000 --- a/tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties +++ /dev/null @@ -1,2 +0,0 @@ -billing.upgrade_box.header=The fake billing plugin is installed -billing.upgrade_box.text=It shows how to change the wording and hide the "Upgrade" button. \ No newline at end of file diff --git a/tests/src/test/java/org/sonarqube/tests/Byteman.java b/tests/src/test/java/org/sonarqube/tests/Byteman.java index 26e21b4a31b..c6d4f1bf61f 100644 --- a/tests/src/test/java/org/sonarqube/tests/Byteman.java +++ b/tests/src/test/java/org/sonarqube/tests/Byteman.java @@ -35,7 +35,6 @@ import static java.lang.String.format; public class Byteman { private final int port; - private final OrchestratorBuilder builder; public enum Process { WEB("sonar.web.javaAdditionalOpts"), CE("sonar.ce.javaAdditionalOpts"); @@ -47,10 +46,12 @@ public class Byteman { } } - public Byteman(OrchestratorBuilder builder, Process process) { - this.builder = builder; - String jar = findBytemanJar(); + public Byteman() { port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); + } + + public void install(OrchestratorBuilder builder, Process process) { + String jar = findBytemanJar(); String bytemanArg = format("-javaagent:%s=boot:%s,port:%d", jar, jar, port); builder.setServerProperty(process.argument, bytemanArg); } @@ -89,7 +90,4 @@ public class Byteman { } } - public OrchestratorBuilder getOrchestratorBuilder() { - return builder; - } } diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index 09e1edb94d4..0a22aa2353a 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -49,26 +49,26 @@ import static util.ItUtils.xooPlugin; public class Category1Suite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .setServerProperty("sonar.notifications.delay", "1") - .addPlugin(pluginArtifact("property-sets-plugin")) - .addPlugin(pluginArtifact("sonar-subcategories-plugin")) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.notifications.delay", "1") + .addPlugin(pluginArtifact("property-sets-plugin")) + .addPlugin(pluginArtifact("sonar-subcategories-plugin")) - // Used in SettingsTest.global_property_change_extension_point - .addPlugin(pluginArtifact("global-property-change-plugin")) + // Used in SettingsTest.global_property_change_extension_point + .addPlugin(pluginArtifact("global-property-change-plugin")) - // Used in SettingsTest.should_get_settings_default_value - .addPlugin(pluginArtifact("server-plugin")) + // Used in SettingsTest.should_get_settings_default_value + .addPlugin(pluginArtifact("server-plugin")) - // Used in I18nTest - .addPlugin(pluginArtifact("l10n-fr-pack")) + // Used in I18nTest + .addPlugin(pluginArtifact("l10n-fr-pack")) - // 1 second. Required for notification test. - .setServerProperty("sonar.notifications.delay", "1") + // 1 second. Required for notification test. + .setServerProperty("sonar.notifications.delay", "1") - .addPlugin(pluginArtifact("posttask-plugin")) + .addPlugin(pluginArtifact("posttask-plugin")) - .addPlugin(xooPlugin()) - .build(); + .addPlugin(xooPlugin())); } diff --git a/tests/src/test/java/org/sonarqube/tests/Category3Suite.java b/tests/src/test/java/org/sonarqube/tests/Category3Suite.java index 6cec2f483b3..468dbf14999 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category3Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category3Suite.java @@ -73,29 +73,28 @@ import static util.ItUtils.xooPlugin; public class Category3Suite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", "LATEST_RELEASE")) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", "LATEST_RELEASE")) - // Used by SettingsEncryptionTest - .addPlugin(pluginArtifact("settings-encryption-plugin")) + // Used by SettingsEncryptionTest + .addPlugin(pluginArtifact("settings-encryption-plugin")) - // Used by IssuesModeTest - .addPlugin(pluginArtifact("access-secured-props-plugin")) + // Used by IssuesModeTest + .addPlugin(pluginArtifact("access-secured-props-plugin")) - // used by TempFolderTest and DecimalScaleMetricTest - .addPlugin(pluginArtifact("batch-plugin")) + // used by TempFolderTest and DecimalScaleMetricTest + .addPlugin(pluginArtifact("batch-plugin")) - // used by ExtensionLifecycleTest - .addPlugin(pluginArtifact("extension-lifecycle-plugin")) + // used by ExtensionLifecycleTest + .addPlugin(pluginArtifact("extension-lifecycle-plugin")) - // used by ProjectBuilderTest - .addPlugin(pluginArtifact("project-builder-plugin")) + // used by ProjectBuilderTest + .addPlugin(pluginArtifact("project-builder-plugin")) - // used by ProjectWithoutSourceTest - .addPlugin(pluginArtifact("save-measure-on-project-plugin")) + // used by ProjectWithoutSourceTest + .addPlugin(pluginArtifact("save-measure-on-project-plugin")) - .setServerProperty("sonar.ce.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005") - - .build(); + .setServerProperty("sonar.ce.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005")); } diff --git a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java index 7e3ccedbc2a..b738d047fa7 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java @@ -35,8 +35,6 @@ import org.sonarqube.tests.serverSystem.LogsTest; import org.sonarqube.tests.serverSystem.PingTest; import org.sonarqube.tests.serverSystem.ServerSystemTest; import org.sonarqube.tests.serverSystem.SystemInfoTest; -import org.sonarqube.tests.ui.UiExtensionsTest; -import org.sonarqube.tests.ui.UiTest; import org.sonarqube.tests.ws.WsLocalCallTest; import org.sonarqube.tests.ws.WsTest; @@ -74,19 +72,18 @@ import static util.ItUtils.xooPlugin; public class Category4Suite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - // Used in UiExtensionsTest - .addPlugin(pluginArtifact("ui-extensions-plugin")) + // Used in UiExtensionsTest + .addPlugin(pluginArtifact("ui-extensions-plugin")) - // Used by WsLocalCallTest - .addPlugin(pluginArtifact("ws-plugin")) + // Used by WsLocalCallTest + .addPlugin(pluginArtifact("ws-plugin")) - // Used by LogsTest - .setServerProperty("sonar.web.accessLogs.pattern", LogsTest.ACCESS_LOGS_PATTERN) + // Used by LogsTest + .setServerProperty("sonar.web.accessLogs.pattern", LogsTest.ACCESS_LOGS_PATTERN) - .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001") - - .build(); + .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001")); } diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java index bcb9a3159f7..123ab4aeb6f 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java @@ -67,18 +67,16 @@ public class Category6Suite { public static final int SEARCH_HTTP_PORT = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + // for ES resiliency tests + .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) + .setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .setServerProperty("sonar.notifications.delay", "1") - // for ES resiliency tests - .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) - .setServerProperty("sonar.search.recovery.delayInMs", "1000") - .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") - .setServerProperty("sonar.notifications.delay", "1") + .addPlugin(xooPlugin()) + .addPlugin(pluginArtifact("ui-extensions-plugin")) - .addPlugin(xooPlugin()) - .addPlugin(pluginArtifact("ui-extensions-plugin")) - - .setServerProperty("sonar.sonarcloud.enabled", "true") - - .build(); + .setServerProperty("sonar.sonarcloud.enabled", "true")); } diff --git a/tests/src/test/java/org/sonarqube/tests/analysis/AnalysisEsResilienceTest.java b/tests/src/test/java/org/sonarqube/tests/analysis/AnalysisEsResilienceTest.java index 9cb1c5d39dd..2829597e286 100644 --- a/tests/src/test/java/org/sonarqube/tests/analysis/AnalysisEsResilienceTest.java +++ b/tests/src/test/java/org/sonarqube/tests/analysis/AnalysisEsResilienceTest.java @@ -64,13 +64,15 @@ public class AnalysisEsResilienceTest { private static final int esHttpPort = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); static { - byteman = new Byteman(newOrchestratorBuilder(), CE); - orchestrator = byteman - .getOrchestratorBuilder() - .addPlugin(ItUtils.xooPlugin()) - .setServerProperty("sonar.search.httpPort", "" + esHttpPort) - .setServerProperty("sonar.sonarcloud.enabled", "true") - .build(); + byteman = new Byteman(); + orchestrator = newOrchestratorBuilder( + builder -> { + byteman.install(builder, CE); + builder + .addPlugin(ItUtils.xooPlugin()) + .setServerProperty("sonar.search.httpPort", "" + esHttpPort) + .setServerProperty("sonar.sonarcloud.enabled", "true"); + }); } @Rule @@ -183,8 +185,7 @@ public class AnalysisEsResilienceTest { tuple("CONFIRMED", 0L), tuple("REOPENED", 0L), tuple("RESOLVED", 0L), - tuple("CLOSED", 0L) - ); + tuple("CLOSED", 0L)); tester.elasticsearch().unlockWrites("issues"); @@ -202,8 +203,7 @@ public class AnalysisEsResilienceTest { tuple("CONFIRMED", 0L), tuple("REOPENED", 0L), tuple("RESOLVED", 0L), - tuple("CLOSED", 0L) - ); + tuple("CLOSED", 0L)); } @Test diff --git a/tests/src/test/java/org/sonarqube/tests/authorization/AuthorizationSuite.java b/tests/src/test/java/org/sonarqube/tests/authorization/AuthorizationSuite.java index 7e0c8cb864c..2c92f49dfb7 100644 --- a/tests/src/test/java/org/sonarqube/tests/authorization/AuthorizationSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/authorization/AuthorizationSuite.java @@ -24,8 +24,8 @@ import org.junit.ClassRule; import org.junit.runner.RunWith; import org.junit.runners.Suite; +import static util.ItUtils.installCoreExtension; import static util.ItUtils.newOrchestratorBuilder; -import static util.ItUtils.pluginArtifact; import static util.ItUtils.xooPlugin; @RunWith(Suite.class) @@ -42,13 +42,14 @@ import static util.ItUtils.xooPlugin; public class AuthorizationSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - // for SystemPasscodeTest - // this privileged plugin provides the WS api/system_passcode/check - // that is used by the tests - .addPlugin(pluginArtifact("fake-governance-plugin")) - .setServerProperty("sonar.web.systemPasscode", SystemPasscodeTest.VALID_PASSCODE) - - .addPlugin(xooPlugin()) - .build(); + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.web.systemPasscode", SystemPasscodeTest.VALID_PASSCODE) + .addPlugin(xooPlugin()), + server -> { + // for SystemPasscodeTest + // this core-extension provides the WS api/system_passcode/check + // that is used by the tests + installCoreExtension(server, "core-extension-it-tests"); + }); } diff --git a/tests/src/test/java/org/sonarqube/tests/authorization/SystemPasscodeTest.java b/tests/src/test/java/org/sonarqube/tests/authorization/SystemPasscodeTest.java index 233c2662d20..fbdafe3697c 100644 --- a/tests/src/test/java/org/sonarqube/tests/authorization/SystemPasscodeTest.java +++ b/tests/src/test/java/org/sonarqube/tests/authorization/SystemPasscodeTest.java @@ -22,7 +22,6 @@ package org.sonarqube.tests.authorization; import com.sonar.orchestrator.Orchestrator; import java.util.Arrays; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; @@ -32,7 +31,6 @@ import org.sonarqube.ws.client.WsResponse; import static org.assertj.core.api.Assertions.assertThat; -@Ignore("FIXME IT disabled because it relies on a WS getting injected with core class, ie. a privileged plugin (fake-governance-plugin)") public class SystemPasscodeTest { static final String VALID_PASSCODE = "123456"; diff --git a/tests/src/test/java/org/sonarqube/tests/ce/CeShutdownTest.java b/tests/src/test/java/org/sonarqube/tests/ce/CeShutdownTest.java index ce8678dc292..a2253f43bcc 100644 --- a/tests/src/test/java/org/sonarqube/tests/ce/CeShutdownTest.java +++ b/tests/src/test/java/org/sonarqube/tests/ce/CeShutdownTest.java @@ -116,12 +116,12 @@ public class CeShutdownTest { pauseFile = temp.newFile(); FileUtils.touch(pauseFile); - orchestrator = newOrchestratorBuilder() - .setServerProperty("sonar.ce.pauseTask.path", pauseFile.getAbsolutePath()) - .setServerProperty("sonar.ce.gracefulStopTimeOutInMs", "" + timeOutInMs) - .addPlugin(ItUtils.xooPlugin()) - .addPlugin(ItUtils.pluginArtifact("server-plugin")) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.ce.pauseTask.path", pauseFile.getAbsolutePath()) + .setServerProperty("sonar.ce.gracefulStopTimeOutInMs", "" + timeOutInMs) + .addPlugin(ItUtils.xooPlugin()) + .addPlugin(ItUtils.pluginArtifact("server-plugin"))); orchestrator.start(); adminWsClient = ItUtils.newAdminWsClient(orchestrator); logsTailer = LogsTailer.builder() diff --git a/tests/src/test/java/org/sonarqube/tests/ce/CeWorkersTest.java b/tests/src/test/java/org/sonarqube/tests/ce/CeWorkersTest.java index e70d3377bd9..2bfb2edbbb8 100644 --- a/tests/src/test/java/org/sonarqube/tests/ce/CeWorkersTest.java +++ b/tests/src/test/java/org/sonarqube/tests/ce/CeWorkersTest.java @@ -21,7 +21,6 @@ package org.sonarqube.tests.ce; import com.google.common.collect.ImmutableList; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.SonarScanner; import com.sonar.orchestrator.http.HttpMethod; import java.io.File; @@ -43,7 +42,6 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonarqube.ws.Ce; @@ -57,12 +55,11 @@ import static java.lang.String.valueOf; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.installCoreExtension; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.newOrchestratorBuilder; -import static util.ItUtils.pluginArtifact; import static util.ItUtils.xooPlugin; -@Ignore("FIXME IT disabled because it relies on a privileged plugin (fake-governance-plugin)") public class CeWorkersTest { private static final int WAIT = 200; // ms private static final int MAX_WAIT_LOOP = 5 * 60 * 5; // 5 minutes @@ -84,13 +81,13 @@ public class CeWorkersTest { public static void setUp() throws Exception { sharedMemory = temporaryFolder.newFile(); - OrchestratorBuilder builder = newOrchestratorBuilder() - .addPlugin(pluginArtifact("fake-governance-plugin")) - .setServerProperty("fakeGoverance.workerLatch.sharedMemoryFile", sharedMemory.getAbsolutePath()) - // overwrite default value to display heap dump on OOM and reduce max heap - .setServerProperty("sonar.ce.javaOpts", "-Xmx256m -Xms128m") - .addPlugin(xooPlugin()); - orchestrator = builder.build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .setServerProperty("itTests.workerLatch.sharedMemoryFile", sharedMemory.getAbsolutePath()) + // overwrite default value to display heap dump on OOM and reduce max heap + .setServerProperty("sonar.ce.javaOpts", "-Xmx256m -Xms128m") + .addPlugin(xooPlugin()), + server -> installCoreExtension(server, "core-extension-it-tests")); orchestrator.start(); adminWsClient = newAdminWsClient(orchestrator); diff --git a/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java b/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java index 9d08069bc36..cce0e2ad99b 100644 --- a/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java @@ -37,8 +37,10 @@ import static util.ItUtils.xooPlugin; public class ComponentSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = ItUtils.newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .build(); + public static final Orchestrator ORCHESTRATOR = ItUtils.newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/duplication/DuplicationSuite.java b/tests/src/test/java/org/sonarqube/tests/duplication/DuplicationSuite.java index e8c1833f402..e0f4bd3c9ba 100644 --- a/tests/src/test/java/org/sonarqube/tests/duplication/DuplicationSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/duplication/DuplicationSuite.java @@ -37,8 +37,9 @@ import static util.ItUtils.xooPlugin; }) public class DuplicationSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/issue/ExternalIssueSuite.java b/tests/src/test/java/org/sonarqube/tests/issue/ExternalIssueSuite.java index c5aa35f5f54..e5d78462f05 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/ExternalIssueSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/ExternalIssueSuite.java @@ -36,7 +36,9 @@ import util.ItUtils; public class ExternalIssueSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = ItUtils.newOrchestratorBuilder() - .addPlugin(ItUtils.xooPlugin()) - .build(); + public static final Orchestrator ORCHESTRATOR = ItUtils.newOrchestratorBuilder( + builder -> builder + .addPlugin(ItUtils.xooPlugin()) + + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java index c085dfa1f72..fcd3d9e4d4d 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java @@ -69,11 +69,13 @@ public class IssueCreationDatePluginChangedTest { private static final String USER_EMAIL = "tester@example.org"; @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .addPlugin(ItUtils.pluginArtifact("backdating-plugin-v1")) - .addPlugin(ItUtils.pluginArtifact("backdating-customplugin")) - .build(); + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + .addPlugin(ItUtils.pluginArtifact("backdating-plugin-v1")) + .addPlugin(ItUtils.pluginArtifact("backdating-customplugin")) + + ); @Rule public Tester tester = new Tester(ORCHESTRATOR); diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueSuite.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueSuite.java index cc6a0097e41..5d700760a77 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueSuite.java @@ -53,16 +53,17 @@ import static util.ItUtils.xooPlugin; public class IssueSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .setServerProperty("sonar.search.httpPort", "9025") - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.search.httpPort", "9025") + .addPlugin(xooPlugin()) - // issue - .addPlugin(pluginArtifact("issue-filter-plugin")) + // issue + .addPlugin(pluginArtifact("issue-filter-plugin")) - // 1 second. Required for notification test. - .setServerProperty("sonar.notifications.delay", "1") + // 1 second. Required for notification test. + .setServerProperty("sonar.notifications.delay", "1") - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/issue/OrganizationIssueSuite.java b/tests/src/test/java/org/sonarqube/tests/issue/OrganizationIssueSuite.java index 943657e0721..3cfc081c2ed 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/OrganizationIssueSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/OrganizationIssueSuite.java @@ -34,11 +34,12 @@ import static util.ItUtils.xooPlugin; public class OrganizationIssueSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - .setServerProperty("sonar.sonarcloud.enabled", "true") + .setServerProperty("sonar.sonarcloud.enabled", "true") - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/lite/LiteTest.java b/tests/src/test/java/org/sonarqube/tests/lite/LiteTest.java index 0c89f7cd8fe..87a49287b39 100644 --- a/tests/src/test/java/org/sonarqube/tests/lite/LiteTest.java +++ b/tests/src/test/java/org/sonarqube/tests/lite/LiteTest.java @@ -25,14 +25,14 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.RuleChain; import org.sonarqube.qa.util.Tester; -import org.sonarqube.ws.Issues; import org.sonarqube.ws.Components; +import org.sonarqube.ws.Issues; import org.sonarqube.ws.Measures; import org.sonarqube.ws.client.components.TreeRequest; import org.sonarqube.ws.client.issues.IssuesService; import org.sonarqube.ws.client.issues.SearchRequest; -import org.sonarqube.ws.client.measures.ComponentTreeRequest; import org.sonarqube.ws.client.measures.ComponentRequest; +import org.sonarqube.ws.client.measures.ComponentTreeRequest; import org.sonarqube.ws.client.measures.MeasuresService; import static java.util.Arrays.asList; @@ -46,10 +46,10 @@ public class LiteTest { private static final String PROJECT_KEY = "com.sonarsource.it.samples:multi-modules-sample"; - private static Orchestrator orchestrator = newOrchestratorBuilder() - .setOrchestratorProperty("sonar.web.context", "/sonarqube") - .addPlugin(xooPlugin()) - .build(); + private static Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder + .setOrchestratorProperty("sonar.web.context", "/sonarqube") + .addPlugin(xooPlugin())); private static Tester tester = new Tester(orchestrator); diff --git a/tests/src/test/java/org/sonarqube/tests/marketplace/UpdateCenterTest.java b/tests/src/test/java/org/sonarqube/tests/marketplace/UpdateCenterTest.java index 8e50a080451..e64590cb23e 100644 --- a/tests/src/test/java/org/sonarqube/tests/marketplace/UpdateCenterTest.java +++ b/tests/src/test/java/org/sonarqube/tests/marketplace/UpdateCenterTest.java @@ -37,10 +37,12 @@ import static util.ItUtils.pluginArtifact; public class UpdateCenterTest { @ClassRule - public static final Orchestrator orchestrator = newOrchestratorBuilder() - .setServerProperty("sonar.updatecenter.url", UpdateCenterTest.class.getResource("/marketplace/UpdateCenterTest/update-center.properties").toString()) - .addPlugin(pluginArtifact("sonar-fake-plugin")) - .build(); + public static final Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.updatecenter.url", UpdateCenterTest.class.getResource("/marketplace/UpdateCenterTest/update-center.properties").toString()) + .addPlugin(pluginArtifact("sonar-fake-plugin")) + + ); @Rule public UserRule userRule = UserRule.from(orchestrator); @@ -57,10 +59,10 @@ public class UpdateCenterTest { MarketplacePage page = nav.logIn().submitCredentials(userRule.createAdminUser()).openMarketplace(); page .hasPluginsCount(2) - .hasPluginWithText("Fake","installed") - .hasPluginWithText("Fake","Uninstall") - .hasPluginWithText("Fake","Licensed under GNU LGPL 3") - .hasPluginWithText("Fake","Developed by SonarSource"); + .hasPluginWithText("Fake", "installed") + .hasPluginWithText("Fake", "Uninstall") + .hasPluginWithText("Fake", "Licensed under GNU LGPL 3") + .hasPluginWithText("Fake", "Developed by SonarSource"); page .searchPlugin("fa") diff --git a/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java b/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java index ea6ad5d0e7f..ee937ed3658 100644 --- a/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java @@ -45,12 +45,13 @@ import static util.ItUtils.xooPlugin; public class MeasureSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - // used by DecimalScaleMetricTest - .addPlugin(pluginArtifact("batch-plugin")) + // used by DecimalScaleMetricTest + .addPlugin(pluginArtifact("batch-plugin")) - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationSuite.java b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationSuite.java index 0e77d7c2854..a2b6c311e43 100644 --- a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationSuite.java @@ -41,13 +41,14 @@ import static util.ItUtils.xooPlugin; public class OrganizationSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder - .addPlugin(xooPlugin()) - .addPlugin(pluginArtifact("fake-billing-plugin")) - .addPlugin(pluginArtifact("ui-extensions-plugin")) + .addPlugin(xooPlugin()) + .addPlugin(pluginArtifact("fake-billing-plugin")) + .addPlugin(pluginArtifact("ui-extensions-plugin")) - .setServerProperty("sonar.sonarcloud.enabled", "true") + .setServerProperty("sonar.sonarcloud.enabled", "true") - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/performance/scanner/ScannerPerformanceSuite.java b/tests/src/test/java/org/sonarqube/tests/performance/scanner/ScannerPerformanceSuite.java index 24eab925762..e7143961452 100644 --- a/tests/src/test/java/org/sonarqube/tests/performance/scanner/ScannerPerformanceSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/performance/scanner/ScannerPerformanceSuite.java @@ -43,14 +43,14 @@ import static util.ItUtils.xooPlugin; public class ScannerPerformanceSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - // should not be so high, but required as long embedded h2 is used -> requires more memory on server - .setServerProperty("sonar.web.javaOpts", "-Xmx1G -XX:+HeapDumpOnOutOfMemoryError") - // Needed by DuplicationTest::hugeJavaFile - .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", "LATEST_RELEASE")) - .restoreProfileAtStartup(FileLocation.ofClasspath("/one-xoo-issue-per-line.xml")) - .build(); + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + // should not be so high, but required as long embedded h2 is used -> requires more memory on server + .setServerProperty("sonar.web.javaOpts", "-Xmx1G -XX:+HeapDumpOnOutOfMemoryError") + // Needed by DuplicationTest::hugeJavaFile + .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", "LATEST_RELEASE")) + .restoreProfileAtStartup(FileLocation.ofClasspath("/one-xoo-issue-per-line.xml"))); @BeforeClass public static void setUp() { diff --git a/tests/src/test/java/org/sonarqube/tests/performance/server/ComputeEnginePerfTest.java b/tests/src/test/java/org/sonarqube/tests/performance/server/ComputeEnginePerfTest.java index f6e15a279a1..864aba6512a 100644 --- a/tests/src/test/java/org/sonarqube/tests/performance/server/ComputeEnginePerfTest.java +++ b/tests/src/test/java/org/sonarqube/tests/performance/server/ComputeEnginePerfTest.java @@ -44,13 +44,13 @@ public class ComputeEnginePerfTest extends AbstractPerfTest { public static TemporaryFolder temp = new TemporaryFolder(); @ClassRule - public static Orchestrator orchestrator = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .setServerProperty( - "sonar.web.javaOpts", - String.format("-Xms%dm -Xmx%dm -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true", MAX_HEAP_SIZE_IN_MEGA, MAX_HEAP_SIZE_IN_MEGA)) - .restoreProfileAtStartup(FileLocation.ofClasspath("/one-xoo-issue-per-line.xml")) - .build(); + public static Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + .setServerProperty( + "sonar.web.javaOpts", + String.format("-Xms%dm -Xmx%dm -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true", MAX_HEAP_SIZE_IN_MEGA, MAX_HEAP_SIZE_IN_MEGA)) + .restoreProfileAtStartup(FileLocation.ofClasspath("/one-xoo-issue-per-line.xml"))); private static File bigProjectBaseDir; diff --git a/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java b/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java index 2d147551db5..0b99aeaa36d 100644 --- a/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java +++ b/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java @@ -20,8 +20,6 @@ package org.sonarqube.tests.performance.server; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.locator.FileLocation; -import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Date; @@ -46,15 +44,17 @@ public class ServerPerfTest extends AbstractPerfTest { @Test public void server_startup_and_shutdown() throws Exception { String defaultWebJavaOptions = "-Xmx768m -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Dfile.encoding=UTF-8"; - Orchestrator orchestrator = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - // See http://wiki.apache.org/tomcat/HowTo/FasterStartUp - // Sometimes source of entropy is too small and Tomcat spends ~20 seconds on the step : - // "Creation of SecureRandom instance for session ID generation using [SHA1PRNG]" - // Using /dev/urandom fixes the issue on linux - .setServerProperty("sonar.web.javaOpts", defaultWebJavaOptions + " -Djava.security.egd=file:/dev/./urandom") - .build(); + // See http://wiki.apache.org/tomcat/HowTo/FasterStartUp + // Sometimes source of entropy is too small and Tomcat spends ~20 seconds on the step : + // "Creation of SecureRandom instance for session ID generation using [SHA1PRNG]" + // Using /dev/urandom fixes the issue on linux + .setServerProperty("sonar.web.javaOpts", defaultWebJavaOptions + " -Djava.security.egd=file:/dev/./urandom") + + ); try { ServerLogs.clear(orchestrator); orchestrator.start(); diff --git a/tests/src/test/java/org/sonarqube/tests/project/OrganizationProjectSuite.java b/tests/src/test/java/org/sonarqube/tests/project/OrganizationProjectSuite.java index 75dc194bac2..7aae5bd8be3 100644 --- a/tests/src/test/java/org/sonarqube/tests/project/OrganizationProjectSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/project/OrganizationProjectSuite.java @@ -52,20 +52,21 @@ public class OrganizationProjectSuite { static final int SEARCH_HTTP_PORT = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - // for ES resiliency tests - .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) - .setServerProperty("sonar.search.recovery.delayInMs", "1000") - .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") - .setServerProperty("sonar.notifications.delay", "1") + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + // for ES resiliency tests + .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) + .setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .setServerProperty("sonar.notifications.delay", "1") - .setServerProperty("sonar.sonarcloud.enabled", "true") + .setServerProperty("sonar.sonarcloud.enabled", "true") - .addPlugin(xooPlugin()) + .addPlugin(xooPlugin()) - // for ProjectSettingsTest - .addPlugin(pluginArtifact("sonar-subcategories-plugin")) + // for ProjectSettingsTest + .addPlugin(pluginArtifact("sonar-subcategories-plugin")) - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java index b469378dce4..79975d34715 100644 --- a/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java @@ -40,18 +40,19 @@ public class ProjectSuite { static final int SEARCH_HTTP_PORT = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - // for ES resiliency tests - .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) - .setServerProperty("sonar.search.recovery.delayInMs", "1000") - .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") - .setServerProperty("sonar.notifications.delay", "1") + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + // for ES resiliency tests + .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) + .setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .setServerProperty("sonar.notifications.delay", "1") - .addPlugin(xooPlugin()) + .addPlugin(xooPlugin()) - // for ProjectSettingsTest - .addPlugin(pluginArtifact("sonar-subcategories-plugin")) + // for ProjectSettingsTest + .addPlugin(pluginArtifact("sonar-subcategories-plugin")) - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java index f91b9cdfbba..d3c1a816e6a 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java @@ -37,13 +37,15 @@ import static util.ItUtils.xooPlugin; public class OrganizationQualityGateSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - // required for notification tests - .setServerProperty("sonar.notifications.delay", "1") - .setServerProperty("sonar.sonarcloud.enabled", "true") + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + // required for notification tests + .setServerProperty("sonar.notifications.delay", "1") + .setServerProperty("sonar.sonarcloud.enabled", "true") - .addPlugin(pluginArtifact("posttask-plugin")) - .addPlugin(xooPlugin()) - .build(); + .addPlugin(pluginArtifact("posttask-plugin")) + .addPlugin(xooPlugin()) + + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java index 910144e75cb..3cb1b8a9205 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java @@ -39,12 +39,14 @@ import static util.ItUtils.xooPlugin; public class QualityGateSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - // required for notification tests - .setServerProperty("sonar.notifications.delay", "1") + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + // required for notification tests + .setServerProperty("sonar.notifications.delay", "1") - .addPlugin(pluginArtifact("posttask-plugin")) - .addPlugin(xooPlugin()) - .build(); + .addPlugin(pluginArtifact("posttask-plugin")) + .addPlugin(xooPlugin()) + + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java index b796cfe6b84..ee286940e76 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java @@ -41,9 +41,10 @@ import static util.ItUtils.xooPlugin; public class QualityModelSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/ActiveRuleEsResilienceTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/ActiveRuleEsResilienceTest.java index 1320f6447fe..9ba5c3505c7 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityProfile/ActiveRuleEsResilienceTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/ActiveRuleEsResilienceTest.java @@ -48,14 +48,15 @@ public class ActiveRuleEsResilienceTest { private static final Byteman byteman; static { - byteman = new Byteman(newOrchestratorBuilder(), WEB); - orchestrator = byteman - .getOrchestratorBuilder() - .setServerProperty("sonar.search.recovery.delayInMs", "1000") - .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") - .setServerProperty("sonar.sonarcloud.enabled", "true") - .addPlugin(ItUtils.xooPlugin()) - .build(); + byteman = new Byteman(); + orchestrator = newOrchestratorBuilder( + builder -> { + byteman.install(builder, WEB); + builder.setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .setServerProperty("sonar.sonarcloud.enabled", "true") + .addPlugin(ItUtils.xooPlugin()); + }); } @Before diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java index 91b687b2d94..4001581cc8f 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java @@ -68,11 +68,11 @@ public class BuiltInQualityProfilesNotificationTest { @Test public void does_not_send_mail_if_no_quality_profile_is_updated() throws Exception { - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("foo-plugin-v1")) - .setServerProperty("email.smtp_host.secured", "localhost") - .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort())) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("foo-plugin-v1")) + .setServerProperty("email.smtp_host.secured", "localhost") + .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))); orchestrator.start(); userRule = UserRule.from(orchestrator); Users.CreateWsResponse.User profileAdmin1 = userRule.generate(); @@ -87,12 +87,12 @@ public class BuiltInQualityProfilesNotificationTest { @Test public void send_mail_if_quality_profile_is_updated() throws Exception { - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("foo-plugin-v1")) - .setServerProperty("sonar.notifications.delay", "1") - .setServerProperty("email.smtp_host.secured", "localhost") - .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort())) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("foo-plugin-v1")) + .setServerProperty("sonar.notifications.delay", "1") + .setServerProperty("email.smtp_host.secured", "localhost") + .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))); orchestrator.start(); userRule = UserRule.from(orchestrator); @@ -143,7 +143,6 @@ public class BuiltInQualityProfilesNotificationTest { "This is a good time to review your quality profiles and update them to benefit from the latest evolutions: " + url + "/profiles") .isEqualTo(messages.get(1).getMimeMessage().getContent().toString()); - // uninstall plugin V2 wsClient.wsConnector().call(new PostRequest("api/plugins/uninstall").setParam("key", "foo")).failIfNotSuccessful(); // install plugin V1 @@ -175,12 +174,12 @@ public class BuiltInQualityProfilesNotificationTest { @Test public void do_not_send_mail_if_notifications_are_disabled_in_settings() throws Exception { - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("foo-plugin-v1")) - .setServerProperty("sonar.builtInQualityProfiles.disableNotificationOnUpdate", "true") - .setServerProperty("email.smtp_host.secured", "localhost") - .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort())) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("foo-plugin-v1")) + .setServerProperty("sonar.builtInQualityProfiles.disableNotificationOnUpdate", "true") + .setServerProperty("email.smtp_host.secured", "localhost") + .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))); orchestrator.start(); userRule = UserRule.from(orchestrator); Users.CreateWsResponse.User profileAdmin1 = userRule.generate(); diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfileUpdateTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfileUpdateTest.java index be34df9fccd..f0a66d8ca5e 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfileUpdateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfileUpdateTest.java @@ -54,10 +54,11 @@ public class QualityProfileUpdateTest { @Test // SONAR-10363 public void updating_an_analyzer_must_update_default_quality_profile() { - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("foo-plugin-v1")) -// .setServerProperty("sonar.sonarcloud.enabled", "true") - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("foo-plugin-v1")) + // .setServerProperty("sonar.sonarcloud.enabled", "true")) + ); orchestrator.start(); tester = new Tester(orchestrator); tester.before(); diff --git a/tests/src/test/java/org/sonarqube/tests/rule/RuleEsResilienceTest.java b/tests/src/test/java/org/sonarqube/tests/rule/RuleEsResilienceTest.java index 1163564bbba..4749cb89790 100644 --- a/tests/src/test/java/org/sonarqube/tests/rule/RuleEsResilienceTest.java +++ b/tests/src/test/java/org/sonarqube/tests/rule/RuleEsResilienceTest.java @@ -47,13 +47,15 @@ public class RuleEsResilienceTest { private static final Byteman byteman; static { - byteman = new Byteman(newOrchestratorBuilder(), WEB); - orchestrator = byteman - .getOrchestratorBuilder() - .setServerProperty("sonar.search.recovery.delayInMs", "1000") - .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") - .addPlugin(ItUtils.xooPlugin()) - .build(); + byteman = new Byteman(); + orchestrator = newOrchestratorBuilder( + builder -> { + byteman.install(builder, WEB); + builder + .setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .addPlugin(ItUtils.xooPlugin()); + }); } @Before diff --git a/tests/src/test/java/org/sonarqube/tests/rule/RuleReKeyingTest.java b/tests/src/test/java/org/sonarqube/tests/rule/RuleReKeyingTest.java index db88a57a092..7508cdd8a37 100644 --- a/tests/src/test/java/org/sonarqube/tests/rule/RuleReKeyingTest.java +++ b/tests/src/test/java/org/sonarqube/tests/rule/RuleReKeyingTest.java @@ -61,9 +61,9 @@ public class RuleReKeyingTest { @Test public void rules_are_re_keyed_when_upgrading_and_downgrading_plugin() { - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("foo-plugin-v1")) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("foo-plugin-v1"))); orchestrator.start(); tester = new Tester(orchestrator); diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java index 5a9c01d65fe..041bc71e128 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java @@ -69,10 +69,10 @@ public class BlueGreenTest { @Test public void upgrade_analyzer_when_analysis_is_pending_in_compute_engine_queue() throws Exception { - orchestrator = newOrchestratorBuilder() + orchestrator = newOrchestratorBuilder( + builder -> builder .addPlugin(pluginArtifact("blue-green-plugin-v1")) - .addPlugin(xooPlugin()) - .build(); + .addPlugin(xooPlugin())); tester = new Tester(orchestrator).disableOrganizations(); orchestrator.start(); tester.before(); diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java index 532925b7c50..52d45e81933 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java @@ -64,9 +64,9 @@ public class RestartTest { public void restart_in_prod_mode_requires_sysadmin_permission_and_restarts() throws Exception { // server classloader locks Jar files on Windows if (!SystemUtils.IS_OS_WINDOWS) { - orchestrator = newOrchestratorBuilder() - .setOrchestratorProperty("orchestrator.keepWorkspace", "true") - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .setOrchestratorProperty("orchestrator.keepWorkspace", "true")); orchestrator.start(); verifyFailWith403(() -> newWsClient(orchestrator).system().restart()); diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java index ed4fd75d914..593a06215e3 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java @@ -20,7 +20,6 @@ package org.sonarqube.tests.serverSystem; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import org.apache.commons.io.FileUtils; import org.junit.After; @@ -32,6 +31,7 @@ import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; +import static util.ItUtils.locationOf; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.newOrchestratorBuilder; @@ -58,9 +58,9 @@ public class ServerSystemRestartingOrchestrator { @Test public void check_minimal_sonar_version_at_startup() throws Exception { try { - orchestrator = newOrchestratorBuilder() - .addPlugin(FileLocation.of(new File(ServerSystemRestartingOrchestrator.class.getResource("/serverSystem/ServerSystemTest/incompatible-plugin-1.0.jar").toURI()))) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(locationOf(ServerSystemRestartingOrchestrator.class.getResource("/serverSystem/ServerSystemTest/incompatible-plugin-1.0.jar")))); orchestrator.start(); fail(); } catch (Exception e) { @@ -73,9 +73,9 @@ public class ServerSystemRestartingOrchestrator { public void support_install_dir_with_whitespaces() throws Exception { String dirName = "build/distributions/has space"; FileUtils.deleteDirectory(new File(dirName)); - orchestrator = newOrchestratorBuilder() - .setOrchestratorProperty("orchestrator.workspaceDir", dirName) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .setOrchestratorProperty("orchestrator.workspaceDir", dirName)); orchestrator.start(); assertThat(newAdminWsClient(orchestrator).system().status().getStatus()).isEqualTo(System.Status.UP); @@ -84,10 +84,10 @@ public class ServerSystemRestartingOrchestrator { // SONAR-4748 @Test public void should_create_in_temp_folder() throws Exception { - orchestrator = newOrchestratorBuilder() - .addPlugin(ItUtils.pluginArtifact("server-plugin")) - .setServerProperty("sonar.createTempFiles", "true") - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(ItUtils.pluginArtifact("server-plugin")) + .setServerProperty("sonar.createTempFiles", "true")); orchestrator.start(); File tempDir = new File(orchestrator.getServer().getHome(), "temp/tmp"); diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java index 7a2ee2e42a5..14cf8137b5f 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java @@ -129,13 +129,13 @@ public class SystemStateTest { void start(Lock lock) { checkState(orchestrator == null); - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("server-plugin")) - .setServerProperty("sonar.web.startupLock.path", lock.webFile.getAbsolutePath()) - .setServerProperty("sonar.ce.startupLock.path", lock.ceFile.getAbsolutePath()) - .setServerProperty("sonar.search.httpPort", "" + esHttpPort) - .setServerProperty("sonar.web.systemPasscode", systemPassCode) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("server-plugin")) + .setServerProperty("sonar.web.startupLock.path", lock.webFile.getAbsolutePath()) + .setServerProperty("sonar.ce.startupLock.path", lock.ceFile.getAbsolutePath()) + .setServerProperty("sonar.search.httpPort", "" + esHttpPort) + .setServerProperty("sonar.web.systemPasscode", systemPassCode)); elasticsearch = new Elasticsearch(esHttpPort); starter = new Thread(orchestrator::start); diff --git a/tests/src/test/java/org/sonarqube/tests/settings/SettingsSuite.java b/tests/src/test/java/org/sonarqube/tests/settings/SettingsSuite.java index 0b73df2a436..d987479b1d0 100644 --- a/tests/src/test/java/org/sonarqube/tests/settings/SettingsSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/settings/SettingsSuite.java @@ -34,10 +34,8 @@ import static util.ItUtils.xooPlugin; public class SettingsSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = ItUtils.newOrchestratorBuilder() - - .addPlugin(xooPlugin()) - - .build(); + public static final Orchestrator ORCHESTRATOR = ItUtils.newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin())); } diff --git a/tests/src/test/java/org/sonarqube/tests/settings/SettingsTestRestartingOrchestrator.java b/tests/src/test/java/org/sonarqube/tests/settings/SettingsTestRestartingOrchestrator.java index 1c4f5a88e3e..5360e463b55 100644 --- a/tests/src/test/java/org/sonarqube/tests/settings/SettingsTestRestartingOrchestrator.java +++ b/tests/src/test/java/org/sonarqube/tests/settings/SettingsTestRestartingOrchestrator.java @@ -60,11 +60,11 @@ public class SettingsTestRestartingOrchestrator { @Test public void test_settings() { URL secretKeyUrl = getClass().getResource("/settings/SettingsTest/sonar-secret.txt"); - orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("settings-plugin")) - .addPlugin(pluginArtifact("license-plugin")) - .setServerProperty("sonar.secretKeyPath", secretKeyUrl.getFile()) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("settings-plugin")) + .addPlugin(pluginArtifact("license-plugin")) + .setServerProperty("sonar.secretKeyPath", secretKeyUrl.getFile())); startOrchestrator(); String adminUser = userRule.createAdminUser(); @@ -86,11 +86,11 @@ public class SettingsTestRestartingOrchestrator { @Test public void property_relocation() { - orchestrator = newOrchestratorBuilder() + orchestrator = newOrchestratorBuilder( + builder -> builder .addPlugin(pluginArtifact("property-relocation-plugin")) .addPlugin(xooPlugin()) - .setServerProperty("sonar.deprecatedKey", "true") - .build(); + .setServerProperty("sonar.deprecatedKey", "true")); startOrchestrator(); SonarScanner withDeprecatedKey = SonarScanner.create(projectDir("shared/xoo-sample")) diff --git a/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java b/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java index 11b0f7f8a6d..075ffdf6d64 100644 --- a/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java @@ -39,9 +39,9 @@ import static util.ItUtils.xooPlugin; public class SourceSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .addPlugin(MavenLocation.of("org.sonarsource.scm.git", "sonar-scm-git-plugin", "LATEST_RELEASE")) - .build(); + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + .addPlugin(MavenLocation.of("org.sonarsource.scm.git", "sonar-scm-git-plugin", "LATEST_RELEASE"))); } diff --git a/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java b/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java index f654949bd26..47a5eb16fe6 100644 --- a/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java @@ -50,8 +50,8 @@ public class StartupIndexationTest { @Test public void elasticsearch_error_at_startup_must_shutdown_node() throws Exception { try (SonarQube sonarQube = new SonarQube(); - LogsTailer.Watch failedInitialization = sonarQube.logsTailer.watch("Background initialization failed. Stopping SonarQube"); - LogsTailer.Watch stopWatcher = sonarQube.logsTailer.watch("SonarQube is stopped")) { + LogsTailer.Watch failedInitialization = sonarQube.logsTailer.watch("Background initialization failed. Stopping SonarQube"); + LogsTailer.Watch stopWatcher = sonarQube.logsTailer.watch("SonarQube is stopped")) { sonarQube.lockAllElasticsearchWrites(); sonarQube.resume(); stopWatcher.waitForLog(10, TimeUnit.SECONDS); @@ -61,7 +61,7 @@ public class StartupIndexationTest { // Restarting is recreating the indexes try (SonarQube sonarQube = new SonarQube(); - LogsTailer.Watch sonarQubeIsUpWatcher = sonarQube.logsTailer.watch("SonarQube is up")) { + LogsTailer.Watch sonarQubeIsUpWatcher = sonarQube.logsTailer.watch("SonarQube is up")) { sonarQube.resume(); sonarQubeIsUpWatcher.waitForLog(20, TimeUnit.SECONDS); SearchRequest searchRequest = new SearchRequest().setQ("admin"); @@ -82,12 +82,12 @@ public class StartupIndexationTest { pauseFile = temp.newFile(); FileUtils.touch(pauseFile); - orchestrator = newOrchestratorBuilder() - .setServerProperty("sonar.web.pause.path", pauseFile.getAbsolutePath()) - .addPlugin(pluginArtifact("wait-at-platform-level4-plugin")) - .setStartupLogWatcher(l -> l.contains("PlatformLevel4 initialization phase is paused")) - .setServerProperty("sonar.search.httpPort", "" + esHttpPort) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.web.pause.path", pauseFile.getAbsolutePath()) + .addPlugin(pluginArtifact("wait-at-platform-level4-plugin")) + .setStartupLogWatcher(l -> l.contains("PlatformLevel4 initialization phase is paused")) + .setServerProperty("sonar.search.httpPort", "" + esHttpPort)); tester = new Tester(orchestrator); orchestrator.start(); diff --git a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryOptOutTest.java b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryOptOutTest.java index a827baa6282..120e4e55f3d 100644 --- a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryOptOutTest.java +++ b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryOptOutTest.java @@ -39,12 +39,12 @@ public class TelemetryOptOutTest { public static MockWebServer server = new MockWebServer(); - private static Orchestrator orchestrator = newOrchestratorBuilder() + private static Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder .addPlugin(xooPlugin()) .setServerProperty("sonar.telemetry.enable", "false") .setServerProperty("sonar.telemetry.url", server.url("").toString()) - .setServerProperty("sonar.telemetry.frequencyInSeconds", "1") - .build(); + .setServerProperty("sonar.telemetry.frequencyInSeconds", "1")); private static Tester tester = new Tester(orchestrator); @ClassRule diff --git a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryUploadTest.java b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryUploadTest.java index 5257a8847cf..56790db2bdb 100644 --- a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryUploadTest.java +++ b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryUploadTest.java @@ -61,13 +61,14 @@ public class TelemetryUploadTest { @Test public void sent_telemetry_data() throws Exception { telemetryServer.enqueue(new MockResponse().setResponseCode(200)); - orchestrator = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .setServerProperty("sonar.telemetry.url", telemetryServer.url("").toString()) - // increase frequency so that payload is sent quickly after startup - .setServerProperty("sonar.telemetry.frequencyInSeconds", "1") - //.setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8001") - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + .setServerProperty("sonar.telemetry.url", telemetryServer.url("").toString()) + // increase frequency so that payload is sent quickly after startup + .setServerProperty("sonar.telemetry.frequencyInSeconds", "1") + // .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8001") + ); orchestrator.start(); // Consume request to no block the telemetry daemon telemetryServer.takeRequest(); @@ -104,10 +105,10 @@ public class TelemetryUploadTest { @Test public void does_not_send_telemetry_data_right_away_by_Default() { - orchestrator = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - .setServerProperty("sonar.telemetry.url", telemetryServer.url("").toString()) - .build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + .setServerProperty("sonar.telemetry.url", telemetryServer.url("").toString())); // by default telemetry payload is sent 6 hours after startup, once a week orchestrator.start(); @@ -127,7 +128,7 @@ public class TelemetryUploadTest { return (int) Math.round(value); } - private void resetTelemetryLastPing(){ + private void resetTelemetryLastPing() { try (PreparedStatement preparedStatement = orchestrator.getDatabase().openConnection().prepareStatement("delete from internal_properties where kee='telemetry.lastPing'");) { preparedStatement.execute(); preparedStatement.close(); diff --git a/tests/src/test/java/org/sonarqube/tests/test/TestSuite.java b/tests/src/test/java/org/sonarqube/tests/test/TestSuite.java index 9afbbfa2de9..e4177ca8ab1 100644 --- a/tests/src/test/java/org/sonarqube/tests/test/TestSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/test/TestSuite.java @@ -37,9 +37,8 @@ import static util.ItUtils.xooPlugin; public class TestSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - - .build(); + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin())); } diff --git a/tests/src/test/java/org/sonarqube/tests/ui/UiSuite.java b/tests/src/test/java/org/sonarqube/tests/ui/UiSuite.java index e35917afc69..31338ac3031 100644 --- a/tests/src/test/java/org/sonarqube/tests/ui/UiSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/ui/UiSuite.java @@ -37,11 +37,9 @@ import static util.ItUtils.xooPlugin; public class UiSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) - - // Used in UiExtensionsTest - .addPlugin(pluginArtifact("ui-extensions-plugin")) - - .build(); + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) + // Used in UiExtensionsTest + .addPlugin(pluginArtifact("ui-extensions-plugin"))); } diff --git a/tests/src/test/java/org/sonarqube/tests/upgrade/UpgradeTest.java b/tests/src/test/java/org/sonarqube/tests/upgrade/UpgradeTest.java index 8f8977c4707..2ec884365d3 100644 --- a/tests/src/test/java/org/sonarqube/tests/upgrade/UpgradeTest.java +++ b/tests/src/test/java/org/sonarqube/tests/upgrade/UpgradeTest.java @@ -156,11 +156,11 @@ public class UpgradeTest { } private void startAndUpgradeDevServer() { - OrchestratorBuilder builder = newOrchestratorBuilder() - .setOrchestratorProperty("orchestrator.keepDatabase", "true") - .keepBundledPlugins() - .setStartupLogWatcher(log -> log.contains("Database must be upgraded")); - orchestrator = builder.build(); + orchestrator = newOrchestratorBuilder( + builder -> builder + .setOrchestratorProperty("orchestrator.keepDatabase", "true") + .keepBundledPlugins() + .setStartupLogWatcher(log -> log.contains("Database must be upgraded"))); orchestrator.start(); initSelenide(orchestrator); diff --git a/tests/src/test/java/org/sonarqube/tests/user/HttpHeadersAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/HttpHeadersAuthenticationTest.java index 300c60c0f60..61659c545d5 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/HttpHeadersAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/HttpHeadersAuthenticationTest.java @@ -55,13 +55,13 @@ public class HttpHeadersAuthenticationTest { private static final String GROUPS_HEADER = "H-Groups"; @ClassRule - public static final Orchestrator orchestrator = newOrchestratorBuilder() - .setServerProperty("sonar.web.sso.enable", "true") - .setServerProperty("sonar.web.sso.loginHeader", LOGIN_HEADER) - .setServerProperty("sonar.web.sso.nameHeader", NAME_HEADER) - .setServerProperty("sonar.web.sso.emailHeader", EMAIL_HEADER) - .setServerProperty("sonar.web.sso.groupsHeader", GROUPS_HEADER) - .build(); + public static final Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder + .setServerProperty("sonar.web.sso.enable", "true") + .setServerProperty("sonar.web.sso.loginHeader", LOGIN_HEADER) + .setServerProperty("sonar.web.sso.nameHeader", NAME_HEADER) + .setServerProperty("sonar.web.sso.emailHeader", EMAIL_HEADER) + .setServerProperty("sonar.web.sso.groupsHeader", GROUPS_HEADER)); @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java b/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java index 440e0d4bba6..515f813f2de 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java @@ -37,7 +37,7 @@ public class OnboardingTest { private static final String ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS = "sonar.onboardingTutorial.showToNewUsers"; @ClassRule - public static final Orchestrator orchestrator = newOrchestratorBuilder().build(); + public static final Orchestrator orchestrator = newOrchestratorBuilder(); @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java index e34e6371168..45f5c23eb97 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java @@ -57,10 +57,10 @@ public class RealmAuthenticationTest { public ExpectedException thrown = ExpectedException.none(); @ClassRule - public static final Orchestrator orchestrator = newOrchestratorBuilder() - .addPlugin(pluginArtifact("security-plugin")) - .setServerProperty("sonar.security.realm", "FakeRealm") - .build(); + public static final Orchestrator orchestrator = newOrchestratorBuilder( + builder -> builder + .addPlugin(pluginArtifact("security-plugin")) + .setServerProperty("sonar.security.realm", "FakeRealm")); @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java index fa2d492d6ee..45c3e1436cd 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java @@ -40,21 +40,22 @@ import static util.ItUtils.xooPlugin; public class SonarCloudUserSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - // Used by OrganizationBaseIdentityProviderTest - .addPlugin(pluginArtifact("base-auth-plugin")) + // Used by OrganizationBaseIdentityProviderTest + .addPlugin(pluginArtifact("base-auth-plugin")) - // Used in OrganizationOAuth2IdentityProviderTest - .addPlugin(pluginArtifact("oauth2-auth-plugin")) + // Used in OrganizationOAuth2IdentityProviderTest + .addPlugin(pluginArtifact("oauth2-auth-plugin")) - .setServerProperty("sonar.sonarcloud.enabled", "true") - .setServerProperty("sonar.organizations.createPersonalOrg", "true") + .setServerProperty("sonar.sonarcloud.enabled", "true") + .setServerProperty("sonar.organizations.createPersonalOrg", "true") - // reduce memory for Elasticsearch - .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java b/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java index 92ff670f0e3..c0205324ebf 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java @@ -48,13 +48,15 @@ public class UserEsResilienceTest { private static final Byteman byteman; static { - byteman = new Byteman(newOrchestratorBuilder(), WEB); - orchestrator = byteman - .getOrchestratorBuilder() - .setServerProperty("sonar.search.recovery.delayInMs", "1000") - .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") - .addPlugin(ItUtils.xooPlugin()) - .build(); + byteman = new Byteman(); + orchestrator = newOrchestratorBuilder( + builder -> { + byteman.install(builder, WEB); + builder + .setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .addPlugin(ItUtils.xooPlugin()); + }); } @Before diff --git a/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java b/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java index e4e1b1c94f8..8e07ffe8404 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java @@ -46,18 +46,19 @@ import static util.ItUtils.xooPlugin; public class UserSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - // Used in BaseIdentityProviderTest - .addPlugin(pluginArtifact("base-auth-plugin")) + // Used in BaseIdentityProviderTest + .addPlugin(pluginArtifact("base-auth-plugin")) - // Used in OAuth2IdentityProviderTest - .addPlugin(pluginArtifact("oauth2-auth-plugin")) + // Used in OAuth2IdentityProviderTest + .addPlugin(pluginArtifact("oauth2-auth-plugin")) - // reduce memory for Elasticsearch - .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") - .build(); + ); } diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java index 8e8d0023081..ae1048dc5eb 100644 --- a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java @@ -35,13 +35,13 @@ import static util.ItUtils.xooPlugin; public class WebhooksSuite { @ClassRule - public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder() - .addPlugin(xooPlugin()) + public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder( + builder -> builder + .addPlugin(xooPlugin()) - // reduce memory for Elasticsearch - .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") - .setServerProperty("sonar.sonarcloud.enabled", "true") - - .build(); + .setServerProperty("sonar.sonarcloud.enabled", "true") + ); } diff --git a/tests/src/test/java/util/ItUtils.java b/tests/src/test/java/util/ItUtils.java index d7451c66776..6daaeefcfd6 100644 --- a/tests/src/test/java/util/ItUtils.java +++ b/tests/src/test/java/util/ItUtils.java @@ -44,6 +44,7 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -99,9 +100,22 @@ public class ItUtils { private ItUtils() { } - public static OrchestratorBuilder newOrchestratorBuilder() { - OrchestratorBuilder builder = Orchestrator.builderEnv(); - builder.setEdition(COMMUNITY); + public static Orchestrator newOrchestratorBuilder() { + return newOrchestratorBuilder(t -> {}, server -> {}); + } + + public static Orchestrator newOrchestratorBuilder(Consumer beforeInstall) { + return newOrchestratorBuilder(beforeInstall, server -> { + }); + } + + public static Orchestrator newOrchestratorBuilder(Consumer beforeInstall, Consumer afterInstall) { + OrchestratorBuilder builder = Orchestrator.builderEnv() + .setEdition(COMMUNITY) + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + .setOrchestratorProperty("orchestrator.workspaceDir", "build/it"); + String version = System.getProperty("sonar.runtimeVersion"); if (StringUtils.isEmpty(version)) { Location zip = FileLocation.byWildcardMavenFilename(new File("../sonar-application/build/distributions"), "sonar-application-*.zip"); @@ -109,10 +123,33 @@ public class ItUtils { } else { builder.setSonarVersion(version); } - return builder - // reduce memory for Elasticsearch - .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") - .setOrchestratorProperty("orchestrator.workspaceDir", "build/it"); + + beforeInstall.accept(builder); + + Orchestrator orchestrator = builder.build(); + + Server server = orchestrator.install(); + afterInstall.accept(server); + + return orchestrator; + } + + public static void installCoreExtension(Server server, String coreExtensionDirName) { + File coreExtensionFile = pluginArtifact(coreExtensionDirName).getFile(); + File libDir = new File(server.getHome(), "lib/common"); + try { + FileUtils.copyFile(coreExtensionFile, new File(libDir, coreExtensionFile.getName())); + } catch (IOException e) { + throw new IllegalStateException("Failed to install core extension", e); + } + } + + public static Location locationOf(URL url) { + try { + return FileLocation.of(new File(url.toURI())); + } catch (URISyntaxException e) { + throw new IllegalStateException("File does not exist", e); + } } public static FileLocation xooPlugin() {