@Test(timeOut = 25000)
public void testProgrammaticDelayBroadcast() {
logger.info("{}: running test: testDelayBroadcast", getClass().getSimpleName());
final CountDownLatch latch = new CountDownLatch(1);
AsyncHttpClient c = new AsyncHttpClient();
try {
final AtomicReference<Response> response = new AtomicReference<Response>();
c.prepareGet(urlTarget + "/forever").execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response r) throws Exception {
try {
response.set(r);
return r;
} finally {
latch.countDown();
}
}
});
// Let Atmosphere suspend the connections.
Thread.sleep(2500);
c.preparePost(urlTarget + "/programmaticDelayBroadcast").addParameter("message", "foo").execute().get();
c.preparePost(urlTarget + "/publishAndResume").addParameter("message", "bar").execute().get();
try {
latch.await(20, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail(e.getMessage());
}
Response r = response.get();
assertNotNull(r);
assertEquals(r.getResponseBody(), AtmosphereResourceImpl.createCompatibleStringJunk() + "foobar\n");
assertEquals(r.getStatusCode(), 200);
} catch (Exception e) {
logger.error("test failed", e);
fail(e.getMessage());
}
c.close();
}