@Test public void populate() { Object object = new Object(); List<CacheEntry<Object, Object>> entries = new ArrayList<CacheEntry<Object, Object>>(); entries.add(entry); doReturn(object).when(entry).getKey(); doReturn(object).when(entry).getValue(); doReturn(entries).when(populator).loadEntries(); doNothing().when(cache).put(object, object); populator.pupulate(); try { Thread.sleep(10); } catch (InterruptedException e) { } verify(cache, atLeast(1)).put(object, object); verify(populator).loadEntries(); }
public void pupulate() { final ExecutorService lazyExecuor = Executors.newSingleThreadExecutor(runnable -> ThreadUtils .createDaemonThread(runnable, "imcache:cachePopulator(name=" + cache.getName() + ",thread=0)")); lazyExecuor.execute(() -> { final List<CacheEntry<K, V>> entries = loadEntries(); for (CacheEntry<K, V> cacheEntry : entries) { cache.put(cacheEntry.getKey(), cacheEntry.getValue()); } }); lazyExecuor.shutdown(); }
LazyCachePopulator extends AbstractCachePopulator<K, V> { public void pupulate() { final ExecutorService lazyExecuor = Executors.newSingleThreadExecutor(runnable -> ThreadUtils .createDaemonThread(runnable, "imcache:cachePopulator(name=" + cache.getName() + ",thread=0)")); lazyExecuor.execute(() -> { final List<CacheEntry<K, V>> entries = loadEntries(); for (CacheEntry<K, V> cacheEntry : entries) { cache.put(cacheEntry.getKey(), cacheEntry.getValue()); } }); lazyExecuor.shutdown(); } }
LazyCachePopulator extends AbstractCachePopulator<K, V> { public void pupulate() { final ExecutorService lazyExecuor = Executors.newSingleThreadExecutor(runnable -> ThreadUtils .createDaemonThread(runnable, "imcache:cachePopulator(name=" + cache.getName() + ",thread=0)")); lazyExecuor.execute(() -> { final List<CacheEntry<K, V>> entries = loadEntries(); for (CacheEntry<K, V> cacheEntry : entries) { cache.put(cacheEntry.getKey(), cacheEntry.getValue()); } }); lazyExecuor.shutdown(); } LazyCachePopulator(Cache<K, V> cache); }
LazyCachePopulator extends AbstractCachePopulator<K, V> { public void pupulate() { final ExecutorService lazyExecuor = Executors.newSingleThreadExecutor(runnable -> ThreadUtils .createDaemonThread(runnable, "imcache:cachePopulator(name=" + cache.getName() + ",thread=0)")); lazyExecuor.execute(() -> { final List<CacheEntry<K, V>> entries = loadEntries(); for (CacheEntry<K, V> cacheEntry : entries) { cache.put(cacheEntry.getKey(), cacheEntry.getValue()); } }); lazyExecuor.shutdown(); } LazyCachePopulator(Cache<K, V> cache); void pupulate(); }
LazyCachePopulator extends AbstractCachePopulator<K, V> { public void pupulate() { final ExecutorService lazyExecuor = Executors.newSingleThreadExecutor(runnable -> ThreadUtils .createDaemonThread(runnable, "imcache:cachePopulator(name=" + cache.getName() + ",thread=0)")); lazyExecuor.execute(() -> { final List<CacheEntry<K, V>> entries = loadEntries(); for (CacheEntry<K, V> cacheEntry : entries) { cache.put(cacheEntry.getKey(), cacheEntry.getValue()); } }); lazyExecuor.shutdown(); } LazyCachePopulator(Cache<K, V> cache); void pupulate();  }