]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4594 Fix DryRun mode when alerts are based on differential measures
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 27 Aug 2013 15:51:21 +0000 (17:51 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 27 Aug 2013 15:52:15 +0000 (17:52 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java
sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java
sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/multi-modules-with-issues.xml
sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database.xml

index 10f5253ea684964ce1970ad146e66a220e299206..c969d44ee6eab498d71bf8c58c26ef5351684a17 100644 (file)
@@ -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 {
 
index 0125142ce2b3ad03df56fc842f075768262e3077..baa3539bfe767b2cf5d1b58d74b4ffee019ed4a2 100644 (file)
@@ -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 + "'");
index 354ab2d0cf9b67885cd95c4142ede9793e5f7462..ce9f35f52fcbedaf7f5ae7cbbf6a8c12d0e71683 100644 (file)
@@ -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
index a9cdf217f0cb19d81f58d15f12ce95ad5b5a3dfe..af4cd1595c52f425ac44d3e5c754b18f14a05518 100644 (file)
   <snapshots id="3002" project_id="302" root_project_id="300" root_snapshot_id="3000" path="3000." islast="[true]"/>
   <snapshots id="3003" project_id="303" root_project_id="300" root_snapshot_id="3000" path="3000.3001." islast="[true]"/>
 
+  <project_measures id="1" value="12" metric_id="1" snapshot_id="3000" />
+  <project_measures id="2" value="5" metric_id="1" snapshot_id="3001" />
+  <project_measures id="3" value="7" metric_id="1" snapshot_id="3002" />
+  <project_measures id="4" value="5" metric_id="1" snapshot_id="3003" />
+  <project_measures id="5" value="35" metric_id="2" snapshot_id="3000" />
+  <project_measures id="6" value="20" metric_id="2" snapshot_id="3001" />
+  <project_measures id="7" value="30" metric_id="2" snapshot_id="3002" />
+  <project_measures id="8" value="20" metric_id="2" snapshot_id="3003" />
+
+
   <rules id="500" plugin_rule_key="AvoidCycle" plugin_name="squid"/>
   <rules id="501" plugin_rule_key="NullRef" plugin_name="squid"/>
 
index 1958f492aaa854e92494bea2e62c54cec437b049..2678396e998d74495dab0bbceb4ea1c57fb3d313 100644 (file)
@@ -23,4 +23,6 @@
 
   <alerts id="1" profile_id="1" metric_id="1" operator="lt" value_error="5" value_warning="" period="[null]"/>
 
+  <project_measures id="1" value="10" metric_id="1" snapshot_id="1000" />
+
 </dataset>