use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ClientTest method testQueueingRequests.
private void testQueueingRequests(int numReq, Long max) throws Exception {
waitFor(numReq);
String expected = TestUtils.randomAlphaString(100);
server.close();
io.vertx.core.http.Http2Settings serverSettings = new io.vertx.core.http.Http2Settings();
if (max != null) {
serverSettings.setMaxConcurrentStreams(max);
}
server = vertx.createHttpServer(serverOptions.setInitialSettings(serverSettings));
server.requestHandler(req -> {
req.response().end(expected);
});
startServer();
CountDownLatch latch = new CountDownLatch(1);
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
}).connectionHandler(conn -> {
conn.remoteSettingsHandler(settings -> {
assertEquals(max == null ? 0xFFFFFFFFL : max, settings.getMaxConcurrentStreams());
latch.countDown();
});
}).exceptionHandler(err -> {
fail();
}).end();
awaitLatch(latch);
for (int i = 0; i < numReq; i++) {
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
Buffer content = Buffer.buffer();
resp.handler(content::appendBuffer);
resp.endHandler(v -> {
assertEquals(expected, content.toString());
complete();
});
}).exceptionHandler(err -> {
fail();
}).end();
}
await();
}
use of io.vertx.core.buffer.Buffer 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.buffer.Buffer in project vert.x by eclipse.
the class Http2ClientTest method testBodyEndHandler.
@Test
public void testBodyEndHandler() throws Exception {
// Large body so it will be fragmented in several HTTP2 data frames
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(128 * 1024));
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.end(expected);
});
startServer();
client.getNow(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
Context ctx = vertx.getOrCreateContext();
resp.exceptionHandler(this::fail);
resp.bodyHandler(body -> {
assertOnIOContext(ctx);
assertEquals(expected, body);
testComplete();
});
});
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ClientTest method testSendPing.
@Test
public void testSendPing() throws Exception {
waitFor(2);
Buffer expected = TestUtils.randomBuffer(8);
Context ctx = vertx.getOrCreateContext();
server.close();
server.connectionHandler(conn -> {
conn.pingHandler(data -> {
assertEquals(expected, data);
complete();
});
});
server.requestHandler(req -> {
});
startServer(ctx);
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
});
req.connectionHandler(conn -> {
conn.ping(expected, ar -> {
assertTrue(ar.succeeded());
Buffer buff = ar.result();
assertEquals(expected, buff);
complete();
});
});
req.end();
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HostnameResolutionTest method testNet.
private void testNet(String hostname) throws Exception {
NetClient client = vertx.createNetClient();
NetServer server = vertx.createNetServer().connectHandler(so -> {
so.handler(buff -> {
so.write(buff);
so.close();
});
});
try {
CountDownLatch listenLatch = new CountDownLatch(1);
server.listen(1234, hostname, onSuccess(s -> {
listenLatch.countDown();
}));
awaitLatch(listenLatch);
client.connect(1234, hostname, onSuccess(so -> {
Buffer buffer = Buffer.buffer();
so.handler(buffer::appendBuffer);
so.closeHandler(v -> {
assertEquals(Buffer.buffer("foo"), buffer);
testComplete();
});
so.write(Buffer.buffer("foo"));
}));
await();
} finally {
client.close();
server.close();
}
}
Aggregations