]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6630 refactor PurgeCeActivities in order to be a ServerStartHandler
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 18 Sep 2015 21:45:07 +0000 (23:45 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sat, 19 Sep 2015 06:56:40 +0000 (08:56 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/PurgeCeActivities.java
server/sonar-server/src/test/java/org/sonar/server/computation/PurgeCeActivitiesTest.java

index 00a6f7d5dbd6703e6efa811532239e02a01e01a4..e7856aab5406e215b745c72fba31e1b5860d37d6 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.server.computation;
 
 import java.util.Calendar;
+import org.sonar.api.platform.Server;
+import org.sonar.api.platform.ServerStartHandler;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Logger;
@@ -28,7 +30,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 
 @ServerSide
-public class PurgeCeActivities {
+public class PurgeCeActivities implements ServerStartHandler {
 
   private static final Logger LOGGER = Loggers.get(PurgeCeActivities.class);
 
@@ -40,10 +42,8 @@ public class PurgeCeActivities {
     this.system2 = system2;
   }
 
-  /**
-   * Do not rename. Used at server startup.
-   */
-  public void start() {
+  @Override
+  public void onServerStart(Server server) {
     DbSession dbSession = dbClient.openSession(false);
     try {
       Calendar sixMonthsAgo = Calendar.getInstance();
index 2b9f65d7172f8599461a1c57b8c55d3e76078a3d..a79936137e33b61b684c9dd2b38bd748fb36e601 100644 (file)
@@ -21,12 +21,14 @@ package org.sonar.server.computation;
 
 import org.junit.Rule;
 import org.junit.Test;
+import org.sonar.api.platform.Server;
 import org.sonar.api.utils.internal.TestSystem2;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
 
 public class PurgeCeActivitiesTest {
 
@@ -42,7 +44,7 @@ public class PurgeCeActivitiesTest {
     insertWithDate("RECENT", 1_500_000_000_000L);
     system2.setNow(1_500_000_000_100L);
 
-    underTest.start();
+    underTest.onServerStart(mock(Server.class));
 
     assertThat(dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), "VERY_OLD").isPresent()).isFalse();
     assertThat(dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), "RECENT").isPresent()).isTrue();