Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit da043e9

Browse files
committed
8268555: Update HttpClient tests that use ITestContext to jtreg 6+1
Reviewed-by: chegar
1 parent a437ce8 commit da043e9

10 files changed

+304
-28
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.test.lib.net.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
@@ -43,6 +43,8 @@
4343

4444
import jdk.test.lib.net.SimpleSSLContext;
4545
import org.testng.ITestContext;
46+
import org.testng.ITestResult;
47+
import org.testng.SkipException;
4648
import org.testng.annotations.AfterTest;
4749
import org.testng.annotations.AfterClass;
4850
import org.testng.annotations.BeforeMethod;
@@ -68,6 +70,7 @@
6870
import java.net.http.HttpResponse.PushPromiseHandler;
6971
import java.nio.ByteBuffer;
7072
import java.nio.charset.StandardCharsets;
73+
import java.util.Arrays;
7174
import java.util.List;
7275
import java.util.Map;
7376
import java.util.concurrent.CompletableFuture;
@@ -79,6 +82,7 @@
7982
import java.util.concurrent.Executors;
8083
import java.util.concurrent.Flow;
8184
import java.util.concurrent.atomic.AtomicLong;
85+
import java.util.concurrent.atomic.AtomicReference;
8286
import java.util.function.BiPredicate;
8387
import java.util.function.Consumer;
8488
import java.util.function.Function;
@@ -151,17 +155,37 @@ protected boolean stopAfterFirstFailure() {
151155
return Boolean.getBoolean("jdk.internal.httpclient.debug");
152156
}
153157

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

161180
@AfterClass
162-
static final void printFailedTests() {
181+
static final void printFailedTests(ITestContext context) {
163182
out.println("\n=========================");
164183
try {
184+
// Exceptions should already have been added to FAILURES
185+
// var failed = context.getFailedTests().getAllResults().stream()
186+
// .collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
187+
// FAILURES.putAll(failed);
188+
165189
out.printf("%n%sCreated %d servers and %d clients%n",
166190
now(), serverCount.get(), clientCount.get());
167191
if (FAILURES.isEmpty()) return;
@@ -360,6 +384,7 @@ private <T,U> void testThrowing(String name, String uri, boolean sameClient,
360384
Finisher finisher, Thrower thrower)
361385
throws Exception
362386
{
387+
checkSkip();
363388
out.printf("%n%s%s%n", now(), name);
364389
try {
365390
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.test.lib.net.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/AggregateRequestBodyTest.java

Lines changed: 36 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
@@ -47,6 +47,7 @@
4747
import java.net.http.HttpResponse;
4848
import java.net.http.HttpResponse.BodyHandlers;
4949
import java.nio.ByteBuffer;
50+
import java.util.Arrays;
5051
import java.util.LinkedHashMap;
5152
import java.util.List;
5253
import java.util.Map;
@@ -63,6 +64,7 @@
6364
import java.util.concurrent.TimeUnit;
6465
import java.util.concurrent.TimeoutException;
6566
import java.util.concurrent.atomic.AtomicLong;
67+
import java.util.concurrent.atomic.AtomicReference;
6668
import java.util.function.Consumer;
6769
import java.util.function.Supplier;
6870
import java.util.stream.Collectors;
@@ -76,6 +78,8 @@
7678
import jdk.test.lib.net.SimpleSSLContext;
7779
import org.testng.Assert;
7880
import org.testng.ITestContext;
81+
import org.testng.ITestResult;
82+
import org.testng.SkipException;
7983
import org.testng.annotations.AfterClass;
8084
import org.testng.annotations.AfterTest;
8185
import org.testng.annotations.BeforeMethod;
@@ -151,17 +155,36 @@ protected boolean stopAfterFirstFailure() {
151155
return Boolean.getBoolean("jdk.internal.httpclient.debug");
152156
}
153157

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

161180
@AfterClass
162-
static final void printFailedTests() {
181+
static final void printFailedTests(ITestContext context) {
163182
out.println("\n=========================");
164183
try {
184+
var failed = context.getFailedTests().getAllResults().stream()
185+
.collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
186+
FAILURES.putAll(failed);
187+
165188
out.printf("%n%sCreated %d servers and %d clients%n",
166189
now(), serverCount.get(), clientCount.get());
167190
if (FAILURES.isEmpty()) return;
@@ -446,13 +469,15 @@ static PublishWithError withNoError(List<String> content) {
446469

447470
@Test(dataProvider = "sparseContent") // checks that NPE is thrown
448471
public void testNullPointerException(String description, String[] content) {
472+
checkSkip();
449473
BodyPublisher[] publishers = publishers(content);
450474
Assert.assertThrows(NullPointerException.class, () -> BodyPublishers.concat(publishers));
451475
}
452476

453477
// Verifies that an empty array creates a "noBody" publisher
454478
@Test
455479
public void testEmpty() {
480+
checkSkip();
456481
BodyPublisher publisher = BodyPublishers.concat();
457482
RequestSubscriber subscriber = new RequestSubscriber();
458483
assertEquals(publisher.contentLength(), 0);
@@ -466,6 +491,7 @@ public void testEmpty() {
466491
// verifies that error emitted by upstream publishers are propagated downstream.
467492
@Test(dataProvider = "sparseContent") // nulls are replaced with error publisher
468493
public void testOnError(String description, String[] content) {
494+
checkSkip();
469495
final RequestSubscriber subscriber = new RequestSubscriber();
470496
final PublishWithError errorPublisher;
471497
final BodyPublisher[] publishers;
@@ -521,6 +547,7 @@ public void testOnError(String description, String[] content) {
521547
// the length should be known.
522548
@Test(dataProvider = "sparseContent") // nulls are replaced with unknown length
523549
public void testUnknownContentLength(String description, String[] content) {
550+
checkSkip();
524551
if (content == null) {
525552
content = BODIES.toArray(String[]::new);
526553
description = "BODIES (known length)";
@@ -561,6 +588,7 @@ private static final Throwable completionCause(CompletionException x) {
561588

562589
@Test(dataProvider = "negativeRequests")
563590
public void testNegativeRequest(long n) {
591+
checkSkip();
564592
assert n <= 0 : "test for negative request called with n > 0 : " + n;
565593
BodyPublisher[] publishers = ContentLengthPublisher.of(List.of(1L, 2L, 3L));
566594
BodyPublisher publisher = BodyPublishers.concat(publishers);
@@ -584,6 +612,7 @@ static BodyPublisher[] ofStrings(String... strings) {
584612

585613
@Test
586614
public void testPositiveRequests() {
615+
checkSkip();
587616
// A composite array of publishers
588617
BodyPublisher[] publishers = Stream.of(
589618
Stream.of(ofStrings("Lorem", " ", "ipsum", " ")),
@@ -626,6 +655,7 @@ public void testPositiveRequests() {
626655

627656
@Test(dataProvider = "contentLengths")
628657
public void testContentLength(long expected, List<Long> lengths) {
658+
checkSkip();
629659
BodyPublisher[] publishers = ContentLengthPublisher.of(lengths);
630660
BodyPublisher aggregate = BodyPublishers.concat(publishers);
631661
assertEquals(aggregate.contentLength(), expected,
@@ -636,6 +666,7 @@ public void testContentLength(long expected, List<Long> lengths) {
636666
// publishers are no longer subscribed etc...
637667
@Test
638668
public void testCancel() {
669+
checkSkip();
639670
BodyPublisher[] publishers = BODIES.stream()
640671
.map(BodyPublishers::ofString)
641672
.toArray(BodyPublisher[]::new);
@@ -695,6 +726,7 @@ public void testCancel() {
695726
// Verifies that cancelling the subscription is propagated downstream
696727
@Test
697728
public void testCancelSubscription() {
729+
checkSkip();
698730
PublishWithError upstream = new PublishWithError(BODIES, BODIES.size(),
699731
() -> new AssertionError("should not come here"));
700732
BodyPublisher publisher = BodyPublishers.concat(upstream);
@@ -756,6 +788,7 @@ public void testCancelSubscription() {
756788

757789
@Test(dataProvider = "variants")
758790
public void test(String uri, boolean sameClient) throws Exception {
791+
checkSkip();
759792
System.out.println("Request to " + uri);
760793

761794
HttpClient client = newHttpClient(sameClient);

0 commit comments

Comments
 (0)