aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
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 /sonar-core/src/test
parentc946ab5883685a67cf5476042905e8b5d66c3bbc (diff)
downloadsonarqube-c06ac5eaa744c05dbc7c779d0de84baea325776a.tar.gz
sonarqube-c06ac5eaa744c05dbc7c779d0de84baea325776a.zip
SONAR-4147 Implemented profiling of purge
+ minor changes like display of percents
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java21
-rw-r--r--sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java7
-rw-r--r--sonar-core/src/test/java/org/sonar/core/purge/PurgeProfilerTest.java105
3 files changed, 123 insertions, 10 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java
index d1199de2ef1..58744362574 100644
--- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java
@@ -20,6 +20,7 @@
package org.sonar.core.purge;
import org.apache.ibatis.session.SqlSession;
+import org.junit.Before;
import org.junit.Test;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.MyBatis;
@@ -27,6 +28,14 @@ import org.sonar.core.persistence.MyBatis;
import java.util.Arrays;
public class PurgeCommandsTest extends AbstractDaoTestCase {
+
+ private PurgeProfiler profiler;
+
+ @Before
+ public void prepare() {
+ profiler = new PurgeProfiler();
+ }
+
/**
* Test that all related data is deleted.
*/
@@ -36,12 +45,12 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
SqlSession session = getMyBatis().openSession();
try {
- new PurgeCommands(session).deleteSnapshots(PurgeSnapshotQuery.create().setId(5L));
+ new PurgeCommands(session, profiler).deleteSnapshots(PurgeSnapshotQuery.create().setId(5L));
} finally {
MyBatis.closeQuietly(session);
}
checkTables("shouldDeleteSnapshot",
- "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "snapshot_data");
+ "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "snapshot_data");
}
/**
@@ -53,12 +62,12 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
SqlSession session = getMyBatis().openSession();
try {
- new PurgeCommands(session).purgeSnapshots(PurgeSnapshotQuery.create().setId(1L));
+ new PurgeCommands(session, profiler).purgeSnapshots(PurgeSnapshotQuery.create().setId(1L));
} finally {
MyBatis.closeQuietly(session);
}
checkTables("shouldPurgeSnapshot",
- "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "reviews", "snapshot_data");
+ "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "reviews", "snapshot_data");
}
@Test
@@ -67,7 +76,7 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
SqlSession session = getMyBatis().openSession();
try {
- new PurgeCommands(session).purgeSnapshots(PurgeSnapshotQuery.create().setId(1L));
+ new PurgeCommands(session, profiler).purgeSnapshots(PurgeSnapshotQuery.create().setId(1L));
} finally {
MyBatis.closeQuietly(session);
}
@@ -79,7 +88,7 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
setupData("shouldDeleteResource");
SqlSession session = getMyBatis().openSession();
try {
- new PurgeCommands(session).deleteResources(Arrays.asList(1L));
+ new PurgeCommands(session, profiler).deleteResources(Arrays.asList(1L));
} finally {
MyBatis.closeQuietly(session);
}
diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
index bfa9316d399..173c2b6876c 100644
--- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
@@ -41,7 +41,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
@Before
public void createDao() {
- dao = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis()));
+ dao = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis()), new PurgeProfiler());
}
@Test
@@ -65,10 +65,9 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
} finally {
MyBatis.closeQuietly(session);
}
- checkTables("shouldCloseReviewWhenDisablingResource", /* excluded column */new String[]{"updated_at"}, "reviews");
+ checkTables("shouldCloseReviewWhenDisablingResource", /* excluded column */new String[] {"updated_at"}, "reviews");
}
-
@Test
public void shouldPurgeProject() {
setupData("shouldPurgeProject");
@@ -79,7 +78,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
@Test
public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles");
- dao.purge(1, new String[]{Scopes.DIRECTORY, Scopes.FILE});
+ dao.purge(1, new String[] {Scopes.DIRECTORY, Scopes.FILE});
checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots");
}
diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeProfilerTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeProfilerTest.java
new file mode 100644
index 00000000000..5a01eb34b06
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeProfilerTest.java
@@ -0,0 +1,105 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.purge;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class PurgeProfilerTest {
+
+ private MockedClock clock;
+ private PurgeProfiler profiler;
+ private ByteArrayOutputStream baos;
+ private PrintStream ps;
+
+ @Before
+ public void prepare() {
+ clock = new MockedClock();
+ profiler = new PurgeProfiler(clock);
+ baos = new ByteArrayOutputStream();
+ ps = new PrintStream(baos);
+ }
+
+ @After
+ public void cleanup() {
+ ps.close();
+ }
+
+ @Test
+ public void shouldProfilePurge() {
+ profiler.start("foo");
+ clock.sleep(10);
+ profiler.stop();
+
+ profiler.start("bar");
+ clock.sleep(5);
+ profiler.stop();
+
+ profiler.start("foo");
+ clock.sleep(8);
+ profiler.stop();
+
+ profiler.dump(50, ps);
+ String content = baos.toString();
+ assertThat(content).contains("foo: 18ms");
+ assertThat(content).contains("bar: 5ms");
+ }
+
+ @Test
+ public void shouldResetPurgeProfiling() {
+ profiler.start("foo");
+ clock.sleep(10);
+ profiler.stop();
+
+ profiler.reset();
+
+ profiler.start("bar");
+ clock.sleep(5);
+ profiler.stop();
+
+ profiler.start("foo");
+ clock.sleep(8);
+ profiler.stop();
+
+ profiler.dump(50, ps);
+ String content = baos.toString();
+ assertThat(content).contains("foo: 8ms");
+ assertThat(content).contains("bar: 5ms");
+ }
+
+ private class MockedClock extends org.sonar.core.purge.PurgeProfiler.Clock {
+ private long now = 0;
+
+ @Override
+ public long now() {
+ return now;
+ }
+
+ public void sleep(long duration) {
+ now += duration;
+ }
+ }
+}