]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13444 fix logs verbosity and code smells
authorPierre <pierre.guillot@sonarsource.com>
Thu, 25 Jun 2020 08:58:50 +0000 (10:58 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Jun 2020 20:04:58 +0000 (20:04 +0000)
server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java
server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java

index dbfcd54a60b6fa2449ad335b9c59aefbbe2935a6..cad4904df0b7bdbccbab153b1981a5caac9eefac 100644 (file)
@@ -169,8 +169,8 @@ public class InternalCeQueueImplTest {
     underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, null, null);
 
     // queue is empty
-    assertThat(db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).isPresent()).isFalse();
-    assertThat(underTest.peek(WORKER_UUID_2, false, false).isPresent()).isFalse();
+    assertThat(db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid())).isNotPresent();
+    assertThat(underTest.peek(WORKER_UUID_2, false, false)).isNotPresent();
 
     // available in history
     Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid());
index a74006db4800c94e7dbc0e92195ddef9ff02ec65..f6b86a5d3ad80f3a34bb71270e1713ca4f54f5d8 100644 (file)
@@ -393,11 +393,11 @@ public class CeQueueDaoTest {
 
   @Test
   public void peek_none_if_no_pendings() {
-    assertThat(underTest.peek(db.getSession(), WORKER_UUID_1, false, false).isPresent()).isFalse();
+    assertThat(underTest.peek(db.getSession(), WORKER_UUID_1, false, false)).isNotPresent();
 
     // not pending, but in progress
     makeInProgress(WORKER_UUID_1, 2_232_222L, insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1));
-    assertThat(underTest.peek(db.getSession(), WORKER_UUID_1, false, false).isPresent()).isFalse();
+    assertThat(underTest.peek(db.getSession(), WORKER_UUID_1, false, false)).isNotPresent();
   }
 
   @Test
@@ -426,7 +426,7 @@ public class CeQueueDaoTest {
     verifyCeQueueStatuses(TASK_UUID_1, IN_PROGRESS, TASK_UUID_2, IN_PROGRESS);
 
     // no more pendings
-    assertThat(underTest.peek(db.getSession(), WORKER_UUID_1, false, false).isPresent()).isFalse();
+    assertThat(underTest.peek(db.getSession(), WORKER_UUID_1, false, false)).isNotPresent();
   }
 
   @Test
index 3539180eacddf11a93f34624ce952bb240b9aac0..8fd541c78f33e7e1794fb576ed8d347f350b7053 100644 (file)
@@ -69,16 +69,13 @@ public class AsyncIssueIndexingImpl implements AsyncIssueIndexing {
 
       dbClient.branchDao().updateAllNeedIssueSync(dbSession);
       List<BranchDto> branchInNeedOfIssueSync = dbClient.branchDao().selectBranchNeedingIssueSync(dbSession);
+      LOG.info("{} branch found in need of issue sync.", branchInNeedOfIssueSync.size());
 
       if (branchInNeedOfIssueSync.isEmpty()) {
-        LOG.info("No branch found in need of issue sync");
         return;
       }
 
-      String branchListForDisplay = branchInNeedOfIssueSync.stream().map(BranchDto::toString).collect(Collectors.joining(", "));
-      LOG.info("{} branch found in need of issue sync : {}", branchInNeedOfIssueSync.size(), branchListForDisplay);
-
-      List<String> projectUuids = new ArrayList<>(branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).collect(Collectors.toSet()));
+      List<String> projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(Collectors.toList());
       LOG.info("{} projects found in need of issue sync.", projectUuids.size());
 
       sortProjectUuids(dbSession, projectUuids);
index 39af227174479cfe73a82e8d9f526f93c1b770bc..c8c25d23fbee43353d9871b25c57a5f1222bf020 100644 (file)
@@ -94,15 +94,14 @@ public class AsyncIssueIndexingImplTest {
     verify(ceQueue, times(1)).prepareSubmit();
     verify(ceQueue, times(1)).massSubmit(anyCollection());
     assertThat(logTester.logs(LoggerLevel.INFO))
-      .contains("1 branch found in need of issue sync : BranchDto{uuid='branch_uuid', projectUuid='project_uuid'," +
-        " kee='branchName', keyType=BRANCH, branchType=BRANCH, mergeBranchUuid='null', excludeFromPurge=false, needIssueSync=true}");
+      .contains("1 branch found in need of issue sync.");
   }
 
   @Test
   public void triggerOnIndexCreation_no_branch() {
     underTest.triggerOnIndexCreation();
 
-    assertThat(logTester.logs(LoggerLevel.INFO)).contains("No branch found in need of issue sync");
+    assertThat(logTester.logs(LoggerLevel.INFO)).contains("0 branch found in need of issue sync.");
   }
 
   @Test
@@ -134,7 +133,7 @@ public class AsyncIssueIndexingImplTest {
 
     assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), REPORT)).hasSize(1);
 
-    assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(Arrays.asList("uuid_2")))).hasSize(0);
+    assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(Arrays.asList("uuid_2")))).isEmpty();
 
     assertThat(logTester.logs(LoggerLevel.INFO))
       .contains(