Package io.karatelabs.process
Class PortUtils
java.lang.Object
io.karatelabs.process.PortUtils
Utilities for waiting on ports and HTTP endpoints.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intFind a free port.static booleanwaitForHttp(String url, int attempts, int intervalMs, BooleanSupplier stillAlive) Wait for an HTTP endpoint to return 200.static booleanwaitForPort(String host, int port, int attempts, int intervalMs, BooleanSupplier stillAlive) Wait for a TCP port to become available.
-
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 toport- Port numberattempts- Maximum number of attemptsintervalMs- Interval between attempts in millisecondsstillAlive- 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.
-