use of io.vertx.core.Future in project vert.x by eclipse.
the class HttpTest method pausingServer.
private void pausingServer(Consumer<Future<Void>> consumer) {
Future<Void> resumeFuture = Future.future();
server.requestHandler(req -> {
req.response().setChunked(true);
req.pause();
Context ctx = vertx.getOrCreateContext();
resumeFuture.setHandler(v1 -> {
ctx.runOnContext(v2 -> {
req.resume();
});
});
req.handler(buff -> {
req.response().write(buff);
});
});
server.listen(onSuccess(s -> consumer.accept(resumeFuture)));
}
use of io.vertx.core.Future in project vert.x by eclipse.
the class HttpTest method drainingServer.
private void drainingServer(Consumer<Future<Void>> consumer) {
Future<Void> resumeFuture = Future.future();
server.requestHandler(req -> {
req.response().setChunked(true);
assertFalse(req.response().writeQueueFull());
req.response().setWriteQueueMaxSize(1000);
Buffer buff = TestUtils.randomBuffer(10000);
vertx.setPeriodic(1, id -> {
req.response().write(buff);
if (req.response().writeQueueFull()) {
vertx.cancelTimer(id);
req.response().drainHandler(v -> {
assertFalse(req.response().writeQueueFull());
testComplete();
});
resumeFuture.complete();
}
});
});
server.listen(onSuccess(s -> consumer.accept(resumeFuture)));
}
use of io.vertx.core.Future in project vert.x by eclipse.
the class FutureTest method testFailFutureToHandler.
@Test
public void testFailFutureToHandler() {
Throwable cause = new Throwable();
Consumer<Handler<AsyncResult<String>>> consumer = handler -> {
handler.handle(Future.failedFuture(cause));
};
Future<String> fut = Future.future();
consumer.accept(fut);
assertTrue(fut.isComplete());
assertTrue(fut.failed());
assertEquals(cause, fut.cause());
}
use of io.vertx.core.Future in project vert.x by eclipse.
the class Http2ServerTest method testClientSendGoAwayInternalError.
@Test
public void testClientSendGoAwayInternalError() throws Exception {
Future<Void> abc = Future.future();
Context ctx = vertx.getOrCreateContext();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
AtomicInteger status = new AtomicInteger();
conn.goAwayHandler(ga -> {
assertOnIOContext(ctx);
assertEquals(0, status.getAndIncrement());
req.response().end();
});
conn.shutdownHandler(v -> {
assertOnIOContext(ctx);
assertEquals(1, status.getAndIncrement());
});
conn.closeHandler(v -> {
assertEquals(2, status.getAndIncrement());
testComplete();
});
abc.complete();
};
server.requestHandler(requestHandler);
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
abc.setHandler(ar -> {
encoder.writeGoAway(request.context, id, 3, Unpooled.EMPTY_BUFFER, request.context.newPromise());
request.context.flush();
});
});
fut.sync();
await();
}
use of io.vertx.core.Future in project vert.x by eclipse.
the class FutureTest method testAllLargeList.
private void testAllLargeList(int size) {
List<Future> list = new ArrayList<>();
for (int i = 0; i < size; i++) {
list.add(Future.succeededFuture());
}
CompositeFuture composite = CompositeFuture.all(list);
Checker<CompositeFuture> checker = new Checker<>(composite);
checker.assertSucceeded(composite);
for (int i = 0; i < size; i++) {
list.clear();
Throwable cause = new Exception();
for (int j = 0; j < size; j++) {
list.add(i == j ? Future.failedFuture(cause) : Future.succeededFuture());
}
composite = CompositeFuture.all(list);
checker = new Checker<>(composite);
checker.assertFailed(cause);
for (int j = 0; j < size; j++) {
if (i == j) {
assertTrue(composite.failed(j));
} else {
assertTrue(composite.succeeded(j));
}
}
}
}
Aggregations