use of io.vertx.core.http.HttpServerRequest 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.HttpServerRequest in project vert.x by eclipse.
the class Http2ServerTest method testShutdownOverride.
@Test
public void testShutdownOverride() throws Exception {
AtomicLong shutdown = new AtomicLong();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
shutdown.set(System.currentTimeMillis());
conn.shutdown(10000);
vertx.setTimer(300, v -> {
conn.shutdown(300);
});
};
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.channel.closeFuture().addListener(v1 -> {
vertx.runOnContext(v2 -> {
assertTrue(shutdown.get() - System.currentTimeMillis() < 1200);
testComplete();
});
});
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.http.HttpServerRequest in project vert.x by eclipse.
the class Http2ServerTest method testServerSendGoAway.
private void testServerSendGoAway(Handler<HttpServerRequest> requestHandler, int expectedError) throws Exception {
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(expectedError, errorCode);
complete();
});
}
});
Http2ConnectionEncoder encoder = request.encoder;
int id1 = request.nextStreamId();
encoder.writeHeaders(request.context, id1, GET("/"), 0, true, request.context.newPromise());
int id2 = request.nextStreamId();
encoder.writeHeaders(request.context, id2, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.http.HttpServerRequest in project vert.x by eclipse.
the class Http2ServerTest method testServerSendGoAwayNoError.
@Test
public void testServerSendGoAwayNoError() throws Exception {
waitFor(2);
AtomicReference<HttpServerRequest> first = new AtomicReference<>();
AtomicInteger status = new AtomicInteger();
AtomicInteger closed = new AtomicInteger();
AtomicBoolean done = new AtomicBoolean();
Context ctx = vertx.getOrCreateContext();
Handler<HttpServerRequest> requestHandler = req -> {
if (first.compareAndSet(null, req)) {
req.exceptionHandler(err -> {
assertTrue(done.get());
});
req.response().exceptionHandler(err -> {
assertTrue(done.get());
});
} else {
assertEquals(0, status.getAndIncrement());
req.exceptionHandler(err -> {
closed.incrementAndGet();
});
req.response().exceptionHandler(err -> {
closed.incrementAndGet();
});
HttpConnection conn = req.connection();
conn.shutdownHandler(v -> {
assertTrue(done.get());
});
conn.closeHandler(v -> {
assertTrue(done.get());
});
ctx.runOnContext(v1 -> {
conn.goAway(0, first.get().response().streamId());
vertx.setTimer(300, timerID -> {
assertEquals(1, status.getAndIncrement());
done.set(true);
complete();
});
});
}
};
testServerSendGoAway(requestHandler, 0);
}
use of io.vertx.core.http.HttpServerRequest in project vert.x by eclipse.
the class Http2ServerTest method testShutdown.
@Test
public void testShutdown() throws Exception {
waitFor(2);
AtomicReference<HttpServerRequest> first = new AtomicReference<>();
AtomicInteger status = new AtomicInteger();
Handler<HttpServerRequest> requestHandler = req -> {
if (first.compareAndSet(null, req)) {
req.exceptionHandler(err -> {
fail();
});
req.response().exceptionHandler(err -> {
fail();
});
} else {
assertEquals(0, status.getAndIncrement());
req.exceptionHandler(err -> {
fail();
});
req.response().exceptionHandler(err -> {
fail();
});
HttpConnection conn = req.connection();
conn.closeHandler(v -> {
assertEquals(2, status.getAndIncrement());
complete();
});
conn.shutdown();
vertx.setTimer(300, timerID -> {
assertEquals(1, status.getAndIncrement());
first.get().response().end();
req.response().end();
});
}
};
testServerSendGoAway(requestHandler, 0);
}
Aggregations