aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-11-22 16:05:20 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-11-24 09:23:58 +0100
commit888854f9dd04feb372be60d249de2056d98d07c0 (patch)
tree73d58639aab6065a3c6e882d7f6e6c420d887bda
parent1765ad3888fbfc1f91b20197ddfd30324cd4c100 (diff)
downloadsonarqube-888854f9dd04feb372be60d249de2056d98d07c0.tar.gz
sonarqube-888854f9dd04feb372be60d249de2056d98d07c0.zip
SONAR-10104 make webhooks run synchronously in the Compute Engine
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/async/SynchronousAsyncExecution.java29
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/async/package-info.java23
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java4
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/async/SynchronousAsyncExecutionTest.java32
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java1
5 files changed, 86 insertions, 3 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/async/SynchronousAsyncExecution.java b/server/sonar-ce/src/main/java/org/sonar/ce/async/SynchronousAsyncExecution.java
new file mode 100644
index 00000000000..3c46c2c3a37
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/async/SynchronousAsyncExecution.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.sonar.ce.async;
+
+import org.sonar.server.async.AsyncExecution;
+
+public class SynchronousAsyncExecution implements AsyncExecution {
+ @Override
+ public void addToQueue(Runnable r) {
+ r.run();
+ }
+}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/async/package-info.java b/server/sonar-ce/src/main/java/org/sonar/ce/async/package-info.java
new file mode 100644
index 00000000000..3f02050f49c
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/async/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.ce.async;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
index febc63da76f..30f22461dd9 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
@@ -46,6 +46,7 @@ import org.sonar.ce.CeHttpModule;
import org.sonar.ce.CeQueueModule;
import org.sonar.ce.CeTaskCommonsModule;
import org.sonar.ce.StandaloneCeDistributedInformation;
+import org.sonar.ce.async.SynchronousAsyncExecution;
import org.sonar.ce.cleaning.CeCleaningModule;
import org.sonar.ce.db.ReadOnlyPropertiesDao;
import org.sonar.ce.log.CeProcessLogging;
@@ -78,7 +79,6 @@ import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
import org.sonar.process.logging.LogbackHelper;
-import org.sonar.server.async.AsyncExecutionModule;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.index.ComponentIndexer;
import org.sonar.server.computation.task.projectanalysis.ProjectAnalysisTaskModule;
@@ -312,7 +312,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
UriReader.class,
ServerImpl.class,
DefaultOrganizationProviderImpl.class,
- AsyncExecutionModule.class);
+ SynchronousAsyncExecution.class);
}
private static void populateLevel4(ComponentContainer container, Props props) {
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/async/SynchronousAsyncExecutionTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/async/SynchronousAsyncExecutionTest.java
new file mode 100644
index 00000000000..57f0a7163df
--- /dev/null
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/async/SynchronousAsyncExecutionTest.java
@@ -0,0 +1,32 @@
+package org.sonar.ce.async;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SynchronousAsyncExecutionTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private SynchronousAsyncExecution underTest = new SynchronousAsyncExecution();
+
+ @Test
+ public void addToQueue_fails_with_NPE_if_Runnable_is_null() {
+ expectedException.expect(NullPointerException.class);
+
+ underTest.addToQueue(null);
+ }
+
+ @Test
+ public void addToQueue_executes_Runnable_synchronously() {
+ Set<String> s = new HashSet<>();
+
+ underTest.addToQueue(() -> s.add("done"));
+
+ assertThat(s).containsOnly("done");
+ }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
index 0793ae11024..c692eed52f4 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
@@ -106,7 +106,6 @@ public class ComputeEngineContainerImplTest {
assertThat(picoContainer.getParent().getComponentAdapters()).hasSize(
CONTAINER_ITSELF
+ 6 // level 3
- + 2 // AsyncExecutionModule
);
assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
CONTAINER_ITSELF