@Override public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { return autoDelegate.getAll(keys); }
@Override public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { return autoDelegate.getAll(keys); }
@Override public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { return delegate().getAll(keys); }
@Override public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { return delegate().getAll(keys); }
private static <K, V> Map<K, V> getAll(LoadingCache<K, V> cache, Iterable<K> keys) { try { return cache.getAll(keys); } catch (ExecutionException | UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throwIfUnchecked(e); throw new UncheckedExecutionException(e); } }
public void testBulkLoad_partial() throws ExecutionException { final Object extraKey = new Object(); final Object extraValue = new Object(); CacheLoader<Object, Object> loader = new CacheLoader<Object, Object>() { @Override public Object load(Object key) throws Exception { throw new AssertionError(); } @Override public Map<Object, Object> loadAll(Iterable<?> keys) throws Exception { Map<Object, Object> result = Maps.newHashMap(); // ignore request keys result.put(extraKey, extraValue); return result; } }; LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().build(loader); Object[] lookupKeys = new Object[] {new Object(), new Object(), new Object()}; try { cache.getAll(asList(lookupKeys)); fail(); } catch (InvalidCacheLoadException expected) { } assertSame(extraValue, cache.asMap().get(extraKey)); }
Map<Object, Object> result = cache.getAll(asList(lookupKeys)); assertThat(result.keySet()).containsExactlyElementsIn(asList(lookupKeys)); for (Entry<Object, Object> entry : result.entrySet()) {
Map<Object, Object> result = cache.getAll(asList(lookupKeys)); assertThat(result.keySet()).containsExactlyElementsIn(asList(lookupKeys)); for (Entry<Object, Object> entry : result.entrySet()) {
cache.getAll(asList(lookupKeys)); fail(); } catch (InvalidCacheLoadException expected) {
public void testLoadingCache() throws ExecutionException { CacheLoader<Integer, Integer> loader = new CacheLoader<Integer, Integer>() { int i = 0; @Override public Integer load(Integer key) throws Exception { return i++; } }; LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().build(loader); cache.put(10, 20); Map<Integer, Integer> map = cache.getAll(ImmutableList.of(10, 20, 30, 54, 443, 1)); assertEquals(Integer.valueOf(20), map.get(10)); assertEquals(Integer.valueOf(0), map.get(20)); assertEquals(Integer.valueOf(1), map.get(30)); assertEquals(Integer.valueOf(2), map.get(54)); assertEquals(Integer.valueOf(3), map.get(443)); assertEquals(Integer.valueOf(4), map.get(1)); assertEquals(Integer.valueOf(5), cache.get(6)); assertEquals(Integer.valueOf(6), cache.apply(7)); }
cache.getAll(asList(lookupKeys)); fail(); } catch (InvalidCacheLoadException expected) {
public void testBulkLoadingExceptionWithCause() { final Exception cause = new Exception(); final UncheckedExecutionException uee = new UncheckedExecutionException(cause); final ExecutionException ee = new ExecutionException(cause); LoadingCache<Object, Object> cacheUnchecked = CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(uee))); LoadingCache<Object, Object> cacheChecked = CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(ee))); try { cacheUnchecked.getAll(asList(new Object())); fail(); } catch (ExecutionException e) { fail(); } catch (UncheckedExecutionException caughtEe) { assertThat(caughtEe).hasCauseThat().isSameAs(uee); } try { cacheChecked.getAll(asList(new Object())); fail(); } catch (ExecutionException caughtEe) { assertThat(caughtEe).hasCauseThat().isSameAs(ee); } }
public void testBulkLoadInterruptedException() { Exception e = new InterruptedException(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } assertTrue(currentThread().interrupted()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadCheckedException() { Exception e = new Exception(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadUncheckedException() throws ExecutionException { Exception e = new RuntimeException(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (UncheckedExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadError() throws ExecutionException { Error e = new Error(); CacheLoader<Object, Object> loader = errorLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionError expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
assertEquals(0, stats.hitCount()); assertEquals(ImmutableMap.of(), cache.getAll(ImmutableList.<Integer>of())); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.hitCount()); assertEquals(ImmutableMap.of(1, 1), cache.getAll(asList(1))); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.hitCount()); assertEquals(ImmutableMap.of(1, 1, 2, 2, 3, 3, 4, 4), cache.getAll(asList(1, 2, 3, 4))); stats = cache.stats(); assertEquals(4, stats.missCount()); assertEquals(1, stats.hitCount()); assertEquals(ImmutableMap.of(2, 2, 3, 3), cache.getAll(asList(2, 3))); stats = cache.stats(); assertEquals(4, stats.missCount()); assertEquals(ImmutableMap.of(4, 4, 5, 5), cache.getAll(asList(4, 5))); stats = cache.stats(); assertEquals(5, stats.missCount());
public void testBulkLoadNull() throws ExecutionException { LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(constantLoader(null))); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (InvalidCacheLoadException expected) { } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
cache.getAll(asList(new Object())); fail(); } catch (InvalidCacheLoadException expected) {