test/jdk/jdk/net/RdmaSockets/rsocket/ServerSocketChannel/SSCConfigureBlocking.java
author bpb
Wed, 06 Feb 2019 12:48:01 -0800
branchrsocket-branch
changeset 57156 81e4a12fd1a4
parent 57115 512e7cc6ccce
child 57160 c502c299d41e
permissions -rw-r--r--
rsocket-branch: change recent copyright year to 2019 and new files to 2019 only
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     1
/*
57156
81e4a12fd1a4 rsocket-branch: change recent copyright year to 2019 and new files to 2019 only
bpb
parents: 57115
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     4
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     8
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    14
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    18
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    21
 * questions.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    22
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    23
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    24
/*
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    25
 * @test
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    26
 * @bug 8195160
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    27
 * @summary Tests blocking configuration of server socket channels
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    28
 * @requires (os.family == "linux")
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    29
 * @library ../ /test/lib
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    30
 * @build RsocketTest
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    31
 * @run testng/othervm SSCConfigureBlocking
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    32
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    33
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    34
import java.io.IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    35
import java.net.ProtocolFamily;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    36
import java.nio.channels.IllegalBlockingModeException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    37
import java.nio.channels.Selector;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    38
import java.nio.channels.ServerSocketChannel;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    39
import org.testng.SkipException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    40
import org.testng.annotations.BeforeTest;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    41
import org.testng.annotations.DataProvider;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    42
import org.testng.annotations.Test;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    43
import static java.net.StandardProtocolFamily.INET;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    44
import static java.net.StandardProtocolFamily.INET6;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    45
import static java.nio.channels.SelectionKey.OP_ACCEPT;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    46
import static jdk.net.RdmaSockets.*;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    47
import static org.testng.Assert.assertThrows;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    48
import static org.testng.Assert.assertTrue;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    49
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    50
public class SSCConfigureBlocking {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    51
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    52
    @BeforeTest
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    53
    public void setup() throws Exception {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    54
        if (!RsocketTest.isRsocketAvailable())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    55
            throw new SkipException("rsocket is not available");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    56
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    57
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    58
    @DataProvider(name = "families")
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    59
    public Object[][] families() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    60
        return new Object[][] { { INET }, { INET6 } };
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    61
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    62
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    63
     // Newly-created selectable channels are always in blocking mode.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    64
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    65
    @Test(dataProvider = "families")
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    66
    public void testServerSocketChannel(ProtocolFamily family)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    67
        throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    68
    {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    69
        try (ServerSocketChannel ssc = openServerSocketChannel(family)) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    70
            assertTrue(ssc.isBlocking(), "Newly created channel is not blocking");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    71
            ssc.configureBlocking(false);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    72
            assertTrue(!ssc.isBlocking(), "Expected non-blocking");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    73
            ssc.configureBlocking(true);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    74
            assertTrue(ssc.isBlocking(), "Expected blocking");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    75
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    76
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    77
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    78
    static final Class<IllegalBlockingModeException> IBME = IllegalBlockingModeException.class;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    79
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    80
    @Test(dataProvider = "families")
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    81
    public void testServerSocketChannelRegister(ProtocolFamily family)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    82
        throws IOException
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    83
    {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    84
        try (ServerSocketChannel ssc = openServerSocketChannel(family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    85
             Selector selector = Selector.open()) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    86
            assertThrows(IBME, () -> ssc.register(selector, OP_ACCEPT));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    87
            assertThrows(IBME, () -> ssc.register(selector, OP_ACCEPT, new Object()));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    88
            ssc.configureBlocking(false);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    89
            ssc.register(selector, OP_ACCEPT);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    90
            assertThrows(IBME, () -> ssc.configureBlocking(true));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    91
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    92
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    93
}