jdk/test/sun/nio/ch/ServerSocketAdaptorTest.java
author prappo
Tue, 27 May 2014 10:27:51 +0100
changeset 24623 c094ffea7aee
permissions -rw-r--r--
8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound Reviewed-by: chegar, michaelm, alanb, mr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24623
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     1
/*
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     4
 *
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     8
 *
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    13
 * accompanied this code).
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    14
 *
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    18
 *
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    21
 * questions.
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    22
 */
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    23
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    24
/*
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    25
 * @test
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    26
 * @bug 8024832
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    27
 */
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    28
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    29
import java.io.IOException;
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    30
import java.net.ServerSocket;
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    31
import java.net.SocketException;
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    32
import java.nio.channels.ServerSocketChannel;
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    33
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    34
public class ServerSocketAdaptorTest {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    35
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    36
    public static void main(String[] args) throws IOException {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    37
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    38
        String message = null;
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    39
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    40
        try (ServerSocket s = new ServerSocket()) {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    41
            s.accept();
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    42
            throw new AssertionError();
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    43
        } catch (IOException e) {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    44
            message = e.getMessage();
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    45
        }
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    46
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    47
        try (ServerSocket ss = ServerSocketChannel.open().socket()) {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    48
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    49
            assert !ss.isBound() : "the assumption !ss.isBound() doesn't hold";
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    50
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    51
            try {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    52
                ss.accept();
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    53
                throw new AssertionError();
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    54
            } catch (Exception e) {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    55
                if (e instanceof SocketException && message.equals(e.getMessage())) {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    56
                    return;
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    57
                } else {
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    58
                    throw new AssertionError(
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    59
                            "Expected to throw SocketException with a particular message", e);
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    60
                }
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    61
            }
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    62
        }
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    63
    }
c094ffea7aee 8024832: ServerSocketChannel.socket().accept() throws IllegalBlockingModeException if not bound
prappo
parents:
diff changeset
    64
}