author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 47270 | 0feb93f627d2 |
permissions | -rw-r--r-- |
47270
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
1 |
/* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
4 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
8 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
13 |
* accompanied this code). |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
14 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
18 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
21 |
* questions. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
22 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
23 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
24 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
25 |
* @test |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
26 |
* @bug 8185072 |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
27 |
* @summary network006 times out in many configs in JDK10-hs nightly |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
28 |
* @run main/othervm/manual HugeDataTransferTest 1 |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
29 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
30 |
import java.io.FileNotFoundException; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
31 |
import java.io.IOException; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
32 |
import java.io.InputStream; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
33 |
import java.io.OutputStream; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
34 |
import java.io.PrintStream; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
35 |
import java.net.InetAddress; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
36 |
import java.net.ServerSocket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
37 |
import java.net.Socket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
38 |
import java.net.UnknownHostException; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
39 |
import java.nio.file.Path; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
40 |
import java.nio.file.Paths; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
41 |
import java.util.Random; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
42 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
43 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
44 |
* This test makes huge number of data transfers between 2 Java virtual machines |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
45 |
* using the TCP/IP protocol, and checks if those data are transfered correctly. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
46 |
* Both client and server VMs run on the same local computer and attach TCP/IP |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
47 |
* sockets to the local host, or to the loopback domain |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
48 |
* ``<code>localhost</code>'' (having IP address <code>127.0.0.1</code>). |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
49 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
50 |
* <p> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
51 |
* In this test, 128 client/server connections are established. Once a |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
52 |
* connection is established, client passes a data parcel to server, and server |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
53 |
* reads that parcel and checks if it is same as expected (byte-to-byte equality |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
54 |
* is desired). Then server passes (some other) parcel to the client, and client |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
55 |
* reads and verifies those bytes. This ping-pong game is repeated 128 times; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
56 |
* and after that each pair of sockets checks if there are no extra bytes |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
57 |
* accedentally passed through their connection. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
58 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
59 |
* <p> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
60 |
* Parcels lengths and contents are chosen randomly, and average parcel length |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
61 |
* is 128 bytes. So totally, each pair of sockets passes ~16Kb of data to each |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
62 |
* other, and thus ~32Kb of data are transfered by each sockets pair. Totally, |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
63 |
* ~4Mb of data are transfered by all client/server pairs. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
64 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
65 |
* @author vtewari |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
66 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
67 |
public class HugeDataTransferTest { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
68 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
69 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
70 |
* Timeout for TCP/IP sockets (currently set to 1 min). |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
71 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
72 |
private static int SO_TIMEOUT;// = 2*60*1000; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
73 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
74 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
75 |
* Maximal number of connections this test should open simultaneously. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
76 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
77 |
private final static int MAX_CONNECTIONS = 128; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
78 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
79 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
80 |
* Check few more connections to make sure that MAX_CONNECTIONS are safe. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
81 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
82 |
private final static int CONNECTIONS_RESERVE = 10; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
83 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
84 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
85 |
* The test used to fail with connection reset by peer set to 50. (and once |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
86 |
* in a three if it was set to 10). So now we set it to MAX_CONNECTIONS |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
87 |
* (128). |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
88 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
89 |
private final static int BACKLOG_QUEUE_LENGTH = MAX_CONNECTIONS; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
90 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
91 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
92 |
* Number of parcels to be sent/recieved. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
93 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
94 |
private final static int DATA_PARCELS = 128; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
95 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
96 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
97 |
* Maximal length of data parcel to be sent/recieved (it equals to 256 bytes |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
98 |
* now). |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
99 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
100 |
private final static int MAX_PARCEL = 1 << 8; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
101 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
102 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
103 |
* Either actually display optional reports or not. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
104 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
105 |
static private final boolean DEBUG_MODE = false; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
106 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
107 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
108 |
* How many IP sockets can we open simultaneously? Check if |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
109 |
* <code>MAX_CONNECTIONS</code> connections can be open simultaneously. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
110 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
111 |
private static int detectOSLimitation() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
112 |
final int CONNECTIONS_TO_TRY = MAX_CONNECTIONS + CONNECTIONS_RESERVE; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
113 |
display("--- Trying to open " + CONNECTIONS_TO_TRY + " connections:"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
114 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
115 |
InetAddress address; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
116 |
ServerSocket serverSocket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
117 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
118 |
address = InetAddress.getLocalHost(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
119 |
int anyPort = 0; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
120 |
int defaultBacklog = BACKLOG_QUEUE_LENGTH; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
121 |
serverSocket = new ServerSocket(anyPort, defaultBacklog, address); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
122 |
} catch (IOException ioe) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
123 |
throw new Error("FATAL error while loading the test: " + ioe); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
124 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
125 |
display(serverSocket.toString()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
126 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
127 |
Socket server[] = new Socket[CONNECTIONS_TO_TRY]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
128 |
Socket client[] = new Socket[CONNECTIONS_TO_TRY]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
129 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
130 |
int i, port = serverSocket.getLocalPort(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
131 |
for (i = 0; i < CONNECTIONS_TO_TRY; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
132 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
133 |
client[i] = new Socket(address, port); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
134 |
display(">Open: client[" + i + "] = " + client[i]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
135 |
server[i] = serverSocket.accept(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
136 |
display(">Open: server[" + i + "] = " + server[i]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
137 |
} catch (IOException ioe) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
138 |
display(">OOPS! -- failed to open connection #" + i); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
139 |
break; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
140 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
141 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
142 |
display("> Could open " |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
143 |
+ (i < CONNECTIONS_TO_TRY ? "only " : "") + i + " connections."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
144 |
display(">Closing them:"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
145 |
for (int j = 0; j < i; j++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
146 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
147 |
server[j].close(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
148 |
client[j].close(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
149 |
} catch (IOException ioe) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
150 |
throw new Error("FATAL error while loading the test: " + ioe); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
151 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
152 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
153 |
display(">OK."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
154 |
int safeConnections = i - CONNECTIONS_RESERVE; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
155 |
if (safeConnections < 1) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
156 |
safeConnections = 1; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
157 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
158 |
if (safeConnections < MAX_CONNECTIONS) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
159 |
complain("------------------------- CAUTION: -------------------"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
160 |
complain("While checking the OS limitations, the test found that"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
161 |
complain("only " + i + " TCP/IP socket connections could be safely open"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
162 |
complain("simultaneously. However, possibility to open at least"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
163 |
complain("" + MAX_CONNECTIONS + "+" + CONNECTIONS_RESERVE |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
164 |
+ " connections were expected."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
165 |
complain(""); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
166 |
complain("So, the test will check only " + safeConnections + " connection" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
167 |
+ (safeConnections == 1 ? "" : "s") + " which seem"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
168 |
complain("safe to be open simultaneously."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
169 |
complain("------------------------------------------------------"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
170 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
171 |
return safeConnections; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
172 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
173 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
174 |
//----------------------------------------------------------------// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
175 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
176 |
* Re-calls to the method <code>run(args[],out)</code> actually performing |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
177 |
* the test. After <code>run(args[],out)</code> stops, follow JDK-like |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
178 |
* convention for exit codes. I.e.: stop with exit status 95 if the test has |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
179 |
* passed, or with status 97 if the test has failed. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
180 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
181 |
* @see #run(String[],PrintStream) |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
182 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
183 |
public static void main(String args[]) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
184 |
int exitCode = run(args, System.out); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
185 |
System.exit(exitCode + 95); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
186 |
// JCK-like exit status. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
187 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
188 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
189 |
public static int run(String args[], PrintStream out) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
190 |
HugeDataTransferTest.out = out; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
191 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
192 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
193 |
// Get the Internet address of the local machine. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
194 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
195 |
InetAddress address = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
196 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
197 |
address = InetAddress.getLocalHost(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
198 |
} catch (UnknownHostException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
199 |
complain(exception.toString()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
200 |
return 2; // FAILED |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
201 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
202 |
display("Host: " + address); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
203 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
204 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
205 |
// Detect if it is safe to open MAX_CONNETIONS simultaneously: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
206 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
207 |
final int CONNECTIONS = detectOSLimitation(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
208 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
209 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
210 |
// Assign ServerSocket, and start client VM which should open |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
211 |
// the prescribed number of CONNECTIONS to that ServerSocket. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
212 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
213 |
ServerSocket serverSocket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
214 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
215 |
final int anyPort = 0; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
216 |
final int defaultBacklog = BACKLOG_QUEUE_LENGTH; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
217 |
serverSocket = new ServerSocket(anyPort, defaultBacklog, address); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
218 |
} catch (IOException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
219 |
complain("Cannot assign a ServerSocket on: " + address); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
220 |
return 2; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
221 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
222 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
223 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
224 |
// Start the client process on different VM. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
225 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
226 |
String jdkPath = System.getProperty("test.jdk"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
227 |
Path toolName = Paths.get("bin", "java" + (isWindows() ? ".exe" : "")); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
228 |
Path jdkTool = Paths.get(jdkPath, toolName.toString()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
229 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
230 |
String IPAddress = address.getHostAddress(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
231 |
int localPort = serverSocket.getLocalPort(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
232 |
String arguments = " " + CONNECTIONS + " " + IPAddress + " " + localPort; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
233 |
//String command = args[0] + " " + network006.class.getName() + "$Client " + arguments; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
234 |
String command = jdkTool.toAbsolutePath().toString() + " " + Client.class.getName() + " " + arguments; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
235 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
236 |
SO_TIMEOUT = Integer.parseInt(args[0]) * 60 * 1000; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
237 |
} catch (NumberFormatException e) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
238 |
complain("Wrong timeout argument: " + e); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
239 |
return 2; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
240 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
241 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
242 |
Runtime runtime = Runtime.getRuntime(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
243 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
244 |
Process client = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
245 |
IORedirector redirectOut = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
246 |
IORedirector redirectErr = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
247 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
248 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
249 |
// Start clients on different JVM: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
250 |
client = runtime.exec(command); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
251 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
252 |
// Provide clients with access to stderr and stdout: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
253 |
InputStream clientOut = client.getInputStream(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
254 |
InputStream clientErr = client.getErrorStream(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
255 |
redirectOut = new IORedirector(clientOut, DEBUG_MODE ? out : null); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
256 |
redirectErr = new IORedirector(clientErr, out); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
257 |
redirectOut.start(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
258 |
redirectErr.start(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
259 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
260 |
} catch (IOException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
261 |
complain("Failed to start client: " + exception); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
262 |
return 2; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
263 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
264 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
265 |
// Start the server threads (and let them establish connections): |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
266 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
267 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
268 |
Server server[] = new Server[CONNECTIONS]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
269 |
for (int i = 0; i < CONNECTIONS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
270 |
server[i] = new Server(serverSocket); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
271 |
display("Server #" + i + ": " + server[i]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
272 |
server[i].start(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
273 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
274 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
275 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
276 |
// Wait for the servers and the clients: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
277 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
278 |
boolean testFailed = false; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
279 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
280 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
281 |
client.waitFor(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
282 |
int clientStatus = client.exitValue(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
283 |
display("Client VM exitCode=" + clientStatus); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
284 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
285 |
// Let I/O redirectors to flush: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
286 |
if (redirectOut.isAlive()) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
287 |
redirectOut.join(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
288 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
289 |
if (redirectErr.isAlive()) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
290 |
redirectErr.join(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
291 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
292 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
293 |
// If client has crashed, also terminate the server (to avoid hangup). |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
294 |
if (clientStatus != 95) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
295 |
complain("Client VM has crashed: exit status=" + clientStatus); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
296 |
testFailed = true; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
297 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
298 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
299 |
// Client has finished OK; wait for the server. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
300 |
for (int i = 0; i < CONNECTIONS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
301 |
display("Server: waiting for #" + i); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
302 |
if (server[i].isAlive()) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
303 |
display("Server #" + i + ": (joining...)" + server[i]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
304 |
server[i].join(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
305 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
306 |
if (server[i].exception != null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
307 |
if (server[i].message != null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
308 |
complain("Server #" + i + "(finished): with message:" + server[i].message); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
309 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
310 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
311 |
complain("Server #" + i + "(finished): " + server[i].exception); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
312 |
server[i].exception.printStackTrace(out); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
313 |
out.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
314 |
// complain("Server #"+i+": "+server[i].exception.getStackTrace()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
315 |
testFailed = true; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
316 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
317 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
318 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
319 |
} catch (InterruptedException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
320 |
complain("Test interrupted: " + exception); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
321 |
testFailed = true; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
322 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
323 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
324 |
if (testFailed) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
325 |
complain("Test failed."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
326 |
} else { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
327 |
display("Test passed."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
328 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
329 |
return testFailed ? 2 : 0; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
330 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
331 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
332 |
private static boolean isWindows() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
333 |
return System.getProperty("os.name").toLowerCase().startsWith("win"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
334 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
335 |
//----------------------------------------------------------------// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
336 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
337 |
* Log stream for error messages and/or (optional) execution trace. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
338 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
339 |
private static PrintStream out; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
340 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
341 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
342 |
* Print error message. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
343 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
344 |
private static synchronized void complain(Object message) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
345 |
out.println("# " + message); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
346 |
out.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
347 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
348 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
349 |
; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
350 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
351 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
352 |
* Display optional report: comment ca va? |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
353 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
354 |
private static synchronized void display(Object report) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
355 |
if (DEBUG_MODE) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
356 |
out.println(report.toString()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
357 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
358 |
out.flush(); //todo shouldn't this be inside if?? |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
359 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
360 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
361 |
; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
362 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
363 |
//----------------------------------------------------------------// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
364 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
365 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
366 |
* Server thread should reply to data parcels sent by Client VM. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
367 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
368 |
private static class Server extends Thread { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
369 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
370 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
371 |
* The socket is assigned at the Server instantiation. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
372 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
373 |
private ServerSocket serverSocket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
374 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
375 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
376 |
* The socket is assigned at the Server runtime. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
377 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
378 |
private Socket socket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
379 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
380 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
381 |
* Display the server socket. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
382 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
383 |
@Override |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
384 |
public String toString() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
385 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
386 |
return "ServerSocket: " + serverSocket.toString(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
387 |
// + " socket: " + socket.toString(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
388 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
389 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
390 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
391 |
* Which port is this socket listening? |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
392 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
393 |
int getPort() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
394 |
return serverSocket.getLocalPort(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
395 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
396 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
397 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
398 |
* Find some free port at the given <code>address</code> and attach new |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
399 |
* server to hear that port. // lidsten to?? |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
400 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
401 |
public Server(ServerSocket serverSocket) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
402 |
this.serverSocket = serverSocket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
403 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
404 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
405 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
406 |
* Exception just arisen while the server was working, or |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
407 |
* <code>null</code> if it was OK with the server. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
408 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
409 |
Exception exception = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
410 |
String message = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
411 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
412 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
413 |
* Accept connection, then reply to client's parcels. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
414 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
415 |
@Override |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
416 |
public void run() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
417 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
418 |
socket = serverSocket.accept(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
419 |
socket.setSoTimeout(SO_TIMEOUT); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
420 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
421 |
InputStream istream = socket.getInputStream(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
422 |
OutputStream ostream = socket.getOutputStream(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
423 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
424 |
Random random = new Random(getPort()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
425 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
426 |
for (int i = 0; i < DATA_PARCELS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
427 |
Parcel etalon = new Parcel(random); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
428 |
message = "reading parcel number " + i; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
429 |
Parcel sample = new Parcel(istream); // read |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
430 |
if (!sample.equals(etalon)) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
431 |
complain("Server thread for port #" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
432 |
+ getPort() + " got unexpected parcel:\n" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
433 |
+ "sample=" + sample + "\n" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
434 |
+ "etalon=" + etalon); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
435 |
throw new TestFailure( //received?? |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
436 |
"server has read unexpected parcel"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
437 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
438 |
message = "sending parcel number " + i; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
439 |
etalon.send(ostream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
440 |
ostream.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
441 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
442 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
443 |
int datum = istream.read(); // wait for client close() |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
444 |
if (datum >= 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
445 |
throw new TestFailure( |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
446 |
"server has read ambigous byte: " + datum); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
447 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
448 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
449 |
ostream.close(); // implies: socket.close(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
450 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
451 |
} catch (Exception oops) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
452 |
exception = oops; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
453 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
454 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
455 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
456 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
457 |
//----------------------------------------------------------------// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
458 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
459 |
* Client VM should send data parcels to Server VM and recieve and verify |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
460 |
* the server's replies. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
461 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
462 |
private static class Client extends Thread { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
463 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
464 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
465 |
* This thread uses the single client socket. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
466 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
467 |
private Socket socket; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
468 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
469 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
470 |
* Address and port of this socket. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
471 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
472 |
@Override |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
473 |
public String toString() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
474 |
return socket.toString(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
475 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
476 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
477 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
478 |
* Did the thread failed? If yes, what is the failure's reason. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
479 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
480 |
Exception exception = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
481 |
String message = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
482 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
483 |
public static java.io.PrintStream complainStream = System.out; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
484 |
public static java.io.PrintStream displayStream = System.err; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
485 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
486 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
487 |
* Connect client socket on the given <code>address</code> and |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
488 |
* <code>port</code>. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
489 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
490 |
Client(InetAddress address, int port) throws IOException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
491 |
socket = new Socket(address, port); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
492 |
socket.setSoTimeout(SO_TIMEOUT); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
493 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
494 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
495 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
496 |
* What is the port number this socket is listening for? |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
497 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
498 |
int getPort() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
499 |
return socket.getPort(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
500 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
501 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
502 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
503 |
* Establish connection, then read/respond <code>DATA_PARCELS</code> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
504 |
* parcels of random data. Set initial seed for pseudo-random numbers |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
505 |
* generator to the value of the local port number. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
506 |
* |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
507 |
* @see #DATA_PARCELS |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
508 |
* @see #getPort() |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
509 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
510 |
@Override |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
511 |
public void run() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
512 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
513 |
InputStream istream = socket.getInputStream(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
514 |
OutputStream ostream = socket.getOutputStream(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
515 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
516 |
Random random = new Random(getPort()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
517 |
// suggested by Oleg -- to avoid race conditions |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
518 |
/* try{ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
519 |
Thread.sleep(500); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
520 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
521 |
catch (java.lang.InterruptedException e) |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
522 |
{ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
523 |
}*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
524 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
525 |
for (int i = 0; i < DATA_PARCELS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
526 |
Parcel etalon = new Parcel(random); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
527 |
message = "sending parcel number: " + i; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
528 |
etalon.send(ostream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
529 |
ostream.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
530 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
531 |
message = "reading parcel number: " + i; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
532 |
Parcel sample = new Parcel(istream); // read |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
533 |
if (!sample.equals(etalon)) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
534 |
complain("Client thread for port #" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
535 |
+ getPort() + " got unexpected parcel:\n" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
536 |
+ "sample=" + sample + "\n" |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
537 |
+ "etalon=" + etalon); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
538 |
throw new TestFailure( |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
539 |
"parcel context is unexpected to client"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
540 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
541 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
542 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
543 |
if (istream.available() > 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
544 |
int datum = istream.read(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
545 |
throw new TestFailure( |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
546 |
"client has read ambigous byte: " + datum); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
547 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
548 |
ostream.close(); // implies: socket.close() |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
549 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
550 |
} catch (Exception oops) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
551 |
exception = oops; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
552 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
553 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
554 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
555 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
556 |
* Establish lots of connections to server socket, attack servers with |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
557 |
* huge data parcels, and check if they reply correctly. The number of |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
558 |
* connections to try, the address and port number for the server socket |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
559 |
* are passed through <code>args[]</code>, like: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
560 |
* <pre> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
561 |
* java network006$Client connections_to_try address port |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
562 |
* </pre> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
563 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
564 |
public static void main(String args[]) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
565 |
if (DEBUG_MODE) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
566 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
567 |
String filename = "Client" + ((args.length == 3) ? args[2] : "new"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
568 |
displayStream = new PrintStream(filename + ".out"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
569 |
complainStream = new PrintStream(filename + ".err"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
570 |
} catch (FileNotFoundException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
571 |
complain(exception); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
572 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
573 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
574 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
575 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
576 |
if (args.length != 3) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
577 |
complain("Client expects 3 paramenets:"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
578 |
complain(" java " + Client.class.getName() + " connections_to_try address port"); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
579 |
exit(1); // FAILED |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
580 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
581 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
582 |
int CONNECTIONS = Integer.parseInt(args[0]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
583 |
display("Client VM: will try " + CONNECTIONS + " connections."); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
584 |
InetAddress address; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
585 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
586 |
address = InetAddress.getByName(args[1]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
587 |
} catch (UnknownHostException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
588 |
address = null; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
589 |
complain("Client: cannot find host: \"" + args[1] + "\""); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
590 |
exit(4); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
591 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
592 |
display("Client: host to contact: " + address); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
593 |
int port = Integer.parseInt(args[2]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
594 |
display("Client: port to contact: " + port); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
595 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
596 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
597 |
// Establish connections, and start client processes: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
598 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
599 |
Client client[] = new Client[CONNECTIONS]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
600 |
for (int i = 0; i < CONNECTIONS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
601 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
602 |
client[i] = new Client(address, port); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
603 |
display("Client #" + i + ": " + client[i]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
604 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
605 |
} catch (IOException ioe) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
606 |
complain("Client #" + i + "(creation): " + ioe); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
607 |
ioe.printStackTrace(complainStream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
608 |
complainStream.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
609 |
// complain("Client #" + i + "(creation): " + ioe.getStackTrace()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
610 |
exit(3); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
611 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
612 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
613 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
614 |
for (int i = 0; i < CONNECTIONS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
615 |
client[i].start(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
616 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
617 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
618 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
619 |
// Wait until testing is not finished: |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
620 |
// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
621 |
int status = 0; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
622 |
for (int i = 0; i < CONNECTIONS; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
623 |
display("Client: waiting for #" + i); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
624 |
if (client[i].isAlive()) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
625 |
display("Client #" + i + ": (joining...)" + client[i]); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
626 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
627 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
628 |
client[i].join(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
629 |
} catch (InterruptedException ie) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
630 |
complain("Client #" + i + ": " + ie); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
631 |
status = 3; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
632 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
633 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
634 |
if (client[i].exception != null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
635 |
if (client[i].message != null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
636 |
complain("Client #" + i + "(finished) with message: " + client[i].message); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
637 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
638 |
complain("Client #" + i + "(finished): " + client[i].exception); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
639 |
client[i].exception.printStackTrace(complainStream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
640 |
complainStream.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
641 |
if (status == 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
642 |
status = 2; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
643 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
644 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
645 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
646 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
647 |
exit(status); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
648 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
649 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
650 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
651 |
* Print error message. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
652 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
653 |
private static synchronized void complain(Object message) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
654 |
complainStream.println("# " + message); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
655 |
complainStream.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
656 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
657 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
658 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
659 |
* Display execution trace. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
660 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
661 |
private static synchronized void display(Object message) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
662 |
if (!DEBUG_MODE) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
663 |
return; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
664 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
665 |
displayStream.println(message.toString()); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
666 |
displayStream.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
667 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
668 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
669 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
670 |
* Exit with JCK-like status. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
671 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
672 |
private static void exit(int exitCode) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
673 |
int status = exitCode + 95; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
674 |
// display("Client: exiting with code=" + status); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
675 |
System.exit(status); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
676 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
677 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
678 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
679 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
680 |
* Two of such threads should redirect <code>out</code> and <code>err</code> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
681 |
* streams of client VM. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
682 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
683 |
private static class IORedirector extends Thread { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
684 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
685 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
686 |
* Source stream. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
687 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
688 |
InputStream in; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
689 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
690 |
* Destination stream. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
691 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
692 |
OutputStream out; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
693 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
694 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
695 |
* Redirect <code>in</code> to <code>out</code>. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
696 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
697 |
public IORedirector(InputStream in, OutputStream out) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
698 |
this.in = in; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
699 |
this.out = out; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
700 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
701 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
702 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
703 |
* Read input stream until the EOF, and write everithing to output |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
704 |
* stream. If output stream is assigned to <code>null</code>, do not |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
705 |
* print anything, but read the input stream anywhere. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
706 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
707 |
@Override |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
708 |
public void run() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
709 |
try { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
710 |
for (;;) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
711 |
int symbol = in.read(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
712 |
if (symbol < 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
713 |
break; // EOF |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
714 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
715 |
if (out != null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
716 |
out.write(symbol); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
717 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
718 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
719 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
720 |
if (out != null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
721 |
out.flush(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
722 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
723 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
724 |
} catch (IOException exception) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
725 |
throw new TestFailure("IORedirector exception: " + exception); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
726 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
727 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
728 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
729 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
730 |
//----------------------------------------------------------------// |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
731 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
732 |
* A data parcel to be sent/recieved between Client VM and Server thread. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
733 |
* When data parcel is sent, first 4 bytes are transfered which encode the |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
734 |
* <code>int</code> number equal to size of the parcel minus 1. I.e.: if |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
735 |
* number of data bytes in the parcel's contents is <code>N</code>, then the |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
736 |
* first 4 bytes encode the number <code>N-1</code>. After that, the |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
737 |
* parcel's contents bytes are transered. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
738 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
739 |
static class Parcel { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
740 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
741 |
private final byte[] parcel; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
742 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
743 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
744 |
* Display all bytes as integer values from 0 to 255; or return |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
745 |
* ``<tt>null</tt>'' if this Parcel is not yet initialized. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
746 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
747 |
@Override |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
748 |
public String toString() { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
749 |
if (parcel == null) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
750 |
return "null"; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
751 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
752 |
String s = "{"; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
753 |
for (int i = 0; i < parcel.length; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
754 |
s += (i > 0 ? ", " : "") + ((int) parcel[i] & 0xFF); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
755 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
756 |
return s + "}"; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
757 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
758 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
759 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
760 |
* Generate new <code>parcel[]</code> array using the given |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
761 |
* <code>random</code> numbers generator. Client and Server threads |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
762 |
* should use identical <code>random</code> generators, so that those |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
763 |
* threads could generate equal data parcels and check the parcel just |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
764 |
* transfered. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
765 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
766 |
public Parcel(Random random) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
767 |
int size = random.nextInt(MAX_PARCEL) + 1; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
768 |
parcel = new byte[size]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
769 |
for (int i = 0; i < size; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
770 |
parcel[i] = (byte) random.nextInt(256); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
771 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
772 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
773 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
774 |
; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
775 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
776 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
777 |
* Read exactly <code>size</code> bytes from the <code>istream</code> |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
778 |
* if possible, or throw <code>TestFailure</code> if unexpected end of |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
779 |
* <code>istream</code> occurs. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
780 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
781 |
private static byte[] readBytes(int size, InputStream istream) |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
782 |
throws IOException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
783 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
784 |
byte data[] = new byte[size]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
785 |
for (int i = 0; i < size; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
786 |
int datum = istream.read(); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
787 |
if (datum < 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
788 |
throw new TestFailure( |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
789 |
"unexpected EOF: have read: " + i + " bytes of " + size); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
790 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
791 |
data[i] = (byte) datum; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
792 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
793 |
return data; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
794 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
795 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
796 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
797 |
* Read 4 bytes from <code>istream</code> and threat them to encode size |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
798 |
* of data parcel following these 4 bytes. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
799 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
800 |
private static int getSize(InputStream istream) throws IOException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
801 |
byte data[] = readBytes(4, istream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
802 |
int data0 = (int) data[0] & 0xFF; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
803 |
int data1 = (int) data[1] & 0xFF; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
804 |
int data2 = (int) data[2] & 0xFF; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
805 |
int data3 = (int) data[3] & 0xFF; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
806 |
int sizeWord = data0 + (data1 << 8) + (data2 << 16) + (data3 << 24); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
807 |
int size = sizeWord + 1; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
808 |
if (size <= 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
809 |
throw new TestFailure("illegal size: " + size); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
810 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
811 |
return size; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
812 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
813 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
814 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
815 |
* Send 4 bytes encoding actual size of the parcel just to be |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
816 |
* transfered. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
817 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
818 |
private static void putSize(OutputStream ostream, int size) |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
819 |
throws IOException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
820 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
821 |
if (size <= 0) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
822 |
throw new TestFailure("illegal size: " + size); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
823 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
824 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
825 |
int sizeWord = size - 1; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
826 |
byte data[] = new byte[4]; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
827 |
data[0] = (byte) sizeWord; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
828 |
data[1] = (byte) (sizeWord >> 8); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
829 |
data[2] = (byte) (sizeWord >> 16); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
830 |
data[3] = (byte) (sizeWord >> 24); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
831 |
ostream.write(data); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
832 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
833 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
834 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
835 |
* Recieve data parcel. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
836 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
837 |
public Parcel(InputStream istream) throws IOException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
838 |
int size = getSize(istream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
839 |
parcel = readBytes(size, istream); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
840 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
841 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
842 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
843 |
* Send <code>this</code> data parcel. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
844 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
845 |
public void send(OutputStream ostream) throws IOException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
846 |
int size = parcel.length; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
847 |
putSize(ostream, size); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
848 |
ostream.write(parcel); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
849 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
850 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
851 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
852 |
* Check byte-to-byte equality between <code>this</code> and the |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
853 |
* <code>other</code> parcels. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
854 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
855 |
public boolean equals(Parcel other) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
856 |
if (this.parcel.length != other.parcel.length) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
857 |
return false; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
858 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
859 |
int size = parcel.length; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
860 |
for (int i = 0; i < size; i++) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
861 |
if (this.parcel[i] != other.parcel[i]) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
862 |
return false; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
863 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
864 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
865 |
return true; |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
866 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
867 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
868 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
869 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
870 |
* Server or Client may throw this exception to report the test failure. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
871 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
872 |
static class TestFailure extends RuntimeException { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
873 |
|
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
874 |
/** |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
875 |
* Report particular <code>purpose</code> of the test failure. |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
876 |
*/ |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
877 |
public TestFailure(String purpose) { |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
878 |
super(purpose); |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
879 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
880 |
} |
0feb93f627d2
8185072: network006 times out in many configs in JDK10-hs nightly
vtewari
parents:
diff
changeset
|
881 |
} |