MetricPublicationArbiter implements Predicate<MetricName> { @Override public boolean test(MetricName metricName) { return Optional.ofNullable(singleMetricFilters.get(metricName)) .map(filters -> allFiltersMatch(metricName, filters)) .orElse(true); } @VisibleForTesting  MetricPublicationArbiter(Map<MetricName, Set<DeduplicatingFilterHolder>> singleMetricFilters); static MetricPublicationArbiter create(); @Override boolean test(MetricName metricName); void registerMetricsFilter(MetricName metricName, MetricPublicationFilter filter);  }
@Test public void exceptionTreatedAsNotFiltered() { MetricPublicationArbiter arbiter = createArbiter(ImmutableMap.of( METRIC_NAME_1, ImmutableSet.of(THROWING_FILTER))); assertThat(arbiter.test(METRIC_NAME_1)).isTrue(); }
@Test public void rejectsMetricWithDefinitivelyFalseFilterEvenWithExceptions() { MetricPublicationArbiter arbiter = createArbiter(ImmutableMap.of( METRIC_NAME_1, ImmutableSet.of(THROWING_FILTER, TRUE_RETURNING_FILTER, FALSE_RETURNING_FILTER))); assertThat(arbiter.test(METRIC_NAME_1)).isFalse(); }
@Test public void metricsWithNoFilterAreAccepted() { MetricPublicationArbiter arbiter = new MetricPublicationArbiter(ImmutableMap.of()); assertThat(arbiter.test(METRIC_NAME_1)).isTrue(); assertThat(arbiter.test(METRIC_NAME_2)).isTrue(); }
@Test public void metricsWithOneFilterAreFiltered() { MetricPublicationArbiter arbiter = createArbiter(ImmutableMap.of( METRIC_NAME_1, ImmutableSet.of(FALSE_RETURNING_FILTER), METRIC_NAME_2, ImmutableSet.of(TRUE_RETURNING_FILTER))); assertThat(arbiter.test(METRIC_NAME_1)).isFalse(); assertThat(arbiter.test(METRIC_NAME_2)).isTrue(); }
@Test public void metricsWithMultipleFiltersAreAcceptedOnlyIfAllFiltersPermit() { MetricPublicationArbiter arbiter = createArbiter(ImmutableMap.of( METRIC_NAME_1, ImmutableSet.of(TRUE_RETURNING_FILTER, FALSE_RETURNING_FILTER, TRUE_RETURNING_FILTER), METRIC_NAME_2, ImmutableSet.of(TRUE_RETURNING_FILTER, TRUE_RETURNING_FILTER, TRUE_RETURNING_FILTER))); assertThat(arbiter.test(METRIC_NAME_1)).isFalse(); assertThat(arbiter.test(METRIC_NAME_2)).isTrue(); }