32
32
import com .arangodb .velocypack .ValueType ;
33
33
import com .arangodb .velocypack .exception .VPackException ;
34
34
import org .junit .BeforeClass ;
35
- import org .junit .Ignore ;
36
35
import org .junit .Test ;
37
36
import org .junit .runner .RunWith ;
38
37
import org .junit .runners .Parameterized ;
39
38
40
39
import java .io .IOException ;
41
40
import 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 ;
42
45
import java .util .concurrent .atomic .AtomicInteger ;
43
46
44
47
import static org .hamcrest .CoreMatchers .notNullValue ;
@@ -903,27 +906,47 @@ public void parseQuery() {
903
906
}
904
907
905
908
@ Test
906
- @ Ignore
907
909
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 ));
915
912
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 ();
927
950
}
928
951
929
952
@ Test
@@ -948,27 +971,6 @@ public void getAndClearSlowQueries() {
948
971
db .setQueryTrackingProperties (properties );
949
972
}
950
973
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
-
972
974
@ Test
973
975
public void createGetDeleteAqlFunction () {
974
976
final Collection <AqlFunctionEntity > aqlFunctionsInitial = db .getAqlFunctions (null );
0 commit comments