Skip to content

Commit

Permalink
Migrate to Failsafe 3
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst authored and diemol committed Aug 8, 2024
1 parent 70b8d22 commit 5f7998e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.jodah</groupId>
<groupId>dev.failsafe</groupId>
<artifactId>failsafe</artifactId>
<version>2.4.4</version>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/saucelabs/saucerest/api/AbstractEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;
import dev.failsafe.Failsafe;
import dev.failsafe.RetryPolicy;

import okhttp3.Credentials;
import okhttp3.HttpUrl;
Expand Down Expand Up @@ -283,21 +283,20 @@ private Response retryRequest(Request request) throws IOException {
LOGGER.debug("Retrying request {} {}", request.method(), request.url());
response =
Failsafe.with(
new RetryPolicy<>()
.handle(
RuntimeException.class, IOException.class, IllegalStateException.class)
RetryPolicy.builder()
.handle(RuntimeException.class, IOException.class, IllegalStateException.class)
.withBackoff(BACKOFF_INITIAL_DELAY, BACKOFF_MULTIPLIER, ChronoUnit.MILLIS)
.withMaxRetries(MAX_RETRIES)
.onRetry(
e -> {
if (e.getLastFailure() != null) {
LOGGER.warn(
"Retrying because of: {}",
e.getLastFailure().getClass().getSimpleName());
Throwable lastException = e.getLastException();
if (lastException != null) {
LOGGER.warn("Retrying because of: {}", lastException.getClass().getSimpleName());
} else {
LOGGER.warn("Retrying");
}
}))
})
.build())
.get(() -> getHttpClient().newCall(request).execute());
} catch (Exception e) {
LOGGER.error("Error retrying request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.saucelabs.saucerest.model.realdevices.DeviceJob;
import com.saucelabs.saucerest.model.realdevices.DeviceJobs;

import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;
import dev.failsafe.Failsafe;
import dev.failsafe.RetryPolicy;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -244,10 +244,11 @@ public String getAppiumServerVersion(String jobID) throws IOException {
.frameworkLogUrl;
// Retry policy to handle the case where the Appium version is not found in the log file
RetryPolicy<String> retryPolicy =
new RetryPolicy<String>()
RetryPolicy.<String> builder()
.handleResultIf(Objects::isNull)
.withMaxRetries(5)
.withDelay(Duration.ofSeconds(20));
.withDelay(Duration.ofSeconds(20))
.build();

String appiumVersion =
Failsafe.with(retryPolicy)
Expand Down

0 comments on commit 5f7998e

Please sign in to comment.