Horreum icon indicating copy to clipboard operation
Horreum copied to clipboard

IllegalStateException: No RESTEasy Reactive request in progress when Injecting TestService for testing

Open willr3 opened this issue 11 months ago • 2 comments

I tried to add:

@Inject
TestService testService;
...
      List<ExportedLabelValues> elvs = testService.labelValues(t.id,"","","",true,true,"start","Ascending",Integer.MAX_VALUE,1,Arrays.asList("labelFoo"),Collections.emptyList());

To the TestServiceTest but it throws an exception when trying to run in intellij

java.lang.IllegalStateException: No RESTEasy Reactive request in progress

	at org.jboss.resteasy.reactive.server.injection.ContextProducers.getContext(ContextProducers.java:149)
	at org.jboss.resteasy.reactive.server.injection.ContextProducers.uriInfo(ContextProducers.java:46)
	at org.jboss.resteasy.reactive.server.injection.ContextProducers_ProducerMethod_uriInfo_LhPIxmZHFcGo50FiGi9PStr8B5U_Bean.doCreate(Unknown Source)
	at org.jboss.resteasy.reactive.server.injection.ContextProducers_ProducerMethod_uriInfo_LhPIxmZHFcGo50FiGi9PStr8B5U_Bean.create(Unknown Source)
	at org.jboss.resteasy.reactive.server.injection.ContextProducers_ProducerMethod_uriInfo_LhPIxmZHFcGo50FiGi9PStr8B5U_Bean.create(Unknown Source)
	at io.quarkus.arc.impl.RequestContext$1.get(RequestContext.java:79)
	at io.quarkus.arc.impl.RequestContext$1.get(RequestContext.java:75)
	at io.quarkus.arc.generator.Default_jakarta_enterprise_context_RequestScoped_ContextInstances.c16(Unknown Source)
	at io.quarkus.arc.generator.Default_jakarta_enterprise_context_RequestScoped_ContextInstances.computeIfAbsent(Unknown Source)
	at io.quarkus.arc.impl.RequestContext.getIfActive(RequestContext.java:75)
	at io.quarkus.arc.impl.ClientProxies.getSingleContextDelegate(ClientProxies.java:28)
	at jakarta.ws.rs.core.ContextProducers_ProducerMethod_uriInfo_LhPIxmZHFcGo50FiGi9PStr8B5U_ClientProxy.arc$delegate(Unknown Source)
	at jakarta.ws.rs.core.ContextProducers_ProducerMethod_uriInfo_LhPIxmZHFcGo50FiGi9PStr8B5U_ClientProxy.getQueryParameters(Unknown Source)
	at io.hyperfoil.tools.horreum.server.TokenInterceptor.wrap(TokenInterceptor.java:38)
	at io.hyperfoil.tools.horreum.server.TokenInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext$NextAroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:97)
	at io.hyperfoil.tools.horreum.server.RolesInterceptor.intercept(RolesInterceptor.java:53)
	at io.hyperfoil.tools.horreum.server.RolesInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext$NextAroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:97)
	at io.quarkus.security.runtime.interceptor.SecurityHandler.handle(SecurityHandler.java:47)
	at io.quarkus.security.runtime.interceptor.PermitAllInterceptor.intercept(PermitAllInterceptor.java:23)
	at io.quarkus.security.runtime.interceptor.PermitAllInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:62)
	at io.quarkus.resteasy.reactive.server.runtime.StandardSecurityCheckInterceptor.intercept(StandardSecurityCheckInterceptor.java:44)
	at io.quarkus.resteasy.reactive.server.runtime.StandardSecurityCheckInterceptor_PermitAllInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:30)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:27)
	at io.hyperfoil.tools.horreum.svc.TestServiceImpl_Subclass.get(Unknown Source)
	at io.hyperfoil.tools.horreum.svc.TestServiceImpl.labelValues(TestServiceImpl.java:557)
	at io.hyperfoil.tools.horreum.svc.TestServiceImpl_Subclass.labelValues$$superforward(Unknown Source)
	at io.hyperfoil.tools.horreum.svc.TestServiceImpl_Subclass$$function$$10.apply(Unknown Source)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:73)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext$NextAroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:97)
	at io.hyperfoil.tools.horreum.server.RolesInterceptor.intercept(RolesInterceptor.java:53)
	at io.hyperfoil.tools.horreum.server.RolesInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:62)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:136)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:107)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:38)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:61)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:32)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:30)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:27)
	at io.hyperfoil.tools.horreum.svc.TestServiceImpl_Subclass.labelValues(Unknown Source)
	at io.hyperfoil.tools.horreum.svc.TestServiceTest.labelValues_include(TestServiceTest.java:454)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:1013)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:827)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

willr3 avatar Mar 22 '24 15:03 willr3

That PR had the wrong issue number. this is still an open issue

willr3 avatar Mar 25 '24 16:03 willr3

I run into similar issue and after quick investigation I think the issue is that the methods you are trying to run are annoted with @WithToken and @WithRoles whose interceptor assume that a context request is existing.

Thus, I think this could be an issue for other tests as well, we should probably mock or find a way to ignore those interceptors on testing (as not really needed in most of the test cases).

lampajr avatar Apr 08 '24 14:04 lampajr