author | prappo |
Wed, 21 Mar 2018 10:25:26 +0000 | |
branch | http-client-branch |
changeset 56327 | efd50952acd9 |
parent 56315 | ec8799d412fb |
child 56417 | 312811f70c43 |
permissions | -rw-r--r-- |
56315
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
1 |
/* |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
4 |
* |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
8 |
* |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
14 |
* |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
18 |
* |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
22 |
*/ |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
23 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
24 |
/* |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
25 |
* @test |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
26 |
* @summary Tests that our client deals correctly with servers that |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
27 |
* close the connection right after sending the last byte. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
28 |
* @library /lib/testlibrary http2/server |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
29 |
* @build jdk.testlibrary.SimpleSSLContext HttpServerAdapters EncodedCharsInURI |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
30 |
* @modules java.base/sun.net.www.http |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
31 |
* java.net.http/jdk.internal.net.http.common |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
32 |
* java.net.http/jdk.internal.net.http.frame |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
33 |
* java.net.http/jdk.internal.net.http.hpack |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
34 |
* @run testng/othervm ServerCloseTest |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
35 |
*/ |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
36 |
//* -Djdk.internal.httpclient.debug=true |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
37 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
38 |
import jdk.testlibrary.SimpleSSLContext; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
39 |
import org.testng.annotations.AfterClass; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
40 |
import org.testng.annotations.AfterTest; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
41 |
import org.testng.annotations.BeforeTest; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
42 |
import org.testng.annotations.DataProvider; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
43 |
import org.testng.annotations.Test; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
44 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
45 |
import javax.net.ServerSocketFactory; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
46 |
import javax.net.ssl.SSLContext; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
47 |
import java.io.IOException; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
48 |
import java.io.InputStream; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
49 |
import java.io.OutputStream; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
50 |
import java.io.OutputStreamWriter; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
51 |
import java.io.PrintWriter; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
52 |
import java.io.Writer; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
53 |
import java.net.InetAddress; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
54 |
import java.net.InetSocketAddress; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
55 |
import java.net.ServerSocket; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
56 |
import java.net.Socket; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
57 |
import java.net.URI; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
58 |
import java.net.http.HttpClient; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
59 |
import java.net.http.HttpRequest; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
60 |
import java.net.http.HttpRequest.BodyPublisher; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
61 |
import java.net.http.HttpRequest.BodyPublishers; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
62 |
import java.net.http.HttpResponse; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
63 |
import java.net.http.HttpResponse.BodyHandler; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
64 |
import java.net.http.HttpResponse.BodyHandlers; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
65 |
import java.util.List; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
66 |
import java.util.Locale; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
67 |
import java.util.StringTokenizer; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
68 |
import java.util.concurrent.CompletableFuture; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
69 |
import java.util.concurrent.ConcurrentHashMap; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
70 |
import java.util.concurrent.ConcurrentLinkedQueue; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
71 |
import java.util.concurrent.ConcurrentMap; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
72 |
import java.util.concurrent.Executor; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
73 |
import java.util.concurrent.Executors; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
74 |
import java.util.concurrent.atomic.AtomicLong; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
75 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
76 |
import static java.lang.System.out; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
77 |
import static java.nio.charset.StandardCharsets.UTF_8; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
78 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
79 |
public class ServerCloseTest implements HttpServerAdapters { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
80 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
81 |
SSLContext sslContext; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
82 |
DummyServer httpDummyServer; // HTTP/1.1 [ 2 servers ] |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
83 |
DummyServer httpsDummyServer; // HTTPS/1.1 |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
84 |
String httpDummy; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
85 |
String httpsDummy; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
86 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
87 |
static final int ITERATION_COUNT = 3; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
88 |
// a shared executor helps reduce the amount of threads created by the test |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
89 |
static final Executor executor = new TestExecutor(Executors.newCachedThreadPool()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
90 |
static final ConcurrentMap<String, Throwable> FAILURES = new ConcurrentHashMap<>(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
91 |
static volatile boolean tasksFailed; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
92 |
static final AtomicLong serverCount = new AtomicLong(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
93 |
static final AtomicLong clientCount = new AtomicLong(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
94 |
static final long start = System.nanoTime(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
95 |
public static String now() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
96 |
long now = System.nanoTime() - start; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
97 |
long secs = now / 1000_000_000; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
98 |
long mill = (now % 1000_000_000) / 1000_000; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
99 |
long nan = now % 1000_000; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
100 |
return String.format("[%d s, %d ms, %d ns] ", secs, mill, nan); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
101 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
102 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
103 |
private volatile HttpClient sharedClient; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
104 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
105 |
static class TestExecutor implements Executor { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
106 |
final AtomicLong tasks = new AtomicLong(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
107 |
Executor executor; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
108 |
TestExecutor(Executor executor) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
109 |
this.executor = executor; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
110 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
111 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
112 |
@Override |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
113 |
public void execute(Runnable command) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
114 |
long id = tasks.incrementAndGet(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
115 |
executor.execute(() -> { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
116 |
try { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
117 |
command.run(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
118 |
} catch (Throwable t) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
119 |
tasksFailed = true; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
120 |
System.out.printf(now() + "Task %s failed: %s%n", id, t); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
121 |
System.err.printf(now() + "Task %s failed: %s%n", id, t); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
122 |
FAILURES.putIfAbsent("Task " + id, t); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
123 |
throw t; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
124 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
125 |
}); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
126 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
127 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
128 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
129 |
@AfterClass |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
130 |
static final void printFailedTests() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
131 |
out.println("\n========================="); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
132 |
try { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
133 |
out.printf("%n%sCreated %d servers and %d clients%n", |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
134 |
now(), serverCount.get(), clientCount.get()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
135 |
if (FAILURES.isEmpty()) return; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
136 |
out.println("Failed tests: "); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
137 |
FAILURES.entrySet().forEach((e) -> { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
138 |
out.printf("\t%s: %s%n", e.getKey(), e.getValue()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
139 |
e.getValue().printStackTrace(out); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
140 |
}); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
141 |
if (tasksFailed) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
142 |
System.out.println("WARNING: Some tasks failed"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
143 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
144 |
} finally { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
145 |
out.println("\n=========================\n"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
146 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
147 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
148 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
149 |
private String[] uris() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
150 |
return new String[] { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
151 |
httpDummy, |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
152 |
httpsDummy, |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
153 |
}; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
154 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
155 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
156 |
@DataProvider(name = "servers") |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
157 |
public Object[][] noThrows() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
158 |
String[] uris = uris(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
159 |
Object[][] result = new Object[uris.length * 2][]; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
160 |
//Object[][] result = new Object[uris.length][]; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
161 |
int i = 0; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
162 |
for (boolean sameClient : List.of(false, true)) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
163 |
//if (!sameClient) continue; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
164 |
for (String uri: uris()) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
165 |
result[i++] = new Object[] {uri, sameClient}; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
166 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
167 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
168 |
assert i == uris.length * 2; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
169 |
// assert i == uris.length ; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
170 |
return result; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
171 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
172 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
173 |
private HttpClient makeNewClient() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
174 |
clientCount.incrementAndGet(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
175 |
return HttpClient.newBuilder() |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
176 |
.executor(executor) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
177 |
.sslContext(sslContext) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
178 |
.build(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
179 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
180 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
181 |
HttpClient newHttpClient(boolean share) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
182 |
if (!share) return makeNewClient(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
183 |
HttpClient shared = sharedClient; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
184 |
if (shared != null) return shared; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
185 |
synchronized (this) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
186 |
shared = sharedClient; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
187 |
if (shared == null) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
188 |
shared = sharedClient = makeNewClient(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
189 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
190 |
return shared; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
191 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
192 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
193 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
194 |
final String ENCODED = "/01%252F03/"; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
195 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
196 |
@Test(dataProvider = "servers") |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
197 |
public void testServerClose(String uri, boolean sameClient) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
198 |
throws Exception { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
199 |
HttpClient client = null; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
200 |
out.printf("%n%s testServerClose(%s, %b)%n", now(), uri, sameClient); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
201 |
uri = uri + ENCODED; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
202 |
for (int i=0; i< ITERATION_COUNT; i++) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
203 |
if (!sameClient || client == null) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
204 |
client = newHttpClient(sameClient); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
205 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
206 |
BodyPublisher bodyPublisher = BodyPublishers.ofString(uri); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
207 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
208 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
209 |
.POST(bodyPublisher) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
210 |
.build(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
211 |
BodyHandler<String> handler = BodyHandlers.ofString(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
212 |
CompletableFuture<HttpResponse<String>> responseCF = client.sendAsync(req, handler); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
213 |
HttpResponse<String> response = responseCF.join(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
214 |
String body = response.body(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
215 |
if (!uri.contains(body)) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
216 |
System.err.println("Test failed: " + response); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
217 |
throw new RuntimeException(uri + " doesn't contain '" + body + "'"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
218 |
} else { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
219 |
System.out.println("Found expected " + body + " in " + uri); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
220 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
221 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
222 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
223 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
224 |
@BeforeTest |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
225 |
public void setup() throws Exception { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
226 |
sslContext = new SimpleSSLContext().get(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
227 |
if (sslContext == null) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
228 |
throw new AssertionError("Unexpected null sslContext"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
229 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
230 |
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
231 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
232 |
// DummyServer |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
233 |
httpDummyServer = DummyServer.create(sa); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
234 |
httpsDummyServer = DummyServer.create(sa, sslContext); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
235 |
httpDummy = "http://" + httpDummyServer.serverAuthority() + "/http1/dummy/x"; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
236 |
httpsDummy = "https://" + httpsDummyServer.serverAuthority() + "/https1/dummy/x"; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
237 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
238 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
239 |
serverCount.addAndGet(2); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
240 |
httpDummyServer.start(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
241 |
httpsDummyServer.start(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
242 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
243 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
244 |
@AfterTest |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
245 |
public void teardown() throws Exception { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
246 |
sharedClient = null; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
247 |
httpDummyServer.stopServer(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
248 |
httpsDummyServer.stopServer(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
249 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
250 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
251 |
static class DummyServer extends Thread { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
252 |
final ServerSocket ss; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
253 |
final boolean secure; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
254 |
ConcurrentLinkedQueue<Socket> connections = new ConcurrentLinkedQueue<>(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
255 |
volatile boolean stopped; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
256 |
DummyServer(ServerSocket ss, boolean secure) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
257 |
super("DummyServer[" + ss.getLocalPort()+"]"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
258 |
this.secure = secure; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
259 |
this.ss = ss; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
260 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
261 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
262 |
// This is a bit shaky. It doesn't handle continuation |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
263 |
// lines, but our client shouldn't send any. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
264 |
// Read a line from the input stream, swallowing the final |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
265 |
// \r\n sequence. Stops at the first \n, doesn't complain |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
266 |
// if it wasn't preceded by '\r'. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
267 |
// |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
268 |
String readLine(InputStream r) throws IOException { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
269 |
StringBuilder b = new StringBuilder(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
270 |
int c; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
271 |
while ((c = r.read()) != -1) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
272 |
if (c == '\n') break; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
273 |
b.appendCodePoint(c); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
274 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
275 |
if (b.codePointAt(b.length() -1) == '\r') { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
276 |
b.delete(b.length() -1, b.length()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
277 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
278 |
return b.toString(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
279 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
280 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
281 |
@Override |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
282 |
public void run() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
283 |
try { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
284 |
while(!stopped) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
285 |
Socket clientConnection = ss.accept(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
286 |
connections.add(clientConnection); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
287 |
System.out.println(now() + getName() + ": Client accepted"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
288 |
StringBuilder headers = new StringBuilder(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
289 |
Socket targetConnection = null; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
290 |
InputStream ccis = clientConnection.getInputStream(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
291 |
OutputStream ccos = clientConnection.getOutputStream(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
292 |
Writer w = new OutputStreamWriter( |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
293 |
clientConnection.getOutputStream(), "UTF-8"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
294 |
PrintWriter pw = new PrintWriter(w); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
295 |
System.out.println(now() + getName() + ": Reading request line"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
296 |
String requestLine = readLine(ccis); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
297 |
System.out.println(now() + getName() + ": Request line: " + requestLine); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
298 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
299 |
StringTokenizer tokenizer = new StringTokenizer(requestLine); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
300 |
String method = tokenizer.nextToken(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
301 |
assert method.equalsIgnoreCase("POST") |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
302 |
|| method.equalsIgnoreCase("GET"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
303 |
String path = tokenizer.nextToken(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
304 |
URI uri; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
305 |
try { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
306 |
String hostport = serverAuthority(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
307 |
uri = new URI((secure ? "https" : "http") +"://" + hostport + path); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
308 |
} catch (Throwable x) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
309 |
System.err.printf("Bad target address: \"%s\" in \"%s\"%n", |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
310 |
path, requestLine); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
311 |
clientConnection.close(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
312 |
continue; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
313 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
314 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
315 |
// Read all headers until we find the empty line that |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
316 |
// signals the end of all headers. |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
317 |
String line = requestLine; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
318 |
while (!line.equals("")) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
319 |
System.out.println(now() + getName() + ": Reading header: " |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
320 |
+ (line = readLine(ccis))); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
321 |
headers.append(line).append("\r\n"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
322 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
323 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
324 |
StringBuilder response = new StringBuilder(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
325 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
326 |
int index = headers.toString() |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
327 |
.toLowerCase(Locale.US) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
328 |
.indexOf("content-length: "); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
329 |
byte[] b = uri.toString().getBytes(UTF_8); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
330 |
if (index >= 0) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
331 |
index = index + "content-length: ".length(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
332 |
String cl = headers.toString().substring(index); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
333 |
StringTokenizer tk = new StringTokenizer(cl); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
334 |
int len = Integer.parseInt(tk.nextToken()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
335 |
assert len < b.length * 2; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
336 |
System.out.println(now() + getName() |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
337 |
+ ": received body: " |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
338 |
+ new String(ccis.readNBytes(len), UTF_8)); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
339 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
340 |
System.out.println(now() |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
341 |
+ getName() + ": sending back " + uri); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
342 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
343 |
response.append("HTTP/1.1 200 OK\r\nContent-Length: ") |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
344 |
.append(b.length) |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
345 |
.append("\r\n\r\n"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
346 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
347 |
// Then send the 200 OK response to the client |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
348 |
System.out.println(now() + getName() + ": Sending " |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
349 |
+ response); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
350 |
pw.print(response); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
351 |
pw.flush(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
352 |
ccos.write(b); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
353 |
ccos.flush(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
354 |
ccos.close(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
355 |
connections.remove(clientConnection); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
356 |
clientConnection.close(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
357 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
358 |
} catch (Throwable t) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
359 |
if (!stopped) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
360 |
System.out.println(now() + getName() + ": failed: " + t); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
361 |
t.printStackTrace(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
362 |
try { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
363 |
stopServer(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
364 |
} catch (Throwable e) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
365 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
366 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
367 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
368 |
} finally { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
369 |
System.out.println(now() + getName() + ": exiting"); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
370 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
371 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
372 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
373 |
void close(Socket s) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
374 |
try { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
375 |
s.close(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
376 |
} catch(Throwable t) { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
377 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
378 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
379 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
380 |
public void stopServer() throws IOException { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
381 |
stopped = true; |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
382 |
ss.close(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
383 |
connections.forEach(this::close); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
384 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
385 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
386 |
public String serverAuthority() { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
387 |
return InetAddress.getLoopbackAddress().getHostName() + ":" |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
388 |
+ ss.getLocalPort(); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
389 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
390 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
391 |
static DummyServer create(InetSocketAddress sa) throws IOException { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
392 |
ServerSocket ss = ServerSocketFactory.getDefault() |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
393 |
.createServerSocket(sa.getPort(), -1, sa.getAddress()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
394 |
return new DummyServer(ss, false); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
395 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
396 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
397 |
static DummyServer create(InetSocketAddress sa, SSLContext sslContext) throws IOException { |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
398 |
ServerSocket ss = sslContext.getServerSocketFactory() |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
399 |
.createServerSocket(sa.getPort(), -1, sa.getAddress()); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
400 |
return new DummyServer(ss, true); |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
401 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
402 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
403 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
404 |
} |
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
405 |
|
ec8799d412fb
http-client-branch: add a test for 8199683; make sure no data is left in the queue after server closes the connection
dfuchs
parents:
diff
changeset
|
406 |
} |