From 2962d98212d1d30ae5b7b25089f76c842e615c8b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 3 Aug 2018 11:24:06 +0200 Subject: [PATCH] SONAR-11077 add statistics to CE FileMoveDetectionStep --- .../filemove/FileMoveDetectionStep.java | 1 + .../filemove/FileMoveDetectionStepTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java index 985b0d51050..96be5de663c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java @@ -131,6 +131,7 @@ public class FileMoveDetectionStep implements ComputationStep { return; } + LOG.debug("dbFiles={} | addedFiles={}", dbFilesByKey.size(), addedFileKeys.size()); MatchesByScore matchesByScore = MatchesByScore.create(scoreMatrix); ElectedMatches electedMatches = electMatches(removedFileKeys, reportFileSourcesByKey, matchesByScore); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java index 350705e1bc1..f0501f89e41 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java @@ -34,6 +34,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.sonar.api.utils.log.LogTester; +import org.sonar.api.utils.log.LoggerLevel; import org.sonar.core.hash.SourceLinesHashesComputer; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -222,6 +224,8 @@ public class FileMoveDetectionStepTest { public SourceLinesRepositoryRule sourceLinesRepository = new SourceLinesRepositoryRule(); @Rule public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule(); + @Rule + public LogTester logTester = new LogTester(); private DbClient dbClient = mock(DbClient.class); private DbSession dbSession = mock(DbSession.class); @@ -325,6 +329,7 @@ public class FileMoveDetectionStepTest { assertThat(originalFile.getId()).isEqualTo(dtos[0].getId()); assertThat(originalFile.getKey()).isEqualTo(dtos[0].getDbKey()); assertThat(originalFile.getUuid()).isEqualTo(dtos[0].uuid()); + verifyStatisticsLog( 1, 1); } @Test @@ -392,6 +397,7 @@ public class FileMoveDetectionStepTest { underTest.execute(); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); + verifyStatisticsLog(1, 2); } @Test @@ -406,6 +412,7 @@ public class FileMoveDetectionStepTest { underTest.execute(); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); + verifyStatisticsLog(2, 1); } @Test @@ -452,6 +459,8 @@ public class FileMoveDetectionStepTest { assertThat(originalFile5.getId()).isEqualTo(dtos[3].getId()); assertThat(originalFile5.getKey()).isEqualTo(dtos[3].getDbKey()); assertThat(originalFile5.getUuid()).isEqualTo(dtos[3].uuid()); + + verifyStatisticsLog(4, 2); } /** @@ -495,6 +504,8 @@ public class FileMoveDetectionStepTest { .isEqualTo("1242_make_analysis_uuid_not_null_on_duplications_index.rb"); assertThat(movedFilesRepository.getOriginalFile(addComponentUuidAndAnalysisUuidColumnToDuplicationsIndex).get().getKey()) .isEqualTo("AddComponentUuidColumnToDuplicationsIndex.java"); + + verifyStatisticsLog( 12, 6); } private String[] readLines(File filename) throws IOException { @@ -558,4 +569,7 @@ public class FileMoveDetectionStepTest { .build(); } + private void verifyStatisticsLog(int expectedDbFiles, int expectedAddedFiles) { + assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("dbFiles=" + expectedDbFiles + " | addedFiles=" + expectedAddedFiles); + } } -- 2.39.5