test/jdk/java/net/SctpSanity.java
changeset 59203 696e6a7e3b6a
equal deleted inserted replaced
59202:533f1183d7c6 59203:696e6a7e3b6a
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25  * @bug 8232097
       
    26  * @summary Basic sanity for creation of SCTP channels
       
    27  * @modules jdk.sctp
       
    28  * @run main/othervm SctpSanity 1
       
    29  * @run main/othervm SctpSanity 2
       
    30  * @run main/othervm SctpSanity 3
       
    31  */
       
    32 
       
    33 import java.io.IOException;
       
    34 import com.sun.nio.sctp.SctpChannel;
       
    35 import com.sun.nio.sctp.SctpMultiChannel;
       
    36 import com.sun.nio.sctp.SctpServerChannel;
       
    37 import static java.lang.System.out;
       
    38 
       
    39 /**
       
    40  * Tests creation of SCTP channels. The channels should either be created
       
    41  * or not. The latter throwing an UnsupportedOperationException. No other
       
    42  * behavior is acceptable. Minimally, exercises the JDK's native library
       
    43  * loading on operating systems that provide an implementation, even if
       
    44  * the system-level support is not configured.
       
    45  */
       
    46 public class SctpSanity {
       
    47 
       
    48     public static void main(String... args) throws IOException {
       
    49         switch (Integer.valueOf(args[0])) {
       
    50             case 1: testSctpChannel();        break;
       
    51             case 2: testSctpServerChannel();  break;
       
    52             case 3: testSctpMultiChannel();   break;
       
    53             default: throw new AssertionError("should not reach here");
       
    54         }
       
    55     }
       
    56 
       
    57     static void testSctpChannel() throws IOException {
       
    58         try (SctpChannel channel = SctpChannel.open()) {
       
    59             out.println("created SctpChannel:" + channel);
       
    60         } catch (UnsupportedOperationException uoe) {
       
    61             // ok - the platform does not support SCTP
       
    62             out.println("ok, caught:" + uoe);
       
    63         }
       
    64     }
       
    65 
       
    66     static void testSctpServerChannel() throws IOException {
       
    67         try (SctpServerChannel channel = SctpServerChannel.open()) {
       
    68             out.println("created SctpServerChannel:" + channel);
       
    69         } catch (UnsupportedOperationException uoe) {
       
    70             // ok - the platform does not support SCTP
       
    71             out.println("ok, caught:" + uoe);
       
    72         }
       
    73     }
       
    74 
       
    75     static void testSctpMultiChannel() throws IOException {
       
    76         try (SctpMultiChannel channel = SctpMultiChannel.open()) {
       
    77             out.println("created SctpMultiChannel:" + channel);
       
    78         } catch (UnsupportedOperationException uoe) {
       
    79             // ok - the platform does not support SCTP
       
    80             out.println("ok, caught:" + uoe);
       
    81         }
       
    82     }
       
    83 }
       
    84