Source:
<code>public void testasync2() throws Exception { <START> Client client = ResteasyClientBuilder.newClient(); <END> Response response = null; AsynchronousDispatcher dispatcher = getDispatcher(server); dispatcher.setMaxCacheSize(1); latch = new CountDownLatch(1); Builder builder = client.target("http://localhost:" + TestPortProvider.getPort() + "?asynch=true").request(); response = builder.post(Entity.entity("content", "text/plain")); Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); String jobUrl1 = response.getHeaderString(HttpHeaders.LOCATION); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); response.close(); latch = new CountDownLatch(1); response = builder.post(Entity.entity("content", "text/plain")); Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); String jobUrl2 = response.getHeaderString(HttpHeaders.LOCATION); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); Assert.assertTrue(!jobUrl1.equals(jobUrl2)); response.close(); builder = client.target(jobUrl1).request(); response = builder.get(); Assert.assertEquals(HttpServletResponse.SC_GONE, response.getStatus()); response.close(); Thread.sleep(1000); builder = client.target(jobUrl2).request(); response = builder.get(); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("content", response.readEntity(String.class)); response = builder.delete(); Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus()); response = builder.get(); Assert.assertEquals(HttpServletResponse.SC_GONE, response.getStatus()); response.close(); }</code><technical_language>Close client () :-)</technical_language>

Target:
public void testasync2() throws Exception { Response response = null; AsynchronousDispatcher dispatcher = getDispatcher(server); dispatcher.setMaxCacheSize(1); latch = new CountDownLatch(1); Builder builder = client.target("http://localhost:" + TestPortProvider.getPort() + "?asynch=true").request(); response = builder.post(Entity.entity("content", "text/plain")); Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); String jobUrl1 = response.getHeaderString(HttpHeaders.LOCATION); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); response.close(); latch = new CountDownLatch(1); response = builder.post(Entity.entity("content", "text/plain")); Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); String jobUrl2 = response.getHeaderString(HttpHeaders.LOCATION); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); Assert.assertTrue(!jobUrl1.equals(jobUrl2)); response.close(); builder = client.target(jobUrl1).request(); response = builder.get(); Assert.assertEquals(HttpServletResponse.SC_GONE, response.getStatus()); response.close(); Thread.sleep(1000); builder = client.target(jobUrl2).request(); response = builder.get(); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("content", response.readEntity(String.class)); response = builder.delete(); Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus()); response = builder.get(); Assert.assertEquals(HttpServletResponse.SC_GONE, response.getStatus()); response.close(); }