Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.FailedRequestException;
import com.marklogic.client.admin.ServerConfigurationManager;
import com.marklogic.client.extra.okhttpclient.OkHttpClientConfigurator;
import com.marklogic.client.impl.SSLUtil;
import com.marklogic.client.impl.okhttp.RetryInterceptor;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.DocumentMetadataHandle.Capability;
import com.marklogic.client.query.QueryManager;
Expand Down Expand Up @@ -45,6 +47,12 @@

public abstract class ConnectedRESTQA {

static {
DatabaseClientFactory.removeConfigurators();
DatabaseClientFactory.addConfigurator((OkHttpClientConfigurator) client ->
client.addInterceptor(new RetryInterceptor(3, 1000, 2, 8000)));
}

private static Properties testProperties = null;

private static String authType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public static OkHttpClient.Builder newOkHttpClientBuilder(String host, DatabaseC
OkHttpUtil.configureSocketFactory(clientBuilder, sslContext, trustManager);
OkHttpUtil.configureHostnameVerifier(clientBuilder, sslVerifier);

// Trying this out for all calls initially to see how the regression test piplines do.
clientBuilder.addInterceptor(new RetryInterceptor(3, 1000, 2, 8000));

return clientBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OkHttp interceptor that retries requests on certain connection failures,
* which can be helpful when MarkLogic is temporarily unavailable during restarts.
*/
class RetryInterceptor implements Interceptor {
public class RetryInterceptor implements Interceptor {

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

Expand All @@ -26,7 +26,7 @@ class RetryInterceptor implements Interceptor {
private final double backoffMultiplier;
private final long maxDelayMs;

RetryInterceptor(int maxRetries, long initialDelayMs, double backoffMultiplier, long maxDelayMs) {
public RetryInterceptor(int maxRetries, long initialDelayMs, double backoffMultiplier, long maxDelayMs) {
this.maxRetries = maxRetries;
this.initialDelayMs = initialDelayMs;
this.backoffMultiplier = backoffMultiplier;
Expand All @@ -36,14 +36,11 @@ class RetryInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
IOException lastException = null;

for (int attempt = 0; attempt <= maxRetries; attempt++) {
try {
return chain.proceed(request);
} catch (IOException e) {
lastException = e;

if (attempt == maxRetries || !isRetryableException(e)) {
logger.warn("Not retryable: {}; {}", e.getClass(), e.getMessage());
throw e;
Expand All @@ -57,7 +54,8 @@ public Response intercept(Chain chain) throws IOException {
}
}

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

private boolean isRetryableException(IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientBuilder;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.extra.okhttpclient.OkHttpClientConfigurator;
import com.marklogic.client.impl.okhttp.RetryInterceptor;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.mgmt.ManageClient;
import com.marklogic.mgmt.ManageConfig;
import okhttp3.OkHttpClient;
import org.springframework.util.FileCopyUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
Expand All @@ -29,6 +32,12 @@

public class Common {

static {
DatabaseClientFactory.removeConfigurators();
DatabaseClientFactory.addConfigurator((OkHttpClientConfigurator) client ->
client.addInterceptor(new RetryInterceptor(3, 1000, 2, 8000)));
}

final public static String USER = "rest-writer";
final public static String PASS = "x";
final public static String REST_ADMIN_USER = "rest-admin";
Expand Down