11/*
2- * Copyright (c) 2018, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
7373import java .util .concurrent .Executors ;
7474import java .util .concurrent .Flow ;
7575import java .util .concurrent .Semaphore ;
76+ import java .util .concurrent .atomic .AtomicInteger ;
7677import java .util .concurrent .atomic .AtomicLong ;
7778import java .util .concurrent .atomic .AtomicReference ;
7879import java .util .function .BiPredicate ;
@@ -112,6 +113,7 @@ public class DependentPromiseActionsTest implements HttpServerAdapters {
112113 static volatile boolean tasksFailed ;
113114 static final AtomicLong serverCount = new AtomicLong ();
114115 static final AtomicLong clientCount = new AtomicLong ();
116+ static final AtomicInteger requestCount = new AtomicInteger ();
115117 static final long start = System .nanoTime ();
116118 public static String now () {
117119 long now = System .nanoTime () - start ;
@@ -244,14 +246,17 @@ HttpClient newHttpClient(boolean share) {
244246 }
245247
246248 @ Test (dataProvider = "noStalls" )
247- public void testNoStalls (String uri , boolean sameClient )
249+ public void testNoStalls (String rootUri , boolean sameClient )
248250 throws Exception {
251+ if (!FAILURES .isEmpty ()) return ;
249252 HttpClient client = null ;
250- out .printf ("%ntestNoStalls(%s, %b)%n" , uri , sameClient );
253+ out .printf ("%ntestNoStalls(%s, %b)%n" , rootUri , sameClient );
251254 for (int i =0 ; i < ITERATION_COUNT ; i ++) {
252255 if (!sameClient || client == null )
253256 client = newHttpClient (sameClient );
254257
258+ String uri = rootUri + "/" + requestCount .incrementAndGet ();
259+ out .printf ("\t sending request %s%n" , uri );
255260 HttpRequest req = HttpRequest .newBuilder (URI .create (uri ))
256261 .build ();
257262 BodyHandler <Stream <String >> handler =
@@ -331,6 +336,10 @@ private <T,U> void testDependent(String name, String uri, boolean sameClient,
331336 SubscriberType subscriberType )
332337 throws Exception
333338 {
339+ if (!FAILURES .isEmpty ()) {
340+ out .printf ("%s: skipping test - previous failure detected%n" , name );
341+ return ;
342+ }
334343 out .printf ("%n%s%s%n" , now (), name );
335344 try {
336345 testDependent (uri , sameClient , handlers , finisher ,
@@ -341,7 +350,7 @@ private <T,U> void testDependent(String name, String uri, boolean sameClient,
341350 }
342351 }
343352
344- private <T ,U > void testDependent (String uri , boolean sameClient ,
353+ private <T ,U > void testDependent (String rootUri , boolean sameClient ,
345354 Supplier <BodyHandler <T >> handlers ,
346355 Finisher finisher ,
347356 Extractor <T > extractor ,
@@ -354,6 +363,8 @@ private <T,U> void testDependent(String uri, boolean sameClient,
354363 if (!sameClient || client == null )
355364 client = newHttpClient (sameClient );
356365
366+ String uri = rootUri + "/" + requestCount .incrementAndGet ();
367+ out .printf ("\t sending request %s%n" , uri );
357368 HttpRequest req = HttpRequest .
358369 newBuilder (URI .create (uri ))
359370 .build ();
@@ -363,7 +374,13 @@ private <T,U> void testDependent(String uri, boolean sameClient,
363374 System .out .println ("try stalling in " + where );
364375 CompletableFuture <HttpResponse <T >> responseCF =
365376 client .sendAsync (req , handler , promiseHandler );
366- assert subscriberType == SubscriberType .LAZZY || !responseCF .isDone ();
377+ // The body of the main response can be received before the body
378+ // of the push promise handlers are received.
379+ // The body of the main response doesn't stall, so the cf of
380+ // the main response may be done here even for EAGER subscribers.
381+ // We cannot make any assumption on the state of the main response
382+ // cf here, so the only thing we can do is to call the finisher
383+ // which will wait for them all.
367384 finisher .finish (where , responseCF , promiseHandler , extractor );
368385 }
369386 }
0 commit comments