ORCHESTRATOR_CONFIG_URL=$2
shift 2
-./gradlew --no-daemon --console plain \
+./gradlew \
+ :tests:clean \
:tests:integrationTest \
-Dcategory="$CATEGORY" \
-Dorchestrator.configUrl=$ORCHESTRATOR_CONFIG_URL \
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'
':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',
--- /dev/null
+dependencies {
+ compileOnly project(path: ':sonar-plugin-api', configuration: 'shadow')
+ compileOnly project(':server:sonar-server')
+}
--- /dev/null
+
+/*
+ * 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);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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();
+ }
+ }
+}
--- /dev/null
+/*
+ * 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<Object> 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");
+ }
+ }
+}
--- /dev/null
+/*
+ * 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<String> getHandledCeTaskTypes() {
+ return Collections.singleton("ISE");
+ }
+
+ @Override
+ public CeTaskResult process(CeTask task) {
+ throw new IllegalStateException("Faking an IllegalStateException thrown processing a task");
+ }
+}
--- /dev/null
+/*
+ * 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<Object> consumeAvailableMemory() {
+ List<Object> holder = new ArrayList<>();
+ while (true) {
+ holder.add(new byte[128 * 1024]);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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<String> getHandledCeTaskTypes() {
+ return Collections.singleton("OK");
+ }
+
+ @Override
+ public CeTaskResult process(CeTask task) {
+ return Optional::empty;
+ }
+
+
+}
--- /dev/null
+/*
+ * 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<String> getHandledCeTaskTypes() {
+ return Collections.singleton("OOM");
+ }
+
+ @Override
+ public CeTaskResult process(CeTask task) {
+ OOMGenerator.consumeAvailableMemory();
+ return null;
+ }
+}
--- /dev/null
+/*
+ * 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
+
+ }
+
+}
--- /dev/null
+/*
+ * 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 {
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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<Metric> getMetrics() {
+ return Collections.singletonList(
+ new Metric.Builder(METRIC_KEY, "Worker latch", Metric.ValueType.BOOL)
+ .setHidden(true)
+ .create());
+ }
+}
--- /dev/null
+ItTestsCoreExtension
--- /dev/null
+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
+++ /dev/null
-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'
- )
- }
-}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
+++ /dev/null
-/*
- * 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();
- }
- }
-}
+++ /dev/null
-/*
- * 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<Object> 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");
- }
- }
-}
+++ /dev/null
-/*
- * 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<String> getHandledCeTaskTypes() {
- return Collections.singleton("ISE");
- }
-
- @Override
- public CeTaskResult process(CeTask task) {
- throw new IllegalStateException("Faking an IllegalStateException thrown processing a task");
- }
-}
+++ /dev/null
-/*
- * 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<Object> consumeAvailableMemory() {
- List<Object> holder = new ArrayList<>();
- while (true) {
- holder.add(new byte[128 * 1024]);
- }
- }
-}
+++ /dev/null
-/*
- * 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<String> getHandledCeTaskTypes() {
- return Collections.singleton("OK");
- }
-
- @Override
- public CeTaskResult process(CeTask task) {
- return Optional::empty;
- }
-
-
-}
+++ /dev/null
-/*
- * 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<String> getHandledCeTaskTypes() {
- return Collections.singleton("OOM");
- }
-
- @Override
- public CeTaskResult process(CeTask task) {
- OOMGenerator.consumeAvailableMemory();
- return null;
- }
-}
+++ /dev/null
-/*
- * 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
-
- }
-
-}
+++ /dev/null
-/*
- * 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 {
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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<Metric> getMetrics() {
- return Collections.singletonList(
- new Metric.Builder(METRIC_KEY, "Worker latch", Metric.ValueType.BOOL)
- .setHidden(true)
- .create());
- }
-}
+++ /dev/null
-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
public class Byteman {
private final int port;
- private final OrchestratorBuilder builder;
public enum Process {
WEB("sonar.web.javaAdditionalOpts"), CE("sonar.ce.javaAdditionalOpts");
}
}
- 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);
}
}
}
- public OrchestratorBuilder getOrchestratorBuilder() {
- return builder;
- }
}
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()));
}
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"));
}
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;
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"));
}
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"));
}
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
tuple("CONFIRMED", 0L),
tuple("REOPENED", 0L),
tuple("RESOLVED", 0L),
- tuple("CLOSED", 0L)
- );
+ tuple("CLOSED", 0L));
tester.elasticsearch().unlockWrites("issues");
tuple("CONFIRMED", 0L),
tuple("REOPENED", 0L),
tuple("RESOLVED", 0L),
- tuple("CLOSED", 0L)
- );
+ tuple("CLOSED", 0L));
}
@Test
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)
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");
+ });
}
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;
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";
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()
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;
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;
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
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);
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())
+
+ );
}
})
public class DuplicationSuite {
@ClassRule
- public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder()
- .addPlugin(xooPlugin())
+ public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder(
+ builder -> builder
+ .addPlugin(xooPlugin())
- .build();
+ );
}
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())
+
+ );
}
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);
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();
+ );
}
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();
+ );
}
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;
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);
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);
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")
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();
+ );
}
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();
+ );
}
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() {
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;
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;
@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();
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();
+ );
}
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();
+ );
}
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())
+
+ );
}
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())
+
+ );
}
public class QualityModelSuite {
@ClassRule
- public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder()
- .addPlugin(xooPlugin())
+ public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder(
+ builder -> builder
+ .addPlugin(xooPlugin())
- .build();
+ );
}
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
@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();
@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);
"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
@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();
@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();
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
@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);
@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();
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());
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;
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;
@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) {
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);
// 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");
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);
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()));
}
@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();
@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"))
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")));
}
@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);
// 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");
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();
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
@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();
@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();
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();
public class TestSuite {
@ClassRule
- public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder()
- .addPlugin(xooPlugin())
-
- .build();
+ public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder(
+ builder -> builder
+ .addPlugin(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")));
}
}
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);
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();
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();
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();
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();
+ );
}
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
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();
+ );
}
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")
+ );
}
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;
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<OrchestratorBuilder> beforeInstall) {
+ return newOrchestratorBuilder(beforeInstall, server -> {
+ });
+ }
+
+ public static Orchestrator newOrchestratorBuilder(Consumer<OrchestratorBuilder> beforeInstall, Consumer<Server> 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");
} 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() {