]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11077 log nb of SQL inserts in CE PersistCrossProjectDuplicationsStep
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 3 Aug 2018 11:09:38 +0000 (13:09 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 5 Aug 2018 21:17:31 +0000 (23:17 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java

index f0be9ded75dfe929a0ca5dcd9d166b018b9968c9..aeacf92b7e41333d7c409f66d37cf3696a1cc59b 100644 (file)
@@ -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;
     }
 
   }
index 5eb3e51d4a308db2879d203f21e29fdb77120ec8..e358e8a86d3a70562603033006b38356d4219019 100644 (file)
@@ -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);
+  }
 }