-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Enable recursive updates to NamespacedHierarchicalStore #5231
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
Conversation
Co-authored-by: martinfrancois <[email protected]>
Co-authored-by: martinfrancois <[email protected]>
164169b to
708bb35
Compare
🔎 No tests executed 🔎🏷️ Commit: 5493055 Learn more about TestLens at testlens.app. |
46f2099 to
be7ab95
Compare
be7ab95 to
1808119
Compare
b0e3f2d to
3c5a571
Compare
|
@martinfrancois would you have time to review this? |
Sure @mpkorstanje, I'll have a look! |
marcphilipp
left a comment
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.
Thanks for codifying the concepts so clearly! 👍
...ngine/src/main/java/org/junit/platform/engine/support/store/NamespacedHierarchicalStore.java
Outdated
Show resolved
Hide resolved
…support/store/NamespacedHierarchicalStore.java Co-authored-by: Marc Philipp <[email protected]>
Users of the extension context may occasionally want to build a non-trivial object graph, of which the individual components are also stored in the extension context store. This naturally leads to a pattern where the store is updated recursively. For example:
While the backing
ConcurrentHashMapdoes not support recursive updates this does work asgetOrComputeIfAbsentdefers the recursive update until the after the map has been updated. This is not the case forcomputeIfAbsentwhich immediately calls the default creator. This poses a problem ascomputeIfAbsentis supposed to be a drop-in replacement forgetOrComputeIfAbsentwith better null and exception semantics.The solution is to defer the execution of the default value creator until after the map has been updated. This is handled by the
DeferredSupplierwhich uses aFutureTaskto support a nice separation of compute and get operations.Because there are some differences between both compute methods in how deferred values are to be handled, this PR introduces a
StoredValue.Value,.DeferredValueand.DeferredOptionalValuecontainers forput,getOrComputeIfAbsentandcomputeIfAbsentrespectively. This allows:DeferredOptionalValuecontaining an exception to be treated as absent ingetStoredValue.DeferredOptionalValuecontaining a a value to return its contents on evaluation.DeferredValueto throw an exception or returns its contents on evaluationValueto simply return its contents on evaluationThis PR does introduce a small change in behavior. Previously any of the concurrent callers of
getOrComputeIfAbsentcould be the one executing the default creator. This can now only be done by the caller that created the stored value that was actually inserted. I don't expect this will break anything.The PR is also slightly bigger than it needs to be.
StoredValue.Valuecould be replaced with.DeferredValue. But asDeferredValueonly exists to support a deprecated method, this makes for easier clean up in the future.Thanks to @martinfrancois who contributed the
CollidingKey,DeferredSupplierand several other useful concepts in #5209.Fixes: #5171
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations