use of reactor.ipc.netty.tcp.BlockingNettyContext in project reactor-netty by reactor.
the class HttpServerTests method defaultHttpPortWithAddress.
@Test
public void defaultHttpPortWithAddress() {
BlockingNettyContext blockingFacade = HttpServer.create("localhost").start((req, resp) -> resp.sendNotFound());
blockingFacade.shutdown();
assertThat(blockingFacade.getPort()).isEqualTo(8080).isEqualTo(blockingFacade.getContext().address().getPort());
}
use of reactor.ipc.netty.tcp.BlockingNettyContext in project reactor-netty by reactor.
the class HttpServerTests method defaultHttpPort.
@Test
public void defaultHttpPort() {
BlockingNettyContext blockingFacade = HttpServer.create().start((req, resp) -> resp.sendNotFound());
blockingFacade.shutdown();
assertThat(blockingFacade.getPort()).isEqualTo(8080).isEqualTo(blockingFacade.getContext().address().getPort());
}
use of reactor.ipc.netty.tcp.BlockingNettyContext in project reactor-netty by reactor.
the class HttpServerTests method httpPortOptionTakesPrecedenceOverBuilderField.
@Test
public void httpPortOptionTakesPrecedenceOverBuilderField() {
HttpServer.Builder builder = HttpServer.builder().options(o -> o.port(9081)).port(9080);
HttpServer binding = builder.build();
BlockingNettyContext blockingFacade = binding.start((req, resp) -> resp.sendNotFound());
blockingFacade.shutdown();
assertThat(builder).hasFieldOrPropertyWithValue("port", 9080);
assertThat(blockingFacade.getPort()).isEqualTo(9081).isEqualTo(blockingFacade.getContext().address().getPort());
assertThat(binding.options().getAddress()).isInstanceOf(InetSocketAddress.class).hasFieldOrPropertyWithValue("port", 9081);
}
use of reactor.ipc.netty.tcp.BlockingNettyContext in project micrometer by micrometer-metrics.
the class AtlasMeterRegistryTest method publishOneLastTimeOnClose.
@Issue("#484")
@Test
void publishOneLastTimeOnClose() throws InterruptedException {
URI uri = URI.create(config.uri());
CountDownLatch latch = new CountDownLatch(1);
BlockingNettyContext blockingFacade = HttpServer.create(uri.getHost(), uri.getPort()).start((req, resp) -> {
latch.countDown();
return resp.send();
});
try {
registry.close();
latch.await(10, TimeUnit.SECONDS);
assertThat(latch.getCount()).isZero();
} finally {
blockingFacade.shutdown();
}
}
use of reactor.ipc.netty.tcp.BlockingNettyContext in project reactor-netty by reactor.
the class NettyConnector method startAndAwait.
/**
* Start a Client or Server in a fully blocking fashion, not only waiting for it to
* initialize but also blocking during the full lifecycle of the client/server.
* Since most servers will be long-lived, this is more adapted to running a server
* out of a main method, only allowing shutdown of the servers through sigkill.
* <p>
* Note that a {@link Runtime#addShutdownHook(Thread) JVM shutdown hook} is added
* by this method in order to properly disconnect the client/server upon receiving
* a sigkill signal.
*
* @param handler the handler to execute.
* @param onStart an optional callback to be invoked once the client/server has finished
* initializing.
*/
default <T extends BiFunction<INBOUND, OUTBOUND, ? extends Publisher<Void>>> void startAndAwait(T handler, @Nullable Consumer<BlockingNettyContext> onStart) {
BlockingNettyContext facade = new BlockingNettyContext(newHandler(handler), getClass().getSimpleName());
facade.installShutdownHook();
if (onStart != null) {
onStart.accept(facade);
}
facade.getContext().onClose().block();
}
Aggregations