@Test public void testReceivePing() throws Exception { Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.ping(expected, ar -> { }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); req.end(); await(); }
/** * Send a frame to the remote endpoint. * <p/> * This is not implemented for HTTP/1.x. * @param data the 8 bytes data of the frame * @param pongHandler an async result handler notified with pong reply or the failure * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpConnection ping(io.vertx.rxjava.core.buffer.Buffer data, Handler<AsyncResult<io.vertx.rxjava.core.buffer.Buffer>> pongHandler) { delegate.ping(data.getDelegate(), new Handler<AsyncResult<io.vertx.core.buffer.Buffer>>() { public void handle(AsyncResult<io.vertx.core.buffer.Buffer> ar) { if (ar.succeeded()) { pongHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.buffer.Buffer.newInstance(ar.result()))); } else { pongHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
@Test public void testSendPing() throws Exception { waitFor(2); Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.ping(expected, ar -> { assertTrue(ar.succeeded()); Buffer buff = ar.result(); assertEquals(expected, buff); complete(); }); }); req.end(); await(); }
/** * Send a frame to the remote endpoint. * <p/> * This is not implemented for HTTP/1.x. * @param data the 8 bytes data of the frame * @param pongHandler an async result handler notified with pong reply or the failure * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpConnection ping(io.vertx.rxjava.core.buffer.Buffer data, Handler<AsyncResult<io.vertx.rxjava.core.buffer.Buffer>> pongHandler) { delegate.ping(data.getDelegate(), new Handler<AsyncResult<io.vertx.core.buffer.Buffer>>() { public void handle(AsyncResult<io.vertx.core.buffer.Buffer> ar) { if (ar.succeeded()) { pongHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.buffer.Buffer.newInstance(ar.result()))); } else { pongHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
@Test public void testReceivePing() throws Exception { Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.ping(expected, ar -> { }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); req.end(); await(); }
@Test public void testSendPing() throws Exception { waitFor(2); Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.ping(expected, ar -> { assertTrue(ar.succeeded()); Buffer buff = ar.result(); assertEquals(expected, buff); complete(); }); }); req.end(); await(); }