SweepOutcomeMetrics { public void registerOccurrenceOf(SweepOutcome outcome) { if (outcome == SweepOutcome.FATAL) { metrics.get().fatal().set(true); return; } metrics.get().reservoir().update(outcome.ordinal()); } private  SweepOutcomeMetrics(Supplier<Metrics> metrics); static SweepOutcomeMetrics registerLegacy(MetricsManager metricsManager); static SweepOutcomeMetrics registerTargeted(
            MetricsManager metricsManager,
            Map<String, String> strategyTag,
            MetricPublicationFilter filter); void registerOccurrenceOf(SweepOutcome outcome); static final List<SweepOutcome> LEGACY_OUTCOMES; static final List<SweepOutcome> TARGETED_OUTCOMES; }
@Test public void testAllOutcomes() { SweepOutcomeMetrics.LEGACY_OUTCOMES.forEach(outcome -> { legacyMetrics.registerOccurrenceOf(outcome); assertThat(metricsManager).hasLegacyOutcomeEqualTo(outcome, 1L); }); SweepOutcomeMetrics.TARGETED_OUTCOMES.forEach(outcome -> { targetedSweepMetrics.registerOccurrenceOf(ShardAndStrategy.conservative(3), outcome); assertThat(metricsManager).hasTargetedOutcomeEqualTo(CONSERVATIVE, outcome, 1L); targetedSweepMetrics.registerOccurrenceOf(ShardAndStrategy.thorough(1), outcome); assertThat(metricsManager).hasTargetedOutcomeEqualTo(CONSERVATIVE, outcome, 1L); assertThat(metricsManager).hasTargetedOutcomeEqualTo(THOROUGH, outcome, 1L); }); }
@Test public void testFatalIsBinary() { SweepOutcomeMetrics.LEGACY_OUTCOMES.forEach(outcome -> IntStream.range(0, 10).forEach(ignore -> legacyMetrics.registerOccurrenceOf(outcome))); assertThat(metricsManager).hasLegacyOutcomeEqualTo(SweepOutcome.FATAL, 1L); }
@Test public void testOtherMetricsAreCumulative() { SweepOutcomeMetrics.LEGACY_OUTCOMES.forEach(outcome -> IntStream.range(0, 10).forEach(ignore -> legacyMetrics.registerOccurrenceOf(outcome))); SweepOutcomeMetrics.LEGACY_OUTCOMES.stream() .filter(outcome -> outcome != SweepOutcome.FATAL) .forEach(outcome -> assertThat(metricsManager).hasLegacyOutcomeEqualTo(outcome, 10L)); }
@Test public void testTargetedSweepMetricsAreCumulative() { SweepOutcomeMetrics.TARGETED_OUTCOMES.forEach(outcome -> IntStream.range(0, 10).forEach(ignore -> legacyMetrics.registerOccurrenceOf(outcome))); SweepOutcomeMetrics.TARGETED_OUTCOMES .forEach(outcome -> assertThat(metricsManager).hasLegacyOutcomeEqualTo(outcome, 10L)); }
@Test public void targetedSweepDoesNotRegisterExcludedOutcomes() { targetedSweepMetrics.registerOccurrenceOf(CONSERVATIVE, SweepOutcome.SUCCESS); targetedSweepMetrics.registerOccurrenceOf(THOROUGH, SweepOutcome.SUCCESS); Arrays.stream(SweepOutcome.values()) .filter(outcome -> !SweepOutcomeMetrics.TARGETED_OUTCOMES.contains(outcome)) .forEach(outcome -> assertThat(metricsManager).hasNotRegisteredTargetedOutcome(CONSERVATIVE, outcome)); Arrays.stream(SweepOutcome.values()) .filter(outcome -> !SweepOutcomeMetrics.TARGETED_OUTCOMES.contains(outcome)) .forEach(outcome -> assertThat(metricsManager).hasNotRegisteredTargetedOutcome(THOROUGH, outcome)); }