3535 */
3636// * -Dseed=3582896013206826205L
3737// * -Dseed=5784221742235559231L
38- import com .sun .net .httpserver .HttpServer ;
39- import com .sun .net .httpserver .HttpsConfigurator ;
40- import com .sun .net .httpserver .HttpsServer ;
4138import jdk .internal .net .http .common .OperationTrackers .Tracker ;
4239import jdk .test .lib .RandomFactory ;
4340import jdk .test .lib .net .SimpleSSLContext ;
5653import java .io .InputStream ;
5754import java .io .OutputStream ;
5855import java .lang .ref .Reference ;
59- import java .net .InetAddress ;
60- import java .net .InetSocketAddress ;
6156import java .net .URI ;
6257import java .net .http .HttpClient ;
6358import java .net .http .HttpConnectTimeoutException ;
8075import java .util .concurrent .atomic .AtomicLong ;
8176import java .util .concurrent .atomic .AtomicReference ;
8277import java .util .stream .Collectors ;
83- import java .util .stream .Stream ;
8478import jdk .httpclient .test .lib .common .HttpServerAdapters ;
85- import jdk .httpclient .test .lib .http2 .Http2TestServer ;
8679
87- import static java .lang .System .arraycopy ;
8880import static java .lang .System .out ;
8981import static java .lang .System .err ;
9082import static java .net .http .HttpClient .Version .HTTP_1_1 ;
9183import static java .net .http .HttpClient .Version .HTTP_2 ;
9284import static java .nio .charset .StandardCharsets .UTF_8 ;
9385import static org .testng .Assert .assertEquals ;
86+ import static org .testng .Assert .assertFalse ;
9487import static org .testng .Assert .assertTrue ;
9588
9689public class CancelRequestTest implements HttpServerAdapters {
@@ -179,19 +172,19 @@ void beforeMethod(ITestContext context) {
179172 }
180173
181174 @ AfterClass
182- static final void printFailedTests (ITestContext context ) {
175+ static void printFailedTests (ITestContext context ) {
183176 out .println ("\n =========================" );
184177 var failed = context .getFailedTests ().getAllResults ().stream ()
185- .collect (Collectors .toMap (r -> name ( r ) , ITestResult ::getThrowable ));
178+ .collect (Collectors .toMap (CancelRequestTest :: name , ITestResult ::getThrowable ));
186179 FAILURES .putAll (failed );
187180 try {
188181 out .printf ("%n%sCreated %d servers and %d clients%n" ,
189182 now (), serverCount .get (), clientCount .get ());
190183 if (FAILURES .isEmpty ()) return ;
191184 out .println ("Failed tests: " );
192- FAILURES .entrySet (). forEach ((e ) -> {
193- out .printf ("\t %s: %s%n" , e . getKey (), e . getValue () );
194- e . getValue () .printStackTrace (out );
185+ FAILURES .forEach ((key , value ) -> {
186+ out .printf ("\t %s: %s%n" , key , value );
187+ value .printStackTrace (out );
195188 });
196189 if (tasksFailed ) {
197190 System .out .println ("WARNING: Some tasks failed" );
@@ -327,7 +320,7 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
327320 out .println ("cf2 after cancel: " + cf2 );
328321 try {
329322 String body = cf2 .get ().body ();
330- assertEquals (body , Stream . of ( BODY .split ("\\ |" )). collect ( Collectors . joining ( )));
323+ assertEquals (body , String . join ( "" , BODY .split ("\\ |" )));
331324 throw new AssertionError ("Expected CancellationException not received" );
332325 } catch (ExecutionException x ) {
333326 out .println ("Got expected exception: " + x );
@@ -348,14 +341,14 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
348341 // completed yet - so wait for it here...
349342 try {
350343 String body = response .get ().body ();
351- assertEquals (body , Stream . of ( BODY .split ("\\ |" )). collect ( Collectors . joining ( )));
344+ assertEquals (body , String . join ( "" , BODY .split ("\\ |" )));
352345 if (mayInterruptIfRunning ) {
353346 // well actually - this could happen... In which case we'll need to
354347 // increase the latency in the server handler...
355348 throw new AssertionError ("Expected Exception not received" );
356349 }
357350 } catch (ExecutionException x ) {
358- assertEquals (response .isDone (), true );
351+ assertTrue (response .isDone ());
359352 Throwable wrapped = x .getCause ();
360353 Throwable cause = wrapped ;
361354 if (mayInterruptIfRunning ) {
@@ -383,11 +376,11 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
383376 }
384377 }
385378
386- assertEquals (response .isDone (), true );
387- assertEquals (response .isCancelled (), false );
379+ assertTrue (response .isDone ());
380+ assertFalse (response .isCancelled ());
388381 assertEquals (cf1 .isCancelled (), hasCancellationException );
389- assertEquals (cf2 .isDone (), true );
390- assertEquals (cf2 .isCancelled (), false );
382+ assertTrue (cf2 .isDone ());
383+ assertFalse (cf2 .isCancelled ());
391384 assertEquals (latch .getCount (), 0 );
392385
393386 var error = TRACKER .check (tracker , 1000 ,
@@ -397,6 +390,8 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
397390 Reference .reachabilityFence (client );
398391 if (error != null ) throw error ;
399392 }
393+ assert client != null ;
394+ //if (!sameClient) client.close();
400395 }
401396
402397 @ Test (dataProvider = "asyncurls" )
@@ -413,7 +408,7 @@ public void testPostSendAsync(String uri, boolean sameClient, boolean mayInterru
413408
414409 CompletableFuture <CompletableFuture <?>> cancelFuture = new CompletableFuture <>();
415410
416- Iterable <byte []> iterable = new Iterable <byte [] >() {
411+ Iterable <byte []> iterable = new Iterable <>() {
417412 @ Override
418413 public Iterator <byte []> iterator () {
419414 // this is dangerous
@@ -448,7 +443,7 @@ public Iterator<byte[]> iterator() {
448443 out .println ("cf2 after cancel: " + cf2 );
449444 try {
450445 String body = cf2 .get ().body ();
451- assertEquals (body , Stream . of ( BODY .split ("\\ |" )). collect ( Collectors . joining ( )));
446+ assertEquals (body , String . join ( "" , BODY .split ("\\ |" )));
452447 throw new AssertionError ("Expected CancellationException not received" );
453448 } catch (ExecutionException x ) {
454449 out .println ("Got expected exception: " + x );
@@ -469,14 +464,14 @@ public Iterator<byte[]> iterator() {
469464 // completed yet - so wait for it here...
470465 try {
471466 String body = response .get ().body ();
472- assertEquals (body , Stream . of ( BODY .split ("\\ |" )). collect ( Collectors . joining ( )));
467+ assertEquals (body , String . join ( "" , BODY .split ("\\ |" )));
473468 if (mayInterruptIfRunning ) {
474469 // well actually - this could happen... In which case we'll need to
475470 // increase the latency in the server handler...
476471 throw new AssertionError ("Expected Exception not received" );
477472 }
478473 } catch (ExecutionException x ) {
479- assertEquals (response .isDone (), true );
474+ assertTrue (response .isDone ());
480475 Throwable wrapped = x .getCause ();
481476 assertTrue (CancellationException .class .isAssignableFrom (wrapped .getClass ()));
482477 Throwable cause = wrapped .getCause ();
@@ -495,11 +490,11 @@ public Iterator<byte[]> iterator() {
495490 }
496491 }
497492
498- assertEquals (response .isDone (), true );
499- assertEquals (response .isCancelled (), false );
493+ assertTrue (response .isDone ());
494+ assertFalse (response .isCancelled ());
500495 assertEquals (cf1 .isCancelled (), hasCancellationException );
501- assertEquals (cf2 .isDone (), true );
502- assertEquals (cf2 .isCancelled (), false );
496+ assertTrue (cf2 .isDone ());
497+ assertFalse (cf2 .isCancelled ());
503498 assertEquals (latch .getCount (), 0 );
504499
505500 var error = TRACKER .check (tracker , 1000 ,
@@ -509,6 +504,8 @@ public Iterator<byte[]> iterator() {
509504 Reference .reachabilityFence (client );
510505 if (error != null ) throw error ;
511506 }
507+ assert client != null ;
508+ //if (!sameClient) client.close();
512509 }
513510
514511 @ Test (dataProvider = "urls" )
@@ -572,17 +569,19 @@ public void testPostInterrupt(String uri, boolean sameClient)
572569 } else {
573570 assert failed == null ;
574571 out .println (uriStr + ": got body: " + body );
575- assertEquals (body , Stream . of ( BODY .split ("\\ |" )). collect ( Collectors . joining ( )));
572+ assertEquals (body , String . join ( "" , BODY .split ("\\ |" )));
576573 }
577574 out .println ("next iteration" );
578575
579- var error = TRACKER .check (tracker , 1000 ,
576+ var error = TRACKER .check (tracker , 2000 ,
580577 (t ) -> t .getOutstandingOperations () > 0 || t .getOutstandingSubscribers () > 0 ,
581578 "subscribers for testPostInterrupt(%s)\n \t step [%s]" .formatted (req .uri (), i ),
582579 false );
583580 Reference .reachabilityFence (client );
584581 if (error != null ) throw error ;
585582 }
583+ assert client != null ;
584+ //if (!sameClient) client.close();
586585 }
587586
588587
0 commit comments