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

Error running Panache Reactive Test with IntelliJ JUnit template #15131

Closed
hernael opened this issue Feb 16, 2021 · 33 comments
Closed

Error running Panache Reactive Test with IntelliJ JUnit template #15131

hernael opened this issue Feb 16, 2021 · 33 comments
Labels
area/panache kind/bug Something isn't working
Milestone

Comments

@hernael
Copy link

hernael commented Feb 16, 2021

Describe the bug
Since 1.11.x Quarkus version, the Test in IntelliJ fail.
In 1.10.5 work fine.

Actual behavior
when run Panache Reactive Test with IntelliJ JUnit template throws the following error:

java.lang.AssertionError: This needs to be run on the Vert.x event loop

	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.<init>(ReactiveSessionImpl.java:129)
	at org.hibernate.reactive.mutiny.impl.MutinySessionFactoryImpl.openSession(MutinySessionFactoryImpl.java:67)
	at io.quarkus.hibernate.reactive.runtime.ReactiveSessionProducer.createMutinySession(ReactiveSessionProducer.java:32)
	at io.quarkus.hibernate.reactive.runtime.ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_Bean.create(ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_Bean.zig:259)
	at io.quarkus.hibernate.reactive.runtime.ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_Bean.create(ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_Bean.zig:297)
	at io.quarkus.arc.impl.RequestContext.getIfActive(RequestContext.java:68)
	at io.quarkus.arc.impl.ClientProxies.getDelegate(ClientProxies.java:33)
	at io.quarkus.hibernate.reactive.runtime.ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_ClientProxy.arc$delegate(ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_ClientProxy.zig:61)
	at io.quarkus.hibernate.reactive.runtime.ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_ClientProxy.createQuery(ReactiveSessionProducer_ProducerMethod_createMutinySession_1321d110ee9e92bda147899150401e0a136779c7_ClientProxy.zig:1129)
	at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.createBaseQuery(CommonPanacheQueryImpl.java:299)
	at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.createQuery(CommonPanacheQueryImpl.java:247)
	at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.list(CommonPanacheQueryImpl.java:218)
	at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.stream(CommonPanacheQueryImpl.java:226)
	at io.quarkus.hibernate.reactive.panache.runtime.PanacheQueryImpl.stream(PanacheQueryImpl.java:154)
	at io.quarkus.hibernate.reactive.panache.runtime.JpaOperations.stream(JpaOperations.java:28)
	at io.quarkus.hibernate.reactive.panache.runtime.JpaOperations.stream(JpaOperations.java:11)
	at io.quarkus.hibernate.reactive.panache.common.runtime.AbstractJpaOperations.streamAll(AbstractJpaOperations.java:240)
	at com.demo.repository.reactive.panache.CurrencyPanacheRepository.streamAll(CurrencyPanacheRepository.java)
	at com.demo.repository.reactive.panache.CurrencyPanacheRepository.getAll(CurrencyPanacheRepository.java:35)
	at com.demo.repository.reactive.panache.CurrencyPanacheRepository_ClientProxy.getAll(CurrencyPanacheRepository_ClientProxy.zig:1208)
	at com.demo.repository.reactive.panache.CurrencyRatePanacheRepositoryTest.insert(CurrencyRatePanacheRepositoryTest.java:85)
	at com.demo.repository.reactive.panache.CurrencyRatePanacheRepositoryTest.basicCRUD(CurrencyRatePanacheRepositoryTest.java:36)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:807)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:714)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:114)

2021-02-16 17:49:04,936 INFO  [io.quarkus] (main) currency stopped in 0.023s

To Reproduce
Just create a test to a Reactive Panache Repository and run it with IntelliJ JUnit template

Environment (please complete the following information):

  • Output of uname -a or ver: Linux 5.3.18-lp152.60-default x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (build 11.0.10+9-LTS, mixed mode)
  • Quarkus version or git rev: 1.11.x
  • Build tool (ie. output of mvnw --version or gradlew --version): 3.6.3
@hernael hernael added the kind/bug Something isn't working label Feb 16, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 16, 2021

/cc @FroMage, @loicmathieu

@FroMage
Copy link
Member

FroMage commented Feb 17, 2021

This must be related to the changes in HR where we mandate access from the IO thread, but I don't understand why this would have passed CI, there's no reason why running from the CLI should behave differently to running from the IDE.

@geoand
Copy link
Contributor

geoand commented Feb 17, 2021

I just tried this on our hibernate-reactive-quickstart and it worked just fine.

Can you share a sample project that exhibits the problematic behavior please?

@FroMage
Copy link
Member

FroMage commented Feb 17, 2021

The quickstart runs from an IO thread, no? This is when running directly from a @Test method, no?

@geoand
Copy link
Contributor

geoand commented Feb 17, 2021

I guess (by just looking at the stacktrace), but that is why I would like to have a project that exhibits the behavior.

@FroMage
Copy link
Member

FroMage commented Feb 17, 2021

Oh, I thought this was our CI tests.

OK, then I bet this is becaue our CI tests run this in a transaction and then block waiting for them, which makes them run on the IO thread, because we can do this for transactions.

@geoand
Copy link
Contributor

geoand commented Feb 17, 2021

Right, that makes sense.

If we have an example of what OP is trying to do, at the very least we need to document what the expected behavior is

@hernael
Copy link
Author

hernael commented Feb 17, 2021

Hi, please note here:

https://github.com/hernael/reactive-demo

I create a test call RepositoryTest with 2 methods.
Both methods fail in IntellIJ 2020.3

@FroMage
Copy link
Member

FroMage commented Feb 17, 2021

Yes, that's it. Can you try using Panache.withTransaction() around the call in your test?

@hernael
Copy link
Author

hernael commented Feb 17, 2021

I just tried like this:

    @Test
    void getFirstBlocking() {
        var response = Panache.withTransaction(() -> repository.getFirst()).await().indefinitely();

        assertNotNull(response);
    }

    @Test
    void getFirst() {
        var response = Panache.withTransaction(() -> repository.getFirst());

        UniAssertSubscriber<Entity> subscriber = response
                .subscribe().withSubscriber(UniAssertSubscriber.create());

        subscriber.assertCompleted().assertTerminated();
    }

but they still keep failing

@FroMage
Copy link
Member

FroMage commented Feb 17, 2021

getFirst will likely fail because it's not waiting. but getFirstBlocking should work…

@hernael
Copy link
Author

hernael commented Feb 17, 2021

running them both together in Intellij fails, or running one by one also fail :(

@geoand
Copy link
Contributor

geoand commented Feb 18, 2021

Can you provide the docker run you are using to start postgresql so we can try your example?

@hernael
Copy link
Author

hernael commented Feb 18, 2021

I use a simple postgres:13.1-alpine image, My data inside this image is very heavy, so i can't share it.

But come on! it's a simple table demo with id and description fields. You can use any table

@geoand
Copy link
Contributor

geoand commented Feb 18, 2021

The issue is that anyone on the team has to run plenty of such examples everyday, so spending time trying to figure out how to run each different one, is not a very productive use of our time.
I spent a couple minutes on this and when my second attempt at running didn't work, that was enough to ask for a docker command.
I don't care about the data, what I care about is having a database up that has the necessary tables

@hernael
Copy link
Author

hernael commented Feb 18, 2021

sorry but i can't provide what you request

@luce98
Copy link

luce98 commented Apr 6, 2021

I'm experiencing the same issue: some tests are failing with this same error after migrating from 10.5 to 11.
Does someone already have a workaround?

@hernael
Copy link
Author

hernael commented Apr 6, 2021

I have not migrated from version 1.10.5 to any later version (1.11.x, 1.12.x or 1.13.0) because I have problems with the test and reactive panache (#14709) in those versions :(

@luce98
Copy link

luce98 commented Apr 12, 2021

Hey everyone, I created a small demo to reproduce the issue; there is also the script to create the DB container, you just need to run that and then run the tests. Hope this can help!
You can find it here: https://github.com/avimedical/quarkus-reactive-demo

@FroMage
Copy link
Member

FroMage commented Apr 14, 2021

I'm trying to see if I can reproduce this in our ITs, but I'm running into this issue @DavideD:

Caused by: org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact org.hibernate.reactive:hibernate-reactive-core:jar:1.0.0.CR1.Vertx4 in central (https://repo.maven.apache.org/maven2)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:357)
	at io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver.resolveManagedDependencies(MavenArtifactResolver.java:269)
	... 46 more

Any idea how I can work around this?

@FroMage
Copy link
Member

FroMage commented Apr 14, 2021

It appears that if Session.withTransaction allows us to get scheduled on the IO thread, but getting a session requires the caller to be in an IO thread, we have a bootstrapping problem.

@DavideD
Copy link
Contributor

DavideD commented Apr 14, 2021

1..0.0.CR2 should be available on Maven Central now

@DavideD
Copy link
Contributor

DavideD commented Apr 14, 2021

@FroMage, it should have been already fixed: #16506

@FroMage
Copy link
Member

FroMage commented Apr 15, 2021

Thanks!

@FroMage
Copy link
Member

FroMage commented Apr 15, 2021

This is worse. Turns out the HR/Panache IT tests don't appear to even run ATM. I wonder why CI doesn't run them?

@gwenneg
Copy link
Member

gwenneg commented Apr 21, 2021

I have the same problem but without Panache. Running a query using Mutiny.Session from a @Test method fails in IntelliJ 2021.1 with Quarkus 1.13.2.Final. Everything's fine if the test is run without IntelliJ.

@geoand
Copy link
Contributor

geoand commented May 11, 2021

This is worse. Turns out the HR/Panache IT tests don't appear to even run ATM. I wonder why CI doesn't run them?

Which tests are you talking about?

@geoand
Copy link
Contributor

geoand commented May 11, 2021

For the benefit of testing, we should provide some kind of facility to allow the repository to be called from a non IO thread

@DavideD
Copy link
Contributor

DavideD commented May 11, 2021

If it helps, Vert.x Unit Testing for Junit 4 has a rule that helps running tests in a Vert.x Context: https://vertx.io/docs/vertx-unit/java/#_running_a_test_on_a_vert_x_context

An equivalent is missing for Junit 5.

@geoand
Copy link
Contributor

geoand commented May 11, 2021

That's very interesting, thanks!

@geoand
Copy link
Contributor

geoand commented Jul 26, 2021

This has likely been fixed in #17728 which is part of 2.1.0.CR1. Can you please check so we can close the issue if so, or else see what else needs to be done?

@DavideD
Copy link
Contributor

DavideD commented Jul 29, 2021

I've just tested this with the latest snapshots and it seems to work without errors now.

I had to change a couple of tests from:

        subscriber.assertCompleted().assertTerminated();

to

        subscriber.awaitItem().assertCompleted().assertTerminated();

But the Vert.x exception doesn't occur anymore

@geoand
Copy link
Contributor

geoand commented Jul 29, 2021

Thanks for checking!

I'll close this based on that information. If this comes up again, feel free to reopen

@geoand geoand closed this as completed Jul 29, 2021
@geoand geoand added this to the 2.1.0.CR1 milestone Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants