From 6e3601d813b96dff0815b3f3b5cc33c49e47278c Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 14 Jun 2017 08:08:01 -0600 Subject: [PATCH] Test: allow setting socket timeout for rest client In #25201, a setting was added to allow setting the retry timeout for the rest client under the impression that this would allow requests to go longer than 30s. However, there is also a socket timeout that needs to be set to greater than 30s, which this change adds a setting for. --- .../upgrades/UpgradeClusterClientYamlTestSuiteIT.java | 1 + .../java/org/elasticsearch/test/rest/ESRestTestCase.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java index 2977e783cf60d..6dfdbb987cc07 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java @@ -55,6 +55,7 @@ protected Settings restClientSettings() { // increase the timeout so that we can actually see the result of failed cluster health // calls that have a default timeout of 30s .put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "40s") + .put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "40s") .build(); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index ce10c6315067b..0aed6fd137b59 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -69,6 +69,7 @@ public abstract class ESRestTestCase extends ESTestCase { public static final String TRUSTSTORE_PATH = "truststore.path"; public static final String TRUSTSTORE_PASSWORD = "truststore.password"; public static final String CLIENT_RETRY_TIMEOUT = "client.retry.timeout"; + public static final String CLIENT_SOCKET_TIMEOUT = "client.socket.timeout"; /** * Convert the entity from a {@link Response} into a map of maps. @@ -346,6 +347,11 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT); builder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis())); } + final String socketTimeoutString = settings.get(CLIENT_SOCKET_TIMEOUT); + if (socketTimeoutString != null) { + final TimeValue socketTimeout = TimeValue.parseTimeValue(socketTimeoutString, CLIENT_SOCKET_TIMEOUT); + builder.setRequestConfigCallback(conf -> conf.setSocketTimeout(Math.toIntExact(socketTimeout.getMillis()))); + } return builder.build(); }