use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testClientRequestWriteability.
@Test
public void testClientRequestWriteability() throws Exception {
Buffer content = Buffer.buffer();
Buffer expected = Buffer.buffer();
String chunk = TestUtils.randomAlphaString(100);
CompletableFuture<Void> done = new CompletableFuture<>();
AtomicBoolean paused = new AtomicBoolean();
AtomicInteger numPause = new AtomicInteger();
server.requestHandler(req -> {
Context ctx = vertx.getOrCreateContext();
done.thenAccept(v1 -> {
paused.set(false);
ctx.runOnContext(v2 -> {
req.resume();
});
});
numPause.incrementAndGet();
req.pause();
paused.set(true);
req.handler(content::appendBuffer);
req.endHandler(v -> {
assertEquals(expected, content);
req.response().end();
});
});
startServer();
HttpClientRequest req = client.post(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
testComplete();
}).setChunked(true).exceptionHandler(err -> {
fail();
});
AtomicInteger sent = new AtomicInteger();
AtomicInteger count = new AtomicInteger();
AtomicInteger drained = new AtomicInteger();
vertx.setPeriodic(1, timerID -> {
Context ctx = vertx.getOrCreateContext();
if (req.writeQueueFull()) {
assertTrue(paused.get());
assertEquals(1, numPause.get());
req.drainHandler(v -> {
assertOnIOContext(ctx);
assertEquals(0, drained.getAndIncrement());
assertEquals(1, numPause.get());
assertFalse(paused.get());
req.end();
});
vertx.cancelTimer(timerID);
done.complete(null);
} else {
count.incrementAndGet();
expected.appendString(chunk);
req.write(chunk);
sent.addAndGet(chunk.length());
}
});
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testResetPendingPushPromise.
@Test
public void testResetPendingPushPromise() throws Exception {
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertFalse(ar.succeeded());
testComplete();
});
});
startServer();
client.close();
client = vertx.createHttpClient(clientOptions.setInitialSettings(new io.vertx.core.http.Http2Settings().setMaxConcurrentStreams(0L)));
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
});
req.pushHandler(pushedReq -> {
pushedReq.reset(Http2Error.CANCEL.code());
});
req.end();
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testReceivePing.
@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();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testConnectionShutdownInConnectionHandler.
@Test
public void testConnectionShutdownInConnectionHandler() throws Exception {
AtomicInteger serverStatus = new AtomicInteger();
server.connectionHandler(conn -> {
if (serverStatus.getAndIncrement() == 0) {
conn.goAwayHandler(ga -> {
assertEquals(0, ga.getErrorCode());
assertEquals(1, serverStatus.getAndIncrement());
});
conn.shutdownHandler(v -> {
assertEquals(2, serverStatus.getAndIncrement());
});
conn.closeHandler(v -> {
assertEquals(3, serverStatus.getAndIncrement());
});
}
});
server.requestHandler(req -> {
assertEquals(5, serverStatus.getAndIncrement());
req.response().end();
});
startServer();
AtomicInteger clientStatus = new AtomicInteger();
HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req1.connectionHandler(conn -> {
Context ctx = Vertx.currentContext();
conn.shutdownHandler(v -> {
assertOnIOContext(ctx);
clientStatus.compareAndSet(1, 2);
});
if (clientStatus.getAndIncrement() == 0) {
conn.shutdown();
}
});
req1.exceptionHandler(err -> {
fail();
});
req1.handler(resp -> {
assertEquals(2, clientStatus.getAndIncrement());
resp.endHandler(v -> {
testComplete();
});
});
req1.end();
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testResetActivePushPromise.
@Test
public void testResetActivePushPromise() throws Exception {
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
HttpServerResponse response = ar.result();
response.exceptionHandler(err -> {
if (err instanceof StreamResetException) {
assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode());
testComplete();
}
});
response.setChunked(true).write("some_content");
});
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
});
req.pushHandler(pushedReq -> {
pushedReq.handler(pushedResp -> {
pushedResp.handler(buff -> {
pushedReq.reset(Http2Error.CANCEL.code());
});
});
});
req.end();
await();
}
Aggregations