Skip to content

Commit

Permalink
Add test for when the bulk load function returns extra entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Dec 2, 2021
1 parent e32f711 commit a681c68
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 41 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ jobs:
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
cache: 'gradle'
distribution: 'zulu'
java-version: ${{ matrix.java }}
- name: Cache Gradle packages
uses: actions/[email protected]
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-${{ github.job }}-${{ matrix.java }}-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Run analyzers
run: ./.github/scripts/analyze.sh
9 changes: 1 addition & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@ jobs:
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
cache: 'gradle'
distribution: 'zulu'
java-version: ${{ matrix.java }}
- name: Cache Gradle packages
uses: actions/[email protected]
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-${{ github.job }}-${{ matrix.java }}-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Run tests
run: ./.github/scripts/test.sh
- name: Publish Coverage
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/lincheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@ jobs:
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v2
with:
cache: 'gradle'
distribution: 'zulu'
java-version: ${{ env.JAVA_VERSION }}
- name: Cache Gradle packages
uses: actions/[email protected]
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-${{ github.job }}-${{ matrix.java }}-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Run lincheck
run: |
set -eux
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ jobs:
with:
distribution: 'zulu'
java-version: ${{ env.JAVA_VERSION }}
- name: Cache Gradle packages
uses: actions/[email protected]
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-${{ github.job }}-${{ env.JAVA_VERSION }}-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build
run: ./gradlew build -x test
- name: Cache Qodana dependencies
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'zulu'
cache: 'gradle'
java-version: 11
- name: Cache Gradle packages
uses: actions/[email protected]
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-${{ github.job }}-${{ matrix.java }}-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
distribution: 'zulu'
- name: Releasing
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.github.benmanes.caffeine.cache.testing.CacheValidationListener;
import com.github.benmanes.caffeine.cache.testing.CheckNoStats;
import com.github.benmanes.caffeine.testing.Int;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.primitives.Ints;
Expand Down Expand Up @@ -360,6 +361,20 @@ public void getAll_present_full(Cache<Int, Int> cache, CacheContext context) {
assertThat(context).stats().hits(result.size()).misses(0).success(0).failures(0);
}

@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches")
public void getAll_exceeds(Cache<Int, Int> cache, CacheContext context) {
var result = cache.getAll(Set.of(context.absentKey()), keys -> context.absent());

var expected = new ImmutableMap.Builder<Int, Int>()
.putAll(context.original())
.putAll(context.absent())
.build();
assertThat(cache).containsExactlyEntriesIn(expected);
assertThat(context).stats().hits(0).misses(result.size()).success(1).failures(0);
assertThat(result).containsExactlyEntriesIn(Map.of(context.absentKey(), context.absentValue()));
}

@Test(dataProvider = "caches")
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
removalListener = { Listener.DEFAULT, Listener.REJECTING })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.github.benmanes.caffeine.cache.testing.CacheContextSubject.assertThat;
import static com.github.benmanes.caffeine.cache.testing.CacheSubject.assertThat;
import static com.github.benmanes.caffeine.testing.Awaits.await;
import static com.github.benmanes.caffeine.testing.CollectionSubject.assertThat;
import static com.github.benmanes.caffeine.testing.FutureSubject.assertThat;
import static com.github.benmanes.caffeine.testing.IntSubject.assertThat;
import static com.github.benmanes.caffeine.testing.MapSubject.assertThat;
Expand Down Expand Up @@ -221,6 +222,17 @@ public void getAll_present_full(LoadingCache<Int, Int> cache, CacheContext conte
assertThat(context).stats().hits(result.size()).misses(0).success(0).failures(0);
}

@Test(dataProvider = "caches")
@CacheSpec(loader = { Loader.BULK_NEGATIVE_EXCEEDS },
removalListener = { Listener.DEFAULT, Listener.REJECTING })
public void getAll_exceeds(LoadingCache<Int, Int> cache, CacheContext context) {
var result = cache.getAll(context.absentKeys());

assertThat(result.keySet()).containsExactlyElementsIn(context.absentKeys());
assertThat(cache).hasSizeGreaterThan(context.initialSize() + context.absentKeys().size());
assertThat(context).stats().hits(0).misses(result.size()).success(1).failures(0);
}

@Test(dataProvider = "caches")
@CacheSpec(loader = { Loader.NEGATIVE, Loader.BULK_NEGATIVE },
population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public Map<Int, Int> absent() {
return absent;
}
absent = new LinkedHashMap<>();
absent.put(absentKey(), absentValue());
do {
Int key = nextAbsentKey();
absent.put(key, key.negate());
Expand Down

0 comments on commit a681c68

Please sign in to comment.