author | aeubanks |
Wed, 27 Mar 2019 09:06:43 -0700 | |
changeset 54314 | 46cf212cdcca |
parent 47216 | 71c04702a3d5 |
child 54841 | 43439afaab4a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 4772077 |
|
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
27 |
* @library /test/lib |
2 | 28 |
* @summary using defaultReadTimeout appear to retry request upon timeout |
30820 | 29 |
* @modules java.base/sun.net.www |
2 | 30 |
*/ |
31 |
||
32 |
import java.net.*; |
|
33 |
import java.io.*; |
|
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
34 |
import jdk.test.lib.net.URIBuilder; |
2 | 35 |
import sun.net.www.*; |
36 |
||
37 |
public class RetryUponTimeout implements Runnable { |
|
38 |
// run server |
|
39 |
public void run(){ |
|
40 |
Socket socket = null; |
|
41 |
try { |
|
42 |
for (int i = 0; i < 2; i++) { |
|
43 |
socket = server.accept(); |
|
44 |
InputStream is = socket.getInputStream (); |
|
45 |
MessageHeader header = new MessageHeader (is); |
|
46 |
count++; |
|
47 |
} |
|
48 |
} catch (Exception ex) { |
|
49 |
// ignored |
|
50 |
} finally { |
|
51 |
try { |
|
52 |
socket.close(); |
|
53 |
server.close(); |
|
54 |
} catch (IOException ioex) { |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
} |
|
59 |
||
60 |
static ServerSocket server; |
|
61 |
static int count = 0; |
|
62 |
public static void main(String[] args) throws Exception { |
|
63 |
try { |
|
64 |
server = new ServerSocket (0); |
|
65 |
int port = server.getLocalPort (); |
|
66 |
new Thread(new RetryUponTimeout()).start (); |
|
67 |
||
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
68 |
URL url = URIBuilder.newBuilder() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
69 |
.scheme("http") |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
70 |
.loopback() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
71 |
.port(port) |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
72 |
.toURL(); |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
47216
diff
changeset
|
73 |
System.out.println("URL: " + url); |
2 | 74 |
java.net.URLConnection uc = url.openConnection(); |
75 |
uc.setReadTimeout(1000); |
|
76 |
uc.getInputStream(); |
|
77 |
} catch (SocketTimeoutException stex) { |
|
78 |
// expected exception |
|
79 |
server.close(); |
|
80 |
} |
|
81 |
||
82 |
if (count > 1) { |
|
83 |
throw new RuntimeException("Server received "+count+" requests instead of one."); |
|
84 |
} |
|
85 |
||
86 |
} |
|
87 |
} |