Skip to content

Commit 506faf8

Browse files
committed
MLE-23230 Applying RetryInterceptor in test plumbing
This avoids hardcoding it in the actual client and let's us still see the results for the tests. Also fixed a warning from Polaris about the interceptor.
1 parent 65e2719 commit 506faf8

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/ConnectedRESTQA.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import com.marklogic.client.DatabaseClientFactory;
1616
import com.marklogic.client.FailedRequestException;
1717
import com.marklogic.client.admin.ServerConfigurationManager;
18+
import com.marklogic.client.extra.okhttpclient.OkHttpClientConfigurator;
1819
import com.marklogic.client.impl.SSLUtil;
20+
import com.marklogic.client.impl.okhttp.RetryInterceptor;
1921
import com.marklogic.client.io.DocumentMetadataHandle;
2022
import com.marklogic.client.io.DocumentMetadataHandle.Capability;
2123
import com.marklogic.client.query.QueryManager;
@@ -45,6 +47,12 @@
4547

4648
public abstract class ConnectedRESTQA {
4749

50+
static {
51+
DatabaseClientFactory.removeConfigurators();
52+
DatabaseClientFactory.addConfigurator((OkHttpClientConfigurator) client ->
53+
client.addInterceptor(new RetryInterceptor(3, 1000, 2, 8000)));
54+
}
55+
4856
private static Properties testProperties = null;
4957

5058
private static String authType;

marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/OkHttpUtil.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ public static OkHttpClient.Builder newOkHttpClientBuilder(String host, DatabaseC
7878
OkHttpUtil.configureSocketFactory(clientBuilder, sslContext, trustManager);
7979
OkHttpUtil.configureHostnameVerifier(clientBuilder, sslVerifier);
8080

81-
// Trying this out for all calls initially to see how the regression test piplines do.
82-
clientBuilder.addInterceptor(new RetryInterceptor(3, 1000, 2, 8000));
83-
8481
return clientBuilder;
8582
}
8683

marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/RetryInterceptor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* OkHttp interceptor that retries requests on certain connection failures,
1818
* which can be helpful when MarkLogic is temporarily unavailable during restarts.
1919
*/
20-
class RetryInterceptor implements Interceptor {
20+
public class RetryInterceptor implements Interceptor {
2121

2222
private final static Logger logger = org.slf4j.LoggerFactory.getLogger(RetryInterceptor.class);
2323

@@ -26,7 +26,7 @@ class RetryInterceptor implements Interceptor {
2626
private final double backoffMultiplier;
2727
private final long maxDelayMs;
2828

29-
RetryInterceptor(int maxRetries, long initialDelayMs, double backoffMultiplier, long maxDelayMs) {
29+
public RetryInterceptor(int maxRetries, long initialDelayMs, double backoffMultiplier, long maxDelayMs) {
3030
this.maxRetries = maxRetries;
3131
this.initialDelayMs = initialDelayMs;
3232
this.backoffMultiplier = backoffMultiplier;
@@ -36,14 +36,11 @@ class RetryInterceptor implements Interceptor {
3636
@Override
3737
public Response intercept(Chain chain) throws IOException {
3838
Request request = chain.request();
39-
IOException lastException = null;
4039

4140
for (int attempt = 0; attempt <= maxRetries; attempt++) {
4241
try {
4342
return chain.proceed(request);
4443
} catch (IOException e) {
45-
lastException = e;
46-
4744
if (attempt == maxRetries || !isRetryableException(e)) {
4845
logger.warn("Not retryable: {}; {}", e.getClass(), e.getMessage());
4946
throw e;
@@ -57,7 +54,8 @@ public Response intercept(Chain chain) throws IOException {
5754
}
5855
}
5956

60-
throw lastException;
57+
// This should never be reached due to loop logic, but is required for compilation.
58+
throw new IllegalStateException("Unexpected end of retry loop");
6159
}
6260

6361
private boolean isRetryableException(IOException e) {

marklogic-client-api/src/test/java/com/marklogic/client/test/Common.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import com.marklogic.client.DatabaseClient;
99
import com.marklogic.client.DatabaseClientBuilder;
1010
import com.marklogic.client.DatabaseClientFactory;
11+
import com.marklogic.client.extra.okhttpclient.OkHttpClientConfigurator;
12+
import com.marklogic.client.impl.okhttp.RetryInterceptor;
1113
import com.marklogic.client.io.DocumentMetadataHandle;
1214
import com.marklogic.mgmt.ManageClient;
1315
import com.marklogic.mgmt.ManageConfig;
16+
import okhttp3.OkHttpClient;
1417
import org.springframework.util.FileCopyUtils;
1518
import org.w3c.dom.DOMException;
1619
import org.w3c.dom.Document;
@@ -29,6 +32,12 @@
2932

3033
public class Common {
3134

35+
static {
36+
DatabaseClientFactory.removeConfigurators();
37+
DatabaseClientFactory.addConfigurator((OkHttpClientConfigurator) client ->
38+
client.addInterceptor(new RetryInterceptor(3, 1000, 2, 8000)));
39+
}
40+
3241
final public static String USER = "rest-writer";
3342
final public static String PASS = "x";
3443
final public static String REST_ADMIN_USER = "rest-admin";

0 commit comments

Comments
 (0)