33import tech .httptoolkit .testapp .cases .*;
44
55import java .lang .management .ManagementFactory ;
6+ import java .util .List ;
67import java .util .Map ;
8+ import java .util .concurrent .*;
79import java .util .concurrent .atomic .AtomicBoolean ;
10+ import java .util .stream .Collectors ;
811
912import static java .lang .Thread .sleep ;
1013
@@ -29,11 +32,15 @@ public static void main(String[] args) throws Exception {
2932 System .out .println ("PID: " + pid ); // Purely for convenient manual attachment to this process
3033
3134 String url = "https://httpbin.org/404/" ; // Always returns a 404, quelle surprise
35+ ExecutorService executor = Executors .newCachedThreadPool ();
3236
3337 while (true ) {
3438 AtomicBoolean allSuccessful = new AtomicBoolean (true );
3539
36- cases .forEach ((name , clientCase ) -> {
40+ List <Future <Void >> tests = executor .invokeAll (cases .entrySet ().stream ().map ((entry ) -> ((Callable <Void >) () -> {
41+ String name = entry .getKey ();
42+ ClientCase <?> clientCase = entry .getValue ();
43+
3744 try {
3845 int result = clientCase .testNew (url );
3946 if (result != 200 ) {
@@ -45,9 +52,7 @@ public static void main(String[] args) throws Exception {
4552 System .out .println (e .toString ());
4653 allSuccessful .set (false );
4754 }
48- });
4955
50- cases .forEach ((name , clientCase ) -> {
5156 try {
5257 int result = clientCase .testExisting (url );
5358 if (result != 200 ) {
@@ -58,7 +63,12 @@ public static void main(String[] args) throws Exception {
5863 System .out .println ("Unexpected failure for existing " + name + ": " + e .toString ());
5964 allSuccessful .set (false );
6065 }
61- });
66+
67+ return null ;
68+ })).collect (Collectors .toList ()));
69+
70+ // Wait for all tests to complete
71+ for (Future <Void > f : tests ) { f .get (); }
6272
6373 if (allSuccessful .get ()) {
6474 System .out .println ("All cases intercepted successfully" );
0 commit comments