/** * Construct a new {@link TestCondition} with a provided supplier for when the state changes. * Alternatively this can be constructed with {@link #TestCondition()} and then the condition can * be reported by overriding {@link #get()}. * * @since 5.0 * @param condition Condition to check for */ public TestCondition(Supplier<Boolean> condition) { blockCondition = (timeoutInMillis, pollIntervalInMillis) -> { long startTime = Clock.accurateForwardProgressingMillis(); long now = startTime; boolean lastResult; while (! (lastResult = condition == null ? get() : condition.get()) && ! Thread.currentThread().isInterrupted() && (now = Clock.accurateForwardProgressingMillis()) - startTime < timeoutInMillis) { delay(pollIntervalInMillis); } if (lastResult) { return 0; // ignored result } else { throw new ConditionTimeoutException("Still 'false' after " + (now - startTime) + "ms, interrupted: " + Thread.currentThread().isInterrupted()); } }; }
return 0; // ignored result } else { throw new ConditionTimeoutException("Still '" + lastResult + "' after " + (now - startTime) + "ms, interrupted: " + Thread.currentThread().isInterrupted());
return 0; // ignored result } else { throw new ConditionTimeoutException("Still '" + lastResult + "' after " + (now - startTime) + "ms, interrupted: " + Thread.currentThread().isInterrupted());
/** * Construct a new {@link TestCondition} with a provided supplier for when the state changes. * Alternatively this can be constructed with {@link #TestCondition()} and then the condition can * be reported by overriding {@link #get()}. * * @since 5.0 * @param condition Condition to check for */ public TestCondition(Supplier<Boolean> condition) { blockCondition = (timeoutInMillis, pollIntervalInMillis) -> { long startTime = Clock.accurateForwardProgressingMillis(); long now = startTime; boolean lastResult; while (! (lastResult = condition == null ? get() : condition.get()) && ! Thread.currentThread().isInterrupted() && (now = Clock.accurateForwardProgressingMillis()) - startTime < timeoutInMillis) { delay(pollIntervalInMillis); } if (lastResult) { return 0; // ignored result } else { throw new ConditionTimeoutException("Still 'false' after " + (now - startTime) + "ms, interrupted: " + Thread.currentThread().isInterrupted()); } }; }