Skip to content

Commit

Permalink
Schedule on absent lookups if maintenance is required (fixed #420)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed May 19, 2020
1 parent 14e4474 commit 7239bb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,9 @@ public boolean containsValue(Object value) {
if (recordStats) {
statsCounter().recordMisses(1);
}
if (drainStatus() == REQUIRED) {
scheduleDrainBuffers();
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,23 @@ public void drain_onRead(Cache<Integer, Integer> cache, CacheContext context) {
assertThat(buffer.size(), is(0));
}

@Test(dataProvider = "caches")
@CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine,
population = Population.FULL, maximumSize = Maximum.FULL)
public void drain_onRead_absent(Cache<Integer, Integer> cache, CacheContext context) {
BoundedLocalCache<Integer, Integer> localCache = asBoundedLocalCache(cache);
Buffer<Node<Integer, Integer>> buffer = localCache.readBuffer;
localCache.get(context.firstKey());
assertThat(buffer.size(), is(1));

assertThat(localCache.get(context.absentKey()), is(nullValue()));
assertThat(buffer.size(), is(1));

localCache.drainStatus = REQUIRED;
assertThat(localCache.get(context.absentKey()), is(nullValue()));
assertThat(buffer.size(), is(0));
}

@Test(dataProvider = "caches")
@CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine,
population = Population.EMPTY, maximumSize = Maximum.FULL)
Expand Down

0 comments on commit 7239bb0

Please sign in to comment.