Skip to content

Commit

Permalink
8300172: java/net/httpclient/MappingResponseSubscriber.java failed wi…
Browse files Browse the repository at this point in the history
…th java.net.ConnectException

Reviewed-by: jpai
  • Loading branch information
dfuch committed Jan 20, 2023
1 parent e189397 commit 49d60fe
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test/jdk/java/net/httpclient/MappingResponseSubscriber.java
@@ -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
Expand Down Expand Up @@ -62,6 +62,8 @@
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;
Expand Down Expand Up @@ -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[][]{
Expand Down Expand Up @@ -130,11 +134,30 @@ public void testAsBytes(String uri, boolean sameClient) throws Exception {
client = newHttpClient();

HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
.build();
.build();
BodyHandler<byte[]> handler = new CRSBodyHandler();
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
}
}

Expand Down

1 comment on commit 49d60fe

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.