-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use explicit checks in tests for removal notifications
Previously the number of notifications were checked for, but this allowed for an incorrect publication to sneak through. The tests now assert that the exact number of expected notifications are observed.
- Loading branch information
Showing
21 changed files
with
1,020 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ jobs: | |
if: always() | ||
run: ./gradlew --stop | ||
- uses: andymckay/[email protected] | ||
continue-on-error: true | ||
if: failure() | ||
|
||
guava: | ||
|
@@ -98,6 +99,7 @@ jobs: | |
if: always() | ||
run: ./gradlew --stop | ||
- uses: andymckay/[email protected] | ||
continue-on-error: true | ||
if: failure() | ||
|
||
event_file: | ||
|
210 changes: 109 additions & 101 deletions
210
caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
156 changes: 75 additions & 81 deletions
156
caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ | |
import static com.github.benmanes.caffeine.testing.FutureSubject.assertThat; | ||
import static com.github.benmanes.caffeine.testing.MapSubject.assertThat; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static java.util.Map.entry; | ||
import static java.util.function.Function.identity; | ||
import static java.util.stream.Collectors.toMap; | ||
import static org.mockito.ArgumentMatchers.any; | ||
|
@@ -58,6 +57,7 @@ | |
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Listener; | ||
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Population; | ||
import com.github.benmanes.caffeine.cache.testing.CacheValidationListener; | ||
import com.github.benmanes.caffeine.cache.testing.CheckNoEvictions; | ||
import com.github.benmanes.caffeine.cache.testing.CheckNoStats; | ||
import com.github.benmanes.caffeine.testing.Int; | ||
import com.google.common.collect.ImmutableSet; | ||
|
@@ -69,6 +69,7 @@ | |
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
@CheckNoEvictions | ||
@Listeners(CacheValidationListener.class) | ||
@Test(dataProviderClass = CacheProvider.class) | ||
@SuppressWarnings("FutureReturnValueIgnored") | ||
|
@@ -934,31 +935,33 @@ public void put_replace_failure_after(AsyncCache<Int, Int> cache, CacheContext c | |
@Test(dataProvider = "caches") | ||
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }) | ||
public void put_replace_nullValue(AsyncCache<Int, Int> cache, CacheContext context) { | ||
var removed = new HashMap<Int, Int>(); | ||
var value = CompletableFuture.completedFuture((Int) null); | ||
for (Int key : context.firstMiddleLastKeys()) { | ||
cache.put(key, value); | ||
assertThat(cache).doesNotContainKey(key); | ||
removed.put(key, context.original().get(key)); | ||
} | ||
int count = context.firstMiddleLastKeys().size(); | ||
assertThat(cache).hasSize(context.initialSize() - count); | ||
assertThat(context).removalNotifications().withCause(EXPLICIT).hasSize(count).exclusively(); | ||
assertThat(context).removalNotifications().withCause(EXPLICIT) | ||
.contains(removed).exclusively(); | ||
} | ||
|
||
@Test(dataProvider = "caches") | ||
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }) | ||
public void put_replace_differentValue(AsyncCache<Int, Int> cache, CacheContext context) { | ||
var replaced = new HashMap<Int, Int>(); | ||
for (Int key : context.firstMiddleLastKeys()) { | ||
var newValue = context.absentValue().asFuture(); | ||
cache.put(key, newValue); | ||
assertThat(cache).containsEntry(key, newValue); | ||
replaced.put(key, context.original().get(key)); | ||
} | ||
|
||
assertThat(cache).hasSize(context.initialSize()); | ||
assertThat(context).removalNotifications().withCause(REPLACED) | ||
.contains(entry(context.firstKey(), context.original().get(context.firstKey())), | ||
entry(context.middleKey(), context.original().get(context.middleKey())), | ||
entry(context.lastKey(), context.original().get(context.lastKey()))) | ||
.exclusively(); | ||
.contains(replaced).exclusively(); | ||
} | ||
|
||
/* --------------- misc --------------- */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ | |
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader; | ||
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Population; | ||
import com.github.benmanes.caffeine.cache.testing.CacheValidationListener; | ||
import com.github.benmanes.caffeine.cache.testing.CheckNoEvictions; | ||
import com.github.benmanes.caffeine.cache.testing.CheckNoStats; | ||
import com.github.benmanes.caffeine.testing.Int; | ||
import com.google.common.collect.ImmutableSet; | ||
|
@@ -67,6 +68,7 @@ | |
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
@CheckNoEvictions | ||
@Listeners(CacheValidationListener.class) | ||
@Test(dataProviderClass = CacheProvider.class) | ||
@SuppressWarnings({"FutureReturnValueIgnored", "PreferJavaTimeOverload"}) | ||
|
@@ -408,15 +410,16 @@ private static final class LoadAllException extends RuntimeException {} | |
@Test(dataProvider = "caches") | ||
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }) | ||
public void put_replace(AsyncLoadingCache<Int, Int> cache, CacheContext context) { | ||
var replaced = new HashMap<Int, Int>(); | ||
var value = context.absentValue().asFuture(); | ||
for (Int key : context.firstMiddleLastKeys()) { | ||
cache.put(key, value); | ||
assertThat(cache.get(key)).succeedsWith(context.absentValue()); | ||
replaced.put(key, context.original().get(key)); | ||
} | ||
assertThat(cache).hasSize(context.initialSize()); | ||
|
||
int count = context.firstMiddleLastKeys().size(); | ||
assertThat(context).removalNotifications().withCause(REPLACED).hasSize(count).exclusively(); | ||
assertThat(context).removalNotifications().withCause(REPLACED) | ||
.contains(replaced).exclusively(); | ||
} | ||
|
||
/* --------------- refresh --------------- */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.