code: public T waitForRequest(long maxWait) {
          long start = System.currentTimeMillis();
          try {
              while (requestsReceived.get() < 1
                      && (System.currentTimeMillis() - start) < maxWait) {
                  try {
                      Thread.sleep(50);
                  } catch (InterruptedException ex) {
                      throw new RuntimeException(ex);
                  }
              }
          } finally {
              stopServer();
          }
  
          return getResponse();
      }
docs: Waits until at least one request is received, and then stops the server.
  @param maxWait ms to wait at most.
  @return response with last request filled, if at least one was received.