From 9a62922f872af2d3dbbe514cd9c47137d66acded Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 1 Dec 2015 14:02:46 +0100 Subject: [PATCH] SONAR-7060 CeQueueInitializer must initialize after plugins --- .../computation/queue/CeQueueInitializer.java | 20 +++++++++------ .../platformlevel/PlatformLevel4.java | 14 +++++------ .../queue/CeQueueInitializerTest.java | 25 ++++++++++++++++--- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeQueueInitializer.java b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeQueueInitializer.java index 3f63721405a..2ee0da9b5d3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeQueueInitializer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/CeQueueInitializer.java @@ -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)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index dd41ae98635..6637c814fed 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -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, diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueInitializerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueInitializerTest.java index 2fdb02bfb39..52f51e16690 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueInitializerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/queue/CeQueueInitializerTest.java @@ -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); } -- 2.39.5