1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
84
84
* java.logging
85
85
* jdk.httpserver
86
86
* @library /test/lib http2/server
87
- * @build Http2TestServer LineBodyHandlerTest HttpServerAdapters
87
+ * @build Http2TestServer LineBodyHandlerTest HttpServerAdapters ReferenceTracker
88
88
* @build jdk.test.lib.net.SimpleSSLContext
89
89
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=1 LineBodyHandlerTest
90
90
*/
@@ -101,6 +101,10 @@ public class LineBodyHandlerTest implements HttpServerAdapters {
101
101
String http2URI ;
102
102
String https2URI ;
103
103
104
+ final ReferenceTracker TRACKER = ReferenceTracker .INSTANCE ;
105
+ final AtomicInteger clientCount = new AtomicInteger ();
106
+ HttpClient sharedClient ;
107
+
104
108
@ DataProvider (name = "uris" )
105
109
public Object [][] variants () {
106
110
return new Object [][]{
@@ -189,10 +193,14 @@ private static final List<String> lines(String text, String eol) {
189
193
}
190
194
191
195
HttpClient newClient () {
192
- return HttpClient .newBuilder ()
196
+ if (sharedClient != null ) {
197
+ return sharedClient ;
198
+ }
199
+ clientCount .incrementAndGet ();
200
+ return sharedClient = TRACKER .track (HttpClient .newBuilder ()
193
201
.sslContext (sslContext )
194
202
.proxy (Builder .NO_PROXY )
195
- .build ();
203
+ .build ()) ;
196
204
}
197
205
198
206
@ Test (dataProvider = "uris" )
@@ -695,10 +703,21 @@ public void setup() throws Exception {
695
703
696
704
@ AfterTest
697
705
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 ());
698
716
httpTestServer .stop ();
699
717
httpsTestServer .stop ();
700
718
http2TestServer .stop ();
701
719
https2TestServer .stop ();
720
+ if (fail != null ) throw fail ;
702
721
}
703
722
704
723
static void printBytes (PrintStream out , String prefix , byte [] bytes ) {
0 commit comments