test/jdk/java/net/httpclient/PlainProxyConnectionTest.java
author jboes
Fri, 08 Nov 2019 11:15:16 +0000
changeset 59029 3786a0962570
parent 58365 73950479184b
child 58679 9c3209ff7550
permissions -rw-r--r--
8232853: AuthenticationFilter.Cache::remove may throw ConcurrentModificationException Summary: Change implementation to use iterator instead of plain LinkedList Reviewed-by: dfuchs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58055
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     1
/*
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     4
 *
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     8
 *
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    14
 *
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    18
 *
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    21
 * questions.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    22
 */
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    23
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    24
import com.sun.net.httpserver.HttpContext;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    25
import com.sun.net.httpserver.HttpExchange;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    26
import com.sun.net.httpserver.HttpHandler;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    27
import com.sun.net.httpserver.HttpServer;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    28
import java.io.IOException;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    29
import java.io.InputStream;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    30
import java.net.HttpURLConnection;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    31
import java.net.InetAddress;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    32
import java.net.InetSocketAddress;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    33
import java.net.Proxy;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    34
import java.net.ProxySelector;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    35
import java.net.SocketAddress;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    36
import java.net.URI;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    37
import java.net.URISyntaxException;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    38
import java.nio.charset.StandardCharsets;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    39
import java.security.NoSuchAlgorithmException;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    40
import java.util.List;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    41
import java.util.Set;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    42
import java.util.concurrent.ConcurrentLinkedQueue;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    43
import java.net.http.HttpClient;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    44
import java.net.http.HttpRequest;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    45
import java.net.http.HttpResponse;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    46
import java.util.stream.Collectors;
58365
73950479184b 8231504: Update networking tests to avoid implicit dependency on the system proxies
chegar
parents: 58055
diff changeset
    47
import static java.net.Proxy.NO_PROXY;
58055
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    48
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    49
/**
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    50
 * @test
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    51
 * @bug 8230526
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    52
 * @summary Verifies that PlainProxyConnections are cached and reused properly. We do this by
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    53
 *          verifying that the remote address of the HTTP exchange (on the fake proxy server)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    54
 *          is always the same InetSocketAddress.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    55
 * @modules jdk.httpserver
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    56
 * @run main/othervm PlainProxyConnectionTest
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    57
 * @author danielfuchs
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    58
 */
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    59
public class PlainProxyConnectionTest {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    60
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    61
    static final String RESPONSE = "<html><body><p>Hello World!</body></html>";
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    62
    static final String PATH = "/foo/";
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    63
    static final ConcurrentLinkedQueue<InetSocketAddress> connections = new ConcurrentLinkedQueue<>();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    64
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    65
    // For convenience the server is used both as a plain server and as a plain proxy.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    66
    // When used as a proxy, it serves the request itself instead of forwarding it
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    67
    // to the requested server.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    68
    static HttpServer createHttpsServer() throws IOException, NoSuchAlgorithmException {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    69
        HttpServer server = com.sun.net.httpserver.HttpServer.create();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    70
        HttpContext context = server.createContext(PATH);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    71
        context.setHandler(new HttpHandler() {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    72
            @Override
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    73
            public void handle(HttpExchange he) throws IOException {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    74
                connections.add(he.getRemoteAddress());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    75
                he.getResponseHeaders().add("encoding", "UTF-8");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    76
                byte[] bytes = RESPONSE.getBytes(StandardCharsets.UTF_8);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    77
                he.sendResponseHeaders(200, bytes.length > 0 ? bytes.length : -1);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    78
                he.getResponseBody().write(bytes);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    79
                he.close();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    80
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    81
        });
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    82
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    83
        InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    84
        server.bind(addr, 0);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    85
        return server;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    86
    }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    87
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    88
    public static void main(String[] args)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    89
            throws IOException,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    90
            URISyntaxException,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    91
            NoSuchAlgorithmException,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    92
            InterruptedException
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    93
    {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    94
        HttpServer server = createHttpsServer();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    95
        server.start();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    96
        try {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    97
            test(server, HttpClient.Version.HTTP_1_1);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    98
            test(server, HttpClient.Version.HTTP_2);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
    99
        } finally {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   100
            server.stop(0);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   101
            System.out.println("Server stopped");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   102
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   103
    }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   104
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   105
    /**
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   106
     * A Proxy Selector that wraps a ProxySelector.of(), and counts the number
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   107
     * of times its select method has been invoked. This can be used to ensure
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   108
     * that the Proxy Selector is invoked only once per HttpClient.sendXXX
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   109
     * invocation.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   110
     */
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   111
    static class CountingProxySelector extends ProxySelector {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   112
        private final ProxySelector proxySelector;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   113
        private volatile int count; // 0
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   114
        private CountingProxySelector(InetSocketAddress proxyAddress) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   115
            proxySelector = ProxySelector.of(proxyAddress);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   116
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   117
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   118
        public static CountingProxySelector of(InetSocketAddress proxyAddress) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   119
            return new CountingProxySelector(proxyAddress);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   120
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   121
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   122
        int count() { return count; }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   123
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   124
        @Override
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   125
        public List<Proxy> select(URI uri) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   126
            count++;
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   127
            return proxySelector.select(uri);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   128
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   129
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   130
        @Override
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   131
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   132
            proxySelector.connectFailed(uri, sa, ioe);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   133
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   134
    }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   135
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   136
    // The sanity test sends request to the server, and through the proxy,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   137
    // using the legacy HttpURLConnection to verify that server and proxy
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   138
    // work as expected.
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   139
    private static void performSanityTest(HttpServer server, URI uri, URI proxiedURI)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   140
        throws IOException {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   141
        connections.clear();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   142
        System.out.println("Verifying communication with server");
58365
73950479184b 8231504: Update networking tests to avoid implicit dependency on the system proxies
chegar
parents: 58055
diff changeset
   143
        try (InputStream is = uri.toURL().openConnection(NO_PROXY).getInputStream()) {
58055
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   144
            String resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   145
            System.out.println(resp);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   146
            if (!RESPONSE.equals(resp)) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   147
                throw new AssertionError("Unexpected response from server");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   148
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   149
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   150
        System.out.println("Communication with server OK");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   151
        int count = connections.size();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   152
        if (count != 1) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   153
            System.err.println("Unexpected connection count: " + count);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   154
            System.err.println("Connections: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   155
            throw new AssertionError("Expected only one connection: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   156
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   157
        try {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   158
            System.out.println("Pretending the server is a proxy...");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   159
            Proxy p = new Proxy(Proxy.Type.HTTP,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   160
                    InetSocketAddress.createUnresolved(
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   161
                            server.getAddress().getAddress().getHostAddress(),
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   162
                            server.getAddress().getPort()));
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   163
            System.out.println("Verifying communication with proxy");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   164
            HttpURLConnection conn = (HttpURLConnection) proxiedURI.toURL().openConnection(p);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   165
            try (InputStream is = conn.getInputStream()) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   166
                String resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   167
                System.out.println(resp);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   168
                if (!RESPONSE.equals(resp)) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   169
                    throw new AssertionError("Unexpected response from proxy");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   170
                }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   171
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   172
            count = connections.size();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   173
            if (count != 2) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   174
                System.err.println("Unexpected connection count: " + count);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   175
                System.err.println("Connections: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   176
                throw new AssertionError("Expected two connection: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   177
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   178
            System.out.println("Communication with proxy OK");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   179
        } finally {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   180
            connections.clear();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   181
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   182
    }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   183
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   184
    public static void test(HttpServer server, HttpClient.Version version)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   185
            throws IOException,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   186
            URISyntaxException,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   187
            InterruptedException {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   188
        connections.clear();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   189
        System.out.println("\n===== Testing with " + version);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   190
        System.out.println("Server is: " + server.getAddress().toString());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   191
        URI uri = new URI("http", null,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   192
                server.getAddress().getAddress().getHostAddress(),
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   193
                server.getAddress().getPort(), PATH + "x",
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   194
                null, null);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   195
        URI proxiedURI = new URI("http://some.host.that.does.not.exist:4242" + PATH + "x");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   196
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   197
        performSanityTest(server, uri, proxiedURI);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   198
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   199
        try {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   200
            connections.clear();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   201
            System.out.println("\nReal test begins here.");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   202
            System.out.println("Setting up request with HttpClient for version: "
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   203
                    + version.name());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   204
            // This will force the HTTP client to see the server as a proxy,
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   205
            // and to (re)use a PlainProxyConnection to send the request
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   206
            // to the fake `proxiedURI` at
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   207
            // http://some.host.that.does.not.exist:4242/foo/x
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   208
            //
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   209
            CountingProxySelector ps = CountingProxySelector.of(
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   210
                    InetSocketAddress.createUnresolved(
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   211
                            server.getAddress().getAddress().getHostAddress(),
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   212
                            server.getAddress().getPort()));
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   213
            HttpClient client = HttpClient.newBuilder()
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   214
                    .version(version)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   215
                    .proxy(ps)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   216
                    .build();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   217
            HttpRequest request = HttpRequest.newBuilder()
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   218
                    .uri(proxiedURI)
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   219
                    .GET()
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   220
                    .build();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   221
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   222
            System.out.println("Sending request with HttpClient: " + request);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   223
            HttpResponse<String> response
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   224
                    = client.send(request, HttpResponse.BodyHandlers.ofString());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   225
            System.out.println("Got response");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   226
            String resp = response.body();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   227
            System.out.println("Received: " + resp);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   228
            if (!RESPONSE.equals(resp)) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   229
                throw new AssertionError("Unexpected response");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   230
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   231
            if (ps.count() > 1) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   232
                throw new AssertionError("CountingProxySelector. Expected 1, got " + ps.count());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   233
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   234
            int count = connections.size();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   235
            if (count != 1) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   236
                System.err.println("Unexpected connection count: " + count);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   237
                System.err.println("Connections: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   238
                throw new AssertionError("Expected only one connection: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   239
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   240
            for (int i = 2; i < 5; i++) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   241
                System.out.println("Sending next request (" + i + ") with HttpClient: " + request);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   242
                response = client.send(request, HttpResponse.BodyHandlers.ofString());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   243
                System.out.println("Got response");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   244
                resp = response.body();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   245
                System.out.println("Received: " + resp);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   246
                if (!RESPONSE.equals(resp)) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   247
                    throw new AssertionError("Unexpected response");
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   248
                }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   249
                if (ps.count() > i) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   250
                    throw new AssertionError("CountingProxySelector. Expected "
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   251
                            + i + ", got " + ps.count());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   252
                }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   253
                count = connections.size();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   254
                if (count != i) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   255
                    System.err.println("Unexpected connection count: " + count);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   256
                    System.err.println("Connections: " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   257
                    throw new AssertionError("Expected " + i + ": " + connections);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   258
                }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   259
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   260
            Set<InetSocketAddress> remote = connections.stream().distinct().collect(Collectors.toSet());
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   261
            count = remote.size();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   262
            if (count != 1) {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   263
                System.err.println("Unexpected connection count: " + count);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   264
                System.err.println("Connections: " + remote);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   265
                throw new AssertionError("Expected only one connection: " + remote);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   266
            } else {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   267
                System.out.println("PASSED: Proxy received only one connection from: " + remote);
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   268
            }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   269
        } finally {
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   270
            connections.clear();
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   271
        }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   272
    }
734f7711f87c 8230526: jdk.internal.net.http.PlainProxyConnection is never reused by HttpClient
dfuchs
parents:
diff changeset
   273
}