From 87b5f228bc4289fdde70ea1fbbd84753183dfad9 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 27 Aug 2013 17:51:21 +0200 Subject: [PATCH] SONAR-4594 Fix DryRun mode when alerts are based on differential measures --- .../timemachine/TimeMachineConfigurationPersister.java | 2 -- .../sonar/core/persistence/DryRunDatabaseFactory.java | 3 +++ .../core/persistence/DryRunDatabaseFactoryTest.java | 6 ++++++ .../multi-modules-with-issues.xml | 10 ++++++++++ .../should_create_database.xml | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 10f5253ea68..c969d44ee6e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -30,11 +30,9 @@ import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; import org.sonar.batch.components.PastSnapshot; import org.sonar.batch.components.TimeMachineConfiguration; -import org.sonar.core.DryRunIncompatible; import java.util.List; -@DryRunIncompatible @DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE) public final class TimeMachineConfigurationPersister implements Decorator { diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index 0125142ce2b..baa3539bfe7 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -106,6 +106,9 @@ public class DryRunDatabaseFactory implements ServerComponent { projectQuery.append(" )"); template.copyTable(source, dest, "projects", projectQuery.toString()); + template.copyTable(source, dest, "snapshots", "SELECT * FROM snapshots WHERE project_id=" + projectId); + template.copyTable(source, dest, "project_measures", "SELECT m.* FROM project_measures m INNER JOIN snapshots s on m.snapshot_id=s.id WHERE s.project_id=" + projectId); + String forRootModule = "root_component_id in (select id from projects where id=" + projectId + " and qualifier='TRK')"; String forSubModule = "component_id in (select id from projects where id=" + projectId + " or root_id=" + projectId + ")"; template.copyTable(source, dest, "issues", "SELECT * FROM issues WHERE ((" + forRootModule + ") OR ( " + forSubModule + ")) AND status <> '" + Issue.STATUS_CLOSED + "'"); diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java index 354ab2d0cf9..ce9f35f52fc 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java @@ -81,6 +81,8 @@ public class DryRunDatabaseFactoryTest extends AbstractDaoTestCase { assertThat(rowCount("metrics")).isEqualTo(2); assertThat(rowCount("projects")).isEqualTo(1); + assertThat(rowCount("snapshots")).isEqualTo(1); + assertThat(rowCount("project_measures")).isEqualTo(1); } @Test @@ -106,6 +108,8 @@ public class DryRunDatabaseFactoryTest extends AbstractDaoTestCase { dataSource = createDatabase(database); assertThat(rowCount("issues")).isEqualTo(1); assertThat(rowCount("projects")).isEqualTo(4); + assertThat(rowCount("snapshots")).isEqualTo(1); + assertThat(rowCount("project_measures")).isEqualTo(2); } @Test @@ -119,6 +123,8 @@ public class DryRunDatabaseFactoryTest extends AbstractDaoTestCase { dataSource = createDatabase(database); assertThat(rowCount("issues")).isEqualTo(1); assertThat(rowCount("projects")).isEqualTo(2); + assertThat(rowCount("snapshots")).isEqualTo(1); + assertThat(rowCount("project_measures")).isEqualTo(2); } @Test diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/multi-modules-with-issues.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/multi-modules-with-issues.xml index a9cdf217f0c..af4cd1595c5 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/multi-modules-with-issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/multi-modules-with-issues.xml @@ -36,6 +36,16 @@ + + + + + + + + + + diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database.xml index 1958f492aaa..2678396e998 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database.xml @@ -23,4 +23,6 @@ + + -- 2.39.5