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
openSession() return error "This needs to be run on the Vert.x event loop" #750
Comments
Hi, This is normally taken care of by Hibernate Reactive when one uses the Your tests aren't working because they run in a JUnit thread, and not a Vert.x one.
This will make sure that your tests run in a Vert.x context. This is not enough though, you also need to make sure that the session is bound to the same Vert.x context defined by the rule. VertxInstance service:In general, the way to achieve this is by creating a custom VertxInstance service. This service tells Hibernate Reactive how to get the correct Vert.x Instance to use when the session is created.
Alternatively, you can define it using the ServiceLoader mechanism of the JDK:
Now Hibernate Reactive will call an instance of Fixing the issue with JUnit 4:Getting back to the tests, one way to fix them would be:
If you are not using the rule, you can run code in a specific Vert.x context in the following way:
|
You should add what you just wrote as a FAQ to the website or wherever. |
Yes, I will |
@DavideD Very appreciate your explanation. Thanks. |
I've created an issue for keeping track of these changes to the documentation/website: #751 I'm going to close this issue. Feel free to ask more questions is something else is not clear. Thank you. |
@DavideD Is it possible to use the following code you mentioned earlier with JUnit 5?
|
Yes, that code is Vert.x, not JUnit. But there is not an equivalent extension for JUnit 5 of:
|
Hi,
till now Vertx was simply hidden from me while using Hibernate reactive API (1.0.0.CR4). But I have to expose an API to return a session that will be kept open until the client that use this API will decide to close it.
I'm running a Junit test, and I have the following API :
And in my junit test:
Stage.Session session = deviceRepository.openSession();
When I run the code I got the error:
This needs to be run on the Vert.x event loop
I tried to refactor the code in many different way but I didn't succeed to make it running.
Can you please give me your recommendation how to do it correctly ?
Thanks.
The text was updated successfully, but these errors were encountered: