Skip to content

Testing maximumSize? #717

Discussion options

You must be logged in to vote

I am not really following the code to be certain what the question is. I think you are observing more than 500 entries cached, which is allowed temporarily by Caffeine.maximumSize javadoc to better cope with concurrency.

The cache defers eviction to the background executor, which by default is ForkJoinPool.commonPool(). In your case the test thread is likely running before the maintenance kicks in. If you use Caffeine.executor(Runnable::run) then it will run on the caller. The cache's own operations are inexpensive, but due to user callbacks we can't know those penalties. Since usually one does not inspect the cache this is a good default, but can be annoying for tests.

The Testing wiki p…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Blackbaud-JasonBodnar
Comment options

You must be logged in to vote
1 reply
@ben-manes
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants