Skip to content

Commit 6285123

Browse files
committed
8268555: Update HttpClient tests that use ITestContext to jtreg 6+1
Reviewed-by: mdoerr Backport-of: da043e9
1 parent 89ee611 commit 6285123

File tree

7 files changed

+214
-19
lines changed

7 files changed

+214
-19
lines changed

test/jdk/java/net/httpclient/AbstractThrowingPublishers.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, 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
@@ -26,6 +26,8 @@
2626
import com.sun.net.httpserver.HttpsServer;
2727
import jdk.testlibrary.SimpleSSLContext;
2828
import org.testng.ITestContext;
29+
import org.testng.ITestResult;
30+
import org.testng.SkipException;
2931
import org.testng.annotations.AfterClass;
3032
import org.testng.annotations.AfterTest;
3133
import org.testng.annotations.BeforeMethod;
@@ -50,6 +52,7 @@
5052
import java.net.http.HttpResponse.BodyHandlers;
5153
import java.nio.ByteBuffer;
5254
import java.nio.charset.StandardCharsets;
55+
import java.util.Arrays;
5356
import java.util.EnumSet;
5457
import java.util.List;
5558
import java.util.Set;
@@ -63,6 +66,7 @@
6366
import java.util.concurrent.Flow;
6467
import java.util.concurrent.SubmissionPublisher;
6568
import java.util.concurrent.atomic.AtomicLong;
69+
import java.util.concurrent.atomic.AtomicReference;
6670
import java.util.function.BiPredicate;
6771
import java.util.function.Consumer;
6872
import java.util.function.Supplier;
@@ -138,17 +142,37 @@ protected boolean stopAfterFirstFailure() {
138142
return Boolean.getBoolean("jdk.internal.httpclient.debug");
139143
}
140144

145+
final AtomicReference<SkipException> skiptests = new AtomicReference<>();
146+
void checkSkip() {
147+
var skip = skiptests.get();
148+
if (skip != null) throw skip;
149+
}
150+
static String name(ITestResult result) {
151+
var params = result.getParameters();
152+
return result.getName()
153+
+ (params == null ? "()" : Arrays.toString(result.getParameters()));
154+
}
155+
141156
@BeforeMethod
142157
void beforeMethod(ITestContext context) {
143158
if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) {
144-
throw new RuntimeException("some tests failed");
159+
if (skiptests.get() == null) {
160+
SkipException skip = new SkipException("some tests failed");
161+
skip.setStackTrace(new StackTraceElement[0]);
162+
skiptests.compareAndSet(null, skip);
163+
}
145164
}
146165
}
147166

148167
@AfterClass
149-
static final void printFailedTests() {
168+
static final void printFailedTests(ITestContext context) {
150169
out.println("\n=========================");
151170
try {
171+
// Exceptions should already have been added to FAILURES
172+
// var failed = context.getFailedTests().getAllResults().stream()
173+
// .collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
174+
// FAILURES.putAll(failed);
175+
152176
out.printf("%n%sCreated %d servers and %d clients%n",
153177
now(), serverCount.get(), clientCount.get());
154178
if (FAILURES.isEmpty()) return;
@@ -385,6 +409,7 @@ private <T,U> void testThrowing(String name, String uri, boolean sameClient,
385409
boolean async, Set<Where> whereValues)
386410
throws Exception
387411
{
412+
checkSkip();
388413
out.printf("%n%s%s%n", now(), name);
389414
try {
390415
testThrowing(uri, sameClient, publishers, finisher, thrower, async, whereValues);

test/jdk/java/net/httpclient/AbstractThrowingPushPromises.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, 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
@@ -42,6 +42,8 @@
4242

4343
import jdk.testlibrary.SimpleSSLContext;
4444
import org.testng.ITestContext;
45+
import org.testng.ITestResult;
46+
import org.testng.SkipException;
4547
import org.testng.annotations.AfterTest;
4648
import org.testng.annotations.AfterClass;
4749
import org.testng.annotations.BeforeMethod;
@@ -67,6 +69,7 @@
6769
import java.net.http.HttpResponse.PushPromiseHandler;
6870
import java.nio.ByteBuffer;
6971
import java.nio.charset.StandardCharsets;
72+
import java.util.Arrays;
7073
import java.util.List;
7174
import java.util.Map;
7275
import java.util.concurrent.CompletableFuture;
@@ -78,6 +81,7 @@
7881
import java.util.concurrent.Executors;
7982
import java.util.concurrent.Flow;
8083
import java.util.concurrent.atomic.AtomicLong;
84+
import java.util.concurrent.atomic.AtomicReference;
8185
import java.util.function.BiPredicate;
8286
import java.util.function.Consumer;
8387
import java.util.function.Function;
@@ -150,17 +154,37 @@ protected boolean stopAfterFirstFailure() {
150154
return Boolean.getBoolean("jdk.internal.httpclient.debug");
151155
}
152156

157+
final AtomicReference<SkipException> skiptests = new AtomicReference<>();
158+
void checkSkip() {
159+
var skip = skiptests.get();
160+
if (skip != null) throw skip;
161+
}
162+
static String name(ITestResult result) {
163+
var params = result.getParameters();
164+
return result.getName()
165+
+ (params == null ? "()" : Arrays.toString(result.getParameters()));
166+
}
167+
153168
@BeforeMethod
154169
void beforeMethod(ITestContext context) {
155170
if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) {
156-
throw new RuntimeException("some tests failed");
171+
if (skiptests.get() == null) {
172+
SkipException skip = new SkipException("some tests failed");
173+
skip.setStackTrace(new StackTraceElement[0]);
174+
skiptests.compareAndSet(null, skip);
175+
}
157176
}
158177
}
159178

160179
@AfterClass
161-
static final void printFailedTests() {
180+
static final void printFailedTests(ITestContext context) {
162181
out.println("\n=========================");
163182
try {
183+
// Exceptions should already have been added to FAILURES
184+
// var failed = context.getFailedTests().getAllResults().stream()
185+
// .collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
186+
// FAILURES.putAll(failed);
187+
164188
out.printf("%n%sCreated %d servers and %d clients%n",
165189
now(), serverCount.get(), clientCount.get());
166190
if (FAILURES.isEmpty()) return;
@@ -359,6 +383,7 @@ private <T,U> void testThrowing(String name, String uri, boolean sameClient,
359383
Finisher finisher, Thrower thrower)
360384
throws Exception
361385
{
386+
checkSkip();
362387
out.printf("%n%s%s%n", now(), name);
363388
try {
364389
testThrowing(uri, sameClient, handlers, finisher, thrower);

test/jdk/java/net/httpclient/AbstractThrowingSubscribers.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, 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
@@ -26,6 +26,8 @@
2626
import com.sun.net.httpserver.HttpsServer;
2727
import jdk.testlibrary.SimpleSSLContext;
2828
import org.testng.ITestContext;
29+
import org.testng.ITestResult;
30+
import org.testng.SkipException;
2931
import org.testng.annotations.AfterTest;
3032
import org.testng.annotations.AfterClass;
3133
import org.testng.annotations.BeforeMethod;
@@ -52,6 +54,7 @@
5254
import java.net.http.HttpResponse.BodySubscriber;
5355
import java.nio.ByteBuffer;
5456
import java.nio.charset.StandardCharsets;
57+
import java.util.Arrays;
5558
import java.util.EnumSet;
5659
import java.util.List;
5760
import java.util.concurrent.CompletableFuture;
@@ -62,6 +65,7 @@
6265
import java.util.concurrent.Executors;
6366
import java.util.concurrent.Flow;
6467
import java.util.concurrent.atomic.AtomicLong;
68+
import java.util.concurrent.atomic.AtomicReference;
6569
import java.util.function.Consumer;
6670
import java.util.function.Predicate;
6771
import java.util.function.Supplier;
@@ -137,17 +141,37 @@ protected boolean stopAfterFirstFailure() {
137141
return Boolean.getBoolean("jdk.internal.httpclient.debug");
138142
}
139143

144+
final AtomicReference<SkipException> skiptests = new AtomicReference<>();
145+
void checkSkip() {
146+
var skip = skiptests.get();
147+
if (skip != null) throw skip;
148+
}
149+
static String name(ITestResult result) {
150+
var params = result.getParameters();
151+
return result.getName()
152+
+ (params == null ? "()" : Arrays.toString(result.getParameters()));
153+
}
154+
140155
@BeforeMethod
141156
void beforeMethod(ITestContext context) {
142157
if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) {
143-
throw new RuntimeException("some tests failed");
158+
if (skiptests.get() == null) {
159+
SkipException skip = new SkipException("some tests failed");
160+
skip.setStackTrace(new StackTraceElement[0]);
161+
skiptests.compareAndSet(null, skip);
162+
}
144163
}
145164
}
146165

147166
@AfterClass
148-
static final void printFailedTests() {
167+
static final void printFailedTests(ITestContext context) {
149168
out.println("\n=========================");
150169
try {
170+
// Exceptions should already have been added to FAILURES
171+
// var failed = context.getFailedTests().getAllResults().stream()
172+
// .collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
173+
// FAILURES.putAll(failed);
174+
151175
out.printf("%n%sCreated %d servers and %d clients%n",
152176
now(), serverCount.get(), clientCount.get());
153177
if (FAILURES.isEmpty()) return;
@@ -379,6 +403,7 @@ private <T,U> void testThrowing(String name, String uri, boolean sameClient,
379403
boolean async, EnumSet<Where> excludes)
380404
throws Exception
381405
{
406+
checkSkip();
382407
out.printf("%n%s%s%n", now(), name);
383408
try {
384409
testThrowing(uri, sameClient, handlers, finisher, thrower, async, excludes);

test/jdk/java/net/httpclient/ForbiddenHeadTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, 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
@@ -49,6 +49,8 @@
4949
import com.sun.net.httpserver.HttpsServer;
5050
import jdk.testlibrary.SimpleSSLContext;
5151
import org.testng.ITestContext;
52+
import org.testng.ITestResult;
53+
import org.testng.SkipException;
5254
import org.testng.annotations.AfterClass;
5355
import org.testng.annotations.AfterTest;
5456
import org.testng.annotations.BeforeMethod;
@@ -72,6 +74,7 @@
7274
import java.net.http.HttpResponse;
7375
import java.net.http.HttpResponse.BodyHandlers;
7476
import java.util.ArrayList;
77+
import java.util.Arrays;
7578
import java.util.List;
7679
import java.util.Optional;
7780
import java.util.concurrent.ConcurrentHashMap;
@@ -80,6 +83,7 @@
8083
import java.util.concurrent.Executor;
8184
import java.util.concurrent.Executors;
8285
import java.util.concurrent.atomic.AtomicLong;
86+
import java.util.concurrent.atomic.AtomicReference;
8387

8488
import static java.lang.System.err;
8589
import static java.lang.System.out;
@@ -148,17 +152,37 @@ protected boolean stopAfterFirstFailure() {
148152
return Boolean.getBoolean("jdk.internal.httpclient.debug");
149153
}
150154

155+
final AtomicReference<SkipException> skiptests = new AtomicReference<>();
156+
void checkSkip() {
157+
var skip = skiptests.get();
158+
if (skip != null) throw skip;
159+
}
160+
static String name(ITestResult result) {
161+
var params = result.getParameters();
162+
return result.getName()
163+
+ (params == null ? "()" : Arrays.toString(result.getParameters()));
164+
}
165+
151166
@BeforeMethod
152167
void beforeMethod(ITestContext context) {
153168
if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) {
154-
throw new RuntimeException("some tests failed");
169+
if (skiptests.get() == null) {
170+
SkipException skip = new SkipException("some tests failed");
171+
skip.setStackTrace(new StackTraceElement[0]);
172+
skiptests.compareAndSet(null, skip);
173+
}
155174
}
156175
}
157176

158177
@AfterClass
159-
static final void printFailedTests() {
178+
static final void printFailedTests(ITestContext context) {
160179
out.println("\n=========================");
161180
try {
181+
// Exceptions should already have been added to FAILURES
182+
// var failed = context.getFailedTests().getAllResults().stream()
183+
// .collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
184+
// FAILURES.putAll(failed);
185+
162186
out.printf("%n%sCreated %d servers and %d clients%n",
163187
now(), serverCount.get(), clientCount.get());
164188
if (FAILURES.isEmpty()) return;
@@ -219,6 +243,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
219243

220244
@Test(dataProvider = "all")
221245
void test(String uriString, int code, boolean async, HttpClient client) throws Throwable {
246+
checkSkip();
222247
var name = String.format("test(%s, %d, %s, %s)", uriString, code, async ? "async" : "sync",
223248
client.authenticator().isPresent() ? "authClient" : "noAuthClient");
224249
out.printf("%n---- starting %s ----%n", name);

test/jdk/java/net/httpclient/ProxySelectorTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, 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
@@ -50,6 +50,8 @@
5050
import com.sun.net.httpserver.HttpsServer;
5151
import jdk.testlibrary.SimpleSSLContext;
5252
import org.testng.ITestContext;
53+
import org.testng.ITestResult;
54+
import org.testng.SkipException;
5355
import org.testng.annotations.AfterClass;
5456
import org.testng.annotations.AfterTest;
5557
import org.testng.annotations.BeforeMethod;
@@ -70,6 +72,7 @@
7072
import java.net.http.HttpRequest;
7173
import java.net.http.HttpResponse;
7274
import java.net.http.HttpResponse.BodyHandlers;
75+
import java.util.Arrays;
7376
import java.util.List;
7477
import java.util.Optional;
7578
import java.util.concurrent.ConcurrentHashMap;
@@ -78,6 +81,8 @@
7881
import java.util.concurrent.Executor;
7982
import java.util.concurrent.Executors;
8083
import java.util.concurrent.atomic.AtomicLong;
84+
import java.util.concurrent.atomic.AtomicReference;
85+
import java.util.stream.Collectors;
8186

8287
import static java.lang.System.err;
8388
import static java.lang.System.out;
@@ -148,17 +153,37 @@ protected boolean stopAfterFirstFailure() {
148153
return Boolean.getBoolean("jdk.internal.httpclient.debug");
149154
}
150155

156+
final AtomicReference<SkipException> skiptests = new AtomicReference<>();
157+
void checkSkip() {
158+
var skip = skiptests.get();
159+
if (skip != null) throw skip;
160+
}
161+
static String name(ITestResult result) {
162+
var params = result.getParameters();
163+
return result.getName()
164+
+ (params == null ? "()" : Arrays.toString(result.getParameters()));
165+
}
166+
151167
@BeforeMethod
152168
void beforeMethod(ITestContext context) {
153169
if (stopAfterFirstFailure() && context.getFailedTests().size() > 0) {
154-
throw new RuntimeException("some tests failed");
170+
if (skiptests.get() == null) {
171+
SkipException skip = new SkipException("some tests failed");
172+
skip.setStackTrace(new StackTraceElement[0]);
173+
skiptests.compareAndSet(null, skip);
174+
}
155175
}
156176
}
157177

158178
@AfterClass
159179
static final void printFailedTests() {
160180
out.println("\n=========================");
161181
try {
182+
// Exceptions should already have been added to FAILURES
183+
// var failed = context.getFailedTests().getAllResults().stream()
184+
// .collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
185+
// FAILURES.putAll(failed);
186+
162187
out.printf("%n%sCreated %d servers and %d clients%n",
163188
now(), serverCount.get(), clientCount.get());
164189
if (FAILURES.isEmpty()) return;
@@ -210,6 +235,7 @@ public Object[][] positive() {
210235
void test(Schemes scheme, HttpClient.Version version, String uri, boolean async)
211236
throws Throwable
212237
{
238+
checkSkip();
213239
var name = String.format("test(%s, %s, %s)", scheme, version, async);
214240
out.printf("%n---- starting %s ----%n", name);
215241

0 commit comments

Comments
 (0)