]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11077 add statistics to CE FileMoveDetectionStep
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 3 Aug 2018 09:24:06 +0000 (11:24 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 5 Aug 2018 21:17:30 +0000 (23:17 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java

index 985b0d510500f52fe61be7c8053426d270c31789..96be5de663c1acda721e25cf7a88622aacb01b59 100644 (file)
@@ -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);
index 350705e1bc1ace0ac36ee1e9ae383ba53f72adef..f0501f89e41d7a7d6a84df9f2e13096ffc403077 100644 (file)
@@ -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);
+  }
 }