use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class Http2ClientTest method testConnectionWindowSize.
@Test
public void testConnectionWindowSize() throws Exception {
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(65535, windowSizeIncrement);
testComplete();
});
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
client.close();
client = vertx.createHttpClient(new HttpClientOptions(clientOptions).setHttp2ConnectionWindowSize(65535 * 2));
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
}).exceptionHandler(this::fail).end();
await();
}
use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class Http2ClientTest method setUp.
@Override
public void setUp() throws Exception {
eventLoopGroups.clear();
super.setUp();
clientOptions = new HttpClientOptions().setUseAlpn(true).setSsl(true).setTrustStoreOptions(Trust.SERVER_JKS.get()).setProtocolVersion(HttpVersion.HTTP_2);
client = vertx.createHttpClient(clientOptions);
}
use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class Http2ClientTest method testMaxConcurrency.
private void testMaxConcurrency(int poolSize, int maxConcurrency) throws Exception {
int rounds = 1 + poolSize;
int maxRequests = poolSize * maxConcurrency;
int totalRequests = maxRequests + maxConcurrency;
Set<HttpConnection> serverConns = new HashSet<>();
server.connectionHandler(conn -> {
serverConns.add(conn);
assertTrue(serverConns.size() <= poolSize);
});
ArrayList<HttpServerRequest> requests = new ArrayList<>();
server.requestHandler(req -> {
if (requests.size() < maxRequests) {
requests.add(req);
if (requests.size() == maxRequests) {
vertx.setTimer(300, v -> {
assertEquals(maxRequests, requests.size());
requests.forEach(r -> r.response().end());
});
}
} else {
req.response().end();
}
});
startServer();
client.close();
client = vertx.createHttpClient(new HttpClientOptions(clientOptions).setHttp2MaxPoolSize(poolSize).setHttp2MultiplexingLimit(maxConcurrency));
AtomicInteger respCount = new AtomicInteger();
Set<HttpConnection> clientConnections = Collections.synchronizedSet(new HashSet<>());
for (int j = 0; j < rounds; j++) {
for (int i = 0; i < maxConcurrency; i++) {
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
resp.endHandler(v -> {
if (respCount.incrementAndGet() == totalRequests) {
testComplete();
}
});
}).connectionHandler(clientConnections::add).end();
}
if (j < poolSize) {
int threshold = j + 1;
waitUntil(() -> clientConnections.size() == threshold);
}
}
await();
}
use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class HttpCompressionTest method setUp.
public void setUp() throws Exception {
super.setUp();
client = vertx.createHttpClient(new HttpClientOptions().setTryUseCompression(true));
clientraw = vertx.createHttpClient(new HttpClientOptions().setTryUseCompression(false));
HttpServerOptions serverOpts = new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setCompressionSupported(true);
// server = vertx.createHttpServer();
serverWithMinCompressionLevel = vertx.createHttpServer(serverOpts.setPort(DEFAULT_HTTP_PORT - 1).setCompressionLevel(1));
serverWithMaxCompressionLevel = vertx.createHttpServer(serverOpts.setPort(DEFAULT_HTTP_PORT + 1).setCompressionLevel(9));
}
use of io.vertx.core.http.HttpClientOptions in project vert.x by eclipse.
the class HttpMetricsTest method testPushPromise.
@Test
public void testPushPromise() throws Exception {
waitFor(2);
int numBuffers = 10;
int contentLength = numBuffers * 1000;
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
HttpServerResponse pushedResp = ar.result();
FakeHttpServerMetrics serverMetrics = FakeMetricsBase.getMetrics(server);
HttpServerMetric serverMetric = serverMetrics.getMetric(pushedResp);
assertNotNull(serverMetric);
pushedResp.putHeader("content-length", "" + contentLength);
AtomicInteger numBuffer = new AtomicInteger(numBuffers);
vertx.setPeriodic(1, timerID -> {
if (numBuffer.getAndDecrement() == 0) {
pushedResp.end();
assertNull(serverMetrics.getMetric(pushedResp));
vertx.cancelTimer(timerID);
complete();
} else {
pushedResp.write(TestUtils.randomBuffer(1000));
}
});
});
});
startServer();
client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2));
FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
});
req.pushHandler(pushedReq -> {
HttpClientMetric metric = metrics.getMetric(pushedReq);
assertNotNull(metric);
assertSame(pushedReq, metric.request);
pushedReq.handler(resp -> {
resp.endHandler(v -> {
assertNull(metrics.getMetric(pushedReq));
complete();
});
});
});
req.end();
await();
}
Aggregations