Skip to content

Commit 47800bf

Browse files
committed
8280868: LineBodyHandlerTest.java creates and discards too many clients
Reviewed-by: michaelm
1 parent 9d57853 commit 47800bf

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

test/jdk/java/net/httpclient/LineBodyHandlerTest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -84,7 +84,7 @@
8484
* java.logging
8585
* jdk.httpserver
8686
* @library /test/lib http2/server
87-
* @build Http2TestServer LineBodyHandlerTest HttpServerAdapters
87+
* @build Http2TestServer LineBodyHandlerTest HttpServerAdapters ReferenceTracker
8888
* @build jdk.test.lib.net.SimpleSSLContext
8989
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=1 LineBodyHandlerTest
9090
*/
@@ -101,6 +101,10 @@ public class LineBodyHandlerTest implements HttpServerAdapters {
101101
String http2URI;
102102
String https2URI;
103103

104+
final ReferenceTracker TRACKER = ReferenceTracker.INSTANCE;
105+
final AtomicInteger clientCount = new AtomicInteger();
106+
HttpClient sharedClient;
107+
104108
@DataProvider(name = "uris")
105109
public Object[][] variants() {
106110
return new Object[][]{
@@ -189,10 +193,14 @@ private static final List<String> lines(String text, String eol) {
189193
}
190194

191195
HttpClient newClient() {
192-
return HttpClient.newBuilder()
196+
if (sharedClient != null) {
197+
return sharedClient;
198+
}
199+
clientCount.incrementAndGet();
200+
return sharedClient = TRACKER.track(HttpClient.newBuilder()
193201
.sslContext(sslContext)
194202
.proxy(Builder.NO_PROXY)
195-
.build();
203+
.build());
196204
}
197205

198206
@Test(dataProvider = "uris")
@@ -695,10 +703,21 @@ public void setup() throws Exception {
695703

696704
@AfterTest
697705
public void teardown() throws Exception {
706+
sharedClient = null;
707+
try {
708+
System.gc();
709+
Thread.sleep(200);
710+
} catch (InterruptedException io) {
711+
// don't care;
712+
}
713+
AssertionError fail = TRACKER.check(500);
714+
System.out.printf("Tear down: %s client created.%n", clientCount.get());
715+
System.err.printf("Tear down: %s client created.%n", clientCount.get());
698716
httpTestServer.stop();
699717
httpsTestServer.stop();
700718
http2TestServer.stop();
701719
https2TestServer.stop();
720+
if (fail != null) throw fail;
702721
}
703722

704723
static void printBytes(PrintStream out, String prefix, byte[] bytes) {

0 commit comments

Comments
 (0)