diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-06-16 17:56:01 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-06-16 17:56:01 +0200 |
commit | e19020d1f3277bbaa9755154b4851c8c5599f830 (patch) | |
tree | 48b61c54dd49ccc79cab3a85d72af64c6924570d | |
parent | 4b866dabfe44891fc40362de199110a3647f6067 (diff) | |
download | sonarqube-e19020d1f3277bbaa9755154b4851c8c5599f830.tar.gz sonarqube-e19020d1f3277bbaa9755154b4851c8c5599f830.zip |
fix update of Measure from batch not support by MeasureRepository
2 files changed, 16 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureRepositoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureRepositoryImpl.java index 0e54bd0080c..e1bec6eedde 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureRepositoryImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureRepositoryImpl.java @@ -199,7 +199,11 @@ public class MeasureRepositoryImpl implements MeasureRepository { } , null); - return batchMeasureToMeasure.toMeasure(batchMeasure, metric); + Optional<Measure> res = batchMeasureToMeasure.toMeasure(batchMeasure, metric); + if (res.isPresent()) { + addLocal(component, metric, res.get()); + } + return res; } private Optional<Measure> findLocal(Component component, Metric metric, diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java index bbb373be528..7dcb72722a8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java @@ -303,6 +303,17 @@ public class MeasureRepositoryImplTest { assertThat(res.get()).isSameAs(addedMeasure); } + @Test + public void getRawMeasure_retrieves_measure_from_batch_and_caches_it_locally_so_that_it_can_be_updated() { + reportReader.putMeasures(FILE_COMPONENT.getRef(), ImmutableList.of( + BatchReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue("some value").build() + )); + + Optional<Measure> measure = underTest.getRawMeasure(FILE_COMPONENT, metric1); + + underTest.update(FILE_COMPONENT, metric1, Measure.updateMeasure(measure.get()).create()); + } + @Test(expected = NullPointerException.class) public void getRawMeasure_for_rule_throws_NPE_if_Component_arg_is_null() { underTest.getRawMeasure(null, metric1, SOME_RULE); |