77import org .junit .jupiter .params .ParameterizedTest ;
88import org .junit .jupiter .params .provider .EnumSource ;
99
10+ import java .util .ArrayList ;
1011import java .util .List ;
1112import java .util .concurrent .CompletableFuture ;
1213import java .util .concurrent .ExecutionException ;
@@ -23,23 +24,23 @@ class ConcurrencyAsyncTests {
2324 @ EnumSource (Protocol .class )
2425 @ Timeout (2 )
2526 void executorLimit (Protocol protocol ) {
27+ ExecutorService asyncExecutor = Executors .newCachedThreadPool ();
2628 ArangoDBAsync adb = new ArangoDB .Builder ()
2729 .loadProperties (ConfigUtils .loadConfig ())
2830 .maxConnections (1 )
2931 .protocol (protocol )
30- .asyncExecutor (Executors .newCachedThreadPool ())
3132 .build ().async ();
3233
3334 List <CompletableFuture <ArangoDBVersion >> futures = IntStream .range (0 , 20 )
3435 .mapToObj (i -> adb .getVersion ()
35- .whenComplete ((dbVersion , ex ) -> {
36+ .whenCompleteAsync ((dbVersion , ex ) -> {
3637 System .out .println (Thread .currentThread ().getName ());
3738 try {
3839 Thread .sleep (1000 );
3940 } catch (InterruptedException e ) {
4041 e .printStackTrace ();
4142 }
42- }))
43+ }, asyncExecutor ))
4344 .collect (Collectors .toList ());
4445
4546 futures .forEach (future -> {
@@ -51,21 +52,26 @@ void executorLimit(Protocol protocol) {
5152 }
5253 });
5354 adb .shutdown ();
55+ asyncExecutor .shutdown ();
5456 }
5557
5658
5759 @ Disabled
5860 @ ParameterizedTest
5961 @ EnumSource (Protocol .class )
60- @ Timeout (1 )
61- void outgoingRequestsParallelismTest (Protocol protocol ) {
62+ @ Timeout (2 )
63+ void outgoingRequestsParallelismTest (Protocol protocol ) throws ExecutionException , InterruptedException {
6264 ArangoDBAsync adb = new ArangoDB .Builder ()
6365 .loadProperties (ConfigUtils .loadConfig ())
6466 .maxConnections (20 )
6567 .protocol (protocol ).build ().async ();
6668
69+ List <CompletableFuture <?>> reqs = new ArrayList <>();
6770 for (int i = 0 ; i < 50_000 ; i ++) {
68- adb .getVersion ();
71+ reqs .add (adb .getVersion ());
72+ }
73+ for (CompletableFuture <?> req : reqs ) {
74+ req .get ();
6975 }
7076 adb .shutdown ();
7177 }
0 commit comments