author | michaelm |
Thu, 25 Feb 2016 23:14:22 +0000 | |
changeset 36131 | 379db4b2f95d |
parent 27720 | aa3983c8fbee |
child 45028 | b0ea3c0bfb81 |
permissions | -rw-r--r-- |
27720
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
1 |
/* |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
2 |
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
4 |
* |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
8 |
* |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
13 |
* accompanied this code). |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
14 |
* |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
18 |
* |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
21 |
* questions. |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
22 |
*/ |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
23 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
24 |
/** |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
25 |
* @test |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
26 |
* @bug 8015692 |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
27 |
* @summary Test HttpServer instantiation, start, and stop repeated in a loop |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
28 |
* Testing for Bind exception on Windows |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
29 |
*/ |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
30 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
31 |
import java.net.InetSocketAddress; |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
32 |
import java.net.ServerSocket; |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
33 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
34 |
import com.sun.net.httpserver.HttpServer; |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
35 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
36 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
37 |
public class SimpleHttpServerTest { |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
38 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
39 |
public static void main(String[] args) throws Exception { |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
40 |
|
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
41 |
System.out.println(System.getProperty("java.version")); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
42 |
InetSocketAddress serverAddr = new InetSocketAddress(0); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
43 |
HttpServer server = HttpServer.create(serverAddr, 0); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
44 |
final int serverPort = server.getAddress().getPort(); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
45 |
server.start(); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
46 |
server.stop(0); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
47 |
serverAddr = new InetSocketAddress(serverPort); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
48 |
int exceptionCount = 0; |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
49 |
System.out.println("Using serverPort == " + serverPort); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
50 |
for (int i = 0; i < 100; i++) { |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
51 |
try { |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
52 |
server = HttpServer.create(serverAddr, 0); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
53 |
server.start(); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
54 |
server.stop(0); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
55 |
} catch (Exception ex) { |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
56 |
ex.printStackTrace(); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
57 |
exceptionCount++; |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
58 |
} |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
59 |
} |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
60 |
if (exceptionCount > 0) { |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
61 |
throw new RuntimeException("Test Failed"); |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
62 |
} |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
63 |
} |
aa3983c8fbee
8015692: java.net.BindException is thrown on Windows XP when HTTP server is started and stopped in the loop.
msheppar
parents:
diff
changeset
|
64 |
} |