.method(Request.METHOD.GET)
.uri(targetUrl + "/suspend")
.header("Content-Type", "application/octet-stream")
.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<byte[]>() {
@Override
public void on(byte[] message) {
logger.info("===Received : {}", message);
if (Arrays.equals(message, binaryEcho) && !hasEchoReplied.get()) {
hasEchoReplied.getAndSet(true);
socket.close();
latch.countDown();
}
}
}).on(new Function<Throwable>() {
@Override
public void on(Throwable t) {
t.printStackTrace();
}
}).open(request.build());
suspendedLatch.await(5, TimeUnit.SECONDS);
socket.fire(binaryEcho).get();
latch.await(10, TimeUnit.SECONDS);
assertEquals(hasEchoReplied.get(), true);
}