Skip to content
Merged
Changes from 1 commit
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 @@ -7,9 +7,12 @@

package org.elasticsearch.repositories.blobstore.testkit.analyze;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.test.rest.ESRestTestCase;

public abstract class AbstractRepositoryAnalysisRestTestCase extends ESRestTestCase {
Expand All @@ -26,12 +29,18 @@ public void testRepositoryAnalysis() throws Exception {
logger.info("creating repository [{}] of type [{}]", repository, repositoryType);
registerRepository(repository, repositoryType, true, repositorySettings);

final TimeValue timeout = TimeValue.timeValueSeconds(120);
final Request request = new Request(HttpPost.METHOD_NAME, "/_snapshot/" + repository + "/_analyze");
request.addParameter("blob_count", "10");
request.addParameter("concurrency", "4");
request.addParameter("max_blob_size", randomFrom("1mb", "10mb"));
request.addParameter("timeout", "120s");
request.addParameter("timeout", timeout.getStringRep());
request.addParameter("seed", Long.toString(randomLong()));
request.setOptions(
RequestOptions.DEFAULT.toBuilder()
.setRequestConfig(RequestConfig.custom().setSocketTimeout(Math.toIntExact(timeout.millis() + 10_000)).build())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.setRequestConfig(RequestConfig.custom().setSocketTimeout(Math.toIntExact(timeout.millis() + 10_000)).build())
.setRequestConfig(RequestConfig.custom().setSocketTimeout(Math.toIntExact(timeout.seconds() + 10)).build())

You have seconds above and milliseconds here. We're probably more accustomed to thinking in milliseconds, so leaving it as-is is fine with me, too 🤷‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parameter to setSocketTimeout is a raw integer representing the timeout in milliseconds - we could add ten seconds like this but then we'd have to convert it to millis either by multiplying by another magic number or else converting it back to a TimeValue and back again

);

assertOK(client().performRequest(request));
}

Expand Down