}
}).build();
Nettosphere server = new Nettosphere.Builder().config(config).build();
assertNotNull(server);
server.start();
final CountDownLatch latch = new CountDownLatch(5);
final AtomicReference<Set> response = new AtomicReference<Set>(new HashSet());
AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class);
RequestBuilder request = client.newRequestBuilder()
.method(Request.METHOD.GET)
.uri(targetUrl + "/suspend")
.transport(Request.TRANSPORT.LONG_POLLING);
final Socket socket = client.create(client.newOptionsBuilder().build());
final CountDownLatch suspendedLatch = new CountDownLatch(1);
socket.on(new Function<Integer>() {
@Override
public void on(Integer statusCode) {
suspendedLatch.countDown();
}
}).on("message", new Function<String>() {
@Override
public void on(String message) {
logger.info("received : {}", message);
response.get().add(message);
latch.countDown();
}
}).on(new Function<Throwable>() {
@Override
public void on(Throwable t) {
t.printStackTrace();
}
}).open(request.build());
suspendedLatch.await(5, TimeUnit.SECONDS);
socket.fire("ECHO1");
socket.fire("ECHO2");
socket.fire("ECHO3");
socket.fire("ECHO4");
socket.fire("ECHO5");
latch.await(10, TimeUnit.SECONDS);
assertEquals(response.get().size(), 5);
socket.close();
server.stop();
}