summaryrefslogtreecommitdiffstats
path: root/tenant-cd
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-06-11 14:02:41 +0200
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-06-12 13:58:50 +0200
commitfbf16092467ec8ddc800b70e634caf29d3e0c8b7 (patch)
tree655fc248d532404e29c97a23778f64feece249e8 /tenant-cd
parente6313d99092650f693c75336a90d0fff96fe5b3f (diff)
Use timeout from query when set
Diffstat (limited to 'tenant-cd')
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java10
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java3
2 files changed, 12 insertions, 1 deletions
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java
index d421dc14322..4bdc63fca1a 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Query.java
@@ -1,6 +1,9 @@
package ai.vespa.hosted.cd;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Stream;
import static java.util.Map.copyOf;
@@ -57,4 +60,11 @@ public class Query {
/** Returns the parameters of this query. */
public Map<String, String> parameters() { return parameters; }
+ /** Returns the timeout parameter of the request, if one is set. */
+ public Optional<Duration> timeout() {
+ return Optional.ofNullable(parameters.get("timeout"))
+ .map(timeout -> Duration.of(Long.parseLong(timeout.replaceAll("\\s*m?s", "")),
+ timeout.contains("ms") ? ChronoUnit.MILLIS : ChronoUnit.SECONDS));
+ }
+
}
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
index af66e20bbc7..4fafa65773d 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
@@ -56,7 +56,8 @@ public class HttpEndpoint implements TestEndpoint {
try {
URI target = endpoint.resolve(searchApiPath).resolve("?" + query.rawQuery());
HttpRequest request = HttpRequest.newBuilder()
- .timeout(Duration.ofSeconds(5))
+ .timeout(query.timeout().orElse(Duration.ofMillis(500))
+ .plus(Duration.ofSeconds(1)))
.uri(target)
.build();
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());