InvalidBloomFilterPurgatory implements Purgatory { @Override public void purge() { for (FilterRecord<F> holder : manager) { final F filter = holder.filter(); if (!filter.valid()) { final String name = holder.name(); manager.remove(name, filter); } } } InvalidBloomFilterPurgatory(BloomFilterManager<F, ?> manager); @Override void purge();  }
@Test public void testPurge() { final ExpirableBloomFilterConfig config = new ExpirableBloomFilterConfig(); final ZonedDateTime creationTime = ZonedDateTime.now(ZoneOffset.UTC).minus(Duration.ofSeconds(10)); final ZonedDateTime expirationTime = creationTime.plusSeconds(5); final GuavaBloomFilterFactory mockedFactory = Mockito.mock(GuavaBloomFilterFactory.class); Mockito.when(mockedFactory.createFilter(config)) .thenReturn(new GuavaBloomFilter( Configuration.defaultExpectedInsertions(), Configuration.defaultFalsePositiveProbability(), creationTime, expirationTime, null)); final BloomFilterManagerImpl<GuavaBloomFilter, ExpirableBloomFilterConfig> manager = new BloomFilterManagerImpl<>(mockedFactory); final GuavaBloomFilter filter = manager.createFilter(testingFilterName, config).getFilter(); final InvalidBloomFilterPurgatory<GuavaBloomFilter> purgatory = new InvalidBloomFilterPurgatory<>(manager); assertThat(filter.expired()).isTrue(); assertThat(manager.getFilter(testingFilterName)).isSameAs(filter); purgatory.purge(); assertThat(manager.getFilter(testingFilterName)).isNull(); }