-
Notifications
You must be signed in to change notification settings - Fork 23
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
Generate constants for JFR event type names and attributes #65
Comments
Hi, I'm not sure if this can be a solution but I created this POC https://github.com/Croway/jfrunit/tree/jfr-event-constants JfrUnitTest.shouldHaveGcAndSleepEvents contains the changes |
Hey @Croway, yeah, I think that looks pretty amazing! How did you do this, did you create some kind of code generator which produces all the constants? In terms of what to generate exactly, instead of String constants, how would you feel about a more typed approach; something like this:
With the right method signatures, the assertion API could then be fully type-safe:
It's just a rough sketch, but the idea would be that WDYT? |
Or maybe even this:
I.e. generate event descriptors with the right methods for all their attributes. Even easier to use actually. |
yes, you are right, it's much better in this way, and I don't think it will be to hard to implement, in order to generate classes I created a simple code generator with freemarker that gets all the events from https://bestsolution-at.github.io/jfr-doc/openjdk-17.json (luckly there is a json api 😄 ), once I'll do the changes I'll share the code generator. |
Hi @gunnarmorling I implemented your first comment solution, JfrUnit should be backwards compatible with the older version (since I had failures with groovy tests), right now all test passes but if you use Attribute instead of strings the compiler will help. This is the code generator app, https://github.com/Croway/jfr-constants-generator |
Very nice! So how would you like to proceed with this one? Moving the generator into the JfrUnit project? We may for instance run it as part of the JfrUnit build. WDYT? |
Sure, I can move the generator into the JfrUnit project, I don't know what is the best practice for this use case, run the generator as part of the build, or use it as a maven plugin. |
Yes, a Maven plug-in could work, or a simple annotation processor which
then would be invoked by the compiler. It's not 100% a use case for an AP
(given it's not reacting to any annotations within the JfrUnit code base),
but might still do the trick for integrating the generator into the
JfrUnit build (then also within IDEs for instance). Your call really :)
… |
I have created an annotation processor, you are right, not 100% a use case, but it works, these are the branches https://github.com/Croway/jfrunit/tree/jfr-event-cons-annotation-proc and https://github.com/Croway/jfr-constants-generator/tree/annotation-processor I think that we can proceed this way:
WDYT? |
I'd definitely prefer option a), making this a multi-module project. This will allow for quicker turnaround times after changes to the generator, and I think it just makes more sense to maintain everything in one place. |
On the style of the generated code, do you think the |
Hi @gunnarmorling, I pushed new commits into https://github.com/Croway/jfrunit/tree/jfr-event-cons-annotation-proc
|
Ok, that sounds great. I'd suggest you create a PR when you feel ready for it. Doesn't have to be polished yet, but it may help to discuss and converge on the overall approach (though I feel we're essentially there yet as per the discussion above). Thanks a lot! |
Allowing for a safe access to these literals in testing code.
The text was updated successfully, but these errors were encountered: