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

MockHeroProxy doesn't work with 2.14 #199

Closed
agoncal opened this issue Nov 15, 2022 · 16 comments
Closed

MockHeroProxy doesn't work with 2.14 #199

agoncal opened this issue Nov 15, 2022 · 16 comments

Comments

@agoncal
Copy link
Collaborator

agoncal commented Nov 15, 2022

@cescoffier now that the HeroResource uses reactive mode, mocking doesn't seem to work. In our documentation we use the same mocking mecanism for imperative and reactive:

@Mock
@ApplicationScoped
@RestClient
public class MockHeroProxy implements HeroProxy { ... }

But when executing the tests, we get the following error:

15:35:23 ERROR [io.qu.ve.ht.ru.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /api/fights/randomfighters failed, error id: a1a10024-7c79-4911-925c-da8a203f537c-1: javax.ws.rs.ProcessingException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:8083
        at org.jboss.resteasy.reactive.client.handlers.ClientSendRequestHandler$3.accept(ClientSendRequestHandler.java:217)
        at org.jboss.resteasy.reactive.client.handlers.ClientSendRequestHandler$3.accept(ClientSendRequestHandler.java:209)
        at io.smallrye.context.impl.wrappers.SlowContextualConsumer.accept(SlowContextualConsumer.java:21)
        at io.smallrye.mutiny.helpers.UniCallbackSubscriber.onFailure(UniCallbackSubscriber.java:65)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at org.jboss.resteasy.reactive.client.AsyncResultUni.lambda$subscribe$1(AsyncResultUni.java:37)
        at io.vertx.core.impl.future.FutureImpl$3.onFailure(FutureImpl.java:153)
        at io.vertx.core.impl.future.FutureBase.lambda$emitFailure$1(FutureBase.java:69)
        at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:86)
        at io.vertx.core.impl.DuplicatedContext.execute(DuplicatedContext.java:163)
        at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:66)
        at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
        at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23)
        at io.vertx.core.http.impl.HttpClientImpl.lambda$doRequest$6(HttpClientImpl.java:658)
        at io.vertx.core.net.impl.pool.Endpoint.lambda$getConnection$0(Endpoint.java:52)
        at io.vertx.core.http.impl.SharedClientHttpStreamEndpoint$Request.handle(SharedClientHttpStreamEndpoint.java:162)
        at io.vertx.core.http.impl.SharedClientHttpStreamEndpoint$Request.handle(SharedClientHttpStreamEndpoint.java:123)
        at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55)
        at io.vertx.core.impl.ContextBase.emit(ContextBase.java:239)
        at io.vertx.core.net.impl.pool.SimpleConnectionPool$ConnectFailed$1.run(SimpleConnectionPool.java:384)
        at io.vertx.core.net.impl.pool.CombinerExecutor.submit(CombinerExecutor.java:50)
        at io.vertx.core.net.impl.pool.SimpleConnectionPool.execute(SimpleConnectionPool.java:245)
        at io.vertx.core.net.impl.pool.SimpleConnectionPool.lambda$connect$2(SimpleConnectionPool.java:259)
        at io.vertx.core.http.impl.SharedClientHttpStreamEndpoint.lambda$connect$2(SharedClientHttpStreamEndpoint.java:104)
        at io.vertx.core.impl.future.FutureImpl$3.onFailure(FutureImpl.java:153)
        at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
        at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
        at io.vertx.core.impl.future.Composition$1.onFailure(Composition.java:66)
        at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
        at io.vertx.core.impl.future.FailedFuture.addListener(FailedFuture.java:98)
        at io.vertx.core.impl.future.Composition.onFailure(Composition.java:55)
        at io.vertx.core.impl.future.FutureBase.emitFailure(FutureBase.java:75)
        at io.vertx.core.impl.future.FutureImpl.tryFail(FutureImpl.java:230)
        at io.vertx.core.impl.future.PromiseImpl.tryFail(PromiseImpl.java:23)
        at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55)
        at io.vertx.core.impl.ContextBase.emit(ContextBase.java:239)
        at io.vertx.core.net.impl.NetClientImpl.failed(NetClientImpl.java:320)
        at io.vertx.core.net.impl.NetClientImpl.lambda$connectInternal2$5(NetClientImpl.java:288)
        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:552)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
        at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
        at io.netty.util.concurrent.DefaultPromise.setFailure(DefaultPromise.java:109)
        at io.vertx.core.net.impl.ChannelProvider.lambda$handleConnect$0(ChannelProvider.java:160)
        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
        at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
        at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:321)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:337)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:833)
@cescoffier
Copy link
Member

Shouldn't you use @InjectMock ?

@agoncal
Copy link
Collaborator Author

agoncal commented Nov 15, 2022

Shouldn't you use imperative code and use Loom ? ;o)

@cescoffier
Copy link
Member

I mean, the stack trace indicates that it's not a mock. So the mock is not configured.

When using the rest client, I only use @InjectMock, and not @mock.

@cescoffier
Copy link
Member

Unfortunately it will have to wait my weekend nightshift.

@cescoffier
Copy link
Member

@agoncal how can I reproduce that issue from this repo?

@cescoffier
Copy link
Member

@Typed(VillainProxy.class) and @Typed(HeroProxy.class) are required, or your mock is just exposed as Mock(Villain|Hero)Proxy.

Now, this seems to be a change in Quarkus CDI/Arc resolution. Let's ask the CDI expert

\CC @geoand @mkouba

@cescoffier
Copy link
Member

Also, I don't know what we should recommend now: @InjectMock which will let you configure the mock in your test, or @Mock which is just a stereotype for an alternative bean.

@mkouba
Copy link

mkouba commented Nov 16, 2022

How do I reproduce the problem? The stack trace is not very useful.

@Typed(VillainProxy.class) and @Typed(HeroProxy.class) are required, or your mock is just exposed as Mock(Villain|Hero)Proxy.

I think that this could be another problem related to quarkusio/quarkus#28429. @manovotn Could it be fixed with quarkusio/quarkus#29155?

Also, I don't know what we should recommend now: @InjectMock which will let you configure the mock in your test, or @mock which is just a stereotype for an alternative bean.

It depends. AFAIK @InjectMock and io.quarkus.test.junit.QuarkusMock can only be used for normal scoped beans. @Mock can be used for any bean. @InjectMock is on the other hand very convenient.

@cescoffier
Copy link
Member

@mkouba

  1. clone the repo
  2. run the test from the rest-fight-service; you will get a failure
  3. using @Typed fixed the issue (I figured that myself, becoming a CDI 🦸)

@manovotn
Copy link

I think that this could be another problem related to quarkusio/quarkus#28429. @manovotn Could it be fixed with quarkusio/quarkus#29155?

Yes, this could be it. I recall the fix was also related to mocking.

using @typed fixed the issue (I figured that myself, becoming a CDI superhero)

Yeah, that's a way to go!

@cescoffier cescoffier changed the title MockHeroProxy doesn't work in reactive mode MockHeroProxy doesn't work with 2.14 Nov 16, 2022
@manovotn
Copy link

Yes, this could be it. I recall the fix was also related to mocking.

@agoncal @mkouba @cescoffier this issue is gone when I use 999-SNAPSHOT and run that test.
I think we can close this issue unless there are some objections.

@geoand
Copy link
Collaborator

geoand commented Nov 17, 2022

this issue is gone when I use 999-SNAPSHOT and run that test.
I think we can close this issue unless there are some objections.

+1

@manovotn
Copy link

@geoand feel free to close it, seems I lack the permissions on this repo...

@geoand
Copy link
Collaborator

geoand commented Nov 17, 2022

I'll let @cescoffier have the final say :)

@cescoffier
Copy link
Member

Actually, it's more a question for @agoncal:

  1. the reported issue is a regression, which has already been fixed, but what do we do in the meantime
  2. I tend to prefer @InjectMock, but from a student POV it @mock might look simpler

@agoncal
Copy link
Collaborator Author

agoncal commented Jan 11, 2023

Fixed with #208

@agoncal agoncal closed this as completed Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants