]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9168 do not fail when indexing measure with unexpected text value
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 5 May 2017 11:39:13 +0000 (13:39 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 9 May 2017 06:53:05 +0000 (08:53 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java

index 2119ca6a2632fd2590b66ede12d513b0b184947b..11741d794fe68a67ddcaa044079b0a6b0232f9d4 100644 (file)
@@ -222,7 +222,6 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
       readTextValue(rs, measures::setLanguages);
       return;
     }
-    throw new IllegalArgumentException("Measure has no value");
   }
 
   private static void readTextValue(ResultSet rs, Consumer<String> action) throws SQLException {
index de2c5745456f3e25b633a5585669bb93798946ea..07b6da72a05e2d91e7937aba6bfddfe96cdf0a59 100644 (file)
@@ -161,14 +161,33 @@ public class ProjectMeasuresIndexerIteratorTest {
   }
 
   @Test
-  public void fail_when_measure_return_no_value() throws Exception {
-    MetricDto metric = insertIntMetric("new_lines");
+  public void ignore_measure_that_does_not_have_value() throws Exception {
+    MetricDto metric1 = insertIntMetric("lines");
+    MetricDto metric2 = insertIntMetric("ncloc");
+    MetricDto leakMetric = insertIntMetric("new_lines");
     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
     SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
-    insertMeasure(project, analysis, metric, 10d);
 
-    expectedException.expect(IllegalStateException.class);
-    createResultSetAndReturnDocsById();
+    MeasureDto withValue = insertMeasure(project, analysis, metric1, 10d);
+    MeasureDto withLeakValue = insertMeasure(project, analysis, leakMetric, null, 20d);
+    MeasureDto withoutValue = insertMeasure(project, analysis, metric2, null, null);
+
+    Map<String, Double> numericMeasures = createResultSetAndReturnDocsById().get(project.uuid()).getMeasures().getNumericMeasures();
+    assertThat(numericMeasures).containsOnly(entry("lines", 10d), entry("new_lines", 20d));
+  }
+
+  @Test
+  public void ignore_numeric_measure_that_has_text_value_but_not_numeric_value() throws Exception {
+    MetricDto metric1 = insertIntMetric("lines");
+    MetricDto metric2 = insertIntMetric("ncloc");
+    ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
+
+    MeasureDto withNumericValue = insertMeasure(project, analysis, metric1, 10d);
+    MeasureDto withTextValue = insertMeasure(project, analysis, metric2, "foo");
+
+    Map<String, Double> numericMeasures = createResultSetAndReturnDocsById().get(project.uuid()).getMeasures().getNumericMeasures();
+    assertThat(numericMeasures).containsOnly(entry("lines", 10d));
   }
 
   @Test