diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-08-03 11:46:54 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-08-05 23:17:31 +0200 |
commit | f4105276fab3ad39f1f8ef3af247afbec0faae16 (patch) | |
tree | 56b8f3c318cb70cd2de10d4e076b7cba18f94fed /server | |
parent | fe003e5e825a357e0afda331b2374393404973d6 (diff) | |
download | sonarqube-f4105276fab3ad39f1f8ef3af247afbec0faae16.tar.gz sonarqube-f4105276fab3ad39f1f8ef3af247afbec0faae16.zip |
SONAR-11077 log nb of inserts in CE PersistMeasuresStep
Diffstat (limited to 'server')
2 files changed, 25 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStep.java index 69d10747645..8b4e9c23936 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStep.java @@ -27,6 +27,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import javax.annotation.Nonnull; +import org.sonar.api.utils.log.Loggers; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.measure.MeasureDao; @@ -83,13 +84,16 @@ public class PersistMeasuresStep implements ComputationStep { @Override public void execute() { try (DbSession dbSession = dbClient.openSession(true)) { - new DepthTraversalTypeAwareCrawler(new MeasureVisitor(dbSession)).visit(treeRootHolder.getRoot()); + MeasureVisitor visitor = new MeasureVisitor(dbSession); + new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot()); dbSession.commit(); + Loggers.get(getClass()).debug("inserts={}", visitor.inserts); } } private class MeasureVisitor extends TypeAwareVisitorAdapter { private final DbSession session; + private int inserts = 0; private MeasureVisitor(DbSession session) { super(CrawlerDepthLimit.LEAVES, PRE_ORDER); @@ -115,6 +119,7 @@ public class PersistMeasuresStep implements ComputationStep { for (Measure measure : from(measures.getValue()).filter(NonEmptyMeasure.INSTANCE).filter(notBestValueOptimized)) { MeasureDto measureDto = measureToMeasureDto.toMeasureDto(measure, metric, component); measureDao.insert(session, measureDto); + inserts++; } } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStepTest.java index 61d0099b157..32a2d5f4216 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistMeasuresStepTest.java @@ -26,6 +26,8 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.measures.Metric; import org.sonar.api.utils.System2; +import org.sonar.api.utils.log.LogTester; +import org.sonar.api.utils.log.LoggerLevel; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -88,7 +90,8 @@ public class PersistMeasuresStepTest extends BaseStepTest { public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); @Rule public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder); - + @Rule + public LogTester logTester = new LogTester(); @Rule public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule(); @@ -105,6 +108,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { public void setUp() { underTest = new PersistMeasuresStep(dbClient, metricRepository, new MeasureToMeasureDto(dbIdsRepository, analysisMetadataHolder), treeRootHolder, measureRepository); analysisMetadataHolder.setUuid(ANALYSIS_UUID); + logTester.setLevel(LoggerLevel.DEBUG); } private void setupReportComponents() { @@ -162,6 +166,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { setupReportComponents(); insertMeasures(); + assertStatisticsLogs(4); } @Test @@ -169,6 +174,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { setupViewsComponents(); insertMeasures(); + assertStatisticsLogs(4); } private void insertMeasures() { @@ -243,6 +249,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { setupReportComponents(); insertMeasureWithVariations(); + assertStatisticsLogs(1); } @Test @@ -250,6 +257,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { setupViewsComponents(); insertMeasureWithVariations(); + assertStatisticsLogs(1); } private void insertMeasureWithVariations() { @@ -279,6 +287,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { underTest.execute(); assertThat(selectSnapshots()).isEmpty(); + assertStatisticsLogs(0); } @Test @@ -294,6 +303,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { underTest.execute(); assertThat(selectSnapshots()).isEmpty(); + assertStatisticsLogs(0); } @Test @@ -315,6 +325,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { assertThat(dto.get("analysisUuid")).isEqualTo(ANALYSIS_UUID); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid()); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); + assertStatisticsLogs(1); } @Test @@ -336,6 +347,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { assertThat(dto.get("analysisUuid")).isEqualTo(ANALYSIS_UUID); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid()); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); + assertStatisticsLogs(1); } @Test @@ -357,6 +369,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { assertThat(dto.get("analysisUuid")).isEqualTo(ANALYSIS_UUID); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid()); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); + assertStatisticsLogs(1); } @Test @@ -377,6 +390,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { assertValue(dto, 1d); assertThat(dto.get("developerId")).isEqualTo(10L); + assertStatisticsLogs(1); } private ComponentDto addComponent(String key, String uuid) { @@ -402,6 +416,10 @@ public class PersistMeasuresStepTest extends BaseStepTest { "ORDER by id asc"); } + private void assertStatisticsLogs(int expectedInserts) { + assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("inserts=" + expectedInserts); + } + @Override protected ComputationStep step() { return underTest; |