Using Awaitility 4.0.1, I put together the following poll that polls my server for data for 5 minutes, in intervals of 10 seconds, and runs perfectly fine:
AtomicReference<Response> response = null;
with().pollInterval(10, TimeUnit.SECONDS)
.and().timeout(5, TimeUnit.MINUTES)
.await("Retrieving data from server")
.until(() -> {
response = restClient.performGetRequest();
boolean isFilled = !response.readEntity(String.class).isEmpty();
return isFilled;
});
return response;
Is there a way to get from Awaitility - within the until lambda - the attempt of retry and the remaining number of retries that it will perform before failing?
No, you cannot get it from within
until. But you can use a Condition Evaluation Listener, but it won't give you the number of tries or tries that are left but it does give you elapsed and remaining time. For example:will log: