Skip to content
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

Hibernate Reactive Panache guide missing documentation on @TestReactiveTransaction #20521

Closed
edeandrea opened this issue Oct 4, 2021 · 18 comments · Fixed by #22989
Closed

Hibernate Reactive Panache guide missing documentation on @TestReactiveTransaction #20521

edeandrea opened this issue Oct 4, 2021 · 18 comments · Fixed by #22989
Assignees
Labels
area/hibernate-reactive Hibernate Reactive area/panache area/persistence OBSOLETE, DO NOT USE kind/enhancement New feature or request
Milestone

Comments

@edeandrea
Copy link
Contributor

Describe the bug

The Quarkus Hibernate Reactive Panache guide does not have any information on the existence of the @TestReactiveTransaction annotation nor how to use it.

Maybe it doesn't belong in that guide because it isn't specific to Panache Reactive and its more generic to reactive transaction management. That being said, it still isn't discussed anywhere in the guides. I think, too, more is needed than a sentence or two just saying that its there. I think there need to be some examples that show how to use it.

Furthermore, the Tests and transactions section of the getting started testing guide is pretty weak. I think both need to be expanded on somewhere.

Maybe there needs to be a guide or something that talks about transaction management in general?

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@edeandrea edeandrea added the kind/bug Something isn't working label Oct 4, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 4, 2021

@quarkus-bot quarkus-bot bot added area/hibernate-reactive Hibernate Reactive area/panache area/persistence OBSOLETE, DO NOT USE labels Oct 4, 2021
@loicmathieu
Copy link
Contributor

There is a transaction guide and as you said, there is a section in the testing guide about @TestTransaction, the reactive counterpart should be listed here.

@gsmet
Copy link
Member

gsmet commented Jan 5, 2022

@DavideD could you have a look at this one? It looks like something we could quickly fix and be done with.

@gsmet gsmet added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Jan 5, 2022
@DavideD
Copy link
Contributor

DavideD commented Jan 6, 2022 via email

@DavideD
Copy link
Contributor

DavideD commented Jan 10, 2022

Can somebody assign this issue to me, please?

@loicmathieu
Copy link
Contributor

Done ;)

@DavideD
Copy link
Contributor

DavideD commented Jan 10, 2022

Thanks

@mkouba
Copy link
Contributor

mkouba commented Feb 23, 2022

Hm, it seems that when I use @TestReactiveTransaction in my test I can't use Uni.await() inside the test method anymore; it results in java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-15... So what's the idiomatic way of asserting some reactive code?

@mkouba
Copy link
Contributor

mkouba commented Feb 23, 2022

Ah, I've just found io.quarkus.test.junit.vertx.UniAsserter. Unfortunately, it seems to be undocumented.

@edeandrea
Copy link
Contributor Author

There are also some examples in the superheros sample app - https://github.com/quarkusio/quarkus-super-heroes/blob/main/rest-heroes/src/test/java/io/quarkus/sample/superheroes/hero/repository/HeroRepositoryTests.java

@DavideD
Copy link
Contributor

DavideD commented Feb 23, 2022

So what's the idiomatic way of asserting some reactive code?

You can use Vert.x unit: https://vertx.io/docs/vertx-unit/java/#_introduction

@DavideD
Copy link
Contributor

DavideD commented Feb 23, 2022

It integrates with JUnit: https://vertx.io/docs/vertx-unit/java/#_junit_integration

@edeandrea
Copy link
Contributor Author

Isnt @Rule from JUnit 4?

@edeandrea
Copy link
Contributor Author

edeandrea commented Feb 23, 2022

@mkouba to use @TestReactiveTransaction your test has to be non-blocking, which Uni.await() is inherently blocking.

If you want to go that route (or use the UniAssertSubscriber - some examples of that are in https://github.com/quarkusio/quarkus-super-heroes/blob/main/rest-heroes/src/test/java/io/quarkus/sample/superheroes/hero/service/HeroServiceTests.java) then you can't use the annotation and instead will have to implement your own cleanup within each test.

@DavideD
Copy link
Contributor

DavideD commented Feb 23, 2022

@edeandrea
Copy link
Contributor Author

Quarkus also has @RunOnVertxContext (for which I can't seem to find much documentation either).

@mkouba
Copy link
Contributor

mkouba commented Feb 23, 2022

to use @TestReactiveTransaction your test has to be non-blocking, which Uni.await() is inherently blocking.

I know but it's a bit confusing as you can do Uni.await() if no @TestReactiveTransaction is present, because the test method body is executed on the main thread and only the panache entity/repository operations is executed on the event loop (see also io.quarkus.hibernate.reactive.panache.common.runtime.AbstractJpaOperations.getSession()).

@FroMage
Copy link
Member

FroMage commented Mar 1, 2022

This looks like something we should document. I did run into the issue too myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-reactive Hibernate Reactive area/panache area/persistence OBSOLETE, DO NOT USE kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants