]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10104 make webhooks run synchronously in the Compute Engine
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 22 Nov 2017 15:05:20 +0000 (16:05 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 24 Nov 2017 08:23:58 +0000 (09:23 +0100)
server/sonar-ce/src/main/java/org/sonar/ce/async/SynchronousAsyncExecution.java [new file with mode: 0644]
server/sonar-ce/src/main/java/org/sonar/ce/async/package-info.java [new file with mode: 0644]
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/async/SynchronousAsyncExecutionTest.java [new file with mode: 0644]
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java

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 (file)
index 0000000..3c46c2c
--- /dev/null
@@ -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 (file)
index 0000000..3f02050
--- /dev/null
@@ -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;
index febc63da76f87aaccb8ee9402450af0e43d52663..30f22461dd960ca97d02795191328c05c12509c6 100644 (file)
@@ -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 (file)
index 0000000..57f0a71
--- /dev/null
@@ -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");
+  }
+}
index 0793ae11024faf9d8f1fc7f2eae9bed6da878ecc..c692eed52f4113651d76737c918b0cdee1864687 100644 (file)
@@ -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