summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-05-07 11:38:54 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-05-07 11:38:54 +0200
commita59b6b9e8fe1b83660a0ef788643c115d3f6bb40 (patch)
tree8405a319473d2463d5eb44e0802985c8c2481129 /plugins/sonar-core-plugin
parentc70e47fb30545a9059d3470c2e086a76e2a6e605 (diff)
downloadsonarqube-a59b6b9e8fe1b83660a0ef788643c115d3f6bb40.tar.gz
sonarqube-a59b6b9e8fe1b83660a0ef788643c115d3f6bb40.zip
Revert "SONAR-5189 Reintroduce a memory cache for measure in decorators"
This reverts commit c70e47fb30545a9059d3470c2e086a76e2a6e605.
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java10
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java12
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java7
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java17
4 files changed, 31 insertions, 15 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
index 81e06451e24..1e20c12f994 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
@@ -38,6 +38,7 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
import org.sonar.batch.components.PeriodsDefinition;
+import org.sonar.batch.index.DefaultIndex;
import org.sonar.core.DryRunIncompatible;
import java.util.List;
@@ -52,9 +53,11 @@ public class TendencyDecorator implements Decorator {
private TimeMachineQuery query;
private TendencyAnalyser analyser;
private List<Metric> metrics;
+ private final DefaultIndex index;
- public TendencyDecorator(TimeMachine timeMachine, MetricFinder metricFinder) {
+ public TendencyDecorator(TimeMachine timeMachine, MetricFinder metricFinder, DefaultIndex index) {
this.timeMachine = timeMachine;
+ this.index = index;
this.analyser = new TendencyAnalyser();
this.metrics = Lists.newLinkedList();
for (Metric metric : metricFinder.findAll()) {
@@ -64,10 +67,11 @@ public class TendencyDecorator implements Decorator {
}
}
- TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser) {
+ TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser, DefaultIndex index) {
this.timeMachine = timeMachine;
this.query = query;
this.analyser = analyser;
+ this.index = index;
}
@DependsUpon
@@ -114,7 +118,7 @@ public class TendencyDecorator implements Decorator {
values.add(measure.getValue());
measure.setTendency(analyser.analyseLevel(valuesPerMetric.get(metric)));
- context.saveMeasure(measure);
+ index.updateMeasure(resource, measure);
}
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
index 46f8f9d93e8..be6d1a8f35e 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
@@ -40,6 +40,7 @@ import org.sonar.api.technicaldebt.batch.Characteristic;
import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.index.DefaultIndex;
import java.util.Collection;
import java.util.List;
@@ -52,16 +53,19 @@ public class VariationDecorator implements Decorator {
private MetricFinder metricFinder;
private PastMeasuresLoader pastMeasuresLoader;
private RuleFinder ruleFinder;
+ private final DefaultIndex sonarIndex;
- public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, TimeMachineConfiguration timeMachineConfiguration, RuleFinder ruleFinder) {
- this(pastMeasuresLoader, metricFinder, timeMachineConfiguration.getProjectPastSnapshots(), ruleFinder);
+ public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, TimeMachineConfiguration timeMachineConfiguration, RuleFinder ruleFinder,
+ DefaultIndex index) {
+ this(pastMeasuresLoader, metricFinder, timeMachineConfiguration.getProjectPastSnapshots(), ruleFinder, index);
}
- VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, List<PastSnapshot> projectPastSnapshots, RuleFinder ruleFinder) {
+ VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, List<PastSnapshot> projectPastSnapshots, RuleFinder ruleFinder, DefaultIndex index) {
this.pastMeasuresLoader = pastMeasuresLoader;
this.projectPastSnapshots = projectPastSnapshots;
this.metricFinder = metricFinder;
this.ruleFinder = ruleFinder;
+ this.sonarIndex = index;
}
public boolean shouldExecuteOnProject(Project project) {
@@ -112,7 +116,7 @@ public class VariationDecorator implements Decorator {
Object[] pastMeasure = pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, personId, ruleId));
if (updateVariation(measure, pastMeasure, index)) {
- context.saveMeasure(measure);
+ sonarIndex.updateMeasure(resource, measure);
}
}
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
index 8713c66537b..a60dfbb5e9e 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
@@ -28,6 +28,7 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Project;
+import org.sonar.batch.index.DefaultIndex;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -53,7 +54,7 @@ public class TendencyDecoratorTest {
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.findAll()).thenReturn(Arrays.asList(CoreMetrics.LINES, CoreMetrics.COVERAGE, CoreMetrics.COVERAGE_LINE_HITS_DATA, CoreMetrics.PROFILE));
- TendencyDecorator decorator = new TendencyDecorator(null, metricFinder);
+ TendencyDecorator decorator = new TendencyDecorator(null, metricFinder, mock(DefaultIndex.class));
TimeMachineQuery query = decorator.initQuery(project);
assertThat(query.getMetrics().size(), is(2));
@@ -80,7 +81,7 @@ public class TendencyDecoratorTest {
when(context.getMeasure(CoreMetrics.LINES)).thenReturn(new Measure(CoreMetrics.LINES, 1400.0));
when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.LINES, 90.0));
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, mock(DefaultIndex.class));
decorator.decorate(new Directory("org/foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
@@ -99,7 +100,7 @@ public class TendencyDecoratorTest {
));
DecoratorContext context = mock(DecoratorContext.class);
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, mock(DefaultIndex.class));
decorator.decorate(new Directory("org/foo"), context);
verify(analyser, never()).analyseLevel(anyList());
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
index c7c1876bf6c..971d6d9f99f 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
@@ -36,12 +36,14 @@ import org.sonar.api.rules.RuleFinder;
import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.index.DefaultIndex;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -61,7 +63,8 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
@Test
public void shouldComputeVariations() {
TimeMachineConfiguration timeMachineConfiguration = mock(TimeMachineConfiguration.class);
- VariationDecorator decorator = new VariationDecorator(mock(PastMeasuresLoader.class), mock(MetricFinder.class), timeMachineConfiguration, mock(RuleFinder.class));
+ VariationDecorator decorator = new VariationDecorator(mock(PastMeasuresLoader.class), mock(MetricFinder.class), timeMachineConfiguration, mock(RuleFinder.class),
+ mock(DefaultIndex.class));
assertThat(decorator.shouldComputeVariation(new Project("foo"))).isTrue();
assertThat(decorator.shouldComputeVariation(new File("foo/bar.c"))).isFalse();
@@ -90,11 +93,13 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
Measure currentCoverage = newMeasure(COVERAGE, 80.0);
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(currentNcloc, currentCoverage));
- VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3), mock(RuleFinder.class));
+ DefaultIndex index = mock(DefaultIndex.class);
+ VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3), mock(RuleFinder.class),
+ index);
decorator.decorate(dir, context);
// context updated for each variation : 2 times for ncloc and 1 time for coverage
- verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
+ verify(index, times(3)).updateMeasure(eq(dir), Matchers.<Measure>anyObject());
assertThat(currentNcloc.getVariation1()).isEqualTo(20.0);
assertThat(currentNcloc.getVariation2()).isNull();
@@ -135,11 +140,13 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
Measure violationsRule2 = RuleMeasure.createForRule(VIOLATIONS, rule2, 70.0);
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(violations, violationsRule1, violationsRule2));
- VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1), ruleFinder);
+ DefaultIndex index = mock(DefaultIndex.class);
+ VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1), ruleFinder,
+ index);
decorator.decorate(dir, context);
// context updated for each variation
- verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
+ verify(index, times(3)).updateMeasure(eq(dir), Matchers.<Measure>anyObject());
assertThat(violations.getVariation1()).isEqualTo(20.0);
}