Skip to content

Commit ce7cf08

Browse files
authored
Feature/3.6/query timeout (#327)
* added timeout option for AQL queries * async tests * changelog upd * renamed cursor timeout to maxRuntime * doc upd
1 parent a174306 commit ce7cf08

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88

99
## [6.5.0] - 2019-xx-xx
1010

11+
- timeout option for AQL queries (ArangoDB v3.6)
1112
- enhancedNgramAnalyzer and enhancedTextAnalyzer (ArangoDB v3.6)
1213

1314
## [6.4.1] - 2019-10-23

src/main/java/com/arangodb/model/AqlQueryOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ public AqlQueryOptions failOnWarning(final Boolean failOnWarning) {
174174
return this;
175175
}
176176

177+
/**
178+
* @param timeout The query has to be executed within the given runtime or it will be killed. The value is specified
179+
* in seconds. The default value is 0.0 (no timeout).
180+
* @return options
181+
*/
182+
public AqlQueryOptions maxRuntime(final Double timeout) {
183+
getOptions().maxRuntime = timeout;
184+
return this;
185+
}
186+
177187
/**
178188
* @return If set to true, then the additional query profiling information will be returned in the sub-attribute
179189
* profile of the extra return attribute if the query result is not served from the query cache.
@@ -396,6 +406,7 @@ private static class Options implements Serializable {
396406
private Integer maxPlans;
397407
private Boolean stream;
398408
private Collection<String> shardIds;
409+
private Double maxRuntime;
399410

400411
protected Optimizer getOptimizer() {
401412
if (optimizer == null) {

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,17 @@ public void queryWithFailOnWarningFalse() {
774774
assertThat(cursor.next(), is("null"));
775775
}
776776

777+
@Test
778+
public void queryWithTimeout() {
779+
assumeTrue(isAtLeastVersion(3, 6));
780+
try {
781+
db.query("RETURN SLEEP(1)", null, new AqlQueryOptions().maxRuntime(0.1), String.class).next();
782+
fail();
783+
} catch (ArangoDBException e) {
784+
assertThat(e.getResponseCode(), is(410));
785+
}
786+
}
787+
777788
@Test
778789
public void queryWithMaxWarningCount() {
779790
final ArangoCursor<String> cursorWithWarnings = db

src/test/java/com/arangodb/async/ArangoDatabaseTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ public void queryStream() throws InterruptedException, ExecutionException {
447447
}
448448
}
449449

450+
@Test
451+
public void queryWithTimeout() throws ExecutionException, InterruptedException {
452+
assumeTrue(isAtLeastVersion(3, 6));
453+
454+
try {
455+
db.query("RETURN SLEEP(1)", null, new AqlQueryOptions().maxRuntime(0.1), String.class).get().next();
456+
fail();
457+
} catch (ExecutionException e) {
458+
assertThat(e.getCause(), instanceOf(ArangoDBException.class));
459+
assertThat(((ArangoDBException) e.getCause()).getResponseCode(), is(410));
460+
}
461+
}
462+
450463
@Test
451464
public void queryWithCount() throws InterruptedException, ExecutionException {
452465
try {

0 commit comments

Comments
 (0)