]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7060 CeQueueInitializer must initialize after plugins 664/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 1 Dec 2015 13:02:46 +0000 (14:02 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 2 Dec 2015 17:14:43 +0000 (18:14 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeQueueInitializer.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueInitializerTest.java

index 3f63721405aaa9b08fe6edf405827c50fe029544..2ee0da9b5d30f60b1f7dc17bdbf5620c6a7c4430 100644 (file)
@@ -19,7 +19,8 @@
  */
 package org.sonar.server.computation.queue;
 
-import org.picocontainer.Startable;
+import org.sonar.api.platform.Server;
+import org.sonar.api.platform.ServerStartHandler;
 import org.sonar.api.server.ServerSide;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -32,12 +33,13 @@ import org.sonar.server.computation.taskprocessor.CeProcessingScheduler;
  * from peeking the queue before it's ready.
  */
 @ServerSide
-public class CeQueueInitializer implements Startable {
+public class CeQueueInitializer implements ServerStartHandler {
 
   private final DbClient dbClient;
   private final CEQueueStatus queueStatus;
   private final CeQueueCleaner cleaner;
   private final CeProcessingScheduler scheduler;
+  private boolean done = false;
 
   public CeQueueInitializer(DbClient dbClient, CEQueueStatus queueStatus, CeQueueCleaner cleaner, CeProcessingScheduler scheduler) {
     this.dbClient = dbClient;
@@ -47,7 +49,14 @@ public class CeQueueInitializer implements Startable {
   }
 
   @Override
-  public void start() {
+  public void onServerStart(Server server) {
+    if (!done) {
+      initCe();
+      this.done = true;
+    }
+  }
+
+  private void initCe() {
     DbSession dbSession = dbClient.openSession(false);
     try {
       initJmxCounters(dbSession);
@@ -59,11 +68,6 @@ public class CeQueueInitializer implements Startable {
     }
   }
 
-  @Override
-  public void stop() {
-    // nothing to do
-  }
-
   private void initJmxCounters(DbSession dbSession) {
     queueStatus.initPendingCount(dbClient.ceQueueDao().countAll(dbSession));
   }
index dd41ae98635f3812950c4502eeedff0e262e16cf..6637c814fed327131a4b413e311f52c145c393b0 100644 (file)
@@ -705,13 +705,6 @@ public class PlatformLevel4 extends PlatformLevel {
       CancelAllAction.class,
       PluginsWs.class,
 
-      // Compute engine
-      CeModule.class,
-      CeQueueModule.class,
-      CeTaskProcessorModule.class,
-      CeWsModule.class,
-      ReportProcessingModule.class,
-
       // Views plugin
       ViewsBootstrap.class,
       ViewsStopper.class,
@@ -720,6 +713,13 @@ public class PlatformLevel4 extends PlatformLevel {
       DevCockpitBootstrap.class,
       DevCockpitStopper.class,
 
+      // Compute engine (must be after Views and Developer Cockpit)
+      CeModule.class,
+      CeQueueModule.class,
+      CeTaskProcessorModule.class,
+      CeWsModule.class,
+      ReportProcessingModule.class,
+
       // UI
       GlobalNavigationAction.class,
       SettingsNavigationAction.class,
index 2fdb02bfb3956a089c2acc252e6ff49394ce3544..52f51e1669070ca1abfea8531ad0bed3b784f575 100644 (file)
@@ -26,19 +26,22 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.InOrder;
 import org.mockito.Mockito;
+import org.sonar.api.platform.Server;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.queue.report.ReportFiles;
 import org.sonar.server.computation.monitoring.CEQueueStatus;
 import org.sonar.server.computation.monitoring.CEQueueStatusImpl;
+import org.sonar.server.computation.queue.report.ReportFiles;
 import org.sonar.server.computation.taskprocessor.CeProcessingScheduler;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
 public class CeQueueInitializerTest {
@@ -49,6 +52,7 @@ public class CeQueueInitializerTest {
   @Rule
   public TemporaryFolder tempFolder = new TemporaryFolder();
 
+  Server server = mock(Server.class);
   ReportFiles reportFiles = mock(ReportFiles.class, Mockito.RETURNS_DEEP_STUBS);
   CEQueueStatus queueStatus = new CEQueueStatusImpl();
   CeQueueCleaner cleaner = mock(CeQueueCleaner.class);
@@ -62,14 +66,14 @@ public class CeQueueInitializerTest {
     // this in-progress task is going to be moved to PENDING
     insertInQueue("TASK_3", CeQueueDto.Status.IN_PROGRESS);
 
-    underTest.start();
+    underTest.onServerStart(server);
 
     assertThat(queueStatus.getPendingCount()).isEqualTo(3);
   }
 
   @Test
   public void init_jmx_counters_when_queue_is_empty() {
-    underTest.start();
+    underTest.onServerStart(server);
 
     assertThat(queueStatus.getPendingCount()).isEqualTo(0);
   }
@@ -78,12 +82,25 @@ public class CeQueueInitializerTest {
   public void clean_queue_then_start_scheduler_of_workers() throws IOException {
     InOrder inOrder = Mockito.inOrder(cleaner, scheduler);
 
-    underTest.start();
+    underTest.onServerStart(server);
 
     inOrder.verify(cleaner).clean(any(DbSession.class));
     inOrder.verify(scheduler).startScheduling();
   }
 
+  @Test
+  public void onServerStart_has_no_effect_if_called_twice_to_support_medium_test_doing_startup_tasks_multiple_times() {
+
+    underTest.onServerStart(server);
+
+    reset(cleaner, scheduler);
+
+    underTest.onServerStart(server);
+
+    verifyZeroInteractions(cleaner, scheduler);
+
+  }
+
   private void insertInQueue(String taskUuid, CeQueueDto.Status status) throws IOException {
     insertInQueue(taskUuid, status, true);
   }