Server implements ListenableAsyncCloseable { public int activeLocalPort() { return activeLocalPort0(null); } Server(ServerConfig config, @Nullable Mapping<String, SslContext> sslContexts); static ServerBuilder builder(); ServerConfig config(); List<ServiceConfig> serviceConfigs(); String defaultHostname(); Map<InetSocketAddress, ServerPort> activePorts(); @Nullable ServerPort activePort(); @Nullable ServerPort activePort(SessionProtocol protocol); int activeLocalPort(); int activeLocalPort(SessionProtocol protocol); MeterRegistry meterRegistry(); void addListener(ServerListener listener); boolean removeListener(ServerListener listener); CompletableFuture<Void> start(); CompletableFuture<Void> stop(); EventLoop nextEventLoop(); @Override boolean isClosing(); @Override boolean isClosed(); @Override CompletableFuture<?> whenClosed(); @Override CompletableFuture<?> closeAsync(); @Override void close(); int numConnections(); void blockUntilShutdown(); @Override String toString();  }
@Test void testActiveLocalPort() throws Exception { final Server server = Server.builder() .http(0) .https(0) .tlsSelfSigned() .service("/", (ctx, res) -> HttpResponse.of("")) .build(); assertThatThrownBy(server::activeLocalPort) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("no active local ports"); server.start().get(); assertThat(server.activeLocalPort()).isPositive(); assertThat(server.activeLocalPort(SessionProtocol.HTTP)).isPositive(); assertThat(server.activeLocalPort(SessionProtocol.HTTPS)).isPositive(); assertThatThrownBy(() -> server.activeLocalPort(SessionProtocol.PROXY)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("no active local ports for " + SessionProtocol.PROXY); }