aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java24
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java117
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java29
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java35
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java94
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml3
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml6
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml8
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml3
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml5
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml3
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml11
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml8
16 files changed, 59 insertions, 302 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index 9624513e288..d5e42948fc5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -176,10 +176,7 @@ public class DefaultIndex extends SonarIndex {
public Measure getMeasure(Resource resource, Metric metric) {
Bucket bucket = buckets.get(resource);
if (bucket != null) {
- Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric));
- if (measure != null) {
- return persistence.reloadMeasure(measure);
- }
+ return bucket.getMeasures(MeasuresFilters.metric(metric));
}
return null;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java
index 14da97381cf..9dd3460e0ff 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java
@@ -40,8 +40,8 @@ public final class DefaultPersistenceManager implements PersistenceManager {
private EventPersister eventPersister;
public DefaultPersistenceManager(ResourcePersister resourcePersister, SourcePersister sourcePersister,
- MeasurePersister measurePersister, DependencyPersister dependencyPersister,
- LinkPersister linkPersister, EventPersister eventPersister) {
+ MeasurePersister measurePersister, DependencyPersister dependencyPersister,
+ LinkPersister linkPersister, EventPersister eventPersister) {
this.resourcePersister = resourcePersister;
this.sourcePersister = sourcePersister;
this.measurePersister = measurePersister;
@@ -88,10 +88,6 @@ public final class DefaultPersistenceManager implements PersistenceManager {
}
}
- public Measure reloadMeasure(Measure measure) {
- return measurePersister.reloadMeasure(measure);
- }
-
public void saveDependency(Project project, Dependency dependency, Dependency parentDependency) {
if (ResourceUtils.isPersistable(dependency.getFrom()) && ResourceUtils.isPersistable(dependency.getTo())) {
dependencyPersister.saveDependency(project, dependency, parentDependency);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index 8e61a931bd0..2e1c8995bac 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -47,25 +47,19 @@ public final class MeasurePersister {
private final MyBatis mybatis;
private final ResourcePersister resourcePersister;
private final RuleFinder ruleFinder;
- private final MemoryOptimizer memoryOptimizer;
private final SetMultimap<Resource, Measure> unsavedMeasuresByResource = LinkedHashMultimap.create();
private boolean delayedMode = false;
- public MeasurePersister(MyBatis mybatis, ResourcePersister resourcePersister, RuleFinder ruleFinder, MemoryOptimizer memoryOptimizer) {
+ public MeasurePersister(MyBatis mybatis, ResourcePersister resourcePersister, RuleFinder ruleFinder) {
this.mybatis = mybatis;
this.resourcePersister = resourcePersister;
this.ruleFinder = ruleFinder;
- this.memoryOptimizer = memoryOptimizer;
}
public void setDelayedMode(boolean delayedMode) {
this.delayedMode = delayedMode;
}
- public Measure reloadMeasure(Measure measure) {
- return memoryOptimizer.reloadMeasure(measure);
- }
-
public void dump() {
LoggerFactory.getLogger(getClass()).debug("{} measures to dump", unsavedMeasuresByResource.size());
@@ -81,16 +75,12 @@ public final class MeasurePersister {
unsavedMeasuresByResource.put(resource, measure);
return;
}
- MeasureModel model;
try {
- model = insertOrUpdate(resource, measure);
+ insertOrUpdate(resource, measure);
} catch (Exception e) {
// SONAR-4066
throw new SonarException(String.format("Unable to save measure for metric [%s] on component [%s]", measure.getMetricKey(), resource.getKey()), e);
}
- if (model != null) {
- memoryOptimizer.evictDataMeasure(measure, model);
- }
}
private MeasureModel insertOrUpdate(Resource resource, Measure measure) {
@@ -192,9 +182,6 @@ public final class MeasurePersister {
for (MeasureModelAndDetails value : values) {
try {
mapper.insert(value.getMeasureModel());
- if (value.getMeasureModel().getMeasureData() != null) {
- mapper.insertData(value.getMeasureModel().getMeasureData());
- }
} catch (Exception e) {
// SONAR-4066
throw new SonarException(String.format("Unable to save measure for metric [%s] on component [%s]", value.getMetricKey(), value.getResourceKey()), e);
@@ -216,9 +203,6 @@ public final class MeasurePersister {
MeasureMapper mapper = session.getMapper(MeasureMapper.class);
mapper.insert(value);
- if (value.getMeasureData() != null) {
- mapper.insertData(value.getMeasureData());
- }
session.commit();
} finally {
@@ -238,10 +222,6 @@ public final class MeasurePersister {
MeasureMapper mapper = session.getMapper(MeasureMapper.class);
mapper.update(value);
- mapper.deleteData(value);
- if (value.getMeasureData() != null) {
- mapper.insertData(value.getMeasureData());
- }
session.commit();
} finally {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java
deleted file mode 100644
index 9daa941b823..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.index;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.events.DecoratorExecutionHandler;
-import org.sonar.api.batch.events.DecoratorsPhaseHandler;
-import org.sonar.api.batch.events.SensorExecutionHandler;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.MeasureData;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.PersistenceMode;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * @since 2.7
- */
-public class MemoryOptimizer implements SensorExecutionHandler, DecoratorExecutionHandler, DecoratorsPhaseHandler {
-
- private static final Logger LOG = LoggerFactory.getLogger(MemoryOptimizer.class);
-
- private List<Measure> loadedMeasures = Lists.newArrayList();
- private Map<Long, Integer> dataIdByMeasureId = Maps.newHashMap();
- private DatabaseSession session;
-
- public MemoryOptimizer(DatabaseSession session) {
- this.session = session;
- }
-
- /**
- * Remove data of a database measure from memory.
- */
- public void evictDataMeasure(Measure measure, MeasureModel model) {
- if (PersistenceMode.DATABASE.equals(measure.getPersistenceMode())) {
- MeasureData data = model.getMeasureData();
- if (data != null && data.getId() != null) {
- measure.unsetData();
- dataIdByMeasureId.put(measure.getId(), data.getId());
- }
- }
- }
-
- public Measure reloadMeasure(Measure measure) {
- if (measure.getId() != null && dataIdByMeasureId.containsKey(measure.getId()) && !measure.hasData()) {
- Integer dataId = dataIdByMeasureId.get(measure.getId());
- MeasureData data = session.getSingleResult(MeasureData.class, "id", dataId);
- if (data == null) {
- LOG.error("The MEASURE_DATA row with id {} is lost", dataId);
-
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Reload the data measure: {}, id={}", measure.getMetricKey(), measure.getId());
- }
- measure.setData(data.getText());
- loadedMeasures.add(measure);
- }
- }
- return measure;
- }
-
- public void flushMemory() {
- if (LOG.isDebugEnabled() && !loadedMeasures.isEmpty()) {
- LOG.debug("Flush {} data measures from memory: ", loadedMeasures.size());
- }
- for (Measure measure : loadedMeasures) {
- measure.unsetData();
- }
- loadedMeasures.clear();
- }
-
- boolean isTracked(Long measureId) {
- return dataIdByMeasureId.get(measureId) != null;
- }
-
- public void onSensorExecution(SensorExecutionEvent event) {
- if (event.isEnd()) {
- flushMemory();
- session.commit();
- }
- }
-
- public void onDecoratorExecution(DecoratorExecutionEvent event) {
- if (event.isEnd()) {
- flushMemory();
- }
- }
-
- public void onDecoratorsPhase(DecoratorsPhaseEvent event) {
- if (event.isEnd()) {
- session.commit();
- }
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java
index d42e1a9f2e1..dec88e49d15 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java
@@ -46,8 +46,6 @@ public interface PersistenceManager {
void saveMeasure(Resource resource, Measure measure);
- Measure reloadMeasure(Measure measure);
-
void saveDependency(Project project, Dependency dependency, Dependency parentDependency);
void saveLink(Project project, ProjectLink link);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index e4eacf6aa8d..59e68e6078c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -21,7 +21,6 @@ package org.sonar.batch.scan;
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.BatchComponent;
-import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
@@ -36,12 +35,33 @@ import org.sonar.batch.DefaultFileLinesContextFactory;
import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.bootstrap.*;
+import org.sonar.batch.bootstrap.BootstrapSettings;
+import org.sonar.batch.bootstrap.ExtensionInstaller;
+import org.sonar.batch.bootstrap.ExtensionMatcher;
+import org.sonar.batch.bootstrap.ExtensionUtils;
+import org.sonar.batch.bootstrap.MetricProvider;
import org.sonar.batch.components.PeriodsDefinition;
import org.sonar.batch.debt.DebtModelProvider;
import org.sonar.batch.debt.IssueChangelogDebtCalculator;
-import org.sonar.batch.index.*;
-import org.sonar.batch.issue.*;
+import org.sonar.batch.index.Caches;
+import org.sonar.batch.index.ComponentDataCache;
+import org.sonar.batch.index.ComponentDataPersister;
+import org.sonar.batch.index.DefaultIndex;
+import org.sonar.batch.index.DefaultPersistenceManager;
+import org.sonar.batch.index.DefaultResourcePersister;
+import org.sonar.batch.index.DependencyPersister;
+import org.sonar.batch.index.EventPersister;
+import org.sonar.batch.index.LinkPersister;
+import org.sonar.batch.index.MeasurePersister;
+import org.sonar.batch.index.ResourceCache;
+import org.sonar.batch.index.ResourceKeyMigration;
+import org.sonar.batch.index.SnapshotCache;
+import org.sonar.batch.index.SourcePersister;
+import org.sonar.batch.issue.DefaultProjectIssues;
+import org.sonar.batch.issue.DeprecatedViolations;
+import org.sonar.batch.issue.IssueCache;
+import org.sonar.batch.issue.IssuePersister;
+import org.sonar.batch.issue.ScanIssueStorage;
import org.sonar.batch.phases.GraphPersister;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
import org.sonar.batch.rule.RulesProvider;
@@ -112,7 +132,6 @@ public class ProjectScanContainer extends ComponentContainer {
EventPersister.class,
LinkPersister.class,
MeasurePersister.class,
- MemoryOptimizer.class,
DefaultResourcePersister.class,
SourcePersister.class,
DefaultNotificationManager.class,
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
index fc3a69628d2..0b3363527da 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
@@ -23,8 +23,6 @@ import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.mockito.ArgumentCaptor;
-import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
@@ -41,10 +39,7 @@ import org.sonar.api.utils.SonarException;
import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class MeasurePersisterTest extends AbstractDaoTestCase {
@@ -64,7 +59,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
MeasurePersister measurePersister;
RuleFinder ruleFinder = mock(RuleFinder.class);
ResourcePersister resourcePersister = mock(ResourcePersister.class);
- MemoryOptimizer memoryOptimizer = mock(MemoryOptimizer.class);
Project project = new Project("foo");
Directory aDirectory = new Directory("org/foo");
File aFile = new File("org/foo/Bar.java");
@@ -78,7 +72,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
when(resourcePersister.getSnapshot(project)).thenReturn(projectSnapshot);
when(resourcePersister.getSnapshot(aDirectory)).thenReturn(packageSnapshot);
- measurePersister = new MeasurePersister(getMyBatis(), resourcePersister, ruleFinder, memoryOptimizer);
+ measurePersister = new MeasurePersister(getMyBatis(), resourcePersister, ruleFinder);
}
@Test
@@ -89,7 +83,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(project, measure);
checkTables("shouldInsertMeasure", "project_measures");
- verify(memoryOptimizer).evictDataMeasure(eq(measure), any(MeasureModel.class));
assertThat(measure.getId()).isNotNull();
}
@@ -106,15 +99,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
}
@Test
- public void should_reload_measure() {
- Measure measure = new Measure(ncloc());
-
- measurePersister.reloadMeasure(measure);
-
- verify(memoryOptimizer).reloadMeasure(measure);
- }
-
- @Test
public void should_insert_rule_measure() {
setupData("empty");
@@ -135,11 +119,8 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
Measure withLargeData = new Measure(ncloc()).setData(LONG);
measurePersister.saveMeasure(project, withLargeData);
- checkTables("shouldInsertMeasureWithLargeData", "project_measures", "measure_data");
+ checkTables("shouldInsertMeasureWithLargeData", "project_measures");
- ArgumentCaptor<MeasureModel> validMeasureModel = ArgumentCaptor.forClass(MeasureModel.class);
- verify(memoryOptimizer).evictDataMeasure(eq(withLargeData), validMeasureModel.capture());
- assertThat(validMeasureModel.getValue().getMeasureData().getId()).isNotNull();
assertThat(withLargeData.getId()).isNotNull();
}
@@ -149,7 +130,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0));
- assertEmptyTables("project_measures", "measure_data");
+ assertEmptyTables("project_measures");
}
@Test
@@ -158,7 +139,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(aFile, new Measure("ncloc").setPersistenceMode(PersistenceMode.MEMORY));
- assertEmptyTables("project_measures", "measure_data");
+ assertEmptyTables("project_measures");
}
@Test
@@ -179,7 +160,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(project, new Measure(coverage()).setData(SHORT).setId(2L));
measurePersister.saveMeasure(aDirectory, new Measure(coverage()).setData(LONG).setId(3L));
- checkTables("shouldUpdateMeasure", "project_measures", "measure_data");
+ checkTables("shouldUpdateMeasure", "project_measures");
}
@Test
@@ -207,7 +188,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
assertEmptyTables("project_measures");
measurePersister.dump();
- checkTables("shouldDelaySaving", "project_measures", "measure_data");
+ checkTables("shouldDelaySaving", "project_measures");
}
@Test
@@ -242,11 +223,11 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.setDelayedMode(true);
measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0));
- assertEmptyTables("project_measures", "measure_data");
+ assertEmptyTables("project_measures");
measurePersister.dump();
- assertEmptyTables("project_measures", "measure_data");
+ assertEmptyTables("project_measures");
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java
deleted file mode 100644
index 468654da72c..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.index;
-
-import org.junit.Test;
-import org.sonar.api.database.model.MeasureData;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.PersistenceMode;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
-public class MemoryOptimizerTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldEvictDatabaseOnlyMeasure() {
- MemoryOptimizer optimizer = new MemoryOptimizer(getSession());
- Measure measure = new Measure(CoreMetrics.CONDITIONS_BY_LINE)
- .setData("10=23")
- .setPersistenceMode(PersistenceMode.DATABASE)
- .setId(12345L);
- MeasureModel model = newPersistedModel();
-
- optimizer.evictDataMeasure(measure, model);
-
- assertThat(optimizer.isTracked(12345L),is(true));
- assertThat(measure.getData(), nullValue());// data has been removed from memory
- }
-
- @Test
- public void shouldNotEvictStandardMeasure() {
- MemoryOptimizer optimizer = new MemoryOptimizer(getSession());
- Measure measure = new Measure(CoreMetrics.PROFILE)
- .setData("Sonar way")
- .setId(12345L);
- MeasureModel model = newPersistedModel();
-
- optimizer.evictDataMeasure(measure, model);
-
- assertThat(optimizer.isTracked(12345L),is(false));
- assertThat(measure.getData(), is("Sonar way"));
- }
-
- @Test
- public void shouldReloadEvictedMeasure() {
- setupData("shouldReloadEvictedMeasure");
- MemoryOptimizer optimizer = new MemoryOptimizer(getSession());
- Measure measure = new Measure(CoreMetrics.CONDITIONS_BY_LINE)
- .setData("initial")
- .setPersistenceMode(PersistenceMode.DATABASE)
- .setId(12345L);
-
- optimizer.evictDataMeasure(measure, newPersistedModel());
- assertThat(measure.getData(), nullValue());
-
- optimizer.reloadMeasure(measure);
-
- assertThat(measure.getData().length(), greaterThan(5));
-
- optimizer.flushMemory();
- assertThat(measure.getData(), nullValue());
- }
-
- private MeasureModel newPersistedModel() {
- MeasureModel model = new MeasureModel();
- model.setId(12345L);
- MeasureData measureData = new MeasureData();
- measureData.setId(500);
- model.setMeasureData(measureData);
- return model;
- }
-}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml
index a9d69262af3..416ec0a604b 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml
@@ -4,6 +4,7 @@
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml
index cc956fb7770..cd064d6d9f1 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml
@@ -4,11 +4,13 @@
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
<project_measures id="2" VALUE="300.0" METRIC_ID="1" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]"
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml
index 97b4eb2090a..28f2942aec1 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml
@@ -5,14 +5,14 @@
RULE_ID="[null]" text_value="SHORT" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
<project_measures id="2" VALUE="50.0" METRIC_ID="1" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]"
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
-
- <measure_data id="1" measure_id="2" snapshot_id="3002" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml
index f7475f591e8..a19db3a8c05 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml
@@ -4,6 +4,7 @@
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml
index 77b6b6049a8..7aec2e88e4e 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml
@@ -5,8 +5,7 @@
tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
-
- <measure_data id="1" measure_id="1" snapshot_id="3001" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml
index 5472c06aaea..89acf2b2223 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml
@@ -4,6 +4,7 @@
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="2" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
index 22201f588e4..07f08fb086c 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
@@ -4,20 +4,21 @@
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
<project_measures id="2" VALUE="[null]" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]"
RULE_ID="[null]" text_value="SHORT" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="[null]"/>
<project_measures id="3" VALUE="[null]" METRIC_ID="2" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]"
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
-
- <measure_data id="1" measure_id="3" snapshot_id="3002" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ measure_data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml
deleted file mode 100644
index 5f40b829f73..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-
-
- <measure_data id="2" measure_id="2" snapshot_id="2" data="[null]"/>
- <measure_data id="500" measure_id="12345" snapshot_id="1" data="value from database"/>
-
-
-</dataset> \ No newline at end of file