test/jdk/java/net/SocketOption/AfterClose.java
author chegar
Wed, 29 May 2019 13:58:05 +0100
changeset 55081 dd321e3596c0
child 55288 ae41e1037bde
permissions -rw-r--r--
8224477: java.net socket types new-style socket option methods - spec and impl mismatch Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55081
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     1
/*
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     4
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     8
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    13
 * accompanied this code).
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    14
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    18
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    21
 * questions.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    22
 */
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    23
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    24
/*
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    25
 * @test
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    26
 * @bug 8224477
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    27
 * @summary Ensures that IOException is thrown after the socket is closed
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    28
 * @run testng AfterClose
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    29
 */
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    30
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    31
import java.io.IOException;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    32
import java.lang.reflect.Field;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    33
import java.lang.reflect.Method;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    34
import java.net.DatagramSocket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    35
import java.net.MulticastSocket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    36
import java.net.ServerSocket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    37
import java.net.Socket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    38
import java.net.SocketOption;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    39
import java.nio.channels.DatagramChannel;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    40
import java.nio.channels.ServerSocketChannel;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    41
import java.nio.channels.SocketChannel;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    42
import java.util.ArrayList;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    43
import java.util.Arrays;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    44
import java.util.HashMap;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    45
import java.util.List;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    46
import java.util.Map;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    47
import org.testng.annotations.DataProvider;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    48
import org.testng.annotations.Test;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    49
import static java.lang.Boolean.*;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    50
import static java.net.StandardSocketOptions.*;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    51
import static org.testng.Assert.expectThrows;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    52
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    53
public class AfterClose {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    54
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    55
    static final Class<IOException> IOE = IOException.class;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    56
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    57
    static Map<SocketOption<?>,List<Object>> OPTION_VALUES_MAP = optionValueMap();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    58
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    59
    static Map<SocketOption<?>,List<Object>> optionValueMap() {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    60
        Map<SocketOption<?>,List<Object>> map = new HashMap<>();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    61
        map.put(IP_MULTICAST_IF,   listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    62
        map.put(IP_MULTICAST_LOOP, listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    63
        map.put(IP_MULTICAST_TTL,  listOf(0, 100, 255) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    64
        map.put(IP_TOS,            listOf(0, 101, 255) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    65
        map.put(SO_BROADCAST,      listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    66
        map.put(SO_KEEPALIVE,      listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    67
        map.put(SO_LINGER,         listOf(0, 5, 15)    );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    68
        map.put(SO_RCVBUF,         listOf(1, 100, 1000));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    69
        map.put(SO_REUSEADDR,      listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    70
        map.put(SO_REUSEPORT,      listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    71
        map.put(SO_SNDBUF,         listOf(1, 100, 1000));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    72
        map.put(TCP_NODELAY,       listOf(TRUE, FALSE) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    73
        // extended options
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    74
        try {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    75
            Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    76
            Field field = c.getField("SO_FLOW_SLA");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    77
            map.put((SocketOption<?>)field.get(null), listOf(createSocketFlow()));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    78
            field = c.getField("TCP_QUICKACK");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    79
            map.put((SocketOption<?>)field.get(null), listOf(TRUE, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    80
            field = c.getField("TCP_KEEPIDLE");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    81
            map.put((SocketOption<?>)field.get(null), listOf(10, 100));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    82
            field = c.getField("TCP_KEEPINTERVAL");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    83
            map.put((SocketOption<?>)field.get(null), listOf(10, 100));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    84
            field = c.getField("TCP_KEEPCOUNT");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    85
            map.put((SocketOption<?>)field.get(null), listOf(10, 100));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    86
        } catch (ClassNotFoundException e) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    87
            // ignore, jdk.net module not present
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    88
        } catch (ReflectiveOperationException e) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    89
            throw new AssertionError(e);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    90
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    91
        return map;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    92
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    93
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    94
    // -- Socket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    95
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    96
    @DataProvider(name = "socketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    97
    public Object[][] socketOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    98
        try (Socket s = new Socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    99
            return s.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   100
                    .map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)})
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   101
                    .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   102
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   103
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   104
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   105
    @Test(dataProvider = "socketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   106
    public <T> void closedSocketImplUncreated(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   107
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   108
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   109
        Socket socket = createClosedSocketImplUncreated();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   110
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   111
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   112
                expectThrows(IOE, () -> socket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   113
                expectThrows(IOE, () -> socket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   114
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   115
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   116
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   117
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   118
    @Test(dataProvider = "socketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   119
    public <T> void closedSocketImplCreated(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   120
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   121
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   122
        Socket socket = createClosedSocketImplCreated();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   123
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   124
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   125
                expectThrows(IOE, () -> socket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   126
                expectThrows(IOE, () -> socket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   127
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   128
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   129
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   130
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   131
    @Test(dataProvider = "socketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   132
    public <T> void closedSocketAdapter(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   133
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   134
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   135
        Socket socket = createClosedSocketFromAdapter();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   136
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   137
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   138
                expectThrows(IOE, () -> socket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   139
                expectThrows(IOE, () -> socket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   140
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   141
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   142
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   143
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   144
    // -- ServerSocket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   145
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   146
    @DataProvider(name = "serverSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   147
    public Object[][] serverSocketOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   148
        try (ServerSocket ss = new ServerSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   149
            return ss.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   150
                     .map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)})
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   151
                     .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   152
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   153
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   154
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   155
    @Test(dataProvider = "serverSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   156
    public <T> void closedServerSocketImplUncreated(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   157
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   158
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   159
        ServerSocket serverSocket = createClosedServerSocketImplUncreated();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   160
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   161
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   162
                expectThrows(IOE, () -> serverSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   163
                expectThrows(IOE, () -> serverSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   164
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   165
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   166
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   167
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   168
    @Test(dataProvider = "serverSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   169
    public <T> void closedServerSocketImplCreated(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   170
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   171
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   172
        ServerSocket serverSocket = createClosedServerSocketImplCreated();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   173
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   174
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   175
                expectThrows(IOE, () -> serverSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   176
                expectThrows(IOE, () -> serverSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   177
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   178
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   179
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   180
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   181
    @Test(dataProvider = "serverSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   182
    public <T> void closedServerSocketAdapter(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   183
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   184
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   185
        if (option == IP_TOS)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   186
            return;  // SSC does not support IP_TOS
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   187
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   188
        ServerSocket serverSocket = createClosedServerSocketFromAdapter();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   189
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   190
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   191
                expectThrows(IOE, () -> serverSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   192
                expectThrows(IOE, () -> serverSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   193
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   194
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   195
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   196
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   197
    // -- DatagramSocket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   198
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   199
    @DataProvider(name = "datagramSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   200
    public Object[][] datagramSocketOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   201
        try (DatagramSocket ds = new DatagramSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   202
            return ds.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   203
                     .map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)})
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   204
                     .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   205
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   206
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   207
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   208
    @Test(dataProvider = "datagramSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   209
    public <T> void closedUnboundDatagramSocket(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   210
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   211
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   212
        DatagramSocket datagramSocket = createClosedUnboundDatagramSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   213
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   214
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   215
                expectThrows(IOE, () -> datagramSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   216
                expectThrows(IOE, () -> datagramSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   217
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   218
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   219
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   220
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   221
    @Test(dataProvider = "datagramSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   222
    public <T> void closedBoundDatagramSocket(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   223
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   224
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   225
        DatagramSocket datagramSocket = createClosedBoundDatagramSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   226
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   227
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   228
                expectThrows(IOE, () -> datagramSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   229
                expectThrows(IOE, () -> datagramSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   230
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   231
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   232
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   233
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   234
    @Test(dataProvider = "datagramSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   235
    public <T> void closedDatagramAdapter(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   236
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   237
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   238
        DatagramSocket datagramSocket = createClosedBoundDatagramSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   239
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   240
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   241
                expectThrows(IOE, () -> datagramSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   242
                expectThrows(IOE, () -> datagramSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   243
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   244
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   245
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   246
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   247
    // -- MulticastSocket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   248
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   249
    @DataProvider(name = "multicastSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   250
    public Object[][] multicastSocketOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   251
        try (MulticastSocket ms = new MulticastSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   252
            return ms.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   253
                     .map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)})
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   254
                     .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   255
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   256
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   257
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   258
    @Test(dataProvider = "multicastSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   259
    public <T> void closedUnboundMulticastSocket(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   260
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   261
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   262
        MulticastSocket multicastSocket = createClosedUnboundMulticastSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   263
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   264
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   265
                expectThrows(IOE, () -> multicastSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   266
                expectThrows(IOE, () -> multicastSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   267
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   268
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   269
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   270
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   271
    @Test(dataProvider = "multicastSocketOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   272
    public <T> void closedBoundMulticastSocket(SocketOption<T> option, List<T> values)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   273
        throws IOException
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   274
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   275
        MulticastSocket multicastSocket = createClosedBoundMulticastSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   276
        for (int i=0; i<3; i++); {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   277
            for (T value : values) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   278
                expectThrows(IOE, () -> multicastSocket.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   279
                expectThrows(IOE, () -> multicastSocket.getOption(option));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   280
            }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   281
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   282
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   283
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   284
    // --
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   285
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   286
    static List<Object> listOf(Object... objs) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   287
        List<Object> l = new ArrayList<>();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   288
        Arrays.stream(objs).forEachOrdered(l::add);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   289
        return l;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   290
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   291
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   292
    // Returns a closed Socket that has an impl whose `create` method has NOT been invoked.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   293
    static Socket createClosedSocketImplUncreated() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   294
        Socket s = new Socket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   295
        s.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   296
        return s;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   297
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   298
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   299
    // Returns a closed Socket that has an impl whose `create` method has been invoked.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   300
    static Socket createClosedSocketImplCreated() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   301
        Socket s = new Socket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   302
        s.bind(null);  // binding causes impl::create to be invoked
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   303
        s.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   304
        return s;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   305
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   306
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   307
    // Returns a closed Socket created from a SocketChannel's adapter.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   308
    static Socket createClosedSocketFromAdapter() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   309
        SocketChannel sc = SocketChannel.open();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   310
        sc.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   311
        return sc.socket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   312
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   313
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   314
    // Returns a closed ServerSocket that has an impl whose `create` method has NOT been invoked.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   315
    static ServerSocket createClosedServerSocketImplUncreated() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   316
        ServerSocket ss = new ServerSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   317
        ss.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   318
        return ss;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   319
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   320
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   321
    // Returns a closed ServerSocket that has an impl whose `create` method has been invoked.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   322
    static ServerSocket createClosedServerSocketImplCreated() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   323
        ServerSocket ss = new ServerSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   324
        ss.bind(null);  // binding causes impl::create to be invoked
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   325
        ss.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   326
        return ss;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   327
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   328
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   329
    // Returns a closed ServerSocket created from a ServerSocketChannel's adapter.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   330
    static ServerSocket createClosedServerSocketFromAdapter() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   331
        ServerSocketChannel ssc = ServerSocketChannel.open();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   332
        ssc.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   333
        return ssc.socket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   334
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   335
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   336
    // Returns a closed unbound DatagramSocket.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   337
    static DatagramSocket createClosedUnboundDatagramSocket() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   338
        DatagramSocket ds = new DatagramSocket(null);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   339
        assert ds.isBound() == false;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   340
        ds.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   341
        return ds;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   342
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   343
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   344
    // Returns a closed bound DatagramSocket.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   345
    static DatagramSocket createClosedBoundDatagramSocket() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   346
        DatagramSocket ds = new DatagramSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   347
        assert ds.isBound() == true;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   348
        ds.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   349
        return ds;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   350
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   351
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   352
    // Returns a closed DatagramSocket that created from a DatagramChannel's adapter.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   353
    static DatagramSocket createClosedDatagramSocketFromAdapter() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   354
        DatagramChannel dc = DatagramChannel.open();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   355
        dc.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   356
        return dc.socket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   357
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   358
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   359
    // Returns a closed unbound MulticastSocket.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   360
    static MulticastSocket createClosedUnboundMulticastSocket() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   361
        MulticastSocket ms = new MulticastSocket(null);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   362
        assert ms.isBound() == false;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   363
        ms.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   364
        return ms;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   365
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   366
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   367
    // Returns a closed bound MulticastSocket.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   368
    static MulticastSocket createClosedBoundMulticastSocket() throws IOException {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   369
        MulticastSocket ms = new MulticastSocket();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   370
        assert ms.isBound() == true;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   371
        ms.close();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   372
        return ms;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   373
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   374
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   375
    static Object createSocketFlow() {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   376
        try {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   377
            Class<?> c = Class.forName("jdk.net.SocketFlow");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   378
            Method method = c.getDeclaredMethod("create");
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   379
            return method.invoke(null);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   380
        } catch (ReflectiveOperationException e) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   381
            throw new AssertionError(e);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   382
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   383
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   384
}