From: Pierre Date: Thu, 25 Jun 2020 08:58:50 +0000 (+0200) Subject: SONAR-13444 fix logs verbosity and code smells X-Git-Tag: 8.4.0.35506~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96af2bcbe7c02a427bd783f8688a1bba775b4006;p=sonarqube.git SONAR-13444 fix logs verbosity and code smells --- diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index dbfcd54a60b..cad4904df0b 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -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 history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java index a74006db480..f6b86a5d3ad 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java @@ -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 diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java index 3539180eacd..8fd541c78f3 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java @@ -69,16 +69,13 @@ public class AsyncIssueIndexingImpl implements AsyncIssueIndexing { dbClient.branchDao().updateAllNeedIssueSync(dbSession); List 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 projectUuids = new ArrayList<>(branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).collect(Collectors.toSet())); + List projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(Collectors.toList()); LOG.info("{} projects found in need of issue sync.", projectUuids.size()); sortProjectUuids(dbSession, projectUuids); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java index 39af2271744..c8c25d23fbe 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java @@ -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(