users@jersey.java.net

[Jersey] Issues with asynchronous resource handlers and integration tests

From: Mark Lehmacher <mark.lehmacher_at_gmail.com>
Date: Thu, 7 Aug 2014 16:46:52 +0200

Hello everyone,

I am currently develpoing a rest api using the following technology stack:

- Jersey 2.11
- Jetty
- rxJava
- Hystrix

All my resource handlers are implemented using @Suspended AsyncResponse.
Internally they subscribe to Observervables and only resume the response
after the Observervables yield their values of interest.

I also wrote integration tests using TestNG
and JerseyTestNg.ContainerPerClassTest. The integration test uses Jetty as
container and the synchronous Jersey HTTP Client.

When running a test which performs a single POST request, I can observe
ApplicationHandler#handle(ContainerRequest) being called several times with
different request objects (wrt identity), all encoding my single request.

As a direct result my POST handler (which is being tested) is also hit
multiple times (>10 times).

This only started happening when I switched from synchronous request
handlers implementations to asynchronous ones. The same integration tests
worked before.

Does anyone have any idea what I can try to fix this?

Thanks in advance!

Mark