use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class HttpTest method testRequestHeaders.
private void testRequestHeaders(boolean individually) {
MultiMap headers = getHeaders(10);
server.requestHandler(req -> {
assertTrue(headers.size() < req.headers().size());
for (Map.Entry<String, String> entry : headers) {
assertEquals(entry.getValue(), req.headers().get(entry.getKey()));
assertEquals(entry.getValue(), req.getHeader(entry.getKey()));
}
req.response().end();
});
server.listen(onSuccess(server -> {
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete());
if (individually) {
for (Map.Entry<String, String> header : headers) {
req.headers().add(header.getKey(), header.getValue());
}
} else {
req.headers().setAll(headers);
}
req.end();
}));
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class HttpTest method testClientRequestExceptionHandlerCalledWhenExceptionOnDrainHandler.
@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 -> {
if (failed.compareAndSet(false, true)) {
testComplete();
}
});
resumeFuture.complete();
}
});
});
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2Test method testResetClientRequestNotYetSent.
@Test
public void testResetClientRequestNotYetSent() throws Exception {
waitFor(2);
server.close();
server = vertx.createHttpServer(createBaseServerOptions().setInitialSettings(new Http2Settings().setMaxConcurrentStreams(1)));
AtomicInteger numReq = new AtomicInteger();
server.requestHandler(req -> {
assertEquals(0, numReq.getAndIncrement());
req.response().end();
complete();
});
startServer();
HttpClientRequest post = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
fail();
});
post.setChunked(true).write(TestUtils.randomBuffer(1024));
assertTrue(post.reset());
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
assertEquals(1, numReq.get());
complete();
});
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class HttpTest method testPauseClientResponse.
@Test
public void testPauseClientResponse() {
int numWrites = 10;
int numBytes = 100;
server.requestHandler(req -> {
req.response().setChunked(true);
for (int i = 0; i < numWrites; i++) {
req.response().write(TestUtils.randomBuffer(numBytes));
}
req.response().end();
});
AtomicBoolean paused = new AtomicBoolean();
Buffer totBuff = Buffer.buffer();
HttpClientRequest clientRequest = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.pause();
paused.set(true);
resp.handler(chunk -> {
if (paused.get()) {
fail("Shouldn't receive chunks when paused");
} else {
totBuff.appendBuffer(chunk);
}
});
resp.endHandler(v -> {
if (paused.get()) {
fail("Shouldn't receive chunks when paused");
} else {
assertEquals(numWrites * numBytes, totBuff.length());
testComplete();
}
});
vertx.setTimer(500, id -> {
paused.set(false);
resp.resume();
});
});
server.listen(onSuccess(s -> clientRequest.end()));
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class HttpTest method testClientDrainHandler.
@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();
});
resumeFuture.complete();
}
});
});
await();
}
Aggregations