PersistentFiltersJob implements Runnable { @Override public void run() { synchronized (filterUpdateTimesCounter) { final long sum = filterUpdateTimesCounter.sum(); if (sum > criteria.updatesThreshold()) { if (logger.isDebugEnabled()) { logger.debug("Updated {} times in last {} seconds meets threshold {} to persistence filters", sum, criteria.checkingPeriod().getSeconds(), criteria.updatesThreshold()); } filterUpdateTimesCounter.reset(); doPersistence(); } } } PersistentFiltersJob(BloomFilterManager<F, ?> bloomFilterManager,
                         PersistentManager<F> persistentManager,
                         LongAdder filterUpdateTimesCounter,
                         TriggerPersistenceCriteria criteria); @Override void run();  }
@Test public void testCriteriaNotMeet() throws IOException { filterUpdateTimesCounter.reset(); filterUpdateTimesCounter.add(5); job.run(); assertThat(filterUpdateTimesCounter.sum()).isEqualTo(5); verify(persistentManager, never()).freezeAllFilters(bloomFilterManager); }
@Test public void testPersistentWhenCriteriaMeet() throws IOException { filterUpdateTimesCounter.add(100); job.run(); assertThat(filterUpdateTimesCounter.sum()).isZero(); verify(persistentManager, times(1)).freezeAllFilters(bloomFilterManager); }
@Test public void testPersistentThrowsException() throws IOException { final Exception exception = new IOException("expected exception"); doThrow(exception).when(persistentManager).freezeAllFilters(bloomFilterManager); filterUpdateTimesCounter.add(100); job.run(); assertThat(filterUpdateTimesCounter.sum()).isZero(); verify(persistentManager, times(1)).freezeAllFilters(bloomFilterManager); }
@Test public void testPersistentThrowsError() throws IOException { final Error error = new Error("expected error"); doThrow(error).when(persistentManager).freezeAllFilters(bloomFilterManager); filterUpdateTimesCounter.add(100); assertThatThrownBy(() -> job.run()).isSameAs(error); assertThat(filterUpdateTimesCounter.sum()).isZero(); verify(persistentManager, times(1)).freezeAllFilters(bloomFilterManager); }