8300172: java/net/httpclient/MappingResponseSubscriber.java failed with java.net.ConnectException
Reviewed-by: jpai
This commit is contained in:
parent
e1893976d5
commit
49d60fee49
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -62,6 +62,8 @@ import java.net.http.HttpResponse.BodySubscribers;
|
|||||||
import java.net.http.HttpResponse.BodySubscriber;
|
import java.net.http.HttpResponse.BodySubscriber;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
|
||||||
|
import jdk.internal.net.http.common.OperationTrackers.Tracker;
|
||||||
import jdk.test.lib.net.SimpleSSLContext;
|
import jdk.test.lib.net.SimpleSSLContext;
|
||||||
import org.testng.annotations.AfterTest;
|
import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
@ -92,6 +94,8 @@ public class MappingResponseSubscriber {
|
|||||||
// a shared executor helps reduce the amount of threads created by the test
|
// a shared executor helps reduce the amount of threads created by the test
|
||||||
static final Executor executor = Executors.newCachedThreadPool();
|
static final Executor executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
static final ReferenceTracker TRACKER = ReferenceTracker.INSTANCE;
|
||||||
|
|
||||||
@DataProvider(name = "variants")
|
@DataProvider(name = "variants")
|
||||||
public Object[][] variants() {
|
public Object[][] variants() {
|
||||||
return new Object[][]{
|
return new Object[][]{
|
||||||
@ -130,11 +134,30 @@ public class MappingResponseSubscriber {
|
|||||||
client = newHttpClient();
|
client = newHttpClient();
|
||||||
|
|
||||||
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
|
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
|
||||||
.build();
|
.build();
|
||||||
BodyHandler<byte[]> handler = new CRSBodyHandler();
|
BodyHandler<byte[]> handler = new CRSBodyHandler();
|
||||||
HttpResponse<byte[]> response = client.send(req, handler);
|
HttpResponse<byte[]> response = client.send(req, handler);
|
||||||
byte[] body = response.body();
|
byte[] body = response.body();
|
||||||
assertEquals(body, bytes);
|
assertEquals(body, bytes);
|
||||||
|
|
||||||
|
// if sameClient we will reuse the client for the next
|
||||||
|
// operation, so there's nothing more to do.
|
||||||
|
if (sameClient) continue;
|
||||||
|
|
||||||
|
// if no error and not same client then wait for the
|
||||||
|
// client to be GC'ed before performing the nex operation
|
||||||
|
Tracker tracker = TRACKER.getTracker(client);
|
||||||
|
client = null;
|
||||||
|
System.gc();
|
||||||
|
AssertionError error = TRACKER.check(tracker, 1500);
|
||||||
|
if (error != null) throw error; // the client didn't shut down properly
|
||||||
|
}
|
||||||
|
if (sameClient) {
|
||||||
|
Tracker tracker = TRACKER.getTracker(client);
|
||||||
|
client = null;
|
||||||
|
System.gc();
|
||||||
|
AssertionError error = TRACKER.check(tracker,1500);
|
||||||
|
if (error != null) throw error; // the client didn't shut down properly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user