*/
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;
* 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;
}
@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);
}
}
- @Override
- public void stop() {
- // nothing to do
- }
-
private void initJmxCounters(DbSession dbSession) {
queueStatus.initPendingCount(dbClient.ceQueueDao().countAll(dbSession));
}
CancelAllAction.class,
PluginsWs.class,
- // Compute engine
- CeModule.class,
- CeQueueModule.class,
- CeTaskProcessorModule.class,
- CeWsModule.class,
- ReportProcessingModule.class,
-
// Views plugin
ViewsBootstrap.class,
ViewsStopper.class,
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,
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 {
@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);
// 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);
}
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);
}