ShutdownHandler implements ExchangeCompletionListener { boolean awaitTermination(long timeoutInMs) throws InterruptedException { long end = System.currentTimeMillis() + timeoutInMs; synchronized (lock) { while (activeRequests.get() > 0) { long left = end - System.currentTimeMillis(); if (left <= 0) { return false; } lock.wait(left); } return true; } }  @Override void exchangeEvent(HttpServerExchange exchange, NextListener next);  }
@Test void awaitTermination() throws InterruptedException { handler.activeRequests.getAndIncrement(); handler.awaitTermination(-1); }