TargetedSweepMetricPublicationFilter implements MetricPublicationFilter { @Override public boolean shouldPublish() { if (publicationLatch.get()) { return true; } boolean conditionsAchieved = testConditions(); if (conditionsAchieved) { publicationLatch.set(true); } return conditionsAchieved; } TargetedSweepMetricPublicationFilter(DecisionMetrics decisionMetrics); @Override boolean shouldPublish();  }
@Test public void shouldNotInitiallyBePublished() { assertThat(filter.shouldPublish()).isFalse(); }
@Test public void shouldNotBePublishedAfterSmallSweep() { entriesRead.addAndGet(10); enqueuedWrites.incrementAndGet(); millisSinceLastSweptTs.set(Duration.ofMinutes(1).toMillis()); assertThat(filter.shouldPublish()).isFalse(); }
@Test public void shouldBePublishedAfterReadingManyValues() { entriesRead.addAndGet(TargetedSweepMetricPublicationFilter.MINIMUM_READS_WRITES_TO_BE_CONSIDERED_ACTIVE); assertThat(filter.shouldPublish()).isTrue(); }
@Test public void shouldBePublishedAfterWritingManyValues() { enqueuedWrites.addAndGet(TargetedSweepMetricPublicationFilter.MINIMUM_READS_WRITES_TO_BE_CONSIDERED_ACTIVE); assertThat(filter.shouldPublish()).isTrue(); }
@Test public void shouldBePublishedIfFarBehind() { millisSinceLastSweptTs.set(TargetedSweepMetricPublicationFilter.MINIMUM_STALE_DURATION.toMillis()); assertThat(filter.shouldPublish()).isTrue(); }
@Test public void continueToBePublishedIfWeCatchUp() { millisSinceLastSweptTs.set(TargetedSweepMetricPublicationFilter.MINIMUM_STALE_DURATION.toMillis()); assertThat(filter.shouldPublish()).isTrue(); millisSinceLastSweptTs.set(1); assertThat(filter.shouldPublish()).isTrue(); }