@Test
public void testTrackAndTryAcquire() throws IOException, ServletException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<AtmosphereSession> session = new AtomicReference<AtmosphereSession>();
framework.addAtmosphereHandler("/acquire", new AtmosphereHandlerAdapter() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
if (session.get() == null) {
session.set(new AtmosphereSession(resource));
}
resource.suspend(2, TimeUnit.SECONDS);
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
latch.countDown();
}
});
final String qs = "&X-Atmosphere-tracking-id=c8834462-c46e-4dad-a22f-b86aabe3f883&X-Atmosphere-Framework=2.0.4-javascript&X-Atmosphere-Transport=sse&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true&_=1380799455333";
AtmosphereRequest request = new AtmosphereRequest.Builder().queryString(qs).pathInfo("/acquire").build();
framework.doCometSupport(request, AtmosphereResponse.newInstance());
latch.await(10, TimeUnit.SECONDS);
assertNull(session.get().acquire());
final AtomicReference<AtmosphereResource> rrr = new AtomicReference<AtmosphereResource>();
final CountDownLatch _latch = new CountDownLatch(1);
framework.addAtmosphereHandler("/acquire", new AtmosphereHandlerAdapter() {
@Override
public void onRequest(final AtmosphereResource resource) throws IOException {
resource.suspend(2, TimeUnit.SECONDS);
}