40 * java.net.http/jdk.internal.net.http.hpack |
40 * java.net.http/jdk.internal.net.http.hpack |
41 * @run testng/othervm -Djdk.internal.httpclient.debug=true <concrete-class-name> |
41 * @run testng/othervm -Djdk.internal.httpclient.debug=true <concrete-class-name> |
42 */ |
42 */ |
43 |
43 |
44 import jdk.test.lib.net.SimpleSSLContext; |
44 import jdk.test.lib.net.SimpleSSLContext; |
|
45 import org.testng.ITestContext; |
45 import org.testng.annotations.AfterTest; |
46 import org.testng.annotations.AfterTest; |
46 import org.testng.annotations.AfterClass; |
47 import org.testng.annotations.AfterClass; |
|
48 import org.testng.annotations.BeforeMethod; |
47 import org.testng.annotations.BeforeTest; |
49 import org.testng.annotations.BeforeTest; |
48 import org.testng.annotations.DataProvider; |
50 import org.testng.annotations.DataProvider; |
49 import org.testng.annotations.Test; |
|
50 |
51 |
51 import javax.net.ssl.SSLContext; |
52 import javax.net.ssl.SSLContext; |
52 import java.io.BufferedReader; |
53 import java.io.BufferedReader; |
53 import java.io.IOException; |
54 import java.io.IOException; |
54 import java.io.InputStream; |
55 import java.io.InputStream; |
144 } |
145 } |
145 }); |
146 }); |
146 } |
147 } |
147 } |
148 } |
148 |
149 |
|
150 protected boolean stopAfterFirstFailure() { |
|
151 return Boolean.getBoolean("jdk.internal.httpclient.debug"); |
|
152 } |
|
153 |
|
154 @BeforeMethod |
|
155 void beforeMethod(ITestContext context) { |
|
156 if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) { |
|
157 throw new RuntimeException("some tests failed"); |
|
158 } |
|
159 } |
|
160 |
149 @AfterClass |
161 @AfterClass |
150 static final void printFailedTests() { |
162 static final void printFailedTests() { |
151 out.println("\n========================="); |
163 out.println("\n========================="); |
152 try { |
164 try { |
153 out.printf("%n%sCreated %d servers and %d clients%n", |
165 out.printf("%n%sCreated %d servers and %d clients%n", |
206 } |
218 } |
207 } |
219 } |
208 |
220 |
209 private Object[][] variants(List<Thrower> throwers) { |
221 private Object[][] variants(List<Thrower> throwers) { |
210 String[] uris = uris(); |
222 String[] uris = uris(); |
211 Object[][] result = new Object[uris.length * 2 * throwers.size()][]; |
223 // reduce traces by always using the same client if |
|
224 // stopAfterFirstFailure is requested. |
|
225 List<Boolean> sameClients = stopAfterFirstFailure() |
|
226 ? List.of(true) |
|
227 : List.of(false, true); |
|
228 Object[][] result = new Object[uris.length * sameClients.size() * throwers.size()][]; |
212 int i = 0; |
229 int i = 0; |
213 for (Thrower thrower : throwers) { |
230 for (Thrower thrower : throwers) { |
214 for (boolean sameClient : List.of(false, true)) { |
231 for (boolean sameClient : sameClients) { |
215 for (String uri : uris()) { |
232 for (String uri : uris()) { |
216 result[i++] = new Object[]{uri, sameClient, thrower}; |
233 result[i++] = new Object[]{uri, sameClient, thrower}; |
217 } |
234 } |
218 } |
235 } |
219 } |
236 } |
220 assert i == uris.length * 2 * throwers.size(); |
237 assert i == uris.length * sameClients.size() * throwers.size(); |
221 return result; |
238 return result; |
222 } |
239 } |
223 |
240 |
224 @DataProvider(name = "ioVariants") |
241 @DataProvider(name = "ioVariants") |
225 public Object[][] ioVariants() { |
242 public Object[][] ioVariants(ITestContext context) { |
|
243 if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) { |
|
244 return new Object[0][]; |
|
245 } |
226 return variants(List.of( |
246 return variants(List.of( |
227 new UncheckedIOExceptionThrower())); |
247 new UncheckedIOExceptionThrower())); |
228 } |
248 } |
229 |
249 |
230 @DataProvider(name = "customVariants") |
250 @DataProvider(name = "customVariants") |
231 public Object[][] customVariants() { |
251 public Object[][] customVariants(ITestContext context) { |
|
252 if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) { |
|
253 return new Object[0][]; |
|
254 } |
232 return variants(List.of( |
255 return variants(List.of( |
233 new UncheckedCustomExceptionThrower())); |
256 new UncheckedCustomExceptionThrower())); |
234 } |
257 } |
235 |
258 |
236 private HttpClient makeNewClient() { |
259 private HttpClient makeNewClient() { |