Skip to content

Commit 815603c

Browse files
author
Mark
committed
killQuery
1 parent 0ee238d commit 815603c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,36 @@ private Request clearSlowQueriesRequest() {
777777
return new Request(name, RequestType.DELETE, ArangoDBConstants.PATH_API_QUERY_SLOW);
778778
}
779779

780+
/**
781+
* Kills a running query. The query will be terminated at the next cancelation point.
782+
*
783+
* @see <a href= "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#kills-a-running-aql-query">API
784+
* Documentation</a>
785+
* @param id
786+
* The id of the query
787+
* @throws ArangoDBException
788+
*/
789+
public void killQuery(final String id) throws ArangoDBException {
790+
executeSync(killQueryRequest(id), Void.class);
791+
}
792+
793+
/**
794+
* Kills a running query. The query will be terminated at the next cancelation point.
795+
*
796+
* @see <a href= "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#kills-a-running-aql-query">API
797+
* Documentation</a>
798+
* @param id
799+
* The id of the query
800+
* @return void
801+
*/
802+
public CompletableFuture<Void> killQueryAsync(final String id) {
803+
return executeAsync(killQueryRequest(id), Void.class);
804+
}
805+
806+
private Request killQueryRequest(final String id) {
807+
return new Request(name, RequestType.DELETE, createPath(ArangoDBConstants.PATH_API_QUERY, id));
808+
}
809+
780810
/**
781811
* Create a new AQL user function
782812
*

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.arangodb;
2222

2323
import static org.hamcrest.CoreMatchers.notNullValue;
24+
import static org.hamcrest.CoreMatchers.nullValue;
2425
import static org.hamcrest.Matchers.empty;
2526
import static org.hamcrest.Matchers.greaterThan;
2627
import static org.hamcrest.Matchers.is;
@@ -610,6 +611,22 @@ public void getAndClearSlowQueries() throws InterruptedException, ExecutionExcep
610611
}
611612
}
612613

614+
@Test
615+
public void killQuery() throws InterruptedException, ExecutionException {
616+
final CompletableFuture<ArangoCursor<Void>> query = db.queryAsync("return sleep(0.1)", null, null, Void.class);
617+
query.whenComplete((r, e) -> {
618+
assertThat(r, is(nullValue()));
619+
assertThat(e, is(notNullValue()));
620+
});
621+
622+
final Collection<QueryEntity> currentlyRunningQueries = db.getCurrentlyRunningQueries();
623+
assertThat(currentlyRunningQueries, is(notNullValue()));
624+
assertThat(currentlyRunningQueries.size(), is(1));
625+
626+
final QueryEntity queryEntity = currentlyRunningQueries.stream().findFirst().get();
627+
db.killQuery(queryEntity.getId());
628+
}
629+
613630
@Test
614631
public void createGetDeleteAqlFunction() {
615632
final Collection<AqlFunctionEntity> aqlFunctionsInitial = db.getAqlFunctions(null);

0 commit comments

Comments
 (0)