aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-08-03 13:09:38 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2018-08-05 23:17:31 +0200
commit62b09adc5a55f957bba40003009d39d34f9f148f (patch)
tree87f383f3332a7fe85a9f58bf19f8d42dd3fa5eb5
parentd08f2ac14b40196c1ee1c696001a6acbcd0160b3 (diff)
downloadsonarqube-62b09adc5a55f957bba40003009d39d34f9f148f.tar.gz
sonarqube-62b09adc5a55f957bba40003009d39d34f9f148f.zip
SONAR-11077 log nb of SQL inserts in CE PersistCrossProjectDuplicationsStep
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java11
2 files changed, 17 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java
index f0be9ded75d..aeacf92b7e4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.computation.task.projectanalysis.step;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.CloseableIterator;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -65,8 +66,10 @@ public class PersistCrossProjectDuplicationIndexStep implements ComputationStep
try (DbSession dbSession = dbClient.openSession(true)) {
Component project = treeRootHolder.getRoot();
- new DepthTraversalTypeAwareCrawler(new DuplicationVisitor(dbSession, analysisMetadataHolder.getUuid())).visit(project);
+ DuplicationVisitor visitor = new DuplicationVisitor(dbSession, analysisMetadataHolder.getUuid());
+ new DepthTraversalTypeAwareCrawler(visitor).visit(project);
dbSession.commit();
+ Loggers.get(getClass()).debug("inserts={}", visitor.count);
}
}
@@ -74,6 +77,7 @@ public class PersistCrossProjectDuplicationIndexStep implements ComputationStep
private final DbSession session;
private final String analysisUuid;
+ private int count = 0;
private DuplicationVisitor(DbSession session, String analysisUuid) {
super(CrawlerDepthLimit.FILE, PRE_ORDER);
@@ -107,6 +111,7 @@ public class PersistCrossProjectDuplicationIndexStep implements ComputationStep
indexInFile++;
}
}
+ count += indexInFile;
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java
index 5eb3e51d4a3..e358e8a86d3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java
@@ -29,6 +29,8 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
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.scanner.protocol.output.ScannerReport;
@@ -77,6 +79,8 @@ public class PersistCrossProjectDuplicationIndexStepTest {
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
+ @Rule
+ public LogTester logTester = new LogTester();
@Mock
CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder;
@@ -94,6 +98,7 @@ public class PersistCrossProjectDuplicationIndexStepTest {
analysisMetadataHolder.setUuid(ANALYSIS_UUID);
analysisMetadataHolder.setBaseAnalysis(baseAnalysis);
underTest = new PersistCrossProjectDuplicationIndexStep(crossProjectDuplicationStatusHolder, dbClient, treeRootHolder, analysisMetadataHolder, reportReader);
+ logTester.setLevel(LoggerLevel.DEBUG);
}
@Test
@@ -110,6 +115,7 @@ public class PersistCrossProjectDuplicationIndexStepTest {
assertThat(dto.get("INDEX_IN_FILE")).isEqualTo(0L);
assertThat(dto.get("COMPONENT_UUID")).isEqualTo(FILE_1.getUuid());
assertThat(dto.get("ANALYSIS_UUID")).isEqualTo(ANALYSIS_UUID);
+ assertStatisticsLog(1);
}
@Test
@@ -132,6 +138,7 @@ public class PersistCrossProjectDuplicationIndexStepTest {
assertThat(dtos).extracting("INDEX_IN_FILE").containsOnly(0L, 1L);
assertThat(dtos).extracting("COMPONENT_UUID").containsOnly(FILE_1.getUuid());
assertThat(dtos).extracting("ANALYSIS_UUID").containsOnly(ANALYSIS_UUID);
+ assertStatisticsLog(2);
}
@Test
@@ -142,6 +149,7 @@ public class PersistCrossProjectDuplicationIndexStepTest {
underTest.execute();
assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(0);
+ assertStatisticsLog(0);
}
@Test
@@ -154,4 +162,7 @@ public class PersistCrossProjectDuplicationIndexStepTest {
assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(0);
}
+ private void assertStatisticsLog(int expectedInserts) {
+ assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("inserts=" + expectedInserts);
+ }
}