aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-05-07 11:37:06 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-05-07 11:37:52 +0200
commitc70e47fb30545a9059d3470c2e086a76e2a6e605 (patch)
treeb49a01d06f9724333d8cd44690740923dcec79f3 /plugins
parent9688a077297d1f52c6bc3cec504d0d5dcf61d800 (diff)
downloadsonarqube-c70e47fb30545a9059d3470c2e086a76e2a6e605.tar.gz
sonarqube-c70e47fb30545a9059d3470c2e086a76e2a6e605.zip
SONAR-5189 Reintroduce a memory cache for measure in decorators
Diffstat (limited to 'plugins')
-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, 15 insertions, 31 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 1e20c12f994..81e06451e24 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,7 +38,6 @@ 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;
@@ -53,11 +52,9 @@ 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, DefaultIndex index) {
+ public TendencyDecorator(TimeMachine timeMachine, MetricFinder metricFinder) {
this.timeMachine = timeMachine;
- this.index = index;
this.analyser = new TendencyAnalyser();
this.metrics = Lists.newLinkedList();
for (Metric metric : metricFinder.findAll()) {
@@ -67,11 +64,10 @@ public class TendencyDecorator implements Decorator {
}
}
- TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser, DefaultIndex index) {
+ TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser) {
this.timeMachine = timeMachine;
this.query = query;
this.analyser = analyser;
- this.index = index;
}
@DependsUpon
@@ -118,7 +114,7 @@ public class TendencyDecorator implements Decorator {
values.add(measure.getValue());
measure.setTendency(analyser.analyseLevel(valuesPerMetric.get(metric)));
- index.updateMeasure(resource, measure);
+ context.saveMeasure(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 be6d1a8f35e..46f8f9d93e8 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,7 +40,6 @@ 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;
@@ -53,19 +52,16 @@ 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,
- DefaultIndex index) {
- this(pastMeasuresLoader, metricFinder, timeMachineConfiguration.getProjectPastSnapshots(), ruleFinder, index);
+ public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, TimeMachineConfiguration timeMachineConfiguration, RuleFinder ruleFinder) {
+ this(pastMeasuresLoader, metricFinder, timeMachineConfiguration.getProjectPastSnapshots(), ruleFinder);
}
- VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, List<PastSnapshot> projectPastSnapshots, RuleFinder ruleFinder, DefaultIndex index) {
+ VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, List<PastSnapshot> projectPastSnapshots, RuleFinder ruleFinder) {
this.pastMeasuresLoader = pastMeasuresLoader;
this.projectPastSnapshots = projectPastSnapshots;
this.metricFinder = metricFinder;
this.ruleFinder = ruleFinder;
- this.sonarIndex = index;
}
public boolean shouldExecuteOnProject(Project project) {
@@ -116,7 +112,7 @@ public class VariationDecorator implements Decorator {
Object[] pastMeasure = pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, personId, ruleId));
if (updateVariation(measure, pastMeasure, index)) {
- sonarIndex.updateMeasure(resource, measure);
+ context.saveMeasure(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 a60dfbb5e9e..8713c66537b 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,7 +28,6 @@ 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;
@@ -54,7 +53,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, mock(DefaultIndex.class));
+ TendencyDecorator decorator = new TendencyDecorator(null, metricFinder);
TimeMachineQuery query = decorator.initQuery(project);
assertThat(query.getMetrics().size(), is(2));
@@ -81,7 +80,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, mock(DefaultIndex.class));
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
decorator.decorate(new Directory("org/foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
@@ -100,7 +99,7 @@ public class TendencyDecoratorTest {
));
DecoratorContext context = mock(DecoratorContext.class);
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, mock(DefaultIndex.class));
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
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 971d6d9f99f..c7c1876bf6c 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,14 +36,12 @@ 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;
@@ -63,8 +61,7 @@ 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),
- mock(DefaultIndex.class));
+ VariationDecorator decorator = new VariationDecorator(mock(PastMeasuresLoader.class), mock(MetricFinder.class), timeMachineConfiguration, mock(RuleFinder.class));
assertThat(decorator.shouldComputeVariation(new Project("foo"))).isTrue();
assertThat(decorator.shouldComputeVariation(new File("foo/bar.c"))).isFalse();
@@ -93,13 +90,11 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
Measure currentCoverage = newMeasure(COVERAGE, 80.0);
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(currentNcloc, currentCoverage));
- DefaultIndex index = mock(DefaultIndex.class);
- VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3), mock(RuleFinder.class),
- index);
+ VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3), mock(RuleFinder.class));
decorator.decorate(dir, context);
// context updated for each variation : 2 times for ncloc and 1 time for coverage
- verify(index, times(3)).updateMeasure(eq(dir), Matchers.<Measure>anyObject());
+ verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
assertThat(currentNcloc.getVariation1()).isEqualTo(20.0);
assertThat(currentNcloc.getVariation2()).isNull();
@@ -140,13 +135,11 @@ 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));
- DefaultIndex index = mock(DefaultIndex.class);
- VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1), ruleFinder,
- index);
+ VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1), ruleFinder);
decorator.decorate(dir, context);
// context updated for each variation
- verify(index, times(3)).updateMeasure(eq(dir), Matchers.<Measure>anyObject());
+ verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
assertThat(violations.getVariation1()).isEqualTo(20.0);
}