test/jdk/com/sun/nio/sctp/SctpChannel/Connect.java
author chegar
Thu, 21 Nov 2019 12:14:29 +0000
changeset 59205 afcc8af048e6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     4
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    13
 * accompanied this code).
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    14
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4678
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4678
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4678
diff changeset
    21
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    22
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    23
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
/* @test
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    25
 * @bug 4927640
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
 * @summary Tests the SCTP protocol implementation
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    27
 * @author chegar
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
import java.net.InetSocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
import java.net.SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    32
import java.io.IOException;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    33
import java.util.Set;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
import java.util.concurrent.Callable;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
import java.nio.channels.AlreadyConnectedException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
import java.nio.channels.ClosedChannelException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
import java.nio.channels.ConnectionPendingException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
import java.nio.channels.NoConnectionPendingException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
import java.nio.channels.UnresolvedAddressException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
import java.nio.channels.UnsupportedAddressTypeException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
import com.sun.nio.sctp.SctpChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
import com.sun.nio.sctp.SctpServerChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
import static java.lang.System.out;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
import static java.lang.System.err;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
 * Tests connect, finishConnect, isConnectionPending,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
 * getRemoteAddresses and association.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
public class Connect {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
    void test(String[] args) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
        if (!Util.isSCTPSupported()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
            out.println("SCTP protocol is not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
            out.println("Test cannot be run");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    59
        doTest();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    62
    void doTest() {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
        SctpChannel channel = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
59205
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
    65
        try (SctpServerChannel ssc = SctpServerChannel.open()) {
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    66
            /* Create a server channel to connect to */
59205
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
    67
            ssc.bind(null);
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    68
            Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    69
            if (addrs.isEmpty())
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    70
                debug("addrs should not be empty");
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    71
            final SocketAddress peerAddress = (InetSocketAddress) addrs.iterator().next();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    72
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
            channel = SctpChannel.open();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
            /* TEST 0.5 Verify default values for new/unconnected channel */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
            check(channel.getRemoteAddresses().isEmpty(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
                    "non empty set for unconnected channel");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
            check(channel.association() == null,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
                    "non-null association for unconnected channel");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
            check(!channel.isConnectionPending(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
                    "should not have a connection pending");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
            /* TEST 1: non-blocking connect */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
            channel.configureBlocking(false);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
            if (channel.connect(peerAddress) != true) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
                debug("non-blocking connect did not immediately succeed");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
                check(channel.isConnectionPending(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
                        "should return true for isConnectionPending");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
                try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
                    channel.connect(peerAddress);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
                    fail("should have thrown ConnectionPendingException");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
                } catch (ConnectionPendingException cpe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
                    pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
                } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
                    unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
                channel.configureBlocking(true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
                check(channel.finishConnect(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
                        "finishConnect should have returned true");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   102
            ssc.accept();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   103
            ssc.close();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   104
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
            /* TEST 1.5 Verify after connect */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
            check(!channel.getRemoteAddresses().isEmpty(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
                    "empty set for connected channel");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
            check(channel.association() != null,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
                    "null association for connected channel");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
            check(!channel.isConnectionPending(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
                    "pending connection for connected channel");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
            /* TEST 2: Verify AlreadyConnectedException thrown */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
                channel.connect(peerAddress);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
                fail("should have thrown AlreadyConnectedException");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
            } catch (AlreadyConnectedException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
            }  catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
                unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   123
            /* TEST 2.5: Verify AlreadyConnectedException thrown */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   124
            try {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   125
                channel.connect(peerAddress, 5, 5);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   126
                fail("should have thrown AlreadyConnectedException");
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   127
            } catch (AlreadyConnectedException unused) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   128
                pass();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   129
            }  catch (IOException ioe) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   130
                unexpected(ioe);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   131
            }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   132
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
            /* TEST 3: UnresolvedAddressException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
            channel.close();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
            channel = SctpChannel.open();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
            InetSocketAddress unresolved =
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
                    InetSocketAddress.createUnresolved("xxyyzzabc", 4567);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
                channel.connect(unresolved);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
                fail("should have thrown UnresolvedAddressException");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
            } catch (UnresolvedAddressException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
            }  catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
                unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
            /* TEST 4: UnsupportedAddressTypeException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   148
            SocketAddress unsupported = new UnsupportedSocketAddress();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   149
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   150
                channel.connect(unsupported);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   151
                fail("should have thrown UnsupportedAddressTypeException");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   152
            } catch (UnsupportedAddressTypeException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   153
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   154
            }  catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   155
                unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   156
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   157
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
            /* TEST 5: ClosedChannelException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
            channel.close();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
            final SctpChannel closedChannel = channel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
            testCCE(new Callable<Void>() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
                public Void call() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
                    closedChannel.connect(peerAddress); return null; } });
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   164
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
            /* TEST 5.5 getRemoteAddresses */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
            testCCE(new Callable<Void>() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
                public Void call() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   168
                    closedChannel.getRemoteAddresses(); return null; } });
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
            testCCE(new Callable<Void>() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
                public Void call() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   171
                    closedChannel.association(); return null; } });
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   172
            check(!channel.isConnectionPending(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   173
                    "pending connection for closed channel");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   174
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   175
            /* Run some more finishConnect tests */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   176
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
            /* TEST 6: NoConnectionPendingException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
            channel = SctpChannel.open();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
                channel.finishConnect();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
                fail("should have thrown NoConnectionPendingException");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
            } catch (NoConnectionPendingException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   183
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
            }  catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
                unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   187
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   188
            /* TEST 7: ClosedChannelException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   189
            channel.close();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   190
            final SctpChannel cceChannel = channel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
            testCCE(new Callable<Void>() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
                public Void call() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
                    cceChannel.finishConnect(); return null; } });
4678
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   194
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   195
            /* TEST 8: IOException: Connection refused. Exercises handleSocketError.
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   196
             *         Assumption: no sctp socket listening on 3456 */
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   197
            SocketAddress addr = new InetSocketAddress("localhost", 3456);
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   198
            channel = SctpChannel.open();
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   199
            try {
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   200
                channel.connect(addr);
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   201
                fail("should have thrown ConnectException: Connection refused");
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   202
            } catch (IOException ioe) {
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   203
                pass();
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   204
            }
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 3072
diff changeset
   205
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   206
        } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
            unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
            try { if (channel != null) channel.close(); }
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   210
            catch (IOException unused) {}
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
    class UnsupportedSocketAddress extends SocketAddress { }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
    void testCCE(Callable callable) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
        try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
            callable.call();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
            fail("should have thrown ClosedChannelException");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
        } catch (ClosedChannelException cce) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
           pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
        } catch (Exception ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
            unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
        //--------------------- Infrastructure ---------------------------
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
    boolean debug = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
    volatile int passed = 0, failed = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
    void pass() {passed++;}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
    void fail() {failed++; Thread.dumpStack();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
    void fail(String msg) {System.err.println(msg); fail();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   233
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
    void check(boolean cond) {if (cond) pass(); else fail();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
    void check(boolean cond, String failMessage) {if (cond) pass(); else fail(failMessage);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
    void debug(String message) {if(debug) { System.out.println(message); }  }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
    public static void main(String[] args) throws Throwable {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
        Class<?> k = new Object(){}.getClass().getEnclosingClass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   239
        try {k.getMethod("instanceMain",String[].class)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
                .invoke( k.newInstance(), (Object) args);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
        catch (Throwable e) {throw e.getCause();}}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
    public void instanceMain(String[] args) throws Throwable {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
        try {test(args);} catch (Throwable t) {unexpected(t);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   244
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   245
        if (failed > 0) throw new AssertionError("Some tests failed");}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   246
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   247
}