Class Poller

java.lang.Object
cloud.opencode.base.test.wait.Poller

public final class Poller extends Object
Poller 轮询器

Fluent API for polling conditions.

用于轮询条件的流式API。

Features | 主要功能:

  • Polling-based condition waiting - 基于轮询的条件等待
  • Configurable interval and timeout - 可配置的间隔和超时

Usage Examples | 使用示例:

Poller.pollUntil(() -> service.isReady(),
    Duration.ofSeconds(30), Duration.ofMillis(500));

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • await

      public static Poller await()
      Create new poller 创建新的轮询器
      Returns:
      the poller | 轮询器
    • timeout

      public Poller timeout(Duration timeout)
      Set timeout 设置超时时间
      Parameters:
      timeout - the timeout | 超时时间
      Returns:
      this poller | 此轮询器
    • pollInterval

      public Poller pollInterval(Duration interval)
      Set poll interval 设置轮询间隔
      Parameters:
      interval - the interval | 间隔
      Returns:
      this poller | 此轮询器
    • describedAs

      public Poller describedAs(String description)
      Set description for error messages 设置错误消息的描述
      Parameters:
      description - the description | 描述
      Returns:
      this poller | 此轮询器
    • until

      public void until(BooleanSupplier condition)
      Wait until condition is true 等待直到条件为真
      Parameters:
      condition - the condition | 条件
    • until

      public <T> T until(Supplier<T> supplier, Predicate<T> predicate)
      Wait until value satisfies predicate 等待直到值满足谓词
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      supplier - the value supplier | 值供应者
      predicate - the predicate | 谓词
      Returns:
      the value | 值
    • untilNotNull

      public <T> T untilNotNull(Supplier<T> supplier)
      Wait until value is not null 等待直到值非空
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      supplier - the value supplier | 值供应者
      Returns:
      the value | 值
    • untilEquals

      public <T> T untilEquals(Supplier<T> supplier, T expected)
      Wait until value equals expected 等待直到值等于期望值
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      supplier - the value supplier | 值供应者
      expected - the expected value | 期望值
      Returns:
      the value | 值