1 /*
2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* Test utilities
25 *
26 */
27
28 import java.io.*;
29 import java.net.*;
30 import java.nio.*;
31 import java.nio.channels.*;
32 import java.util.Random;
33
34
35 public class TestUtil {
36
37 // Test hosts used by the channels tests - change these when
38 // executing in a different network.
39 public static final String HOST = "javaweb.sfbay.sun.com";
40 public static final String REFUSING_HOST = "jano1.sfbay.sun.com";
41 public static final String FAR_HOST = "irejano.ireland.sun.com";
42 public static final String UNRESOLVABLE_HOST = "blah-blah.blah-blah.blah";
43
44 private TestUtil() { }
45
46 // Repeatedly try random ports until we bind to one. You might be tempted
47 // to do this:
48 //
49 // ServerSocketChannel ssc = ServerSocketChannel.open();
50 // ssc.socket().bind(new InetSocketAddress(0));
51 // SocketAddress sa = ssc.socket().getLocalSocketAddress();
52 //
53 // but unfortunately it doesn't work on NT 4.0.
54 //
55 // Returns the bound port.
56 //
57 static int bind(ServerSocketChannel ssc) throws IOException {
58 InetAddress lh = InetAddress.getLocalHost();
59 Random r = new Random();
60 for (;;) {
61 int p = r.nextInt((1 << 16) - 1024) + 1024;
|
1 /*
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* Test utilities
25 *
26 */
27
28 import java.io.*;
29 import java.net.*;
30 import java.nio.channels.*;
31 import java.util.Random;
32
33
34 public class TestUtil {
35
36 // Test hosts used by the channels tests - change these when
37 // executing in a different network.
38 public static final String UNRESOLVABLE_HOST = "blah-blah.blah-blah.blah";
39
40 private TestUtil() { }
41
42 // Repeatedly try random ports until we bind to one. You might be tempted
43 // to do this:
44 //
45 // ServerSocketChannel ssc = ServerSocketChannel.open();
46 // ssc.socket().bind(new InetSocketAddress(0));
47 // SocketAddress sa = ssc.socket().getLocalSocketAddress();
48 //
49 // but unfortunately it doesn't work on NT 4.0.
50 //
51 // Returns the bound port.
52 //
53 static int bind(ServerSocketChannel ssc) throws IOException {
54 InetAddress lh = InetAddress.getLocalHost();
55 Random r = new Random();
56 for (;;) {
57 int p = r.nextInt((1 << 16) - 1024) + 1024;
|