27
27
* @summary Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
28
28
* @library /test/lib /test/jdk/java/net/httpclient/lib
29
29
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
30
- * @run testng/othervm -ea -esa MaxStreams
30
+ * @run testng/othervm MaxStreams
31
31
*/
32
32
33
33
import java .io .IOException ;
44
44
import java .util .concurrent .CountDownLatch ;
45
45
import java .util .concurrent .Executors ;
46
46
import java .util .concurrent .ExecutorService ;
47
- import java .util .concurrent .Semaphore ;
48
47
import javax .net .ssl .SSLContext ;
49
48
import java .net .http .HttpClient ;
50
49
import java .net .http .HttpRequest ;
@@ -71,9 +70,7 @@ public class MaxStreams {
71
70
SSLContext ctx ;
72
71
String http2FixedURI ;
73
72
String https2FixedURI ;
74
- volatile CountDownLatch latch ;
75
73
ExecutorService exec ;
76
- final Semaphore canStartTestRun = new Semaphore (1 );
77
74
78
75
// we send an initial warm up request, then MAX_STREAMS+1 requests
79
76
// in parallel. The last of them should hit the limit.
@@ -95,11 +92,9 @@ public Object[][] variants() {
95
92
}
96
93
97
94
98
- @ Test (dataProvider = "uris" , timeOut = 20000 )
95
+ @ Test (dataProvider = "uris" )
99
96
void testAsString (String uri ) throws Exception {
100
- System .err .println ("Semaphore acquire" );
101
- canStartTestRun .acquire ();
102
- latch = new CountDownLatch (1 );
97
+ CountDownLatch latch = new CountDownLatch (1 );
103
98
handler .setLatch (latch );
104
99
HttpClient client = HttpClient .newBuilder ().sslContext (ctx ).build ();
105
100
List <CompletableFuture <HttpResponse <String >>> responses = new LinkedList <>();
@@ -206,12 +201,11 @@ synchronized CountDownLatch getLatch() {
206
201
207
202
@ Override
208
203
public void handle (Http2TestExchange t ) throws IOException {
209
- int c = -1 ;
210
204
try (InputStream is = t .getRequestBody ();
211
205
OutputStream os = t .getResponseBody ()) {
212
206
213
207
is .readAllBytes ();
214
- c = counter .getAndIncrement ();
208
+ int c = counter .getAndIncrement ();
215
209
if (c > 0 && c <= MAX_STREAMS ) {
216
210
// Wait for latch.
217
211
try {
@@ -220,18 +214,15 @@ public void handle(Http2TestExchange t) throws IOException {
220
214
getLatch ().await ();
221
215
System .err .println ("Latch resume" );
222
216
} catch (InterruptedException ee ) {}
217
+ } else if (c == MAX_STREAMS + 1 ) {
218
+ // client issues MAX_STREAMS + 3 requests in total
219
+ // but server should only see MAX_STREAMS + 2 in total. One is rejected by client
220
+ // counter c captured before increment so final value is MAX_STREAMS + 1
221
+ System .err .println ("Counter reset" );
222
+ counter .set (0 );
223
223
}
224
224
t .sendResponseHeaders (200 , RESPONSE .length ());
225
225
os .write (RESPONSE .getBytes ());
226
- } finally {
227
- // client issues MAX_STREAMS + 3 requests in total
228
- // but server should only see MAX_STREAMS + 2 in total. One is rejected by client
229
- // counter c captured before increment so final value is MAX_STREAMS + 1
230
- if (c == MAX_STREAMS + 1 ) {
231
- System .err .println ("Semaphore release" );
232
- counter .set (0 );
233
- canStartTestRun .release ();
234
- }
235
226
}
236
227
}
237
228
}
0 commit comments