mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-04 12:08:36 +00:00
8296610: java/net/HttpURLConnection/SetAuthenticator/HTTPSetAuthenticatorTest.java failed with "BindException: Address already in use: connect"
Reviewed-by: michaelm
This commit is contained in:
parent
ed8a2120ca
commit
0dce5b811d
@ -191,25 +191,25 @@ public class HTTPSetAuthenticatorTest extends HTTPTest {
|
||||
// Now tries with explicitly setting the default authenticator: it should
|
||||
// be invoked again.
|
||||
// Uncomment the code below when 8169068 is available.
|
||||
// System.out.println("\nClient: Explicitly setting the default authenticator: "
|
||||
// + toString(Authenticator.getDefault()));
|
||||
// HTTPTestClient.connect(protocol, server, mode, Authenticator.getDefault());
|
||||
// count = authOne.count.get();
|
||||
// if (count != expectedIncrement) {
|
||||
// throw new AssertionError("Authenticator #1 called " + count(count)
|
||||
// + " expected it to be called " + expected(expectedIncrement));
|
||||
// }
|
||||
// count = authTwo.count.get();
|
||||
// if (count != expectedIncrement) {
|
||||
// throw new AssertionError("Authenticator #2 called " + count(count)
|
||||
// + " expected it to be called " + expected(expectedIncrement));
|
||||
// }
|
||||
// count = AUTHENTICATOR.count.get();
|
||||
// if (count != defaultCount + 2 * expectedIncrement) {
|
||||
// throw new AssertionError("Default Authenticator called " + count(count)
|
||||
// + " expected it to be called "
|
||||
// + expected(defaultCount + 2 * expectedIncrement));
|
||||
// }
|
||||
System.out.println("\nClient: Explicitly setting the default authenticator: "
|
||||
+ toString(Authenticator.getDefault()));
|
||||
HTTPTestClient.connect(protocol, server, mode, Authenticator.getDefault());
|
||||
count = authOne.count.get();
|
||||
if (count != expectedIncrement) {
|
||||
throw new AssertionError("Authenticator #1 called " + count(count)
|
||||
+ " expected it to be called " + expected(expectedIncrement));
|
||||
}
|
||||
count = authTwo.count.get();
|
||||
if (count != expectedIncrement) {
|
||||
throw new AssertionError("Authenticator #2 called " + count(count)
|
||||
+ " expected it to be called " + expected(expectedIncrement));
|
||||
}
|
||||
count = AUTHENTICATOR.count.get();
|
||||
if (count != defaultCount + 2 * expectedIncrement) {
|
||||
throw new AssertionError("Default Authenticator called " + count(count)
|
||||
+ " expected it to be called "
|
||||
+ expected(defaultCount + 2 * expectedIncrement));
|
||||
}
|
||||
|
||||
// Now tries to set an authenticator on a connected connection.
|
||||
URL url = url(protocol, server.getAddress(), "/");
|
||||
@ -238,16 +238,16 @@ public class HTTPSetAuthenticatorTest extends HTTPTest {
|
||||
+ ise);
|
||||
}
|
||||
// Uncomment the code below when 8169068 is available.
|
||||
// try {
|
||||
// conn.setAuthenticator(Authenticator.getDefault());
|
||||
// throw new RuntimeException("Expected IllegalStateException"
|
||||
// + " trying to set an authenticator after connect"
|
||||
// + " not raised.");
|
||||
// } catch (IllegalStateException ise) {
|
||||
// System.out.println("Client: caught expected ISE"
|
||||
// + " trying to set an authenticator after connect: "
|
||||
// + ise);
|
||||
// }
|
||||
try {
|
||||
conn.setAuthenticator(Authenticator.getDefault());
|
||||
throw new RuntimeException("Expected IllegalStateException"
|
||||
+ " trying to set an authenticator after connect"
|
||||
+ " not raised.");
|
||||
} catch (IllegalStateException ise) {
|
||||
System.out.println("Client: caught expected ISE"
|
||||
+ " trying to set an authenticator after connect: "
|
||||
+ ise);
|
||||
}
|
||||
try {
|
||||
conn.setAuthenticator(null);
|
||||
throw new RuntimeException("Expected"
|
||||
@ -279,7 +279,7 @@ public class HTTPSetAuthenticatorTest extends HTTPTest {
|
||||
// All good!
|
||||
// return the number of times the default authenticator is supposed
|
||||
// to have been called.
|
||||
return scheme == HttpSchemeType.NONE ? 0 : 1 * EXPECTED_AUTH_CALLS_PER_TEST;
|
||||
return scheme == HttpSchemeType.NONE ? 0 : 2 * EXPECTED_AUTH_CALLS_PER_TEST;
|
||||
}
|
||||
|
||||
static String toString(Authenticator a) {
|
||||
|
||||
@ -23,10 +23,12 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Authenticator;
|
||||
import java.net.BindException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
/**
|
||||
@ -35,11 +37,39 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
*/
|
||||
public class HTTPTestClient extends HTTPTest {
|
||||
|
||||
public static final long DELAY_BEFORE_RETRY = 2500; // milliseconds
|
||||
|
||||
public static void connect(HttpProtocolType protocol,
|
||||
HTTPTestServer server,
|
||||
HttpAuthType authType,
|
||||
Authenticator auth)
|
||||
throws IOException {
|
||||
try {
|
||||
doConnect(protocol, server, authType, auth);
|
||||
} catch (BindException ex) {
|
||||
// sleep a bit then try again once
|
||||
System.out.println("WARNING: Unexpected BindException: " + ex);
|
||||
System.out.println("\tSleeping a bit and try again...");
|
||||
long start = System.nanoTime();
|
||||
System.gc();
|
||||
try {
|
||||
Thread.sleep(DELAY_BEFORE_RETRY);
|
||||
} catch (InterruptedException iex) {
|
||||
// ignore
|
||||
}
|
||||
System.gc();
|
||||
System.out.println("\tRetrying after "
|
||||
+ Duration.ofNanos(System.nanoTime() - start).toMillis()
|
||||
+ " milliseconds");
|
||||
doConnect(protocol, server, authType, auth);
|
||||
}
|
||||
}
|
||||
|
||||
public static void doConnect(HttpProtocolType protocol,
|
||||
HTTPTestServer server,
|
||||
HttpAuthType authType,
|
||||
Authenticator auth)
|
||||
throws IOException {
|
||||
|
||||
InetSocketAddress address = server.getAddress();
|
||||
final URL url = url(protocol, address, "/");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user