Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retryIf(BooleanSupplier): when your boolean logic does not depend on the return of the Callable #41

Open
alb-i986 opened this issue May 25, 2015 · 1 comment

Comments

@alb-i986
Copy link

If I'm not mistaken, the Retryer assumes that our boolean logic always depends on the return of the Callable.
But what if it didn't?

A workaround could be to have the Predicate to simply ignore its parameter:

Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
        .retryIfResult(
                     (ignored) -> { return myBooleanLogic(); }
        )
        ...

Or, better, give the user the option to build a Retryer that takes a BooleanSupplier.

BooleanSupplier myBS;

Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
        .retryIf(myBS) // **** new RetryerBuilder.retryIf
        .retryIfResult(Predicates.<Boolean>isNull())
        .retryIfExceptionOfType(IOException.class)
        .retryIfRuntimeException()
        .withStopStrategy(StopStrategies.stopAfterAttempt(3))
        .build();

It doesn't need to be "either a Predicate or a BooleanSupplier": I think it should be legal to build a Retryer with both:

  • the predicate to check that the Callable doesn't return weird values like null
  • the BooleanSupplier to check some other condition, not related to (the result of) the Callable.
public V call(Callable<V> callable) throws ExecutionException, RetryException {

....

if (!rejectionPredicate.apply(attempt)) {
return attempt.get();
}

if (!retryBooleanSupplier.getAsBoolean()){ // <---
return attempt.get();
}
...

Use case (Selenium UI testing)

I want to keep clicking on the 'refresh' button until some other element changes, e.g. the text of a div changes to "LOADED".

Here:

  • my callable is "keep clicking on the 'refresh' button"
refreshBtn.click();
  • my predicate is "has the text of the div changed to 'LOADED'?"
div.getText().contains("LOADED");

=> the predicate does not depend on the return of the Callable

If you agree with this I'll try to submit a PR.
Thanks

@JensRantil
Copy link

I would propose you implement a StopStrategy instead of adding a retryIf method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants