From 1e175c1f25b46050a4be209688eff36c71ad6c6e Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 27 Aug 2019 17:35:14 +0200 Subject: [PATCH] SONAR-12423 fix misleading naming in notification stat classes --- .../step/SendIssueNotificationsStep.java | 16 ++- .../step/SendIssueNotificationsStepTest.java | 6 +- .../DistributedMetricStatsInt.java | 10 +- .../issue/notification/MetricStatsInt.java | 22 ++-- .../issue/notification/MetricStatsLong.java | 26 ++--- .../notification/NewIssuesNotification.java | 22 ++-- .../notification/NewIssuesStatistics.java | 38 +++--- .../NewIssuesNotificationTest.java | 4 +- .../notification/NewIssuesStatisticsTest.java | 108 +++++++++--------- 9 files changed, 125 insertions(+), 127 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java index 8393918369b..31b5d3369d4 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java @@ -80,8 +80,6 @@ public class SendIssueNotificationsStep implements ComputationStep { private final NotificationFactory notificationFactory; private final DbClient dbClient; - private Map componentsByDbKey; - public SendIssueNotificationsStep(IssueCache issueCache, TreeRootHolder treeRootHolder, NotificationService service, AnalysisMetadataHolder analysisMetadataHolder, NotificationFactory notificationFactory, DbClient dbClient) { @@ -110,8 +108,8 @@ public class SendIssueNotificationsStep implements ComputationStep { private void doExecute(NotificationStatistics notificationStatistics, Component project) { long analysisDate = analysisMetadataHolder.getAnalysisDate(); - Predicate isOnLeakPredicate = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate); - NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(isOnLeakPredicate); + Predicate onCurrentAnalysis = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate); + NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(onCurrentAnalysis); Map assigneesByUuid; try (DbSession dbSession = dbClient.openSession(false)) { Iterable iterable = issueCache::traverse; @@ -122,7 +120,7 @@ public class SendIssueNotificationsStep implements ComputationStep { try (CloseableIterator issues = issueCache.traverse()) { processIssues(newIssuesStats, issues, assigneesByUuid, notificationStatistics); } - if (newIssuesStats.hasIssuesOnLeak()) { + if (newIssuesStats.hasIssuesOnCurrentAnalysis()) { sendNewIssuesNotification(newIssuesStats, project, assigneesByUuid, analysisDate, notificationStatistics); sendMyNewIssuesNotification(newIssuesStats, project, assigneesByUuid, analysisDate, notificationStatistics); } @@ -182,7 +180,7 @@ public class SendIssueNotificationsStep implements ComputationStep { .setProjectVersion(project.getProjectAttributes().getProjectVersion()) .setAnalysisDate(new Date(analysisDate)) .setStatistics(project.getName(), globalStatistics) - .setDebt(Duration.create(globalStatistics.effort().getOnLeak())); + .setDebt(Duration.create(globalStatistics.effort().getOnCurrentAnalysis())); notificationStatistics.newIssuesDeliveries += service.deliverEmails(singleton(notification)); notificationStatistics.newIssues++; @@ -195,7 +193,7 @@ public class SendIssueNotificationsStep implements ComputationStep { Map userDtoByUuid = loadUserDtoByUuid(statistics); Set myNewIssuesNotifications = statistics.getAssigneesStatistics().entrySet() .stream() - .filter(e -> e.getValue().hasIssuesOnLeak()) + .filter(e -> e.getValue().hasIssuesOnCurrentAnalysis()) .map(e -> { String assigneeUuid = e.getKey(); NewIssuesStatistics.Stats assigneeStatistics = e.getValue(); @@ -207,7 +205,7 @@ public class SendIssueNotificationsStep implements ComputationStep { .setProjectVersion(project.getProjectAttributes().getProjectVersion()) .setAnalysisDate(new Date(analysisDate)) .setStatistics(project.getName(), assigneeStatistics) - .setDebt(Duration.create(assigneeStatistics.effort().getOnLeak())); + .setDebt(Duration.create(assigneeStatistics.effort().getOnCurrentAnalysis())); return myNewIssuesNotification; }) @@ -223,7 +221,7 @@ public class SendIssueNotificationsStep implements ComputationStep { private Map loadUserDtoByUuid(NewIssuesStatistics statistics) { List> entriesWithIssuesOnLeak = statistics.getAssigneesStatistics().entrySet() - .stream().filter(e -> e.getValue().hasIssuesOnLeak()).collect(toList()); + .stream().filter(e -> e.getValue().hasIssuesOnCurrentAnalysis()).collect(toList()); List assigneeUuids = entriesWithIssuesOnLeak.stream().map(Map.Entry::getKey).collect(toList()); try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, u -> u)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java index 6d077e53d34..0f294755fd5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -225,7 +225,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { assertThat(stats.hasIssues()).isTrue(); // just checking all issues have been added to the stats DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE); - assertThat(severity.getOnLeak()).isEqualTo(efforts.length); + assertThat(severity.getOnCurrentAnalysis()).isEqualTo(efforts.length); assertThat(severity.getTotal()).isEqualTo(backDatedEfforts.length + efforts.length); verifyStatistics(context, 1, 0, 0); } @@ -415,7 +415,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { assertThat(stats.hasIssues()).isTrue(); // just checking all issues have been added to the stats DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE); - assertThat(severity.getOnLeak()).isEqualTo(assigned.length); + assertThat(severity.getOnCurrentAnalysis()).isEqualTo(assigned.length); assertThat(severity.getTotal()).isEqualTo(assigned.length); verifyStatistics(context, 1, 2, 0); @@ -464,7 +464,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { assertThat(stats.hasIssues()).isTrue(); // just checking all issues have been added to the stats DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE); - assertThat(severity.getOnLeak()).isEqualTo(efforts.length); + assertThat(severity.getOnCurrentAnalysis()).isEqualTo(efforts.length); assertThat(severity.getTotal()).isEqualTo(backDatedEfforts.length + efforts.length); verifyStatistics(context, 1, 1, 0); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/DistributedMetricStatsInt.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/DistributedMetricStatsInt.java index 41f03de3f28..754850b89c9 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/DistributedMetricStatsInt.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/DistributedMetricStatsInt.java @@ -28,9 +28,9 @@ public class DistributedMetricStatsInt { private MetricStatsInt globalStats = new MetricStatsInt(); private Map statsPerLabel = new HashMap<>(); - DistributedMetricStatsInt increment(String label, boolean onLeak) { - this.globalStats.increment(onLeak); - statsPerLabel.computeIfAbsent(label, l -> new MetricStatsInt()).increment(onLeak); + DistributedMetricStatsInt increment(String label, boolean onCurrentAnalysis) { + this.globalStats.increment(onCurrentAnalysis); + statsPerLabel.computeIfAbsent(label, l -> new MetricStatsInt()).increment(onCurrentAnalysis); return this; } @@ -42,8 +42,8 @@ public class DistributedMetricStatsInt { return Optional.ofNullable(statsPerLabel.get(label)); } - public int getOnLeak() { - return globalStats.getOnLeak(); + public int getOnCurrentAnalysis() { + return globalStats.getOnCurrentAnalysis(); } public int getTotal() { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsInt.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsInt.java index 6d4e5d231e6..2f9c9ca479b 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsInt.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsInt.java @@ -20,31 +20,31 @@ package org.sonar.server.issue.notification; public class MetricStatsInt { - private int onLeak = 0; - private int offLeak = 0; + private int onCurrentAnalysis = 0; + private int offCurrentAnalysis = 0; - MetricStatsInt increment(boolean onLeak) { - if (onLeak) { - this.onLeak += 1; + MetricStatsInt increment(boolean onCurrentAnalysis) { + if (onCurrentAnalysis) { + this.onCurrentAnalysis += 1; } else { - this.offLeak += 1; + this.offCurrentAnalysis += 1; } return this; } - public int getOnLeak() { - return onLeak; + public int getOnCurrentAnalysis() { + return onCurrentAnalysis; } public int getTotal() { - return onLeak + offLeak; + return onCurrentAnalysis + offCurrentAnalysis; } @Override public String toString() { return "MetricStatsInt{" + - "onLeak=" + onLeak + - ", offLeak=" + offLeak + + "on=" + onCurrentAnalysis + + ", off=" + offCurrentAnalysis + '}'; } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsLong.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsLong.java index d47ce1d2398..ff3b4e6f7a8 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsLong.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsLong.java @@ -20,35 +20,35 @@ package org.sonar.server.issue.notification; public class MetricStatsLong { - private long onLeak = 0; - private long offLeak = 0; + private long onCurrentAnalysis = 0; + private long offCurrentAnalysis = 0; - MetricStatsLong add(long toAdd, boolean onLeak) { - if (onLeak) { - this.onLeak += toAdd; + MetricStatsLong add(long toAdd, boolean onCurrentAnalysis) { + if (onCurrentAnalysis) { + this.onCurrentAnalysis += toAdd; } else { - this.offLeak += toAdd; + this.offCurrentAnalysis += toAdd; } return this; } - public long getOnLeak() { - return onLeak; + public long getOnCurrentAnalysis() { + return onCurrentAnalysis; } - public long getOffLeak() { - return offLeak; + public long getOffCurrentAnalysis() { + return offCurrentAnalysis; } public long getTotal() { - return onLeak + offLeak; + return onCurrentAnalysis + offCurrentAnalysis; } @Override public String toString() { return "MetricStatsLong{" + - "onLeak=" + onLeak + - ", offLeak=" + offLeak + + "on=" + onCurrentAnalysis + + ", off=" + offCurrentAnalysis + '}'; } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java index aac875a40f5..36b023e6c9a 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java @@ -158,7 +158,7 @@ public class NewIssuesNotification extends Notification { } public NewIssuesNotification setStatistics(String projectName, NewIssuesStatistics.Stats stats) { - setDefaultMessage(stats.getDistributedMetricStats(RULE_TYPE).getOnLeak() + " new issues on " + projectName + ".\n"); + setDefaultMessage(stats.getDistributedMetricStats(RULE_TYPE).getOnCurrentAnalysis() + " new issues on " + projectName + ".\n"); setRuleTypeStatistics(stats); setAssigneesStatistics(stats); @@ -171,7 +171,7 @@ public class NewIssuesNotification extends Notification { private void setRuleStatistics(NewIssuesStatistics.Stats stats) { Metric metric = Metric.RULE; - List> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); + List> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis); int i = 1; for (Map.Entry ruleStats : fiveBiggest) { String ruleKey = ruleStats.getKey(); @@ -179,7 +179,7 @@ public class NewIssuesNotification extends Notification { .orElseThrow(() -> new IllegalStateException(String.format("Rule with key '%s' does not exist", ruleKey))); String name = rule.getName() + " (" + rule.getLanguage() + ")"; setFieldValue(metric + DOT + i + LABEL, name); - setFieldValue(metric + DOT + i + COUNT, String.valueOf(ruleStats.getValue().getOnLeak())); + setFieldValue(metric + DOT + i + COUNT, String.valueOf(ruleStats.getValue().getOnCurrentAnalysis())); i++; } } @@ -187,13 +187,13 @@ public class NewIssuesNotification extends Notification { private void setComponentsStatistics(NewIssuesStatistics.Stats stats) { Metric metric = Metric.COMPONENT; int i = 1; - List> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); + List> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis); for (Map.Entry componentStats : fiveBiggest) { String uuid = componentStats.getKey(); String componentName = detailsSupplier.getComponentNameByUuid(uuid) .orElseThrow(() -> new IllegalStateException(String.format("Component with uuid '%s' not found", uuid))); setFieldValue(metric + DOT + i + LABEL, componentName); - setFieldValue(metric + DOT + i + COUNT, String.valueOf(componentStats.getValue().getOnLeak())); + setFieldValue(metric + DOT + i + COUNT, String.valueOf(componentStats.getValue().getOnCurrentAnalysis())); i++; } } @@ -201,8 +201,8 @@ public class NewIssuesNotification extends Notification { private void setTagsStatistics(NewIssuesStatistics.Stats stats) { Metric metric = Metric.TAG; int i = 1; - for (Map.Entry tagStats : fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak)) { - setFieldValue(metric + DOT + i + COUNT, String.valueOf(tagStats.getValue().getOnLeak())); + for (Map.Entry tagStats : fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis)) { + setFieldValue(metric + DOT + i + COUNT, String.valueOf(tagStats.getValue().getOnCurrentAnalysis())); setFieldValue(metric + DOT + i + LABEL, tagStats.getKey()); i++; } @@ -210,14 +210,14 @@ public class NewIssuesNotification extends Notification { private void setAssigneesStatistics(NewIssuesStatistics.Stats stats) { Metric metric = Metric.ASSIGNEE; - List> entries = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); + List> entries = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis); int i = 1; for (Map.Entry assigneeStats : entries) { String assigneeUuid = assigneeStats.getKey(); String name = detailsSupplier.getUserNameByUuid(assigneeUuid).orElse(assigneeUuid); setFieldValue(metric + DOT + i + LABEL, name); - setFieldValue(metric + DOT + i + COUNT, String.valueOf(assigneeStats.getValue().getOnLeak())); + setFieldValue(metric + DOT + i + COUNT, String.valueOf(assigneeStats.getValue().getOnCurrentAnalysis())); i++; } } @@ -240,11 +240,11 @@ public class NewIssuesNotification extends Notification { private void setRuleTypeStatistics(NewIssuesStatistics.Stats stats) { DistributedMetricStatsInt distributedMetricStats = stats.getDistributedMetricStats(RULE_TYPE); - setFieldValue(RULE_TYPE + COUNT, String.valueOf(distributedMetricStats.getOnLeak())); + setFieldValue(RULE_TYPE + COUNT, String.valueOf(distributedMetricStats.getOnCurrentAnalysis())); Arrays.stream(RuleType.values()) .forEach(ruleType -> setFieldValue( RULE_TYPE + DOT + ruleType + COUNT, - String.valueOf(distributedMetricStats.getForLabel(ruleType.name()).map(MetricStatsInt::getOnLeak).orElse(0)))); + String.valueOf(distributedMetricStats.getForLabel(ruleType.name()).map(MetricStatsInt::getOnCurrentAnalysis).orElse(0)))); } @Override diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java index 060da6e483a..ddad91d5e40 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java @@ -34,20 +34,20 @@ import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RUL import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class NewIssuesStatistics { - private final Predicate onLeakPredicate; + private final Predicate onCurrentAnalysisPredicate; private final Map assigneesStatistics = new LinkedHashMap<>(); private final Stats globalStatistics; - public NewIssuesStatistics(Predicate onLeakPredicate) { - this.onLeakPredicate = onLeakPredicate; - this.globalStatistics = new Stats(onLeakPredicate); + public NewIssuesStatistics(Predicate onCurrentAnalysisPredicate) { + this.onCurrentAnalysisPredicate = onCurrentAnalysisPredicate; + this.globalStatistics = new Stats(onCurrentAnalysisPredicate); } public void add(DefaultIssue issue) { globalStatistics.add(issue); String userUuid = issue.assignee(); if (userUuid != null) { - assigneesStatistics.computeIfAbsent(userUuid, a -> new Stats(onLeakPredicate)).add(issue); + assigneesStatistics.computeIfAbsent(userUuid, a -> new Stats(onCurrentAnalysisPredicate)).add(issue); } } @@ -63,8 +63,8 @@ public class NewIssuesStatistics { return globalStatistics.hasIssues(); } - public boolean hasIssuesOnLeak() { - return globalStatistics.hasIssuesOnLeak(); + public boolean hasIssuesOnCurrentAnalysis() { + return globalStatistics.hasIssuesOnCurrentAnalysis(); } public enum Metric { @@ -89,12 +89,12 @@ public class NewIssuesStatistics { } public static class Stats { - private final Predicate onLeakPredicate; + private final Predicate onCurrentAnalysisPredicate; private final Map distributions = new EnumMap<>(Metric.class); private MetricStatsLong effortStats = new MetricStatsLong(); - public Stats(Predicate onLeakPredicate) { - this.onLeakPredicate = onLeakPredicate; + public Stats(Predicate onCurrentAnalysisPredicate) { + this.onCurrentAnalysisPredicate = onCurrentAnalysisPredicate; for (Metric metric : Metric.values()) { if (metric.isComputedByDistribution()) { distributions.put(metric, new DistributedMetricStatsInt()); @@ -103,26 +103,26 @@ public class NewIssuesStatistics { } public void add(DefaultIssue issue) { - boolean isOnLeak = onLeakPredicate.test(issue); - distributions.get(RULE_TYPE).increment(issue.type().name(), isOnLeak); + boolean onCurrentAnalysis = onCurrentAnalysisPredicate.test(issue); + distributions.get(RULE_TYPE).increment(issue.type().name(), onCurrentAnalysis); String componentUuid = issue.componentUuid(); if (componentUuid != null) { - distributions.get(COMPONENT).increment(componentUuid, isOnLeak); + distributions.get(COMPONENT).increment(componentUuid, onCurrentAnalysis); } RuleKey ruleKey = issue.ruleKey(); if (ruleKey != null) { - distributions.get(RULE).increment(ruleKey.toString(), isOnLeak); + distributions.get(RULE).increment(ruleKey.toString(), onCurrentAnalysis); } String assigneeUuid = issue.assignee(); if (assigneeUuid != null) { - distributions.get(ASSIGNEE).increment(assigneeUuid, isOnLeak); + distributions.get(ASSIGNEE).increment(assigneeUuid, onCurrentAnalysis); } for (String tag : issue.tags()) { - distributions.get(TAG).increment(tag, isOnLeak); + distributions.get(TAG).increment(tag, onCurrentAnalysis); } Duration effort = issue.effort(); if (effort != null) { - effortStats.add(effort.toMinutes(), isOnLeak); + effortStats.add(effort.toMinutes(), onCurrentAnalysis); } } @@ -138,8 +138,8 @@ public class NewIssuesStatistics { return getDistributedMetricStats(RULE_TYPE).getTotal() > 0; } - public boolean hasIssuesOnLeak() { - return getDistributedMetricStats(RULE_TYPE).getOnLeak() > 0; + public boolean hasIssuesOnCurrentAnalysis() { + return getDistributedMetricStats(RULE_TYPE).getOnCurrentAnalysis() > 0; } @Override diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java index 0beecfe0f3e..72d519b5f23 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java @@ -180,7 +180,7 @@ public class NewIssuesNotificationTest { } @Test - public void set_statistics_when_no_issues_created_in_current_analysis() { + public void set_statistics_when_no_issues_created_on_current_analysis() { UserDto maynard = db.users().insertUser(u -> u.setLogin("maynard")); UserDto keenan = db.users().insertUser(u -> u.setLogin("keenan")); ComponentDto project = db.components().insertPrivateProject(); @@ -222,7 +222,7 @@ public class NewIssuesNotificationTest { } @Test - public void set_statistics_when_some_issues_are_no_created_in_current_analysis() { + public void set_statistics_when_some_issues_are_no_created_on_current_analysis() { UserDto maynard = db.users().insertUser(u -> u.setLogin("maynard")); UserDto keenan = db.users().insertUser(u -> u.setLogin("keenan")); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java index e8311de87ad..5d16b3e69c4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java @@ -96,7 +96,7 @@ public class NewIssuesStatisticsTest { } @Test - public void add_counts_issue_per_RuleType_on_leak_globally_and_per_assignee() { + public void add_counts_issue_per_RuleType_on_current_analysis_globally_and_per_assignee() { String assignee = randomAlphanumeric(10); Arrays.stream(RuleType.values()) .map(ruleType -> new DefaultIssue().setType(ruleType).setAssigneeUuid(assignee).setNew(true)) @@ -105,11 +105,11 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE_TYPE); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE_TYPE); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 1, 0, 1))); + .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 1, 1))); } @Test - public void add_counts_issue_per_RuleType_off_leak_globally_and_per_assignee() { + public void add_counts_issue_per_RuleType_off_current_analysis_globally_and_per_assignee() { String assignee = randomAlphanumeric(10); Arrays.stream(RuleType.values()) .map(ruleType -> new DefaultIssue().setType(ruleType).setAssigneeUuid(assignee).setNew(false)) @@ -118,11 +118,11 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE_TYPE); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE_TYPE); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 0, 1, 1))); + .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 0, 1))); } @Test - public void add_counts_issue_per_component_on_leak_globally_and_per_assignee() { + public void add_counts_issue_per_component_on_current_analysis_globally_and_per_assignee() { List componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); componentUuids.stream() @@ -132,11 +132,11 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> componentUuids.forEach(componentUuid -> assertStats(distribution, componentUuid, 1, 0, 1))); + .forEach(distribution -> componentUuids.forEach(componentUuid -> assertStats(distribution, componentUuid, 1, 1))); } @Test - public void add_counts_issue_per_component_off_leak_globally_and_per_assignee() { + public void add_counts_issue_per_component_off_current_analysis_globally_and_per_assignee() { List componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); componentUuids.stream() @@ -147,7 +147,7 @@ public class NewIssuesStatisticsTest { NewIssuesStatistics.Stats stats = underTest.getAssigneesStatistics().get(assignee); DistributedMetricStatsInt assigneeDistribution = stats.getDistributedMetricStats(Metric.COMPONENT); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> componentUuids.forEach(componentUuid -> assertStats(distribution, componentUuid, 0, 1, 1))); + .forEach(distribution -> componentUuids.forEach(componentUuid -> assertStats(distribution, componentUuid, 0, 1))); } @Test @@ -165,7 +165,7 @@ public class NewIssuesStatisticsTest { } @Test - public void add_counts_issue_per_ruleKey_on_leak_globally_and_per_assignee() { + public void add_counts_issue_per_ruleKey_on_current_analysis_globally_and_per_assignee() { String repository = randomAlphanumeric(3); List ruleKeys = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); @@ -177,11 +177,11 @@ public class NewIssuesStatisticsTest { NewIssuesStatistics.Stats stats = underTest.getAssigneesStatistics().get(assignee); DistributedMetricStatsInt assigneeDistribution = stats.getDistributedMetricStats(Metric.RULE); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> ruleKeys.forEach(ruleKey -> assertStats(distribution, RuleKey.of(repository, ruleKey).toString(), 1, 0, 1))); + .forEach(distribution -> ruleKeys.forEach(ruleKey -> assertStats(distribution, RuleKey.of(repository, ruleKey).toString(), 1, 1))); } @Test - public void add_counts_issue_per_ruleKey_off_leak_globally_and_per_assignee() { + public void add_counts_issue_per_ruleKey_off_current_analysis_globally_and_per_assignee() { String repository = randomAlphanumeric(3); List ruleKeys = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); @@ -192,7 +192,7 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> ruleKeys.forEach(ruleKey -> assertStats(distribution, RuleKey.of(repository, ruleKey).toString(), 0, 1, 1))); + .forEach(distribution -> ruleKeys.forEach(ruleKey -> assertStats(distribution, RuleKey.of(repository, ruleKey).toString(), 0, 1))); } @Test @@ -210,25 +210,25 @@ public class NewIssuesStatisticsTest { } @Test - public void add_counts_issue_per_assignee_on_leak_globally_and_per_assignee() { + public void add_counts_issue_per_assignee_on_current_analysis_globally_and_per_assignee() { List assignees = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); assignees.stream() .map(assignee -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setAssigneeUuid(assignee).setNew(true)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE); - assignees.forEach(assignee -> assertStats(globalDistribution, assignee, 1, 0, 1)); + assignees.forEach(assignee -> assertStats(globalDistribution, assignee, 1, 1)); assignees.forEach(assignee -> { NewIssuesStatistics.Stats stats = underTest.getAssigneesStatistics().get(assignee); DistributedMetricStatsInt assigneeStats = stats.getDistributedMetricStats(Metric.ASSIGNEE); - assertThat(assigneeStats.getOnLeak()).isEqualTo(1); + assertThat(assigneeStats.getOnCurrentAnalysis()).isEqualTo(1); assertThat(assigneeStats.getTotal()).isEqualTo(1); assignees.forEach(s -> { Optional forLabelOpts = assigneeStats.getForLabel(s); if (s.equals(assignee)) { assertThat(forLabelOpts.isPresent()).isTrue(); MetricStatsInt forLabel = forLabelOpts.get(); - assertThat(forLabel.getOnLeak()).isEqualTo(1); + assertThat(forLabel.getOnCurrentAnalysis()).isEqualTo(1); assertThat(forLabel.getTotal()).isEqualTo(1); } else { assertThat(forLabelOpts.isPresent()).isFalse(); @@ -238,25 +238,25 @@ public class NewIssuesStatisticsTest { } @Test - public void add_counts_issue_per_assignee_off_leak_globally_and_per_assignee() { + public void add_counts_issue_per_assignee_off_current_analysis_globally_and_per_assignee() { List assignees = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); assignees.stream() .map(assignee -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setAssigneeUuid(assignee).setNew(false)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE); - assignees.forEach(assignee -> assertStats(globalDistribution, assignee, 0, 1, 1)); + assignees.forEach(assignee -> assertStats(globalDistribution, assignee, 0, 1)); assignees.forEach(assignee -> { NewIssuesStatistics.Stats stats = underTest.getAssigneesStatistics().get(assignee); DistributedMetricStatsInt assigneeStats = stats.getDistributedMetricStats(Metric.ASSIGNEE); - assertThat(assigneeStats.getOnLeak()).isEqualTo(0); + assertThat(assigneeStats.getOnCurrentAnalysis()).isEqualTo(0); assertThat(assigneeStats.getTotal()).isEqualTo(1); assignees.forEach(s -> { Optional forLabelOpts = assigneeStats.getForLabel(s); if (s.equals(assignee)) { assertThat(forLabelOpts.isPresent()).isTrue(); MetricStatsInt forLabel = forLabelOpts.get(); - assertThat(forLabel.getOnLeak()).isEqualTo(0); + assertThat(forLabel.getOnCurrentAnalysis()).isEqualTo(0); assertThat(forLabel.getTotal()).isEqualTo(1); } else { assertThat(forLabelOpts.isPresent()).isFalse(); @@ -276,7 +276,7 @@ public class NewIssuesStatisticsTest { } @Test - public void add_counts_issue_per_tags_on_leak_globally_and_per_assignee() { + public void add_counts_issue_per_tags_on_current_analysis_globally_and_per_assignee() { List tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(tags).setAssigneeUuid(assignee).setNew(true)); @@ -284,11 +284,11 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> tags.forEach(tag -> assertStats(distribution, tag, 1, 0, 1))); + .forEach(distribution -> tags.forEach(tag -> assertStats(distribution, tag, 1, 1))); } @Test - public void add_counts_issue_per_tags_off_leak_globally_and_per_assignee() { + public void add_counts_issue_per_tags_off_current_analysis_globally_and_per_assignee() { List tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(tags).setAssigneeUuid(assignee).setNew(false)); @@ -296,7 +296,7 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> tags.forEach(tag -> assertStats(distribution, tag, 0, 1, 1))); + .forEach(distribution -> tags.forEach(tag -> assertStats(distribution, tag, 0, 1))); } @Test @@ -314,7 +314,7 @@ public class NewIssuesStatisticsTest { } @Test - public void add_sums_effort_on_leak_globally_and_per_assignee() { + public void add_sums_effort_on_current_analysis_globally_and_per_assignee() { Random random = new Random(); List efforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10_000 * i).collect(Collectors.toList()); int expected = efforts.stream().mapToInt(s -> s).sum(); @@ -327,14 +327,14 @@ public class NewIssuesStatisticsTest { MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> { - assertThat(distribution.getOnLeak()).isEqualTo(expected); - assertThat(distribution.getOffLeak()).isEqualTo(0); + assertThat(distribution.getOnCurrentAnalysis()).isEqualTo(expected); + assertThat(distribution.getOffCurrentAnalysis()).isEqualTo(0); assertThat(distribution.getTotal()).isEqualTo(expected); }); } @Test - public void add_sums_effort_off_leak_globally_and_per_assignee() { + public void add_sums_effort_off_current_analysis_globally_and_per_assignee() { Random random = new Random(); List efforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10_000 * i).collect(Collectors.toList()); int expected = efforts.stream().mapToInt(s -> s).sum(); @@ -347,8 +347,8 @@ public class NewIssuesStatisticsTest { MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> { - assertThat(distribution.getOnLeak()).isEqualTo(0); - assertThat(distribution.getOffLeak()).isEqualTo(expected); + assertThat(distribution.getOnCurrentAnalysis()).isEqualTo(0); + assertThat(distribution.getOffCurrentAnalysis()).isEqualTo(expected); assertThat(distribution.getTotal()).isEqualTo(expected); }); } @@ -388,29 +388,29 @@ public class NewIssuesStatisticsTest { .isEqualTo("NewIssuesStatistics{" + "assigneesStatistics={" + assignee + "=" + "Stats{distributions={" + - "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + randomRuleTypeExceptHotspot.name() + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + tag + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + componentUuid + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "ASSIGNEE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + assignee + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "RULE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{onLeak=1, offLeak=0}}}}, " + - "effortStats=MetricStatsLong{onLeak=" + effort + ", offLeak=0}}}, " + + "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + randomRuleTypeExceptHotspot.name() + "=MetricStatsInt{on=1, off=0}}}, " + + "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + tag + "=MetricStatsInt{on=1, off=0}}}, " + + "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + componentUuid + "=MetricStatsInt{on=1, off=0}}}, " + + "ASSIGNEE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + assignee + "=MetricStatsInt{on=1, off=0}}}, " + + "RULE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{on=1, off=0}}}}, " + + "effortStats=MetricStatsLong{on=" + effort + ", off=0}}}, " + "globalStatistics=Stats{distributions={" + - "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + randomRuleTypeExceptHotspot.name() + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + tag + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + componentUuid + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "ASSIGNEE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + assignee + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + - "RULE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{onLeak=1, offLeak=0}}}}, " + - "effortStats=MetricStatsLong{onLeak=" + effort + ", offLeak=0}}}"); + "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + randomRuleTypeExceptHotspot.name() + "=MetricStatsInt{on=1, off=0}}}, " + + "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + tag + "=MetricStatsInt{on=1, off=0}}}, " + + "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + componentUuid + "=MetricStatsInt{on=1, off=0}}}, " + + "ASSIGNEE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + assignee + "=MetricStatsInt{on=1, off=0}}}, " + + "RULE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + + "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{on=1, off=0}}}}, " + + "effortStats=MetricStatsLong{on=" + effort + ", off=0}}}"); } @CheckForNull @@ -422,11 +422,11 @@ public class NewIssuesStatisticsTest { .orElse(null); } - private void assertStats(DistributedMetricStatsInt distribution, String label, int onLeak, int offLeak, int total) { + private void assertStats(DistributedMetricStatsInt distribution, String label, int onCurrentAnalysis, int total) { Optional statsOption = distribution.getForLabel(label); assertThat(statsOption.isPresent()).describedAs("distribution for label %s not found", label).isTrue(); MetricStatsInt stats = statsOption.get(); - assertThat(stats.getOnLeak()).isEqualTo(onLeak); + assertThat(stats.getOnCurrentAnalysis()).isEqualTo(onCurrentAnalysis); assertThat(stats.getTotal()).isEqualTo(total); } -- 2.39.5