Hibernate-reactive: Investigate how to create a template for JBang to help with bug reports

Created on 23 Apr 2021  ·  31Comments  ·  Source: hibernate/hibernate-reactive

See https://github.com/jbangdev/jbang#init-templates

It would be nice if users could generate a basic test project using JBang so that they have a quick way to start creating a project for reproducing the issue they are having.

I haven't checked if this is feasible or helpful yet. In my head it should make it even easier than cloning a template from our repository.

testing

All 31 comments

@maxandersen already played with this. What he didn't like, and what might also be a problem here, is that he couldn't easily use a testcontainers database.

It works but yeah users would need to manually setup the database.

But so should users using more complex setups :)

What you can do is to have the jbang script setup via test containers manually rather than using the jdbc url magic which does not work (yet) with hibernate reactive.

I did look briefly at making the testcontainers bootstrap code in our test suite reusable, but it wasn't going to be that trivial.

I mean... testcontainers is a great tool... but I'm going out on a limb here and say that we can expect people using Hibernate Reactive (or ORM) to be able to start a db without it :-)

It's certainly not a deal breaker to me, most of the boring part is really the configuration of the project. If I have to start a db launching a script manually before being able to run the main of the app, it would already be a great improvement.

Sure, that's fine. But it's a nice-to-have.

Thinking about it, we probably don't even need a template to begin with, we could provide a java file with all the dependencies needed for JBang to run it.

I figured by "template" you were hoping to parameterize by database type.

I was talking about a JBang template, something that would allow the user to write:

jbang init --template=hibernate-reactive Issue456.java

but I guess this would also be possible:

jbang init --template=hibernate-reactive-db2 Issue456.java

Now I think we could achieve the same result providing a single file (or one per database) so that a user can run it with:

jbang HReactiveWithDb2.java

With the caveat that a Db2 instance with the right credentials must be already running.

Then they could start editing it with:

 jbang edit --open=idea  HReactiveWithDb2.java

We can think of ways to add all the bells and whistles we want, but this would be a good starting point for me.

In my previous example, HReactiveWithDb2.java is somewhere on our GitHub repository and a user has to download it first.

Although, I expect JBang to have some way to run something like:

jbang https://github.com/hibernate/hibernate-reactive/HReactiveWithDb2.java

Well jbang templates have some sort of support for parameters AFAIU, and I think that should be enough to say switch in a certain persistence.xml file.

Sure, sounds great.

Very interesting!

One additional thing that maybe you want to consider: very often Quarkus users are encouraged to create a "reproducer project" but in most cases this then ends up being something I have to re-adapt into a real integration test to be merged in Quarkus mainline.

I do wonder if we could structure our "reproducers" in such a way that it could be automatically promoted into a new integration test.

You can have the "main" class be basically a junit test runner that runs classes with @Test in it.

Btw. If Properties / qute template is not enough / not working let me know. The init templates are new so if you find things missing I Can easily fix/release new jbang.

@maxanderson I'm able to add templates and init with them thx!

I'm looking at our hibernate-reactive examples which use the entity manager factory and persistence.xml and separate entity classes. The tests chain multiple transactions by waiting indefinitely. All of our HR JUnit tests use chained CompletionStage's as opposed to the single session transactions used in our examples.

JBang features allow attaching resources (entity classes and persistence.xml) on the add (or registration) process which will be included in the Jbang template registry. This will result in a copy of those entities will be included in the project and build. So in theory, we can generate the Main.java and/or MutinyMain.java test classes and end up with something similar to these example directories.

Note there is another feature that uses .jsh script that allows setting user-defined parameters to be replaced in a template file. (alluded to earlier ^^^) but @MaxAndersen indicated they could be added to the JBang init command.

Questions:

  1. Is there a target hibernate-reactive user/customer and use case we're aiming for?

    • Based on the complexity, we may need to build/publish a hibernate-reactive-test to maven, which would need to be maintained
  2. Do we want to be able to test these generated tests against older or newer versions of HR & HR ORM?

    • The basic templates require dependencies (like future imports) that are pulled in during project build (example: //DEPS org.hibernate:hibernate-core:5.4.10.Final)
    • This would help users define/document their build environment as part of the test generation
  3. Simple examples like we have now are still viable, of course.

I would suggest just doing the Simplest Thing That Could Possibly Work for now.

@blafond, here's your use case:
You are User and found this issue while using hibernate reactive in your
project : https://github.com/hibernate/hibernate-reactive/issues/702

You want to send us a reproducer without having to clone the whole
hibernate reactive project and without having to spend too much time on all
the scaffolding needed to create a brand new project. Ideally, with jbang,
you could just send us a single file and we could run it.

Use ORM 5.4, the default, for now.
Not sure why we need to worry about maven, but do what you think is right.

Don't worry about CI, if it's easy for a user to run, it's easy for us to
add it to ci

On Wed, 5 May 2021, 21:48 Gavin King, @.*> wrote:

I would suggest just doing the Simplest Thing That Could Possibly Work for
now.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/hibernate/hibernate-reactive/issues/721#issuecomment-832997030,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAEIQ5JQIPGKCNFSHOWKCD3TMGVKTANCNFSM43OEZPUQ
.

Just to clarify, the issue was found using quarkus, but the reproducer
should only use hibernate reactive

On Thu, 6 May 2021, 10:51 Davide D'Alto, @.*> wrote:

@blafond, here's your use case:
You are User and found this issue while using hibernate reactive in your
project : https://github.com/hibernate/hibernate-reactive/issues/702

You want to send us a reproducer without having to clone the whole
hibernate reactive project and without having to spend too much time on all
the scaffolding needed to create a brand new project. Ideally, with jbang,
you could just send us a single file and we could run it.

Use ORM 5.4, the default, for now.
Not sure why we need to worry about maven, but do what you think is right.

Don't worry about CI, if it's easy for a user to run, it's easy for us to
add it to ci

On Wed, 5 May 2021, 21:48 Gavin King, @.*> wrote:

I would suggest just doing the Simplest Thing That Could Possibly Work
for now.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/hibernate/hibernate-reactive/issues/721#issuecomment-832997030,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAEIQ5JQIPGKCNFSHOWKCD3TMGVKTANCNFSM43OEZPUQ
.

@blafond, invariably, there will be bugs integrating with HR. For example, suppose Quarkus passes arguments to HR in the wrong order. This is not a use case that you need to be concerned about here. Integration bugs will need to be reproduced in some other way.

One way to make it easy for us to add a user's reproducer to a unit test is to have the template somehow extend BaseReactiveTest, so all we have to do is copy/paste into the test suite. I have no idea if that is the proper approach here. I'm just mentioning it as an example.

@maxandersen @gavinking What was the problem with JBang and testcontainers? It seems to work fine to me:

jbang https://github.com/DavideD/hibernate-reactive/blob/721-jbang-executable-test/tooling/jbang/SampleIssueTest.java

Yes if you set it up manually it works. Issue is it won't work by just setting the jdbc or similar url.

The problem is with the use of JDBC URLs containing tc:.

Ah, I remember now. We still have this issue open: https://github.com/hibernate/hibernate-reactive/issues/468

I think we have good starting point now and we can improve on it later.
In particular, when we have a solution for #468

is there a reason you don't have that jbang script available as a template so you can do

jbang init -t testcase@hibernate/hibernate-reactive mytest.java ?

No, not really, mainly because I'm still tweaking it and I find it easier to work when it's not a template.

But I'm not sure I understand the syntax you are using. What's testcase@hibernate/hibernate-reactive? Is it something that's been added to the catalog via jbang template add ... or does it refer to something else?

Would it be possible to refer to a github repository as the location of the template?

testcase is the template name found in jbang-catalog.

hibernate/hibernate-reactive maps to github.com/hibernate/hibernate-reactive.

so that is the github repository location.

Ah nice! I will try it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gavinking picture gavinking  ·  16Comments

yaakov-berkovitch picture yaakov-berkovitch  ·  16Comments

DavideD picture DavideD  ·  17Comments

akoufa picture akoufa  ·  30Comments

pqab picture pqab  ·  21Comments