Class PortUtils

java.lang.Object
io.karatelabs.process.PortUtils

public final class PortUtils extends Object
Utilities for waiting on ports and HTTP endpoints.
  • Method Details

    • waitForPort

      public static boolean waitForPort(String host, int port, int attempts, int intervalMs, BooleanSupplier stillAlive)
      Wait for a TCP port to become available.
      Parameters:
      host - Host to connect to
      port - Port number
      attempts - Maximum number of attempts
      intervalMs - Interval between attempts in milliseconds
      stillAlive - Supplier that returns false if we should stop waiting (e.g., process died)
      Returns:
      true if port is available, false if timed out or process died
    • waitForHttp

      public static boolean waitForHttp(String url, int attempts, int intervalMs, BooleanSupplier stillAlive)
      Wait for an HTTP endpoint to return 200.
    • findFreePort

      public static int findFreePort()
      Find a free port.