From 9ca86cd73f8807401910cf8610b7b37bfb528b10 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 15 Aug 2011 15:47:40 +0200 Subject: [PATCH] SONAR-2707 Some dependencies might miss in the Libraries, Dependencies and Design services when running several sonar analysis at same time --- .../dbcleaner/purges/PurgeDependencies.java | 6 +- .../purges/PurgeDependenciesTest.java | 9 +++ ...uldNotPurgeUnprocessedSnapshots-result.xml | 73 +++++++++++++++++++ .../shouldNotPurgeUnprocessedSnapshots.xml | 73 +++++++++++++++++++ 4 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml create mode 100644 plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java index a05bd16bb02..65792f152aa 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java @@ -37,8 +37,10 @@ public final class PurgeDependencies extends Purge { public void purge(PurgeContext context) { Query query = getSession().createQuery("SELECT d.projectSnapshotId FROM " + DependencyDto.class.getSimpleName() + - " d WHERE NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last)"); - query.setParameter("last", true); + " d WHERE EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last and s.status=:status)"); + query.setParameter("last", false); + query.setParameter("status", Snapshot.STATUS_PROCESSED); + final List projectSnapshotIds = query.getResultList(); PurgeUtils.executeQuery(getSession(), "", projectSnapshotIds, "DELETE FROM " + DependencyDto.class.getSimpleName() + " WHERE projectSnapshotId in (:ids)"); } diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java index 3ce14d6d27b..5fb68a63e88 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java @@ -31,6 +31,15 @@ public class PurgeDependenciesTest extends AbstractDbUnitTestCase { assertPurge("purgeDependencies"); } + /** + * See https://jira.codehaus.org/browse/SONAR-2707 + * Do not remove dependencies which are computed at the same time in other parallel jobs. + */ + @Test + public void shouldNotPurgeUnprocessedSnapshots() throws SQLException { + assertPurge("shouldNotPurgeUnprocessedSnapshots"); + } + private void assertPurge(String testName) { setupData(testName); new PurgeDependencies(getSession()).purge(null); diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml new file mode 100644 index 00000000000..2d2599d8794 --- /dev/null +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml new file mode 100644 index 00000000000..6b143bea1ec --- /dev/null +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.39.5