]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12423 fix misleading naming in notification stat classes
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 27 Aug 2019 15:35:14 +0000 (17:35 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 30 Aug 2019 18:21:02 +0000 (20:21 +0200)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/DistributedMetricStatsInt.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsInt.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/MetricStatsLong.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java

index 8393918369b617551fd8fe344fe2f2ea5dba53e6..31b5d3369d4f8bf0de7d471ea87506ce716c7d31 100644 (file)
@@ -80,8 +80,6 @@ public class SendIssueNotificationsStep implements ComputationStep {
   private final NotificationFactory notificationFactory;
   private final DbClient dbClient;
 
-  private Map<String, Component> 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<DefaultIssue> isOnLeakPredicate = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate);
-    NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(isOnLeakPredicate);
+    Predicate<DefaultIssue> onCurrentAnalysis = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate);
+    NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(onCurrentAnalysis);
     Map<String, UserDto> assigneesByUuid;
     try (DbSession dbSession = dbClient.openSession(false)) {
       Iterable<DefaultIssue> iterable = issueCache::traverse;
@@ -122,7 +120,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
     try (CloseableIterator<DefaultIssue> 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<String, UserDto> userDtoByUuid = loadUserDtoByUuid(statistics);
     Set<MyNewIssuesNotification> 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<String, UserDto> loadUserDtoByUuid(NewIssuesStatistics statistics) {
     List<Map.Entry<String, NewIssuesStatistics.Stats>> entriesWithIssuesOnLeak = statistics.getAssigneesStatistics().entrySet()
-      .stream().filter(e -> e.getValue().hasIssuesOnLeak()).collect(toList());
+      .stream().filter(e -> e.getValue().hasIssuesOnCurrentAnalysis()).collect(toList());
     List<String> 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));
index 6d077e53d34c3e7e75d5ca5ba4bc65129834e580..0f294755fd5792ad74489ff0625f8036194559ba 100644 (file)
@@ -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);
index 41f03de3f28f478201d8a0586808f112abd1f9cd..754850b89c97abb1d3b0c38d7a2da8803f7c0c51 100644 (file)
@@ -28,9 +28,9 @@ public class DistributedMetricStatsInt {
   private MetricStatsInt globalStats = new MetricStatsInt();
   private Map<String, MetricStatsInt> 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() {
index 6d4e5d231e6f82ac15c89a6c3d36b8e3c6524a30..2f9c9ca479bf5968a0ce93d277a8d31e74dd83ad 100644 (file)
 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 +
       '}';
   }
 }
index d47ce1d2398dbf0add7d29f7dcda747bdeed4bbd..ff3b4e6f7a85c73164743639b3c0a7fc58e4d9a4 100644 (file)
 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 +
       '}';
   }
 }
index aac875a40f5ab1c3878c17d5f2e9751385078e3b..36b023e6c9a12d55bf21a8c7921f835b2ef63c6e 100644 (file)
@@ -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<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak);
+    List<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis);
     int i = 1;
     for (Map.Entry<String, MetricStatsInt> 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<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak);
+    List<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis);
     for (Map.Entry<String, MetricStatsInt> 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<String, MetricStatsInt> tagStats : fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak)) {
-      setFieldValue(metric + DOT + i + COUNT, String.valueOf(tagStats.getValue().getOnLeak()));
+    for (Map.Entry<String, MetricStatsInt> 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<Map.Entry<String, MetricStatsInt>> entries = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak);
+    List<Map.Entry<String, MetricStatsInt>> entries = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnCurrentAnalysis);
 
     int i = 1;
     for (Map.Entry<String, MetricStatsInt> 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
index 060da6e483a6a72b2af46a8a4fc69aad980c0098..ddad91d5e40e21e2ea6fc3fe0f06d334cacf2e6d 100644 (file)
@@ -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<DefaultIssue> onLeakPredicate;
+  private final Predicate<DefaultIssue> onCurrentAnalysisPredicate;
   private final Map<String, Stats> assigneesStatistics = new LinkedHashMap<>();
   private final Stats globalStatistics;
 
-  public NewIssuesStatistics(Predicate<DefaultIssue> onLeakPredicate) {
-    this.onLeakPredicate = onLeakPredicate;
-    this.globalStatistics = new Stats(onLeakPredicate);
+  public NewIssuesStatistics(Predicate<DefaultIssue> 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<DefaultIssue> onLeakPredicate;
+    private final Predicate<DefaultIssue> onCurrentAnalysisPredicate;
     private final Map<Metric, DistributedMetricStatsInt> distributions = new EnumMap<>(Metric.class);
     private MetricStatsLong effortStats = new MetricStatsLong();
 
-    public Stats(Predicate<DefaultIssue> onLeakPredicate) {
-      this.onLeakPredicate = onLeakPredicate;
+    public Stats(Predicate<DefaultIssue> 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
index 0beecfe0f3e5131da7fe2d4d7cf2f5d556d32c3e..72d519b5f23b47be3a1b10fd21df00135f31bf4a 100644 (file)
@@ -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"));
index e8311de87ada1fa42a5834b1355aa1b4f5edbada..5d16b3e69c46d7eab21237082f70b7877610c850 100644 (file)
@@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<MetricStatsInt> 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<String> 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<MetricStatsInt> 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<String> 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<String> 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<Integer> 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<Integer> 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<MetricStatsInt> 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);
   }