running Rapidoid from JUnit - exception when handling async response
mzheravin opened this issue · comments
Maksim Zheravin commented
Hi!
When running rapidoid from JUnit (4 or 5) I'm getting following error for async requests. Sync handling works fine. Exception happens when calling done() method:
2019-08-13/21:07:49.230/EEST [Thread-9] ERROR o.r.h.impl.lowlevel.LowLevelHttpIO - Error occurred when handling request! | error = java.lang.IllegalArgumentException: The customization request (POST /syncAdminApi/v1/users) doesn't match the context request (null)!
java.lang.IllegalArgumentException: The customization request (POST /syncAdminApi/v1/users) doesn't match the context request (null)!
at org.rapidoid.u.U.illegal(U.java:443)
at org.rapidoid.u.U.must(U.java:476)
at org.rapidoid.http.customize.Customization.inValidContext(Customization.java:130)
at org.rapidoid.http.customize.Customization.of(Customization.java:121)
at org.rapidoid.http.impl.BodyRenderer.mediaResponseRenderer(BodyRenderer.java:91)
at org.rapidoid.http.impl.BodyRenderer.resultToRespBody(BodyRenderer.java:85)
at org.rapidoid.http.impl.BodyRenderer.createRespBodyFromResult(BodyRenderer.java:75)
at org.rapidoid.http.impl.BodyRenderer.toRespBody(BodyRenderer.java:41)
at org.rapidoid.http.impl.ReqImpl.renderResponse(ReqImpl.java:569)
at org.rapidoid.http.impl.ReqImpl.renderResponseOrError(ReqImpl.java:549)
at org.rapidoid.http.impl.ReqImpl.onDone(ReqImpl.java:524)
at org.rapidoid.http.impl.ReqImpl.done(ReqImpl.java:510)
at org.rapidoid.http.impl.RespImpl.done(RespImpl.java:294)
...
How I do async processing in the code:
in rapidoid handler thread:
- Resp resp = req.async()
- ... publish resp to processing pipeline...
- return resp
later from another thread:
- resp.code(..)
- resp.json(..)
- resp.done()
When running as standalone application, above approach works fine.
I have noticed that startup log is different when starting rapidoid from the junit, for some reason main=null:
INFO org.rapidoid.setup.App - Inferred application root | main = null | package = com.package.my
Many thanks!