Class Readiness

java.lang.Object
io.github.pgatzka.docker.internal.Readiness

public final class Readiness extends Object
Container readiness probes used by start tasks. Each probe blocks the calling thread until the desired condition is met or timeout elapses, in which case a NotReadyException is thrown. Stateless utility — instances are not constructible.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    healthcheck(com.github.dockerjava.api.DockerClient client, String containerId, Duration timeout, Duration pollInterval)
    Poll the daemon's healthcheck status for containerId until it reports healthy or timeout elapses.
    static void
    logLine(com.github.dockerjava.api.DockerClient client, String containerId, String regex, Duration timeout)
    Stream the container's combined stdout/stderr logs until a line matches regex or timeout elapses.
    static boolean
    logLineMatch(String text, String regex)
    Pure-logic helper used by unit tests: returns whether any line in text matches regex.
    static void
    tcpPort(String host, int port, Duration timeout, Duration pollInterval)
    Repeatedly attempt a TCP connection to host:port until one succeeds or timeout elapses.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • healthcheck

      public static void healthcheck(com.github.dockerjava.api.DockerClient client, String containerId, Duration timeout, Duration pollInterval)
      Poll the daemon's healthcheck status for containerId until it reports healthy or timeout elapses.
      Parameters:
      client - the docker-java client used to inspect the container
      containerId - the daemon-side container id (or name)
      timeout - maximum time to wait for the healthy status
      pollInterval - delay between successive inspect calls
      Throws:
      NotReadyException - if the container disappears, is interrupted, or never becomes healthy within timeout
    • tcpPort

      public static void tcpPort(String host, int port, Duration timeout, Duration pollInterval)
      Repeatedly attempt a TCP connection to host:port until one succeeds or timeout elapses. Each connection attempt uses pollInterval as its socket connect timeout, and the loop also sleeps pollInterval between attempts.
      Parameters:
      host - the host to connect to (typically localhost for published ports)
      port - the TCP port to probe
      timeout - maximum total time to wait for a successful connection
      pollInterval - per-attempt connect timeout and delay between attempts
      Throws:
      NotReadyException - if no connection succeeds within timeout or the thread is interrupted while waiting
    • logLine

      public static void logLine(com.github.dockerjava.api.DockerClient client, String containerId, String regex, Duration timeout)
      Stream the container's combined stdout/stderr logs until a line matches regex or timeout elapses. Partial frames are buffered so a match split across docker log frames is still detected.
      Parameters:
      client - the docker-java client used to follow the log stream
      containerId - the daemon-side container id (or name)
      regex - Java regular expression matched against each complete log line
      timeout - maximum time to wait for a matching line
      Throws:
      NotReadyException - if no matching line is observed within timeout, the stream is interrupted, or it closes before a match is seen
    • logLineMatch

      public static boolean logLineMatch(String text, String regex)
      Pure-logic helper used by unit tests: returns whether any line in text matches regex. Does not read from a docker daemon.
      Parameters:
      text - multi-line text, lines separated by \n or \r\n
      regex - Java regular expression matched against each line
      Returns:
      true if at least one line contains a match for regex