Java Code Examples for org.cache2k.Cache#prefetchAll()
The following examples show how to use
org.cache2k.Cache#prefetchAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void testSeparateLoaderExecutor() { final AtomicInteger executionCount = new AtomicInteger(0); Cache<Integer,Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() { @Override public void extend(final Cache2kBuilder<Integer, Integer> b) { b.loader(new CacheLoader<Integer, Integer>() { @Override public Integer load(final Integer key) throws Exception { return key * 2; } }); b.loaderExecutor(new Executor() { @Override public void execute(final Runnable command) { executionCount.incrementAndGet(); getLoaderExecutor().execute(command); } }); } }); assertEquals((Integer) 10, c.get(5)); assertEquals((Integer) 20, c.get(10)); assertEquals(0, executionCount.get()); CompletionWaiter waiter = new CompletionWaiter(); c.loadAll(toIterable(1, 2, 3), waiter); waiter.awaitCompletion(); assertEquals("executor is used", 3, executionCount.get()); waiter = new CompletionWaiter(); c.prefetchAll(toIterable(6, 7, 8), waiter); waiter.awaitCompletion(); assertEquals("prefetch uses executor, too", 6, executionCount.get()); }
Example 2
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetchAll() { final Cache<Integer,Integer> c = cacheWithLoader(); c.prefetchAll(toIterable(1,2,3), null); assertTrue(isLoadStarted(c)); await(new Condition() { @Override public boolean check() throws Exception { return c.containsKey(1); } }); }
Example 3
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetch_noLoader_listener() { Cache<Integer,Integer> c = target.cache(); CompletionWaiter w = new CompletionWaiter(); c.prefetchAll(toIterable(1), w); w.awaitCompletion(); }
Example 4
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetch_listener() { final Cache<Integer,Integer> c = cacheWithLoader(); CompletionWaiter w = new CompletionWaiter(); c.prefetchAll(toIterable(1), w); assertTrue(isLoadStarted(c)); w.awaitCompletion(); assertTrue(c.containsKey(1)); }
Example 5
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetch_present_listener() { final Cache<Integer,Integer> c = cacheWithLoader(); CompletionWaiter w = new CompletionWaiter(); c.put(1, 1); c.prefetchAll(toIterable(1), w); w.awaitCompletion(); assertTrue(c.containsKey(1)); assertTrue(latestInfo(c).getAsyncLoadsStarted() == 0); }
Example 6
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetchAll_noLoader_listener() { Cache<Integer,Integer> c = target.cache(); CompletionWaiter w = new CompletionWaiter(); c.prefetchAll(toIterable(1), w); w.awaitCompletion(); }
Example 7
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetchAll_listener() { final Cache<Integer,Integer> c = cacheWithLoader(); CompletionWaiter w = new CompletionWaiter(); c.prefetchAll(toIterable(1), w); assertTrue(isLoadStarted(c)); w.awaitCompletion(); assertTrue(c.containsKey(1)); }
Example 8
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetchAll_present_listener() { final Cache<Integer,Integer> c = cacheWithLoader(); CompletionWaiter w = new CompletionWaiter(); c.put(1, 1); c.prefetchAll(toIterable(1), w); w.awaitCompletion(); assertTrue(c.containsKey(1)); assertTrue(latestInfo(c).getAsyncLoadsStarted() == 0); }
Example 9
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void prefetchAll_partiallyPresent_listener() { final Cache<Integer,Integer> c = cacheWithLoader(); CompletionWaiter w = new CompletionWaiter(); c.put(1, 1); c.put(2, 2); c.prefetchAll(toIterable(1, 2, 3, 4), w); assertTrue(isLoadStarted(c)); w.awaitCompletion(); assertTrue(c.containsKey(3)); assertThat("expect 2 started loads, since 1 is in the cache", latestInfo(c).getAsyncLoadsStarted(), allOf(greaterThanOrEqualTo(2L), lessThanOrEqualTo(3L))); }
Example 10
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void testNoPrefetchAll() { Cache<Integer,Integer> c = cacheWithLoader(); c.put(1,1); c.put(2,2); c.put(3,3); c.prefetchAll(toIterable(1,2,3), null); assertTrue(latestInfo(c).getAsyncLoadsStarted() == 0); }
Example 11
Source File: CacheLoaderTest.java From cache2k with Apache License 2.0 | 4 votes |
@Test public void prefetch_noLoader() { Cache<Integer,Integer> c = target.cache(); c.prefetchAll(toIterable(1,2,3), null); assertEquals(0, latestInfo(c).getAsyncLoadsStarted()); }