Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2013 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4450991 to your computer and use it in GitHub Desktop.
Save anonymous/4450991 to your computer and use it in GitHub Desktop.
ClosedChannelException when using netty and resteasy with concurrent requests
//this is the testcase
class RestNodeStarterTest {
ResteasyDeployment deployment;
SomeApi someApi;
NettyJaxrsServer server;
@Before
public void setUp() {
someApi = new SomeApi();
deployment = new ResteasyDeployment();
deployment.setResources(Arrays.asList(someApi));
server = new NettyJaxrsServer();
server.setDeployment(deployment);
int port = 3000;
server.setPort(port);
server.start();
}
@Test
//dummy test to make the server stand still
public void testBasicFlow() throws Exception {
//when i execute the request with curl it seems fine
//curl --include http://127.0.0.1:3000/api/1234
Thread.sleep(100000)
//but when i use ab tool for more requests, i get the java.nio.channels.ClosedChannelException
//ab -n 100 -c 1 http://127.0.0.1:3000/api/1234
}
@After
public void tearDown() {
server.stop()
}
}
//this is the rest resource
@Path("/")
public class SomeApi {
@GET
@Path("api/{someValue}")
public Response getSomeStuff(@PathParam("someValue") String someValue) {
return Response.status(200).entity("Parameter is: " + someValue).build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment