*/
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;
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);
}
}
private final DbSession session;
private final String analysisUuid;
+ private int count = 0;
private DuplicationVisitor(DbSession session, String analysisUuid) {
super(CrawlerDepthLimit.FILE, PRE_ORDER);
indexInFile++;
}
}
+ count += indexInFile;
}
}
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;
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
+ @Rule
+ public LogTester logTester = new LogTester();
@Mock
CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder;
analysisMetadataHolder.setUuid(ANALYSIS_UUID);
analysisMetadataHolder.setBaseAnalysis(baseAnalysis);
underTest = new PersistCrossProjectDuplicationIndexStep(crossProjectDuplicationStatusHolder, dbClient, treeRootHolder, analysisMetadataHolder, reportReader);
+ logTester.setLevel(LoggerLevel.DEBUG);
}
@Test
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
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
underTest.execute();
assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(0);
+ assertStatisticsLog(0);
}
@Test
assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(0);
}
+ private void assertStatisticsLog(int expectedInserts) {
+ assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("inserts=" + expectedInserts);
+ }
}