3232import com .arangodb .velocypack .ValueType ;
3333import com .arangodb .velocypack .exception .VPackException ;
3434import org .junit .BeforeClass ;
35- import org .junit .Ignore ;
3635import org .junit .Test ;
3736import org .junit .runner .RunWith ;
3837import org .junit .runners .Parameterized ;
3938
4039import java .io .IOException ;
4140import java .util .*;
41+ import java .util .concurrent .ExecutionException ;
42+ import java .util .concurrent .ExecutorService ;
43+ import java .util .concurrent .Executors ;
44+ import java .util .concurrent .Future ;
4245import java .util .concurrent .atomic .AtomicInteger ;
4346
4447import static org .hamcrest .CoreMatchers .notNullValue ;
@@ -903,27 +906,47 @@ public void parseQuery() {
903906 }
904907
905908 @ Test
906- @ Ignore
907909 public void getCurrentlyRunningQueries () throws InterruptedException {
908- final Thread t = new Thread () {
909- @ Override
910- public void run () {
911- super .run ();
912- db .query ("return sleep(0.2)" , null , null , Void .class );
913- }
914- };
910+ String query = "return sleep(1)" ;
911+ Thread t = new Thread (() -> db .query (query , null , null , Void .class ));
915912 t .start ();
916- Thread .sleep (100 );
917- try {
918- final Collection <QueryEntity > currentlyRunningQueries = db .getCurrentlyRunningQueries ();
919- assertThat (currentlyRunningQueries , is (notNullValue ()));
920- assertThat (currentlyRunningQueries .size (), is (1 ));
921- final QueryEntity queryEntity = currentlyRunningQueries .iterator ().next ();
922- assertThat (queryEntity .getQuery (), is ("return sleep(0.2)" ));
923- assertThat (queryEntity .getState (), is (QueryExecutionState .EXECUTING ));
924- } finally {
925- t .join ();
926- }
913+ Thread .sleep (300 );
914+ final Collection <QueryEntity > currentlyRunningQueries = db .getCurrentlyRunningQueries ();
915+ assertThat (currentlyRunningQueries , is (notNullValue ()));
916+ assertThat (currentlyRunningQueries .size (), is (1 ));
917+ final QueryEntity queryEntity = currentlyRunningQueries .iterator ().next ();
918+ assertThat (queryEntity .getQuery (), is (query ));
919+ assertThat (queryEntity .getState (), is (QueryExecutionState .EXECUTING ));
920+ t .join ();
921+ }
922+
923+ @ Test
924+ public void killQuery () throws InterruptedException , ExecutionException {
925+ ExecutorService es = Executors .newSingleThreadExecutor ();
926+ Future <?> future = es .submit (() -> {
927+ try {
928+ db .query ("return sleep(5)" , null , null , Void .class );
929+ fail ();
930+ } catch (ArangoDBException e ) {
931+ assertThat (e .getResponseCode (), is (410 ));
932+ assertThat (e .getErrorNum (), is (1500 ));
933+ assertThat (e .getErrorMessage (), containsString ("query killed" ));
934+ }
935+ });
936+ Thread .sleep (500 );
937+
938+ Collection <QueryEntity > currentlyRunningQueries = db .getCurrentlyRunningQueries ();
939+ assertThat (currentlyRunningQueries .size (), is (1 ));
940+ QueryEntity queryEntity = currentlyRunningQueries .iterator ().next ();
941+ assertThat (queryEntity .getState (), is (QueryExecutionState .EXECUTING ));
942+ db .killQuery (queryEntity .getId ());
943+
944+ db .getCurrentlyRunningQueries ().forEach (q ->
945+ assertThat (q .getState (), is (QueryExecutionState .KILLED ))
946+ );
947+
948+ future .get ();
949+ es .shutdown ();
927950 }
928951
929952 @ Test
@@ -948,27 +971,6 @@ public void getAndClearSlowQueries() {
948971 db .setQueryTrackingProperties (properties );
949972 }
950973
951- @ Test
952- @ Ignore
953- public void killQuery () throws InterruptedException {
954- final Thread t = new Thread () {
955- @ Override
956- public void run () {
957- super .run ();
958- db .query ("return sleep(0.2)" , null , null , Void .class );
959- fail ();
960- }
961- };
962- t .start ();
963- Thread .sleep (100 );
964-
965- final Collection <QueryEntity > currentlyRunningQueries = db .getCurrentlyRunningQueries ();
966- assertThat (currentlyRunningQueries .size (), is (1 ));
967-
968- final QueryEntity queryEntity = currentlyRunningQueries .iterator ().next ();
969- db .killQuery (queryEntity .getId ());
970- }
971-
972974 @ Test
973975 public void createGetDeleteAqlFunction () {
974976 final Collection <AqlFunctionEntity > aqlFunctionsInitial = db .getAqlFunctions (null );
0 commit comments