blob: cce1134f27d8d14e39feb963b4a248cd8eaac25d [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * Tests that a thread blocked in ServerSocket.accept
26 * throws a SocketException if the socket is asynchronously closed.
27 */
28import java.net.*;
29
30public class ServerSocket_accept extends AsyncCloseTest implements Runnable {
31 ServerSocket ss;
32 int timeout = 0;
33
34 public ServerSocket_accept() {
35 }
36
37 public ServerSocket_accept(int timeout) {
38 this.timeout = timeout;
39 }
40
41 public String description() {
42 String s = "ServerSocket.accept()";
43 if (timeout > 0) {
44 s += " (with timeout)";
45 }
46 return s;
47 }
48
49 public void run() {
50 try {
51 Socket s = ss.accept();
52 } catch (SocketException se) {
53 closed();
54 } catch (Exception e) {
55 failed(e.getMessage());
56 }
57 }
58
59 public boolean go() throws Exception {
60 ss = new ServerSocket(0);
61
62 Thread thr = new Thread(this);
63 thr.start();
64
65 Thread.currentThread().sleep(1000);
66
67 ss.close();
68
69 Thread.currentThread().sleep(1000);
70
71 if (isClosed()) {
72 return true;
73 } else {
74 failed("ServerSocket.accept() wasn't preempted");
75 return false;
76 }
77 }
78}