8300172: java/net/httpclient/MappingResponseSubscriber.java failed with java.net.ConnectException

Reviewed-by: jpai
This commit is contained in:
Daniel Fuchs 2023-01-20 09:23:37 +00:00
parent e1893976d5
commit 49d60fee49

View File

@ -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.
*
* 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.util.function.Function;
import javax.net.ssl.SSLContext;
import jdk.internal.net.http.common.OperationTrackers.Tracker;
import jdk.test.lib.net.SimpleSSLContext;
import org.testng.annotations.AfterTest;
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
static final Executor executor = Executors.newCachedThreadPool();
static final ReferenceTracker TRACKER = ReferenceTracker.INSTANCE;
@DataProvider(name = "variants")
public Object[][] variants() {
return new Object[][]{
@ -135,6 +139,25 @@ public class MappingResponseSubscriber {
HttpResponse<byte[]> response = client.send(req, handler);
byte[] body = response.body();
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
}
}