diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java index 04347d4614..0c63293071 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java @@ -165,9 +165,9 @@ default void notifyOnReplace(K key, V oldValue, V newValue) { long startTime = statsTicker().read(); try { value = mappingFunction.apply(key); - } catch (RuntimeException | Error e) { + } catch (Throwable t) { statsCounter().recordLoadFailure(statsTicker().read() - startTime); - throw e; + throw t; } long loadTime = statsTicker().read() - startTime; if (recordLoad) { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java index c88bb28693..03a13b4941 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java @@ -2752,7 +2752,7 @@ public void entrySet_removeAll_bySet(Map map, CacheContext context) { @CheckNoStats @Test(dataProvider = "caches") public void entrySet_remove_null(Map map, CacheContext context) { - assertThat(map.values().remove(null)).isFalse(); + assertThat(map.entrySet().remove(null)).isFalse(); assertThat(map).isEqualTo(context.original()); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java index b423c5ac1d..d3f0776323 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java @@ -2507,7 +2507,7 @@ public void entrySet_removeAll_bySet(AsyncCache cache, CacheContext co @CheckNoStats @Test(dataProvider = "caches") public void entrySet_remove_null(AsyncCache cache, CacheContext context) { - assertThat(cache.asMap().values().remove(null)).isFalse(); + assertThat(cache.asMap().entrySet().remove(null)).isFalse(); assertThat(cache.synchronous().asMap()).isEqualTo(context.original()); } @@ -2586,7 +2586,6 @@ public void entrySet_removeIf_partial(AsyncCache cache, CacheContext c Predicate>> isEven = entry -> (entry.getValue().join().intValue() % 2) == 0; boolean hasEven = cache.asMap().entrySet().stream().anyMatch(isEven); - boolean removedIfEven = cache.asMap().entrySet().removeIf(isEven); assertThat(cache.asMap().entrySet().stream().anyMatch(isEven)).isFalse(); assertThat(removedIfEven).isEqualTo(hasEven); @@ -2610,21 +2609,6 @@ public void entrySet_removeIf_all(AsyncCache cache, CacheContext conte } } - @CacheSpec - @CheckNoStats - @Test(dataProvider = "caches") - public void entrySet_removeIf(AsyncCache cache, CacheContext context) { - Predicate>> isEven = - entry -> (entry.getValue().join().intValue() % 2) == 0; - boolean hasEven = cache.asMap().entrySet().stream().anyMatch(isEven); - boolean removedIfEven = cache.asMap().entrySet().removeIf(isEven); - assertThat(cache.asMap().entrySet().stream().anyMatch(isEven)).isFalse(); - assertThat(removedIfEven).isEqualTo(hasEven); - if (removedIfEven) { - assertThat(cache).hasSizeLessThan(context.initialSize()); - } - } - @CacheSpec @CheckNoStats @Test(dataProvider = "caches") diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncCacheTest.java index 3098629344..908b1b6157 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncCacheTest.java @@ -36,6 +36,7 @@ import static org.mockito.Mockito.verify; import static org.slf4j.event.Level.WARN; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -262,7 +263,16 @@ public void getBiFunc_nullKeyAndLoader(AsyncCache cache, CacheContext @CacheSpec @Test(dataProvider = "caches") - public void getBiFunc_throwsException(AsyncCache cache, CacheContext context) { + public void getBiFunc_throwsCheckedException(AsyncCache cache, CacheContext context) { + assertThrows(IOException.class, () -> cache.get(context.absentKey(), + (key, executor) -> { throw uncheckedThrow(new IOException()); })); + assertThat(context).stats().hits(0).misses(1).success(0).failures(1); + assertThat(cache).doesNotContainKey(context.absentKey()); + } + + @CacheSpec + @Test(dataProvider = "caches") + public void getBiFunc_throwsRuntimeException(AsyncCache cache, CacheContext context) { assertThrows(IllegalStateException.class, () -> cache.get(context.absentKey(), (key, executor) -> { throw new IllegalStateException(); })); assertThat(context).stats().hits(0).misses(1).success(0).failures(1); @@ -751,7 +761,22 @@ public void getAllBifunction_absent_failure(AsyncCache cache, CacheCon @CacheSpec @Test(dataProvider = "caches") - public void getAllBifunction_absent_throwsException( + public void getAllBifunction_absent_throwsCheckedException( + AsyncCache cache, CacheContext context) { + var error = assertThrows(CompletionException.class, () -> { + cache.getAll(context.absentKeys(), + (keys, executor) -> { throw uncheckedThrow(new IOException()); }); + }); + assertThat(error).hasCauseThat().isInstanceOf(IOException.class); + + int misses = context.absentKeys().size(); + assertThat(context).stats().hits(0).misses(misses).success(0).failures(1); + assertThat(cache).doesNotContainKey(context.absentKey()); + } + + @CacheSpec + @Test(dataProvider = "caches") + public void getAllBifunction_absent_throwsRuntimeException( AsyncCache cache, CacheContext context) { assertThrows(IllegalStateException.class, () -> { cache.getAll(context.absentKeys(), @@ -1151,6 +1176,11 @@ public void serialize(AsyncCache cache, CacheContext context) { assertThat(cache).isReserialize(); } + @SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"}) + static E uncheckedThrow(Throwable throwable) throws E { + throw (E) throwable; + } + private static final class LoadAllException extends RuntimeException { private static final long serialVersionUID = 1L; } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CacheTest.java index 018aee0749..8519e9b6df 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CacheTest.java @@ -36,6 +36,7 @@ import static org.slf4j.event.Level.ERROR; import static org.slf4j.event.Level.WARN; +import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.lang.reflect.InvocationTargetException; @@ -174,7 +175,20 @@ public void get_absent_null(Cache cache, CacheContext context) { @CacheSpec @Test(dataProvider = "caches") - public void get_absent_throwsException(Cache cache, CacheContext context) { + public void get_absent_throwsCheckedException(Cache cache, CacheContext context) { + var error = assertThrows(Exception.class, () -> + cache.get(context.absentKey(), key -> { throw uncheckedThrow(new IOException()); })); + if (context.isSync() && context.isCaffeine()) { + assertThat(error).isInstanceOf(IOException.class); + } else { + assertThat(error).hasCauseThat().isInstanceOf(IOException.class); + } + assertThat(context).stats().hits(0).misses(1).success(0).failures(1); + } + + @CacheSpec + @Test(dataProvider = "caches") + public void get_absent_throwsRuntimeException(Cache cache, CacheContext context) { assertThrows(IllegalStateException.class, () -> cache.get(context.absentKey(), key -> { throw new IllegalStateException(); })); assertThat(context).stats().hits(0).misses(1).success(0).failures(1); @@ -404,7 +418,22 @@ public void getAll_nullLookup(Cache cache, CacheContext context) { @CacheSpec @Test(dataProvider = "caches") - public void getAll_absent_throwsException(Cache cache, CacheContext context) { + public void getAll_absent_throwsCheckedException(Cache cache, CacheContext context) { + var error = assertThrows(Exception.class, () -> + cache.getAll(context.absentKeys(), keys -> { throw uncheckedThrow(new IOException()); })); + if (context.isSync()) { + assertThat(error).isInstanceOf(IOException.class); + } else { + assertThat(error).hasCauseThat().isInstanceOf(IOException.class); + } + + int misses = context.absentKeys().size(); + assertThat(context).stats().hits(0).misses(misses).success(0).failures(1); + } + + @CacheSpec + @Test(dataProvider = "caches") + public void getAll_absent_throwsRuntimeException(Cache cache, CacheContext context) { assertThrows(IllegalStateException.class, () -> cache.getAll(context.absentKeys(), keys -> { throw new IllegalStateException(); })); int misses = context.absentKeys().size(); @@ -413,7 +442,7 @@ public void getAll_absent_throwsException(Cache cache, CacheContext co @CacheSpec @Test(dataProvider = "caches") - public void getAll_function_throwsError(Cache cache, CacheContext context) { + public void getAll_absent_throwsError(Cache cache, CacheContext context) { assertThrows(UnknownError.class, () -> cache.getAll(context.absentKeys(), keys -> { throw new UnknownError(); })); int misses = context.absentKeys().size(); @@ -1114,4 +1143,9 @@ public void cacheEntry_equals_hashCode_toString() { } tester.testEquals(); } + + @SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"}) + static E uncheckedThrow(Throwable throwable) throws E { + throw (E) throwable; + } } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecTest.java index 97b1308a76..5d6803b30b 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecTest.java @@ -118,7 +118,7 @@ private void runScenarios(CacheContext context, Epoch epoch) { } private void runTest(CacheContext context, Epoch epoch, Function formatter) { - CaffeineSpec spec = toSpec(context, epoch, formatter); + CaffeineSpec spec = toSpec(context, formatter); Caffeine builder = Caffeine.from(spec); checkInitialCapacity(spec, context, builder); @@ -134,8 +134,7 @@ private void runTest(CacheContext context, Epoch epoch, Function formatter) { + static CaffeineSpec toSpec(CacheContext context, Function formatter) { var options = new ArrayList(); if (context.initialCapacity() != InitialCapacity.DEFAULT) { options.add("initialCapacity=" + context.initialCapacity().size()); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java index ca95e74cb4..2c8fac5015 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java @@ -205,13 +205,13 @@ public void loading_nullLoader() { @Test public void async_weakValues() { var builder = Caffeine.newBuilder().weakValues(); - assertThrows(IllegalStateException.class, () -> builder.buildAsync(loader)); + assertThrows(IllegalStateException.class, () -> builder.buildAsync()); } @Test public void async_softValues() { var builder = Caffeine.newBuilder().softValues(); - assertThrows(IllegalStateException.class, () -> builder.buildAsync(loader)); + assertThrows(IllegalStateException.class, () -> builder.buildAsync()); } @Test diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java index a8c2043c2f..4aac036b00 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java @@ -69,6 +69,7 @@ import com.github.benmanes.caffeine.cache.testing.CheckNoStats; import com.github.benmanes.caffeine.cache.testing.RemovalListeners.RejectingRemovalListener; import com.github.benmanes.caffeine.testing.Int; +import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.common.collect.Range; @@ -325,6 +326,46 @@ public void getAll_weigherFails_async(AsyncCache cache, CacheContext c .hasSize(context.absentKeys().size()); } + @Test(dataProvider = "caches") + @CacheSpec(population = Population.FULL, + maximumSize = Maximum.FULL, weigher = CacheWeigher.MOCKITO) + public void getAll_weigherFails_newEntries(Cache cache, CacheContext context) { + when(context.weigher().weigh(any(), any())).thenThrow(IllegalStateException.class); + assertThrows(IllegalStateException.class, () -> + cache.getAll(context.absentKeys(), keys -> HashBiMap.create(context.original()).inverse())); + assertThat(cache).containsExactlyEntriesIn(context.original()); + if (context.isCaffeine()) { + assertThat(logEvents() + .withMessage("Exception thrown during asynchronous load") + .withThrowable(IllegalStateException.class) + .withLevel(WARN) + .exclusively()) + .hasSize(context.isAsync() ? context.original().size() : 0); + } + } + + @Test(dataProvider = "caches") + @CacheSpec(population = Population.FULL, + maximumSize = Maximum.FULL, weigher = CacheWeigher.MOCKITO) + public void getAll_weigherFails_newEntries_async( + AsyncCache cache, CacheContext context) { + when(context.weigher().weigh(any(), any())).thenThrow(IllegalStateException.class); + var future = new CompletableFuture>(); + var result = cache.getAll(context.absentKeys(), (keys, executor) -> future); + future.complete(HashBiMap.create(context.original()).inverse()); + + assertThat(context).stats().failures(1); + assertThat(result).failsWith(CompletionException.class) + .hasCauseThat().isInstanceOf(IllegalStateException.class); + assertThat(cache).containsExactlyEntriesIn(context.original()); + assertThat(logEvents() + .withMessage("Exception thrown during asynchronous load") + .withThrowable(IllegalStateException.class) + .withLevel(WARN) + .exclusively()) + .hasSize(context.original().size()); + } + @Test(dataProvider = "caches") @CacheSpec(population = Population.EMPTY, maximumSize = Maximum.FULL, weigher = CacheWeigher.NEGATIVE) @@ -563,41 +604,9 @@ public void replaceConditionally_weigherFails_absent( public void replaceConditionally_weigherFails_presentKey( Cache cache, CacheContext context, Eviction eviction) { when(context.weigher().weigh(any(), any())).thenThrow(IllegalStateException.class); - assertThrows(IllegalStateException.class, () -> cache.asMap().replace( - context.firstKey(), context.original().get(context.firstKey()), context.absentValue())); - assertThat(cache).containsExactlyEntriesIn(context.original()); - assertThat(eviction.weightOf(context.firstKey())).hasValue(1); - } - - @Test(dataProvider = "caches") - @CacheSpec(population = Population.FULL, - maximumSize = Maximum.FULL, weigher = CacheWeigher.MOCKITO) - public void replaceConditionally_weigherFails_presentKey_async( - AsyncCache cache, CacheContext context) { - when(context.weigher().weigh(any(), any())).thenThrow(IllegalStateException.class); - var future = new CompletableFuture(); - cache.asMap().replace(context.firstKey(), cache.getIfPresent(context.firstKey()), future); - future.complete(context.absentValue()); - assertThat(context).stats().failures(1); - assertThat(cache).doesNotContainKey(context.absentKey()); - assertThat(logEvents() - .withMessage("Exception thrown during asynchronous load") - .withThrowable(IllegalStateException.class) - .withLevel(WARN) - .exclusively()) - .hasSize(1); - } - - @Test(dataProvider = "caches") - @CacheSpec(population = Population.FULL, - maximumSize = Maximum.FULL, weigher = CacheWeigher.MOCKITO) - public void replaceConditionally_weigherFails_presentKeyAndValue( - Cache cache, CacheContext context, Eviction eviction) { - when(context.weigher().weigh(any(), any())).thenThrow(IllegalStateException.class); - assertThrows(IllegalStateException.class, () -> { + assertThrows(IllegalStateException.class, () -> cache.asMap().replace(context.firstKey(), - context.original().get(context.firstKey()), context.absentValue()); - }); + context.original().get(context.firstKey()), context.absentValue())); assertThat(cache).containsExactlyEntriesIn(context.original()); assertThat(eviction.weightOf(context.firstKey())).hasValue(1); } @@ -605,7 +614,7 @@ public void replaceConditionally_weigherFails_presentKeyAndValue( @Test(dataProvider = "caches") @CacheSpec(population = Population.FULL, maximumSize = Maximum.FULL, weigher = CacheWeigher.MOCKITO) - public void replaceConditionally_weigherFails_presentKeyAndValue_async( + public void replaceConditionally_weigherFails_presentKey_async( AsyncCache cache, CacheContext context) { when(context.weigher().weigh(any(), any())).thenThrow(IllegalStateException.class); var future = new CompletableFuture(); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java index eea96ad211..c78d03dd39 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java @@ -1557,7 +1557,7 @@ public void entrySet_toArray(Map map, CacheContext context) { expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE}, expiryTime = Expire.ONE_MINUTE) public void entrySet_iterator(Map map, CacheContext context) { context.ticker().advance(Duration.ofMinutes(10)); - assertThat(map.keySet().iterator().hasNext()).isFalse(); + assertThat(map.entrySet().iterator().hasNext()).isFalse(); assertThat(map).isExhaustivelyEmpty(); assertThat(context).notifications().withCause(EXPIRED) .contains(context.original()).exclusively(); @@ -1630,10 +1630,10 @@ public void entrySet_hashCode(Map map, CacheContext context) { map.putAll(context.absent()); context.ticker().advance(Duration.ofSeconds(45)); - assertThat(map.hashCode()).isEqualTo(context.absent().hashCode()); + assertThat(map.entrySet().hashCode()).isEqualTo(context.absent().entrySet().hashCode()); context.cleanUp(); - assertThat(map.hashCode()).isEqualTo(context.absent().hashCode()); + assertThat(map.entrySet().hashCode()).isEqualTo(context.absent().entrySet().hashCode()); } @Test(dataProvider = "caches") diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterVarTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterVarTest.java index acfe70b48a..e6e1fcce5f 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterVarTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterVarTest.java @@ -78,6 +78,7 @@ import com.github.benmanes.caffeine.cache.testing.CheckNoStats; import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.github.benmanes.caffeine.testing.Int; +import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.common.testing.SerializableTester; @@ -412,6 +413,14 @@ public void getAll_expiryFails(Cache cache, CacheContext context) { cache.getAll(context.absentKeys(), keys -> Maps.toMap(keys, Int::negate))); context.ticker().advance(Duration.ofHours(-1)); assertThat(cache).containsExactlyEntriesIn(context.original()); + if (context.isCaffeine()) { + assertThat(logEvents() + .withMessage("Exception thrown during asynchronous load") + .withThrowable(ExpirationException.class) + .withLevel(WARN) + .exclusively()) + .hasSize(context.isAsync() ? context.absentKeys().size() : 0); + } } @Test(dataProvider = "caches") @@ -434,6 +443,47 @@ public void getAll_expiryFails_async(AsyncCache cache, CacheContext co .hasSize(context.absentKeys().size()); } + @Test(dataProvider = "caches") + @CacheSpec(population = Population.FULL, expiry = CacheExpiry.MOCKITO) + public void getAll_expiryFails_newEntries(Cache cache, CacheContext context) { + context.ticker().advance(Duration.ofHours(1)); + when(context.expiry().expireAfterCreate(any(), any(), anyLong())) + .thenThrow(ExpirationException.class); + assertThrows(ExpirationException.class, () -> + cache.getAll(context.absentKeys(), keys -> HashBiMap.create(context.original()).inverse())); + context.ticker().advance(Duration.ofHours(-1)); + assertThat(cache).containsExactlyEntriesIn(context.original()); + if (context.isCaffeine()) { + assertThat(logEvents() + .withMessage("Exception thrown during asynchronous load") + .withThrowable(ExpirationException.class) + .withLevel(WARN) + .exclusively()) + .hasSize(context.isAsync() ? context.original().size() : 0); + } + } + + @Test(dataProvider = "caches") + @CacheSpec(population = Population.FULL, expiry = CacheExpiry.MOCKITO) + public void getAll_expiryFails_newEntries_async( + AsyncCache cache, CacheContext context) { + context.ticker().advance(Duration.ofHours(1)); + when(context.expiry().expireAfterCreate(any(), any(), anyLong())) + .thenThrow(ExpirationException.class); + var future = new CompletableFuture>(); + var result = cache.getAll(context.absentKeys(), (keys, executor) -> future); + future.complete(HashBiMap.create(context.original()).inverse()); + assertThat(result).failsWith(CompletionException.class) + .hasCauseThat().isInstanceOf(ExpirationException.class); + assertThat(cache).containsExactlyEntriesIn(context.original()); + assertThat(logEvents() + .withMessage("Exception thrown during asynchronous load") + .withThrowable(ExpirationException.class) + .withLevel(WARN) + .exclusively()) + .hasSize(context.original().size()); + } + @Test(dataProvider = "caches") @CacheSpec(population = Population.FULL, expiry = CacheExpiry.MOCKITO) public void getAllPresent_expiryFails(Cache cache, CacheContext context) { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/FrequencySketchTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/FrequencySketchTest.java index 442a87be1d..d6e851be8c 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/FrequencySketchTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/FrequencySketchTest.java @@ -125,13 +125,13 @@ public void full() { for (int i = 0; i < 100_000; i++) { sketch.increment(i); } - for (long item : sketch.table) { - assertThat(Long.bitCount(item)).isEqualTo(64); + for (long slot : sketch.table) { + assertThat(Long.bitCount(slot)).isEqualTo(64); } sketch.reset(); - for (long item : sketch.table) { - assertThat(item).isEqualTo(FrequencySketch.RESET_MASK); + for (long slot : sketch.table) { + assertThat(slot).isEqualTo(FrequencySketch.RESET_MASK); } } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java index 65a7dd08af..3b7864c1fe 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java @@ -1110,7 +1110,7 @@ public void refreshAll_nullFuture_reload(CacheContext context) { /* --------------- CacheLoader --------------- */ @Test - public void loadAll() throws Exception { + public void loadAll() { CacheLoader loader = key -> key; assertThrows(UnsupportedOperationException.class, () -> loader.loadAll(Set.of())); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/QueueSanityTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/QueueSanityTest.java index 08e3522e63..e3baffdc05 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/QueueSanityTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/QueueSanityTest.java @@ -87,7 +87,6 @@ public void sanity() { } else { // expect sum of elements is (size - 1) * size / 2 = 0 + 1 + .... + (size - 1) int sum = (size - 1) * size / 2; - i = 0; Integer e; while ((e = queue.poll()) != null) { assertEquals(--size, queue.size()); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java index 29d4736430..326ae2fbbf 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java @@ -964,9 +964,10 @@ public void setRefreshAfter_excessive(Cache cache, } @Test(dataProvider = "caches") + @SuppressWarnings("PreferJavaTimeOverload") @CacheSpec(refreshAfterWrite = Expire.ONE_MINUTE) public void setRefreshesAfter(CacheContext context, FixedRefresh refreshAfterWrite) { - refreshAfterWrite.setRefreshesAfter(Duration.ofMinutes(2)); + refreshAfterWrite.setRefreshesAfter(2, TimeUnit.MINUTES); assertThat(refreshAfterWrite.getRefreshesAfter().toMinutes()).isEqualTo(2); assertThat(refreshAfterWrite.getRefreshesAfter(TimeUnit.MINUTES)).isEqualTo(2); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/TimerWheelTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/TimerWheelTest.java index 7a04601e88..871c2ddc18 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/TimerWheelTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/TimerWheelTest.java @@ -82,7 +82,7 @@ public void beforeMethod() throws Exception { } @AfterMethod - public void afterMethod(ITestResult testResult) throws Exception { + public void afterMethod(ITestResult testResult) { if (!testResult.isSuccess()) { printTimerWheel(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java index 93f1d649a0..2a593bbca2 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java @@ -42,7 +42,7 @@ public Iterator buffers() { @Test(dataProvider = "buffers") @SuppressWarnings("ThreadPriorityCheck") - public void record(ReadBuffer buffer) { + public void offer(ReadBuffer buffer) { ConcurrentTestHarness.timeTasks(100, () -> { for (int i = 0; i < 1000; i++) { int added = buffer.offer(Boolean.TRUE); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue193Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue193Test.java index 5b2d523cad..0c2a143ade 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue193Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue193Test.java @@ -42,23 +42,23 @@ * @author boschb (Robert Bosch) */ public final class Issue193Test { + private final String testKey = Issue193Test.class.getSimpleName(); private final AtomicLong counter = new AtomicLong(0); private final FakeTicker ticker = new FakeTicker(); private ListenableFutureTask loadingTask; - private final AsyncCacheLoader loader = (key, exec) -> { + private final AsyncCacheLoader loader = (key, executor) -> { // Fools the cache into thinking there is a future that's not immediately ready. // (The Cache has optimizations for this that we want to avoid) loadingTask = ListenableFutureTask.create(counter::getAndIncrement); var f = new CompletableFuture(); loadingTask.addListener(() -> { f.complete(Futures.getUnchecked(loadingTask)); - }, exec); + }, executor); return f; }; - private final String key = Issue193Test.class.getSimpleName(); /** This ensures that any outstanding async loading is completed as well */ private long loadGet(AsyncLoadingCache cache, String key) { @@ -70,7 +70,7 @@ private long loadGet(AsyncLoadingCache cache, String key) { } @Test - public void invalidateDuringRefreshRemovalCheck() throws Exception { + public void invalidateDuringRefreshRemovalCheck() { var removed = new ArrayList(); AsyncLoadingCache cache = Caffeine.newBuilder() .removalListener((String key, Long value, RemovalCause reason) -> removed.add(value)) @@ -80,19 +80,16 @@ public void invalidateDuringRefreshRemovalCheck() throws Exception { .buildAsync(loader); // Load so there is an initial value. - assertThat(loadGet(cache, key)).isEqualTo(0); + assertThat(loadGet(cache, testKey)).isEqualTo(0); ticker.advance(Duration.ofNanos(11)); // Refresh should fire on next access - assertThat(cache).containsEntry(key, 0); // Old value + assertThat(cache).containsEntry(testKey, 0); // Old value - cache.synchronous().invalidate(key); // Invalidate key entirely - assertThat(cache).doesNotContainKey(key); // No value in cache (good) + cache.synchronous().invalidate(testKey); // Invalidate key entirely + assertThat(cache).doesNotContainKey(testKey); // No value in cache (good) loadingTask.run(); // Completes refresh - // FIXME: java.lang.AssertionError: Not true that <1> is null - assertThat(cache).doesNotContainKey(key); // Value in cache (bad) - - // FIXME: Maybe? This is what I wanted to actually test :) + assertThat(cache).doesNotContainKey(testKey); // Value in cache (bad) assertThat(removed).containsExactly(0L, 1L).inOrder(); // 1L was sent to removalListener anyway } } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java index 4fa2494fef..371e2aca1a 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java @@ -49,19 +49,19 @@ public final class Issue298Test { static final long EXPIRE_NS = Duration.ofDays(1).toNanos(); - AtomicBoolean startedLoad; - AtomicBoolean doLoad; + private AtomicBoolean startedLoad; + private AtomicBoolean doLoad; - AtomicBoolean startedCreate; - AtomicBoolean doCreate; + private AtomicBoolean startedCreate; + private AtomicBoolean doCreate; - AtomicBoolean startedRead; - AtomicBoolean doRead; - AtomicBoolean endRead; + private AtomicBoolean startedRead; + private AtomicBoolean doRead; + private AtomicBoolean endRead; - AsyncLoadingCache cache; - VarExpiration policy; - String key; + private AsyncLoadingCache cache; + private VarExpiration policy; + private String testKey; @BeforeMethod public void before() { @@ -73,7 +73,7 @@ public void before() { doLoad = new AtomicBoolean(); doRead = new AtomicBoolean(); - key = "key"; + testKey = "key"; cache = makeAsyncCache(); policy = cache.synchronous().policy().expireVariably().orElseThrow(); } @@ -87,7 +87,7 @@ public void after() { @SuppressWarnings("FutureReturnValueIgnored") public void readDuringCreate() { // Loaded value and waiting at expireAfterCreate (expire: infinite) - var initialValue = cache.get(key); + var initialValue = cache.get(testKey); assertThat(initialValue).isNotNull(); await().untilTrue(startedLoad); @@ -97,14 +97,14 @@ public void readDuringCreate() { // Async read trying to wait at expireAfterRead var reader = CompletableFuture.runAsync(() -> { do { - var value = cache.get(key); + var value = cache.get(testKey); assertThat(value).isEqualTo(initialValue); } while (!endRead.get()); }, executor); // Ran expireAfterCreate (expire: infinite -> create) doCreate.set(true); - await().until(() -> policy.getExpiresAfter(key).orElseThrow().toNanos() <= EXPIRE_NS); + await().until(() -> policy.getExpiresAfter(testKey).orElseThrow().toNanos() <= EXPIRE_NS); await().untilTrue(startedRead); // Ran reader (expire: create -> ?) @@ -113,7 +113,7 @@ public void readDuringCreate() { reader.join(); // Ensure expire is [expireAfterCreate], not [infinite] - assertThat(policy.getExpiresAfter(key).orElseThrow().toNanos()).isAtMost(EXPIRE_NS); + assertThat(policy.getExpiresAfter(testKey).orElseThrow().toNanos()).isAtMost(EXPIRE_NS); } private AsyncLoadingCache makeAsyncCache() { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContext.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContext.java index 050da3c207..0234c6e29c 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContext.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContext.java @@ -441,29 +441,31 @@ public FakeTicker ticker() { } public LoadingCache build(CacheLoader loader) { - LoadingCache cache; + LoadingCache loading; if (isCaffeine()) { - cache = isAsync() ? caffeine.buildAsync(loader).synchronous() : caffeine.build(loader); + loading = isAsync() ? caffeine.buildAsync(loader).synchronous() : caffeine.build(loader); } else { var guavaLoader = new SingleLoader<>(loader); - cache = new GuavaLoadingCache<>(guava.build(asyncReloading(guavaLoader, executor)), this); + loading = new GuavaLoadingCache<>(guava.build(asyncReloading(guavaLoader, executor)), this); } - this.cache = cache; - return cache; + this.cache = loading; + return loading; } public AsyncLoadingCache buildAsync(CacheLoader loader) { checkState(isCaffeine() && isAsync()); - AsyncLoadingCache cache = caffeine.buildAsync(loader); - this.cache = cache.synchronous(); - return cache; + AsyncLoadingCache async = caffeine.buildAsync(loader); + this.cache = asyncCache.synchronous(); + this.asyncCache = async; + return async; } public AsyncLoadingCache buildAsync(AsyncCacheLoader loader) { checkState(isCaffeine() && isAsync()); - AsyncLoadingCache cache = caffeine.buildAsync(loader); - this.cache = cache.synchronous(); - return cache; + AsyncLoadingCache async = caffeine.buildAsync(loader); + this.cache = asyncCache.synchronous(); + this.asyncCache = async; + return async; } public boolean isCaffeine() { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java index dbe13ceaf3..2e73a71e49 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java @@ -378,8 +378,8 @@ public Exclusive contains(Entry... entries) { var notifications = Arrays.stream(entries) .map(entry -> new RemovalNotification<>(entry.getKey(), entry.getValue(), cause)) .collect(toImmutableListMultimap(RemovalNotification::getCause, identity())); - var actual = Multimaps.index(listener.removed(), RemovalNotification::getCause); - check(type).that(actual).containsAtLeastEntriesIn(notifications); + var removed = Multimaps.index(listener.removed(), RemovalNotification::getCause); + check(type).that(removed).containsAtLeastEntriesIn(notifications); }); return new Exclusive(entries.length); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java index 071368f3c0..976f34c45b 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java @@ -183,7 +183,7 @@ public V get(K key, Function mappingFunction) { } throw (RuntimeException) e.getCause(); } catch (ExecutionException e) { - throw new CompletionException(e); + throw new CompletionException(e.getCause()); } catch (ExecutionError e) { throw (Error) e.getCause(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/Collection8Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/Collection8Test.java index 603b5684fc..84cd142eda 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/Collection8Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/Collection8Test.java @@ -178,7 +178,7 @@ else if (c instanceof Set) { } } - public void testNullPointerExceptions() throws InterruptedException { + public void testNullPointerExceptions() { Collection c = impl.emptyCollection(); Collection nullCollection = null; assertThrows( diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMap8Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMap8Test.java index 97cb27b65a..6f3c791fde 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMap8Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMap8Test.java @@ -33,7 +33,7 @@ @SuppressWarnings({"IdentityConversion", "PreferredInterfaceType", "rawtypes", "try", "unchecked"}) public class ConcurrentHashMap8Test extends JSR166TestCase { public static void main(String[] args) { - main(suite(), args); + main(suite()); } public static Test suite() { return new TestSuite(ConcurrentHashMap8Test.class); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMapTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMapTest.java index 03aabb736a..3dbcdb20c8 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMapTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/ConcurrentHashMapTest.java @@ -28,7 +28,7 @@ "rawtypes", "ReturnValueIgnored", "unchecked", "UnnecessaryParentheses"}) public class ConcurrentHashMapTest extends JSR166TestCase { public static void main(String[] args) { - main(suite(), args); + main(suite()); } public static Test suite() { class Implementation implements MapImplementation { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/JSR166TestCase.java b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/JSR166TestCase.java index 08ed20235e..e06cb5ba94 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/JSR166TestCase.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/JSR166TestCase.java @@ -382,7 +382,7 @@ protected void runTestProfiled() throws Throwable { * Runs all JSR166 unit tests using junit.textui.TestRunner. */ public static void main(String[] args) { - main(suite(), args); + main(suite()); } static class PithyResultPrinter extends junit.textui.ResultPrinter { @@ -420,7 +420,7 @@ static junit.textui.TestRunner newPithyTestRunner() { * Runs all unit tests in the given test suite. * Actual behavior influenced by jsr166.* system properties. */ - static void main(Test suite, String[] args) { + static void main(Test suite) { // if (useSecurityManager) { // System.err.println("Setting a permissive security manager"); // Policy.setPolicy(permissivePolicy()); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/KeySetTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/KeySetTest.java index 8c50f62f4e..6caca8e481 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/KeySetTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/KeySetTest.java @@ -18,7 +18,7 @@ @SuppressWarnings("rawtypes") public class KeySetTest extends JSR166TestCase { public static void main(String[] args) { - main(suite(), args); + main(suite()); } public static Test suite() { diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java index e8076bdd33..93a75233a7 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java @@ -96,7 +96,7 @@ public void testReload_throwable() { cache.refresh(1); } - public void testCacheLoader_null() throws Exception { + public void testCacheLoader_null() { assertThrows(NullPointerException.class, () -> CaffeinatedGuava.caffeinate(null)); var caffeine1 = CaffeinatedGuava.caffeinate(CacheLoader.from(key -> null)); @@ -121,13 +121,13 @@ public ListenableFuture reload(Integer key, Integer oldValue) { assertThat(e2).hasCauseThat().isInstanceOf(InvalidCacheLoadException.class); } - public void testCacheLoader_exception() throws Exception { + public void testCacheLoader_exception() { runCacheLoaderExceptionTest(new InterruptedException()); runCacheLoaderExceptionTest(new RuntimeException()); runCacheLoaderExceptionTest(new Exception()); } - public void runCacheLoaderExceptionTest(Exception error) throws Exception { + public void runCacheLoaderExceptionTest(Exception error) { var guava = new CacheLoader() { @Override public Integer load(Integer key) throws Exception { throw error; diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheBuilderTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheBuilderTest.java index 09d6d9f7da..c1e611c96f 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheBuilderTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheBuilderTest.java @@ -389,7 +389,7 @@ public void testRemovalListener_setTwice() { Caffeine.newBuilder().removalListener(testListener); try { // even to the same instance is not allowed - builder = builder.removalListener(testListener); + builder.removalListener(testListener); fail(); } catch (IllegalStateException expected) {} } @@ -629,7 +629,7 @@ public void testRemovalNotification_get_basher() throws InterruptedException { } @GwtIncompatible("NullPointerTester") - public void testNullParameters() throws Exception { + public void testNullParameters() { NullPointerTester tester = new NullPointerTester(); Caffeine builder = Caffeine.newBuilder(); tester.testAllPublicInstanceMethods(builder); diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheEvictionTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheEvictionTest.java index 17337dda15..59465420c7 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheEvictionTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheEvictionTest.java @@ -228,7 +228,7 @@ public void testEviction_overflow() { assertEquals(1, removalListener.getCount()); } - // FIXME(ben): Caffeine uses W-TinyLfu, not Lru + // Caffeine uses W-TinyLfu, not Lru public void disabled_testEviction_lru() { // test lru within a single segment IdentityLoader loader = identityLoader(); @@ -261,7 +261,7 @@ public void disabled_testEviction_lru() { assertThat(keySet).containsExactly(2, 10, 11, 12, 6, 7, 8, 13, 14, 15); } - // FIXME(ben): Caffeine uses W-TinyLfu, not Lru + // Caffeine uses W-TinyLfu, not Lru public void disabled_testEviction_weightedLru() { // test weighted lru within a single segment IdentityLoader loader = identityLoader(); diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheLoadingTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheLoadingTest.java index e511222039..b348a12e40 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheLoadingTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheLoadingTest.java @@ -163,7 +163,7 @@ public void testLoad() throws ExecutionException { assertEquals(2, stats.hitCount()); } - public void testReload() throws ExecutionException { + public void testReload() { final Object one = new Object(); final Object two = new Object(); CacheLoader loader = new CacheLoader() { @@ -658,7 +658,7 @@ public void testLoadNull() throws ExecutionException { assertEquals(0, stats.hitCount()); } - public void testReloadNull() throws ExecutionException { + public void testReloadNull() { final Object one = new Object(); CacheLoader loader = new CacheLoader() { @Override @@ -704,7 +704,7 @@ public ListenableFuture reload(Object key, Object oldValue) { assertEquals(1, stats.hitCount()); } - public void testReloadNullFuture() throws ExecutionException { + public void testReloadNullFuture() { final Object one = new Object(); CacheLoader loader = new CacheLoader() { @Override @@ -936,7 +936,7 @@ public Object call() { assertEquals(0, stats.hitCount()); } - public void testReloadError() throws ExecutionException { + public void testReloadError() { final Object one = new Object(); final Error e = new Error(); CacheLoader loader = new CacheLoader() { @@ -983,7 +983,7 @@ public ListenableFuture reload(Object key, Object oldValue) { assertEquals(1, stats.hitCount()); } - public void testReloadFutureError() throws ExecutionException { + public void testReloadFutureError() { final Object one = new Object(); final Error e = new Error(); CacheLoader loader = new CacheLoader() { @@ -1264,7 +1264,7 @@ public void testLoadInterruptedException() { public void testReloadCheckedException() { final Object one = new Object(); - final RuntimeException e = new RuntimeException(); + final Exception e = new Exception(); CacheLoader loader = new CacheLoader() { @Override public Object load(Object key) { @@ -1272,7 +1272,7 @@ public Object load(Object key) { } @Override - public ListenableFuture reload(Object key, Object oldValue) { + public ListenableFuture reload(Object key, Object oldValue) throws Exception { throw e; } }; @@ -1536,7 +1536,7 @@ public void testLoadUncheckedException() throws ExecutionException { assertEquals(0, stats.hitCount()); } - public void testReloadUncheckedException() throws ExecutionException { + public void testReloadUncheckedException() { final Object one = new Object(); final RuntimeException e = new RuntimeException(); CacheLoader loader = new CacheLoader() { @@ -1583,7 +1583,7 @@ public ListenableFuture reload(Object key, Object oldValue) { assertEquals(1, stats.hitCount()); } - public void testReloadFutureUncheckedException() throws ExecutionException { + public void testReloadFutureUncheckedException() { final Object one = new Object(); final Exception e = new RuntimeException(); CacheLoader loader = new CacheLoader() { @@ -1716,7 +1716,7 @@ public void testBulkLoadUncheckedException() throws ExecutionException { assertEquals(0, stats.hitCount()); } - public void testReloadAfterFailure() throws ExecutionException { + public void testReloadAfterFailure() { final AtomicInteger count = new AtomicInteger(); final RuntimeException e = new IllegalStateException("exception to trigger failure on first load()"); @@ -2068,7 +2068,7 @@ private static List doConcurrentGet(final LoadingCache cache, return resultList; } - public void testAsMapDuringLoading() throws InterruptedException, ExecutionException { + public void testAsMapDuringLoading() throws InterruptedException { final CountDownLatch getStartedSignal = new CountDownLatch(2); final CountDownLatch letGetFinishSignal = new CountDownLatch(1); final CountDownLatch getFinishedSignal = new CountDownLatch(2); @@ -2175,8 +2175,7 @@ public String load(String key) { } // ConcurrentHashMap does not support this, as it returns the removed entry - public void disabled_testInvalidateAndReloadDuringLoading() - throws InterruptedException, ExecutionException { + public void disabled_testInvalidateAndReloadDuringLoading() throws InterruptedException { // computation starts; clear() is called, computation finishes final CountDownLatch computationStarted = new CountDownLatch(2); final CountDownLatch letGetFinishSignal = new CountDownLatch(1); diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/LocalLoadingCacheTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/LocalLoadingCacheTest.java index 2d238ab9e0..58cdc6b767 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/LocalLoadingCacheTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/LocalLoadingCacheTest.java @@ -69,7 +69,7 @@ public Object load(Object from) { // null parameters test - public void testNullParameters() throws Exception { + public void testNullParameters() { NullPointerTester tester = new NullPointerTester(); CacheLoader loader = identityLoader(); tester.testAllPublicInstanceMethods(makeCache(createCacheBuilder(), loader)); diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/JCacheProfiler.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/JCacheProfiler.java index b373decfa5..f94a87cf9d 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/JCacheProfiler.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/JCacheProfiler.java @@ -86,9 +86,9 @@ public void start() { private ScheduledFuture scheduleStatusTask() { var stopwatch = Stopwatch.createStarted(); return Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> { - long count = this.count.longValue(); - long rate = count / stopwatch.elapsed(TimeUnit.SECONDS); - System.out.printf(US, "%s - %,d [%,d / sec]%n", stopwatch, count, rate); + long iterations = count.longValue(); + long rate = iterations / stopwatch.elapsed(TimeUnit.SECONDS); + System.out.printf(US, "%s - %,d [%,d / sec]%n", stopwatch, iterations, rate); }, 5, 5, TimeUnit.SECONDS); } diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java index 51e0a4acc4..9580d4f334 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java @@ -67,11 +67,10 @@ public Option[] config() { @Test public void sanity() { - var cachingProvider = Caching.getCachingProvider( + var provider = Caching.getCachingProvider( "com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider", getClass().getClassLoader()); - var cache = cachingProvider.getCacheManager() - .getCache("osgi-cache", String.class, Integer.class); + var cache = provider.getCacheManager().getCache("osgi-cache", String.class, Integer.class); assertNull(cache.get("a")); } diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java index ade405b10b..b1b951527e 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java @@ -65,7 +65,7 @@ public void setConfigSource_supplier() { @Test public void setConfigSource_function() { - TypesafeConfigurator.setConfigSource((uri, classloader) -> null); + TypesafeConfigurator.setConfigSource((uri, loader) -> null); assertThat(configSource()).isNotSameInstanceAs(defaultConfigSource); assertThrows(NullPointerException.class, () ->