assertTrue(paused.get()); assertEquals(1, numPause.get()); req.drainHandler(v -> { assertOnIOContext(ctx); assertEquals(0, drained.getAndIncrement());
@Test public void testClientRequestExceptionHandlerCalledWhenExceptionOnDrainHandler() { pausingServer(resumeFuture -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.setChunked(true); assertFalse(req.writeQueueFull()); req.setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); AtomicBoolean failed = new AtomicBoolean(); vertx.setPeriodic(1, id -> { req.write(buff); if (req.writeQueueFull()) { vertx.cancelTimer(id); req.drainHandler(v -> { throw new RuntimeException("error"); }) .exceptionHandler(t -> { // Called a second times when testComplete is called and close the http client if (failed.compareAndSet(false, true)) { testComplete(); } }); // Tell the server to resume resumeFuture.complete(); } }); }); await(); }
@Override public WriteStream<Buffer> drainHandler(Handler<Void> drainHandler) { httpClientRequest.drainHandler(aVoid -> drainHandler.handle(null)); return this; }
@Test public void testClientDrainHandler() { pausingServer(resumeFuture -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.setChunked(true); assertFalse(req.writeQueueFull()); req.setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); vertx.setPeriodic(1, id -> { req.write(buff); if (req.writeQueueFull()) { vertx.cancelTimer(id); req.drainHandler(v -> { assertFalse(req.writeQueueFull()); testComplete(); }); // Tell the server to resume resumeFuture.complete(); } }); }); await(); }
@Test public void testUseRequestAfterComplete() { server.requestHandler(noOpHandler()); server.listen(onSuccess(server -> { HttpClientRequest req = client.request(HttpMethod.POST, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.end(); Buffer buff = Buffer.buffer(); assertIllegalStateException(() -> req.end()); assertIllegalStateException(() -> req.continueHandler(noOpHandler())); assertIllegalStateException(() -> req.drainHandler(noOpHandler())); assertIllegalStateException(() -> req.end("foo")); assertIllegalStateException(() -> req.end(buff)); assertIllegalStateException(() -> req.end("foo", "UTF-8")); assertIllegalStateException(() -> req.sendHead()); assertIllegalStateException(() -> req.setChunked(false)); assertIllegalStateException(() -> req.setWriteQueueMaxSize(123)); assertIllegalStateException(() -> req.write(buff)); assertIllegalStateException(() -> req.write("foo")); assertIllegalStateException(() -> req.write("foo", "UTF-8")); assertIllegalStateException(() -> req.write(buff)); assertIllegalStateException(() -> req.writeQueueFull()); testComplete(); })); await(); }
public io.vertx.rxjava.core.http.HttpClientRequest drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; }
public io.vertx.rxjava.core.http.HttpClientRequest drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; }
assertTrue(paused.get()); assertEquals(1, numPause.get()); req.drainHandler(v -> { assertOnIOContext(ctx); assertEquals(0, drained.getAndIncrement());
@Test public void testClientRequestExceptionHandlerCalledWhenExceptionOnDrainHandler() { pausingServer(resumeFuture -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.setChunked(true); assertFalse(req.writeQueueFull()); req.setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); AtomicBoolean failed = new AtomicBoolean(); vertx.setPeriodic(1, id -> { req.write(buff); if (req.writeQueueFull()) { vertx.cancelTimer(id); req.drainHandler(v -> { throw new RuntimeException("error"); }) .exceptionHandler(t -> { // Called a second times when testComplete is called and close the http client if (failed.compareAndSet(false, true)) { testComplete(); } }); // Tell the server to resume resumeFuture.complete(); } }); }); await(); }
@Override public WriteStream<Buffer> drainHandler(Handler<Void> drainHandler) { httpClientRequest.drainHandler(aVoid -> drainHandler.handle(null)); return this; }
@Override public WriteStream<Buffer> drainHandler(Handler<Void> drainHandler) { httpClientRequest.drainHandler(aVoid -> drainHandler.handle(null)); return this; }
@Override public WriteStream<Buffer> drainHandler(@Nullable Handler<Void> handler) { cReq.drainHandler(handler); return this; } };
req.exceptionHandler(null); req.endHandler(null); req.drainHandler(null); req.connectionHandler(null); req.continueHandler(null);
@Test public void testClientDrainHandler() { pausingServer(resumeFuture -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.setChunked(true); assertFalse(req.writeQueueFull()); req.setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); vertx.setPeriodic(1, id -> { req.write(buff); if (req.writeQueueFull()) { vertx.cancelTimer(id); req.drainHandler(v -> { assertFalse(req.writeQueueFull()); testComplete(); }); // Tell the server to resume resumeFuture.complete(); } }); }); await(); }
@Test public void testUseRequestAfterComplete() { server.requestHandler(noOpHandler()); server.listen(onSuccess(server -> { HttpClientRequest req = client.request(HttpMethod.POST, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.end(); Buffer buff = Buffer.buffer(); assertIllegalStateException(() -> req.end()); assertIllegalStateException(() -> req.continueHandler(noOpHandler())); assertIllegalStateException(() -> req.drainHandler(noOpHandler())); assertIllegalStateException(() -> req.end("foo")); assertIllegalStateException(() -> req.end(buff)); assertIllegalStateException(() -> req.end("foo", "UTF-8")); assertIllegalStateException(() -> req.sendHead()); assertIllegalStateException(() -> req.setChunked(false)); assertIllegalStateException(() -> req.setWriteQueueMaxSize(123)); assertIllegalStateException(() -> req.write(buff)); assertIllegalStateException(() -> req.write("foo")); assertIllegalStateException(() -> req.write("foo", "UTF-8")); assertIllegalStateException(() -> req.write(buff)); assertIllegalStateException(() -> req.writeQueueFull()); testComplete(); })); await(); }
@Override public void write(IApimanBuffer chunk) { if (inboundFinished) { throw new IllegalStateException(Messages.getString("HttpConnector.0")); } if (chunk.getNativeBuffer() instanceof Buffer) { clientRequest.write((Buffer) chunk.getNativeBuffer()); // When write queue has diminished sufficiently, drain handler will be invoked. if (clientRequest.writeQueueFull() && drainHandler != null) { clientRequest.drainHandler(drainHandler::handle); } } else { throw new IllegalArgumentException(Messages.getString("HttpConnector.1")); } }