aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-dbcleaner-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-04-17 16:50:20 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-04-17 16:51:12 +0200
commitc06ac5eaa744c05dbc7c779d0de84baea325776a (patch)
treeb7b41f3683e95fb5cd00b4237c27617bb980355a /plugins/sonar-dbcleaner-plugin
parentc946ab5883685a67cf5476042905e8b5d66c3bbc (diff)
downloadsonarqube-c06ac5eaa744c05dbc7c779d0de84baea325776a.tar.gz
sonarqube-c06ac5eaa744c05dbc7c779d0de84baea325776a.zip
SONAR-4147 Implemented profiling of purge
+ minor changes like display of percents
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin')
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java19
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java32
3 files changed, 43 insertions, 10 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java
index 7df47385763..6fa9a7be83e 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java
@@ -21,12 +21,15 @@ package org.sonar.plugins.dbcleaner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Scopes;
+import org.sonar.api.utils.TimeUtils;
import org.sonar.core.purge.PurgeDao;
+import org.sonar.core.purge.PurgeProfiler;
import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
import org.sonar.plugins.dbcleaner.api.PurgeTask;
import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
@@ -50,11 +53,13 @@ public class DefaultPurgeTask implements PurgeTask {
private PurgeDao purgeDao;
private Settings settings;
private DefaultPeriodCleaner periodCleaner;
+ private final PurgeProfiler profiler;
- public DefaultPurgeTask(PurgeDao purgeDao, Settings settings, DefaultPeriodCleaner periodCleaner) {
+ public DefaultPurgeTask(PurgeDao purgeDao, Settings settings, DefaultPeriodCleaner periodCleaner, PurgeProfiler profiler) {
this.purgeDao = purgeDao;
this.settings = settings;
this.periodCleaner = periodCleaner;
+ this.profiler = profiler;
}
public PurgeTask delete(long resourceId) {
@@ -63,8 +68,16 @@ public class DefaultPurgeTask implements PurgeTask {
}
public PurgeTask purge(long resourceId) {
+ long start = System.currentTimeMillis();
+ profiler.reset();
cleanHistoricalData(resourceId);
doPurge(resourceId);
+ if (settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) {
+ long duration = System.currentTimeMillis() - start;
+ System.out.println("\n -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------\n");
+ profiler.dump(duration);
+ System.out.println("\n -------- End of profiling for purge --------\n");
+ }
return this;
}
@@ -79,9 +92,9 @@ public class DefaultPurgeTask implements PurgeTask {
private String[] getScopesWithoutHistoricalData() {
if (settings.getBoolean(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY)) {
- return new String[]{Scopes.DIRECTORY, Scopes.FILE};
+ return new String[] {Scopes.DIRECTORY, Scopes.FILE};
}
- return new String[]{Scopes.FILE};
+ return new String[] {Scopes.FILE};
}
private void doPurge(long resourceId) {
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java
index 530a629b462..07f30e51ac1 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java
@@ -19,10 +19,10 @@
*/
package org.sonar.plugins.dbcleaner;
-import org.sonar.core.DryRunIncompatible;
import org.sonar.api.batch.PostJob;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
+import org.sonar.core.DryRunIncompatible;
import org.sonar.plugins.dbcleaner.api.PurgeTask;
@DryRunIncompatible
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java
index f059d70d180..82337478b15 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java
@@ -20,14 +20,20 @@
package org.sonar.plugins.dbcleaner;
import org.junit.Test;
+import org.sonar.api.CoreProperties;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Scopes;
import org.sonar.core.purge.PurgeDao;
+import org.sonar.core.purge.PurgeProfiler;
import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class DefaultPurgeTaskTest {
@Test
@@ -35,32 +41,46 @@ public class DefaultPurgeTaskTest {
PurgeDao purgeDao = mock(PurgeDao.class);
Settings settings = new Settings(new PropertyDefinitions(DefaultPurgeTask.class));
settings.setProperty(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY, "false");
- DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class));
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class), mock(PurgeProfiler.class));
task.purge(1L);
- verify(purgeDao).purge(1L, new String[]{Scopes.FILE});
+ verify(purgeDao).purge(1L, new String[] {Scopes.FILE});
}
@Test
public void shouldDeleteHistoricalDataOfDirectoriesByDefault() {
PurgeDao purgeDao = mock(PurgeDao.class);
Settings settings = new Settings(new PropertyDefinitions(DefaultPurgeTask.class));
- DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class));
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class), mock(PurgeProfiler.class));
task.purge(1L);
- verify(purgeDao).purge(1L, new String[]{Scopes.DIRECTORY, Scopes.FILE});
+ verify(purgeDao).purge(1L, new String[] {Scopes.DIRECTORY, Scopes.FILE});
}
@Test
public void shouldNotFailOnErrors() {
PurgeDao purgeDao = mock(PurgeDao.class);
when(purgeDao.purge(anyLong(), (String[]) any())).thenThrow(new RuntimeException());
- DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class));
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class), mock(PurgeProfiler.class));
task.purge(1L);
verify(purgeDao).purge(anyLong(), (String[]) any());
}
+
+ @Test
+ public void shouldDumpProfiling() {
+ PurgeDao purgeDao = mock(PurgeDao.class);
+ when(purgeDao.purge(anyLong(), (String[]) any())).thenThrow(new RuntimeException());
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
+ PurgeProfiler profiler = mock(PurgeProfiler.class);
+ DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class), profiler);
+
+ task.purge(1L);
+
+ verify(profiler).dump(anyLong());
+ }
}