]> source.dussan.org Git - sonarqube.git/commitdiff
move package computation.dbcleaner to org.sonar.server
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 17 Sep 2015 12:38:48 +0000 (14:38 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 22 Sep 2015 15:20:56 +0000 (17:20 +0200)
there should not be any org.sonar.core package in module sonar-server

13 files changed:
server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/IndexPurgeListener.java [deleted file]
server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java [deleted file]
server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/IndexPurgeListener.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/IndexPurgeListenerTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/IndexPurgeListenerTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java

diff --git a/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/IndexPurgeListener.java b/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/IndexPurgeListener.java
deleted file mode 100644 (file)
index 010e92c..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.computation.dbcleaner;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.purge.PurgeListener;
-import org.sonar.server.test.index.TestIndexer;
-
-@ServerSide
-public class IndexPurgeListener implements PurgeListener {
-  private final TestIndexer testIndexer;
-
-  public IndexPurgeListener(TestIndexer testIndexer) {
-    this.testIndexer = testIndexer;
-  }
-
-  @Override
-  public void onComponentDisabling(String uuid) {
-    testIndexer.deleteByFile(uuid);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java b/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java
deleted file mode 100644 (file)
index 0c756dc..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.computation.dbcleaner;
-
-import java.util.Date;
-import javax.annotation.Nullable;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.TimeUtils;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.DbSession;
-import org.sonar.db.purge.IdUuidPair;
-import org.sonar.db.purge.PurgeConfiguration;
-import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.purge.PurgeListener;
-import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.db.purge.period.DefaultPeriodCleaner;
-import org.sonar.server.issue.index.IssueIndex;
-
-import static org.sonar.db.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
-
-@ServerSide
-public class ProjectCleaner {
-  private static final Logger LOG = Loggers.get(ProjectCleaner.class);
-
-  private final PurgeProfiler profiler;
-  private final PurgeListener purgeListener;
-  private final PurgeDao purgeDao;
-  private final DefaultPeriodCleaner periodCleaner;
-  private final IssueIndex issueIndex;
-
-  public ProjectCleaner(PurgeDao purgeDao, DefaultPeriodCleaner periodCleaner, PurgeProfiler profiler, PurgeListener purgeListener,
-    IssueIndex issueIndex) {
-    this.purgeDao = purgeDao;
-    this.periodCleaner = periodCleaner;
-    this.profiler = profiler;
-    this.purgeListener = purgeListener;
-    this.issueIndex = issueIndex;
-  }
-
-  public ProjectCleaner purge(DbSession session, IdUuidPair idUuidPair, Settings projectSettings) {
-    long start = System.currentTimeMillis();
-    profiler.reset();
-
-    PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectSettings, idUuidPair);
-
-    cleanHistoricalData(session, configuration.rootProjectIdUuid().getId(), projectSettings);
-    doPurge(session, configuration);
-
-    deleteIndexedIssuesBefore(idUuidPair.getUuid(), configuration.maxLiveDateOfClosedIssues());
-
-    session.commit();
-    logProfiling(start, projectSettings);
-    return this;
-  }
-
-  private void deleteIndexedIssuesBefore(String uuid, @Nullable Date lastDateWithClosedIssues) {
-    if (lastDateWithClosedIssues != null) {
-      issueIndex.deleteClosedIssuesOfProjectBefore(uuid, lastDateWithClosedIssues);
-    }
-  }
-
-  private void logProfiling(long start, Settings settings) {
-    if (settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) {
-      long duration = System.currentTimeMillis() - start;
-      LOG.info("\n -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------\n");
-      profiler.dump(duration, LOG);
-      LOG.info("\n -------- End of profiling for purge --------\n");
-    }
-  }
-
-  private void cleanHistoricalData(DbSession session, long resourceId, Settings settings) {
-    try {
-      periodCleaner.clean(session, resourceId, settings);
-    } catch (Exception e) {
-      // purge errors must no fail the batch
-      LOG.error("Fail to clean historical data [id=" + resourceId + "]", e);
-    }
-  }
-
-  private void doPurge(DbSession session, PurgeConfiguration configuration) {
-    try {
-      purgeDao.purge(session, configuration, purgeListener, profiler);
-    } catch (Exception e) {
-      // purge errors must no fail the report analysis
-      LOG.error("Fail to purge data [id=" + configuration.rootProjectIdUuid().getId() + "]", e);
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/package-info.java b/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/package-info.java
deleted file mode 100644 (file)
index 8a7156f..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.computation.dbcleaner;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/IndexPurgeListener.java b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/IndexPurgeListener.java
new file mode 100644 (file)
index 0000000..1181e15
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.dbcleaner;
+
+import org.sonar.api.server.ServerSide;
+import org.sonar.db.purge.PurgeListener;
+import org.sonar.server.test.index.TestIndexer;
+
+@ServerSide
+public class IndexPurgeListener implements PurgeListener {
+  private final TestIndexer testIndexer;
+
+  public IndexPurgeListener(TestIndexer testIndexer) {
+    this.testIndexer = testIndexer;
+  }
+
+  @Override
+  public void onComponentDisabling(String uuid) {
+    testIndexer.deleteByFile(uuid);
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java
new file mode 100644 (file)
index 0000000..a3f9e26
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.dbcleaner;
+
+import java.util.Date;
+import javax.annotation.Nullable;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.TimeUtils;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.DbSession;
+import org.sonar.db.purge.IdUuidPair;
+import org.sonar.db.purge.PurgeConfiguration;
+import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.purge.PurgeListener;
+import org.sonar.db.purge.PurgeProfiler;
+import org.sonar.db.purge.period.DefaultPeriodCleaner;
+import org.sonar.server.issue.index.IssueIndex;
+
+import static org.sonar.db.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
+
+@ServerSide
+public class ProjectCleaner {
+  private static final Logger LOG = Loggers.get(ProjectCleaner.class);
+
+  private final PurgeProfiler profiler;
+  private final PurgeListener purgeListener;
+  private final PurgeDao purgeDao;
+  private final DefaultPeriodCleaner periodCleaner;
+  private final IssueIndex issueIndex;
+
+  public ProjectCleaner(PurgeDao purgeDao, DefaultPeriodCleaner periodCleaner, PurgeProfiler profiler, PurgeListener purgeListener,
+    IssueIndex issueIndex) {
+    this.purgeDao = purgeDao;
+    this.periodCleaner = periodCleaner;
+    this.profiler = profiler;
+    this.purgeListener = purgeListener;
+    this.issueIndex = issueIndex;
+  }
+
+  public ProjectCleaner purge(DbSession session, IdUuidPair idUuidPair, Settings projectSettings) {
+    long start = System.currentTimeMillis();
+    profiler.reset();
+
+    PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectSettings, idUuidPair);
+
+    cleanHistoricalData(session, configuration.rootProjectIdUuid().getId(), projectSettings);
+    doPurge(session, configuration);
+
+    deleteIndexedIssuesBefore(idUuidPair.getUuid(), configuration.maxLiveDateOfClosedIssues());
+
+    session.commit();
+    logProfiling(start, projectSettings);
+    return this;
+  }
+
+  private void deleteIndexedIssuesBefore(String uuid, @Nullable Date lastDateWithClosedIssues) {
+    if (lastDateWithClosedIssues != null) {
+      issueIndex.deleteClosedIssuesOfProjectBefore(uuid, lastDateWithClosedIssues);
+    }
+  }
+
+  private void logProfiling(long start, Settings settings) {
+    if (settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) {
+      long duration = System.currentTimeMillis() - start;
+      LOG.info("\n -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------\n");
+      profiler.dump(duration, LOG);
+      LOG.info("\n -------- End of profiling for purge --------\n");
+    }
+  }
+
+  private void cleanHistoricalData(DbSession session, long resourceId, Settings settings) {
+    try {
+      periodCleaner.clean(session, resourceId, settings);
+    } catch (Exception e) {
+      // purge errors must no fail the batch
+      LOG.error("Fail to clean historical data [id=" + resourceId + "]", e);
+    }
+  }
+
+  private void doPurge(DbSession session, PurgeConfiguration configuration) {
+    try {
+      purgeDao.purge(session, configuration, purgeListener, profiler);
+    } catch (Exception e) {
+      // purge errors must no fail the report analysis
+      LOG.error("Fail to purge data [id=" + configuration.rootProjectIdUuid().getId() + "]", e);
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/package-info.java
new file mode 100644 (file)
index 0000000..f3a8c77
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.dbcleaner;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 9cd2a478cdebe2f161fd7e5cc59fe4258d4a0f76..627536a9114339d2477d6ab1bac911be7fbf7a4c 100644 (file)
@@ -20,7 +20,7 @@
 
 package org.sonar.server.computation.step;
 
-import org.sonar.core.computation.dbcleaner.ProjectCleaner;
+import org.sonar.server.computation.dbcleaner.ProjectCleaner;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.IdUuidPair;
index 2eb8e2e84c82e76d2c53ce6fed94a93ae6b5a131..8529c5cdf412e146dc8175ce336ea1514f543cc8 100644 (file)
@@ -31,8 +31,8 @@ import org.sonar.api.rules.AnnotationRuleParser;
 import org.sonar.api.rules.XMLRuleParser;
 import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
 import org.sonar.core.component.DefaultResourceTypes;
-import org.sonar.core.computation.dbcleaner.IndexPurgeListener;
-import org.sonar.core.computation.dbcleaner.ProjectCleaner;
+import org.sonar.server.computation.dbcleaner.IndexPurgeListener;
+import org.sonar.server.computation.dbcleaner.ProjectCleaner;
 import org.sonar.core.issue.IssueUpdater;
 import org.sonar.core.issue.workflow.FunctionExecutor;
 import org.sonar.core.issue.workflow.IssueWorkflow;
diff --git a/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/IndexPurgeListenerTest.java b/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/IndexPurgeListenerTest.java
deleted file mode 100644 (file)
index cfd25f3..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.computation.dbcleaner;
-
-import org.junit.Test;
-import org.sonar.server.test.index.TestIndexer;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class IndexPurgeListenerTest {
-
-  @Test
-  public void call_test_indexer() {
-    TestIndexer testIndexer = mock(TestIndexer.class);
-    IndexPurgeListener underTest = new IndexPurgeListener(testIndexer);
-
-    underTest.onComponentDisabling("123456");
-
-    verify(testIndexer).deleteByFile("123456");
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java b/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java
deleted file mode 100644 (file)
index b50c763..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.computation.dbcleaner;
-
-import java.util.Date;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.core.config.PurgeConstants;
-import org.sonar.db.DbSession;
-import org.sonar.db.purge.IdUuidPair;
-import org.sonar.db.purge.PurgeConfiguration;
-import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.purge.PurgeListener;
-import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.db.purge.period.DefaultPeriodCleaner;
-import org.sonar.server.issue.index.IssueIndex;
-
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyLong;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
-public class ProjectCleanerTest {
-
-  private ProjectCleaner underTest;
-  private PurgeDao dao = mock(PurgeDao.class);
-  private PurgeProfiler profiler = mock(PurgeProfiler.class);
-  private DefaultPeriodCleaner periodCleaner = mock(DefaultPeriodCleaner.class);
-  private PurgeListener purgeListener = mock(PurgeListener.class);
-  private IssueIndex issueIndex = mock(IssueIndex.class);
-  private Settings settings = new Settings();
-
-  @Before
-  public void before() {
-    this.underTest = new ProjectCleaner(dao, periodCleaner, profiler, purgeListener, issueIndex);
-  }
-
-  @Test
-  public void no_profiling_when_property_is_false() {
-    settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false);
-
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
-
-    verify(profiler, never()).dump(anyLong(), any(Logger.class));
-  }
-
-  @Test
-  public void no_indexing_when_no_issue_to_delete() {
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
-
-    verifyZeroInteractions(issueIndex);
-  }
-
-  @Test
-  public void profiling_when_property_is_true() {
-    settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
-
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
-
-    verify(profiler).dump(anyLong(), any(Logger.class));
-  }
-
-  @Test
-  public void call_period_cleaner_index_client_and_purge_dao() {
-    settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5);
-
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
-
-    verify(periodCleaner).clean(any(DbSession.class), any(Long.class), any(Settings.class));
-    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
-    verify(issueIndex).deleteClosedIssuesOfProjectBefore(any(String.class), any(Date.class));
-  }
-
-  @Test
-  public void if_dao_purge_fails_it_should_not_interrupt_program_execution() {
-    doThrow(RuntimeException.class).when(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
-
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
-
-    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
-  }
-
-  @Test
-  public void if_profiler_cleaning_fails_it_should_not_interrupt_program_execution() {
-    doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class));
-
-    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
-
-    verify(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class));
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/IndexPurgeListenerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/IndexPurgeListenerTest.java
new file mode 100644 (file)
index 0000000..1256894
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.dbcleaner;
+
+import org.junit.Test;
+import org.sonar.server.test.index.TestIndexer;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class IndexPurgeListenerTest {
+
+  @Test
+  public void call_test_indexer() {
+    TestIndexer testIndexer = mock(TestIndexer.class);
+    IndexPurgeListener underTest = new IndexPurgeListener(testIndexer);
+
+    underTest.onComponentDisabling("123456");
+
+    verify(testIndexer).deleteByFile("123456");
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java
new file mode 100644 (file)
index 0000000..beefdc0
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.dbcleaner;
+
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.core.config.PurgeConstants;
+import org.sonar.db.DbSession;
+import org.sonar.db.purge.IdUuidPair;
+import org.sonar.db.purge.PurgeConfiguration;
+import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.purge.PurgeListener;
+import org.sonar.db.purge.PurgeProfiler;
+import org.sonar.db.purge.period.DefaultPeriodCleaner;
+import org.sonar.server.issue.index.IssueIndex;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+public class ProjectCleanerTest {
+
+  private ProjectCleaner underTest;
+  private PurgeDao dao = mock(PurgeDao.class);
+  private PurgeProfiler profiler = mock(PurgeProfiler.class);
+  private DefaultPeriodCleaner periodCleaner = mock(DefaultPeriodCleaner.class);
+  private PurgeListener purgeListener = mock(PurgeListener.class);
+  private IssueIndex issueIndex = mock(IssueIndex.class);
+  private Settings settings = new Settings();
+
+  @Before
+  public void before() {
+    this.underTest = new ProjectCleaner(dao, periodCleaner, profiler, purgeListener, issueIndex);
+  }
+
+  @Test
+  public void no_profiling_when_property_is_false() {
+    settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false);
+
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
+
+    verify(profiler, never()).dump(anyLong(), any(Logger.class));
+  }
+
+  @Test
+  public void no_indexing_when_no_issue_to_delete() {
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
+
+    verifyZeroInteractions(issueIndex);
+  }
+
+  @Test
+  public void profiling_when_property_is_true() {
+    settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
+
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
+
+    verify(profiler).dump(anyLong(), any(Logger.class));
+  }
+
+  @Test
+  public void call_period_cleaner_index_client_and_purge_dao() {
+    settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5);
+
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
+
+    verify(periodCleaner).clean(any(DbSession.class), any(Long.class), any(Settings.class));
+    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
+    verify(issueIndex).deleteClosedIssuesOfProjectBefore(any(String.class), any(Date.class));
+  }
+
+  @Test
+  public void if_dao_purge_fails_it_should_not_interrupt_program_execution() {
+    doThrow(RuntimeException.class).when(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
+
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
+
+    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
+  }
+
+  @Test
+  public void if_profiler_cleaning_fails_it_should_not_interrupt_program_execution() {
+    doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class));
+
+    underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
+
+    verify(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class));
+  }
+}
index 0585eff4bd3fa1b4fa7c8fee11b3060b34935f0c..ab560db9327d3882ef5e100b0cbf137b03629b57 100644 (file)
@@ -33,7 +33,7 @@ import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 import org.sonar.api.config.Settings;
-import org.sonar.core.computation.dbcleaner.ProjectCleaner;
+import org.sonar.server.computation.dbcleaner.ProjectCleaner;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.IdUuidPair;
 import org.sonar.server.computation.batch.TreeRootHolderRule;