RefreshOnReadPolicy implements ReaderRefreshPolicy, IndexUpdateListener { @Override public void refreshOnWriteIfRequired(Runnable refreshCallback) { long currentTime = clock.getTime(); if (currentTime - lastRefreshTime > refreshDelta) { refreshWithLock(refreshCallback, true); } else { synchronized (lock){ dirty.set(true); } } } RefreshOnReadPolicy(Clock clock, TimeUnit unit, long refreshDelta); @Override void refreshOnReadIfRequired(Runnable refreshCallback); @Override void refreshOnWriteIfRequired(Runnable refreshCallback); @Override void updated();  }
@Test public void refreshOnFirstWrite() throws Exception{ clock.waitUntil(System.currentTimeMillis()); policy.refreshOnWriteIfRequired(refreshCallback); refreshCallback.assertInvokedAndReset(); }
@Test public void refreshOnWriteWithTimeElapsed() throws Exception{ clock.waitUntil(System.currentTimeMillis()); policy.refreshOnWriteIfRequired(refreshCallback); refreshCallback.reset(); policy.refreshOnWriteIfRequired(refreshCallback); refreshCallback.assertNotInvokedAndReset(); clock.waitUntil(clock.getTime() + refreshDelta); policy.refreshOnWriteIfRequired(refreshCallback); refreshCallback.assertInvokedAndReset(); }