TopNMetricPublicationController { public MetricPublicationFilter registerAndCreateFilter(Gauge<T> gauge) { gauges.add(gauge); return () -> shouldPublishIndividualGaugeMetric(gauge); } @VisibleForTesting  TopNMetricPublicationController(
            Comparator<T> comparator,
            int maxPermittedRank,
            Duration refreshInterval); @SuppressWarnings("unchecked") // Guaranteed correct static TopNMetricPublicationController<T> create(int maxPermittedRank); MetricPublicationFilter registerAndCreateFilter(Gauge<T> gauge);  }
@Test public void eligibleGaugesChangeOverTime() { AtomicLong value1 = new AtomicLong(42); AtomicLong value2 = new AtomicLong(157); Gauge<Long> gauge1 = value1::get; Gauge<Long> gauge2 = value2::get; TopNMetricPublicationController<Long> controller = new TopNMetricPublicationController<>( Comparator.<Long>naturalOrder(), 1, Duration.ofNanos(1)); MetricPublicationFilter filter1 = controller.registerAndCreateFilter(gauge1); MetricPublicationFilter filter2 = controller.registerAndCreateFilter(gauge2); assertThat(filter1.shouldPublish()).isFalse(); assertThat(filter2.shouldPublish()).isTrue(); value1.set(8888); assertThat(filter1.shouldPublish()).isTrue(); assertThat(filter2.shouldPublish()).isFalse(); }