aboutsummaryrefslogtreecommitdiffstats
path: root/tests/plugins
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-10 10:49:46 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-18 08:51:46 +0200
commit179311a789bbfb5025f446d3259c9ae0bac2cc95 (patch)
treef8e283fd0344fe1f29c2450a010952f417c6b613 /tests/plugins
parent601fafa4f5e03a83c0fd48a1f88b5ae9fae2e20d (diff)
downloadsonarqube-179311a789bbfb5025f446d3259c9ae0bac2cc95.tar.gz
sonarqube-179311a789bbfb5025f446d3259c9ae0bac2cc95.zip
SONAR-9525 add IT on dynamic update of CE worker count
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java3
-rw-r--r--tests/plugins/fake-governance-plugin/src/main/java/workerCount/FakeWorkerCountProviderImpl.java (renamed from tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java)4
-rw-r--r--tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java67
3 files changed, 72 insertions, 2 deletions
diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java
index 2e236fded30..9460af58547 100644
--- a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java
+++ b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java
@@ -20,6 +20,8 @@
*/
import org.sonar.api.Plugin;
+import workerCount.FakeWorkerCountProviderImpl;
+import workerCount.RefreshWorkerCountAction;
import workerlatch.LatchControllerWorkerMeasureComputer;
import workerlatch.WorkerLatchMetrics;
@@ -32,6 +34,7 @@ public class FakeGovernancePlugin implements Plugin {
context.addExtension(FakeWorkerCountProviderImpl.class);
context.addExtension(WorkerLatchMetrics.class);
context.addExtension(LatchControllerWorkerMeasureComputer.class);
+ context.addExtension(RefreshWorkerCountAction.class);
}
}
diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java b/tests/plugins/fake-governance-plugin/src/main/java/workerCount/FakeWorkerCountProviderImpl.java
index ad737c42eb0..467642e86a1 100644
--- a/tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java
+++ b/tests/plugins/fake-governance-plugin/src/main/java/workerCount/FakeWorkerCountProviderImpl.java
@@ -1,4 +1,4 @@
-
+package workerCount;
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
@@ -24,7 +24,7 @@ import org.sonar.ce.configuration.WorkerCountProvider;
public class FakeWorkerCountProviderImpl implements WorkerCountProvider {
- private static final String PROPERTY_WORKER_COUNT = "fakeGovernance.workerCount";
+ static final String PROPERTY_WORKER_COUNT = "fakeGovernance.workerCount";
private final Configuration configuration;
diff --git a/tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java b/tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java
new file mode 100644
index 00000000000..93089508919
--- /dev/null
+++ b/tests/plugins/fake-governance-plugin/src/main/java/workerCount/RefreshWorkerCountAction.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+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) throws Exception {
+ 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();
+ }
+}