use of io.vertx.core.Handler 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.Handler 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.Handler in project vert.x by eclipse.
the class Http2ServerTest method testShutdownWithTimeout.
@Test
public void testShutdownWithTimeout() throws Exception {
waitFor(2);
AtomicInteger closed = new AtomicInteger();
AtomicReference<HttpServerRequest> first = new AtomicReference<>();
AtomicInteger status = new AtomicInteger();
Handler<HttpServerRequest> requestHandler = req -> {
if (first.compareAndSet(null, req)) {
req.exceptionHandler(err -> {
fail();
});
req.response().closeHandler(err -> {
closed.incrementAndGet();
});
req.response().endHandler(err -> {
closed.incrementAndGet();
});
} else {
assertEquals(0, status.getAndIncrement());
req.exceptionHandler(err -> {
fail();
});
req.response().closeHandler(err -> {
closed.incrementAndGet();
});
req.response().endHandler(err -> {
closed.incrementAndGet();
});
HttpConnection conn = req.connection();
conn.closeHandler(v -> {
assertEquals(4, closed.get());
assertEquals(1, status.getAndIncrement());
complete();
});
conn.shutdown(300);
}
};
testServerSendGoAway(requestHandler, 0);
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class RecordParserTest method testIllegalArguments.
@Test
public void testIllegalArguments() throws Exception {
assertNullPointerException(() -> RecordParser.newDelimited((Buffer) null, handler -> {
}));
assertNullPointerException(() -> RecordParser.newDelimited((String) null, handler -> {
}));
RecordParser parser = RecordParser.newDelimited("", handler -> {
});
assertNullPointerException(() -> parser.setOutput(null));
assertNullPointerException(() -> parser.delimitedMode((Buffer) null));
assertNullPointerException(() -> parser.delimitedMode((String) null));
}
use of io.vertx.core.Handler in project yyl_example by Relucent.
the class HelloVertxVerticle method start.
/** 运行 */
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/hello").handler(new Handler<RoutingContext>() {
public void handle(RoutingContext event) {
event.response().putHeader("content-type", "text/html").end("Hello Vert.x");
}
});
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest event) {
router.accept(event);
}
}).listen(//监听端口号
8080);
}
Aggregations