-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add UUID to parsing for matching elements across instances #152
Conversation
This is a prototype of trying to tag parsed elements with unique IDs so that one could match them even if you `newBuilder`'d it, you could match back other elements that reference the now-old reference to them. This would allow for one to normalize references in a `Schema` after changing a bunch of elements in it, such as with a preprocessor to edit Schemas before code gen. If the implementation here looks good, I can proceed with figuring out how to update tests to handle this in a deterministic way
@benjamin-bader absolutely no CR expected for at least 3-4 weeks! Focus on your honeymoon :) |
Hm, the tests failed, but it's not immediately clear why. I'm guessing that the tests haven't been updated to account for the new UUID member, probably the AutoValue parser elements that would automatically include it in |
Yeah I haven't updated the tests yet, wanted to get a review of the API first before taking a crack at them |
API looks fine to me; it's what I'd do if I were implementing the feature, so no complaints here. |
Cool, I'll work on updating the tests then. My initial thinking is to basically add some way to set a seed to use for uuids for test-only purposes. Alternatively, we could make mark the uuid as transient to autovalue somehow so it's ignored, but not sure how nicely that plays with builders and whatnot. Will try some stuff |
This makes it more testable as well as flexible if others have their own needs. This could also be used to conceivably turn it off, if they don't care about it and want the slight perf gain
Codecov Report
@@ Coverage Diff @@
## master #152 +/- ##
============================================
- Coverage 65.45% 65.41% -0.05%
- Complexity 931 936 +5
============================================
Files 88 89 +1
Lines 4806 4843 +37
Branches 561 562 +1
============================================
+ Hits 3146 3168 +22
- Misses 1423 1437 +14
- Partials 237 238 +1
Continue to review full report at Codecov.
|
/** | ||
* Utility class to inject handlers to certain standard Thrifty operations. | ||
*/ | ||
public final class ThriftyParserPlugins { |
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.
Interesting, I must have missed this class the last time I looked at this PR. Why would you need something other than UUID::randomUUID
- for testing, it seems?
If so, and there aren't any larger plans for this class, have you considered simply adding a UUIDProvider
param to a ThriftParser
constructor, and making the parser itself responsible for assigning the UUIDs? It would mean also changing the autovalue factory functions for the parser elements, to add a UUID, but would have the benefit of being less stateful.
I think you might have deliberately decided against doing this, so I'm curious about why.
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 added it in this followup. The primary case is testing, but one could conceivably also use this to supply their own no-op version if they don't need it and want the slight perf boost from not calculating a random one.
I opted to make it a plugin setup because I wanted to have a simple static location for both simplicity in the parser's access as well as making it public for anyone creating/modifying their own types to use if they create their own (to keep things consistent). This is borrowed largely from RxJava's style of plugins
Thanks! For the PR, and for your patience seeing it through. |
Thanks! |
This is a prototype of trying to tag parsed elements with unique IDs so that one could match them even if you
newBuilder
'd it, you could match back other elements that reference the now-old reference to them. This would allow for one to normalize references in aSchema
after changing a bunch of elements in it, such as with a preprocessor to edit Schemas before code gen.If the implementation here looks good, I can proceed with figuring out how to update tests to handle this in a deterministic way