{
HttpClient client = new HttpClient();
{
latch = new CountDownLatch(1);
PostMethod method = createPostMethod("?asynch=true");
method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
long start = System.currentTimeMillis();
int status = client.executeMethod(method);
@SuppressWarnings("unused")
long end = System.currentTimeMillis() - start;
Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
String jobUrl = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
System.out.println("JOB: " + jobUrl);
GetMethod get = new GetMethod(jobUrl);
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
// there's a lag between when the latch completes and the executor
// registers the completion of the call
String existingQueryString = get.getQueryString();
get.setQueryString((existingQueryString == null ? "" : "&") + "wait=1000");
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_OK, status);
Assert.assertEquals(get.getResponseBodyAsString(), "content");
// test its still there
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_OK, status);
Assert.assertEquals(get.getResponseBodyAsString(), "content");
// delete and test delete
DeleteMethod delete = new DeleteMethod(jobUrl);
status = client.executeMethod(delete);
Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, status);
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_GONE, status);
method.releaseConnection();
}
{
dispatcher.setMaxCacheSize(1);
latch = new CountDownLatch(1);
PostMethod method = createPostMethod("?asynch=true");
method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
int status = client.executeMethod(method);
Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
String jobUrl1 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
latch = new CountDownLatch(1);
method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
status = client.executeMethod(method);
Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
String jobUrl2 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
Assert.assertTrue(!jobUrl1.equals(jobUrl2));
GetMethod get = new GetMethod(jobUrl1);
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_GONE, status);
// test its still there
get = new GetMethod(jobUrl2);
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_OK, status);
Assert.assertEquals(get.getResponseBodyAsString(), "content");
// delete and test delete
DeleteMethod delete = new DeleteMethod(jobUrl2);
status = client.executeMethod(delete);
Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, status);
status = client.executeMethod(get);
Assert.assertEquals(HttpServletResponse.SC_GONE, status);
method.releaseConnection();
}
// test readAndRemove
{
dispatcher.setMaxCacheSize(10);
latch = new CountDownLatch(1);
PostMethod method = createPostMethod("?asynch=true");
method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
int status = client.executeMethod(method);
Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
String jobUrl2 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));