New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored mock cache to be non-blocking. #470
Conversation
Current coverage is 87.64%
|
cd210cc
to
330e8e9
Compare
generator = avoidingClassLeakageCache.putIfAbsent(new WeakKey<ClassLoader>(classLoader, this), newGenerator = new CachedBytecodeGenerator(mockBytecodeGenerator, weak)); | ||
if (generator == null) { | ||
generator = newGenerator; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change that code to one variable declaration per line. And I would avoid inline assignment too (the first newGenerator
is not needed before the if
).
Those too may confuse most readers.
330e8e9
to
0ff47d4
Compare
return (Class<T>) generatedMockClass; | ||
} finally { | ||
avoidingClassLeakCacheLock.unlock(); | ||
void pollAndClearReferences() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like a comment on this, or maybe rename it better (I'm thinking loudly).
Not everyone knows ReferenceQueue
or how it works, and thus why we need to invoke this method upon get(...)
.
Ideas welcome.
Looks good codewise. |
0ff47d4
to
2cb54f2
Compare
2cb54f2
to
fabed34
Compare
LGTM |
The previous cache used a lock to unify concurrency and weak references. Instead, keys are now explicitly wrapped using weak references and similarly to the functioning of a weak hash map, the entries are polled upon accessing the cache. This avoids blocking.