Dropwizard: Testing async request using ResourceTestRule

Created on 4 Jun 2015  路  2Comments  路  Source: dropwizard/dropwizard

Hello,
I am setting up testing my rest endpoints with ResourceTestRule. With jersey api I am able to get the Future<Response> object from the async().post(Entity) call, but then got the below warning:

WARN  [2015-06-04 10:46:47,508] org.glassfish.jersey.test.inmemory.InMemoryConnector: Asynchronous server side invocations are not supported by InMemoryContainer.

and the test keep hanging. This Warning seems to be coming from jersey org.glassfish.jersey.test.inmemory.InMemoryConnector is there any plan for tackling this so async request could work with InMemoryConnector? Or any resource we can look at while this is not available yet.

Thanks,

Most helpful comment

Looks like InMemoryConnector doesn't support endpoints that can be suspended and are async, so a new testing container is needed. You may need to try out the Grizzly test web server. I was able to swap it out and have my test cases pass.

First you'll need to look up how to import the Grizzly test web server in your pom (see the Dropwizard documentation on testing resources

Here's the code for swapping:

@Rule
public final ResourceTestRule resources = ResourceTestRule.builder()
        .addResource(new HelloWorldResource())
        .setTestContainerFactory(new GrizzlyWebTestContainerFactory())
        .build();

and instead of calling resources.client().target(/*...*/), you want resources.getJerseyTest().target(/*...*/)

Let me know if this works.

All 2 comments

Looks like InMemoryConnector doesn't support endpoints that can be suspended and are async, so a new testing container is needed. You may need to try out the Grizzly test web server. I was able to swap it out and have my test cases pass.

First you'll need to look up how to import the Grizzly test web server in your pom (see the Dropwizard documentation on testing resources

Here's the code for swapping:

@Rule
public final ResourceTestRule resources = ResourceTestRule.builder()
        .addResource(new HelloWorldResource())
        .setTestContainerFactory(new GrizzlyWebTestContainerFactory())
        .build();

and instead of calling resources.client().target(/*...*/), you want resources.getJerseyTest().target(/*...*/)

Let me know if this works.

@nickbabcock thanks this works! I have tried to work around by overloading the suspend method in InMemoryConnector but seems Grizzly test factory did the work already. Thanks again

Was this page helpful?
0 / 5 - 0 ratings