use of reactor.ipc.netty.tcp.BlockingNettyContext in project reactor-netty by reactor.
the class HttpServerTests method startRouter.
@Test
public void startRouter() {
BlockingNettyContext facade = HttpServer.create(0).startRouter(routes -> routes.get("/hello", (req, resp) -> resp.sendString(Mono.just("hello!"))));
try {
HttpClientResponse res = HttpClient.create(facade.getPort()).get("/hello").block();
assertThat(res.status().code()).isEqualTo(200);
res.dispose();
res = HttpClient.create(facade.getPort()).get("/helloMan", req -> req.failOnClientError(false)).block();
assertThat(res.status().code()).isEqualTo(404);
res.dispose();
} finally {
facade.shutdown();
}
}
use of reactor.ipc.netty.tcp.BlockingNettyContext in project reactor-netty by reactor.
the class HttpServerTests method startRouterAndAwait.
@Test
public void startRouterAndAwait() throws InterruptedException {
ExecutorService ex = Executors.newSingleThreadExecutor();
AtomicReference<BlockingNettyContext> ref = new AtomicReference<>();
Future<?> f = ex.submit(() -> HttpServer.create(0).startRouterAndAwait(routes -> routes.get("/hello", (req, resp) -> resp.sendString(Mono.just("hello!"))), ref::set));
// if the server cannot be started, a ExecutionException will be thrown instead
assertThatExceptionOfType(TimeoutException.class).isThrownBy(() -> f.get(1, TimeUnit.SECONDS));
// the router is not done and is still blocking the thread
assertThat(f.isDone()).isFalse();
assertThat(ref.get()).isNotNull().withFailMessage("Server is not initialized after 1s");
// shutdown the router to unblock the thread
ref.get().shutdown();
Thread.sleep(100);
assertThat(f.isDone()).isTrue();
}
Aggregations