author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 49255 | acdb8531cc8b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49255
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4430139 |
|
26 |
* @summary Test result of read on stream from nonblocking channel |
|
49255
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
47216
diff
changeset
|
27 |
* @library .. /test/lib |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
47216
diff
changeset
|
28 |
* @build jdk.test.lib.Utils TestServers |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
47216
diff
changeset
|
29 |
* @run main Stream |
2 | 30 |
*/ |
31 |
||
14415
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
32 |
import java.io.*; |
2 | 33 |
import java.net.*; |
34 |
import java.nio.channels.*; |
|
35 |
||
36 |
||
37 |
public class Stream { |
|
38 |
||
14415
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
39 |
static void test(TestServers.DayTimeServer daytimeServer) throws Exception { |
2 | 40 |
InetSocketAddress isa |
14415
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
41 |
= new InetSocketAddress(daytimeServer.getAddress(), |
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
42 |
daytimeServer.getPort()); |
2 | 43 |
SocketChannel sc = SocketChannel.open(); |
44 |
sc.connect(isa); |
|
45 |
sc.configureBlocking(false); |
|
46 |
InputStream is = sc.socket().getInputStream(); |
|
47 |
byte b[] = new byte[10]; |
|
48 |
try { |
|
49 |
int n = is.read(b); |
|
50 |
throw new RuntimeException("Exception expected; none thrown"); |
|
51 |
} catch (IllegalBlockingModeException e) { |
|
52 |
// expected result |
|
53 |
} |
|
54 |
sc.close(); |
|
55 |
} |
|
56 |
||
57 |
public static void main(String[] args) throws Exception { |
|
14415
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
58 |
try (TestServers.DayTimeServer dayTimeServer |
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
59 |
= TestServers.DayTimeServer.startNewServer(100)) { |
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
60 |
test(dayTimeServer); |
7a31b0e0cfaf
6720349: (ch) Channels tests depending on hosts inside Sun
dfuchs
parents:
5506
diff
changeset
|
61 |
} |
2 | 62 |
} |
63 |
} |