8223632: Replace wildcard address with loopback or local host in tests - part 5

Replaces wildcard usage by loopback, when possible, adds intermittent keyword and a comment, when not.

Reviewed-by: chegar
This commit is contained in:
Daniel Fuchs 2019-05-13 17:31:23 +01:00
parent 4a59b995da
commit 3103d346a7
9 changed files with 131 additions and 53 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2019, 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
@ -26,7 +26,7 @@
* @bug 4696512
* @summary HTTP client: Improve proxy server configuration and selection
* @modules java.base/sun.net.www
* @library ../../../sun/net/www/httptest/
* @library ../../../sun/net/www/httptest/ /test/lib
* @build ClosedChannelList TestHttpServer HttpTransaction HttpCallback
* @compile ProxyTest.java
* @run main/othervm -Dhttp.proxyHost=inexistant -Dhttp.proxyPort=8080 ProxyTest
@ -35,6 +35,7 @@
import java.net.*;
import java.io.*;
import java.util.ArrayList;
import jdk.test.lib.net.URIBuilder;
public class ProxyTest implements HttpCallback {
static TestHttpServer server;
@ -52,8 +53,8 @@ public class ProxyTest implements HttpCallback {
}
static public class MyProxySelector extends ProxySelector {
private ProxySelector def = null;
private ArrayList<Proxy> noProxy;
private static volatile URI lastURI;
private final ArrayList<Proxy> noProxy;
public MyProxySelector() {
noProxy = new ArrayList<Proxy>(1);
@ -61,13 +62,16 @@ public class ProxyTest implements HttpCallback {
}
public java.util.List<Proxy> select(URI uri) {
System.out.println("Selecting no proxy for " + uri);
lastURI = uri;
return noProxy;
}
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
}
}
public static URI lastURI() { return lastURI; }
}
public static void main(String[] args) {
ProxySelector defSelector = ProxySelector.getDefault();
@ -75,12 +79,21 @@ public class ProxyTest implements HttpCallback {
throw new RuntimeException("Default ProxySelector is null");
ProxySelector.setDefault(new MyProxySelector());
try {
InetAddress loopback = InetAddress.getLoopbackAddress();
server = new TestHttpServer (new ProxyTest(), 1, 10, 0);
URL url = new URL("http://localhost:"+server.getLocalPort());
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(server.getLocalPort())
.toURL();
System.out.println ("client opening connection to: " + url);
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
InputStream is = urlc.getInputStream ();
is.close();
URI lastURI = MyProxySelector.lastURI();
if (!String.valueOf(lastURI).equals(url + "/")) {
throw new AssertionError("Custom proxy was not used: last URI was " + lastURI);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {