jdk/test/com/sun/nio/sctp/SctpMultiChannel/Send.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
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: 4677
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4677
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4677
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;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    33
import java.util.Set;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
import java.util.Iterator;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
import java.util.concurrent.CountDownLatch;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
import java.util.concurrent.TimeUnit;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
import java.nio.ByteBuffer;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
import com.sun.nio.sctp.Association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
import com.sun.nio.sctp.InvalidStreamException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
import com.sun.nio.sctp.MessageInfo;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
import com.sun.nio.sctp.SctpMultiChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
import static java.lang.System.out;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
import static java.lang.System.err;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
public class Send {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
    /* Latches used to synchronize between the client and server so that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
     * connections without any IO may not be closed without being accepted */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
    final CountDownLatch clientFinishedLatch = new CountDownLatch(1);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
    final CountDownLatch serverFinishedLatch = new CountDownLatch(1);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
    void test(String[] args) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
        SocketAddress address = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
        Server server = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
        if (!Util.isSCTPSupported()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
            out.println("SCTP protocol is not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
            out.println("Test cannot be run");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
        if (args.length == 2) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
            /* requested to connecct to a specific address */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
                int port = Integer.valueOf(args[1]);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
                address = new InetSocketAddress(args[0], port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
            } catch (NumberFormatException nfe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
                err.println(nfe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    68
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
            /* start server on local machine, default */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
                server = new Server();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
                server.start();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
                address = server.address();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
                debug("Server started and listening on " + address);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
            } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
                ioe.printStackTrace();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
                return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
        doTest(address);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
    void doTest(SocketAddress peerAddress) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
        SctpMultiChannel channel = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
        ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
        MessageInfo info = MessageInfo.createOutgoing(null, 0);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
        try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
            channel = SctpMultiChannel.open();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
            /* TEST 1: send small message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
            int streamNumber = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
            debug("sending to " + peerAddress + " on stream number: " + streamNumber);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
            info = MessageInfo.createOutgoing(peerAddress, streamNumber);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
            buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
            buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
            int position = buffer.position();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
            int remaining = buffer.remaining();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   102
            debug("sending small message: " + buffer);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
            int sent = channel.send(buffer, info);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   104
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
            check(sent == remaining, "sent should be equal to remaining");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
            check(buffer.position() == (position + sent),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
                    "buffers position should have been incremented by sent");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
            /* TEST 2: receive the echoed message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
            buffer.clear();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
            info = channel.receive(buffer, null, null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
            buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
            check(info != null, "info is null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
            check(info.streamNumber() == streamNumber,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
                    "message not sent on the correct stream");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
            check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
                  length, "bytes received not equal to message length");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
            check(info.bytes() == buffer.remaining(), "bytes != remaining");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
            check(Util.compare(buffer, Util.SMALL_MESSAGE),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
              "received message not the same as sent message");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
            /* TEST 3: send large message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
            Set<Association> assocs = channel.associations();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
            check(assocs.size() == 1, "there should be only one association");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
            Iterator<Association> it = assocs.iterator();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
            check(it.hasNext());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   128
            Association assoc = it.next();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
            streamNumber = assoc.maxOutboundStreams() - 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
            debug("sending on stream number: " + streamNumber);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
            info = MessageInfo.createOutgoing(assoc, null, streamNumber);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
            buffer.clear();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
            buffer.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1"));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
            buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
            position = buffer.position();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
            remaining = buffer.remaining();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
            debug("sending large message: " + buffer);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
            sent = channel.send(buffer, info);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
            check(sent == remaining, "sent should be equal to remaining");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
            check(buffer.position() == (position + sent),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
                    "buffers position should have been incremented by sent");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
            /* TEST 4: receive the echoed message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
            buffer.clear();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   148
            info = channel.receive(buffer, null, null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   149
            buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   150
            check(info != null, "info is null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   151
            check(info.streamNumber() == streamNumber,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   152
                    "message not sent on the correct stream");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   153
            check(info.bytes() == Util.LARGE_MESSAGE.getBytes("ISO-8859-1").
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   154
                  length, "bytes received not equal to message length");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   155
            check(info.bytes() == buffer.remaining(), "bytes != remaining");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   156
            check(Util.compare(buffer, Util.LARGE_MESSAGE),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   157
              "received message not the same as sent message");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
            /* TEST 5: InvalidStreamExcepton */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
            streamNumber = assoc.maxOutboundStreams() + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
            info = MessageInfo.createOutgoing(assoc, null, streamNumber);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
            buffer.clear();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   164
            buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
            buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
            position = buffer.position();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
            remaining = buffer.remaining();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   168
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
            debug("sending on stream number: " + streamNumber);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
            debug("sending small message: " + buffer);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   171
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   172
                sent = channel.send(buffer, info);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   173
                fail("should have thrown InvalidStreamExcepton");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   174
            } catch (InvalidStreamException ise){
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   175
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   176
            } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
                unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
            check(buffer.remaining() == remaining,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
                    "remaining should not be changed");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
            check(buffer.position() == position,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
                    "buffers position should not be changed");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   183
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
            /* TEST 5: getRemoteAddresses(Association) */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
            channel.getRemoteAddresses(assoc);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   187
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   188
            /* TEST 6: Send from heap buffer to force implementation to
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   189
             * substitute with a native buffer, then check that its position
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   190
             * is updated correctly */
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   191
            info = MessageInfo.createOutgoing(assoc, null, 0);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   192
            buffer.clear();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   193
            buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   194
            buffer.flip();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   195
            final int offset = 1;
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   196
            buffer.position(offset);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   197
            remaining = buffer.remaining();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   198
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   199
            try {
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   200
                sent = channel.send(buffer, info);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   201
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   202
                check(sent == remaining, "sent should be equal to remaining");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   203
                check(buffer.position() == (offset + sent),
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   204
                        "buffers position should have been incremented by sent");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   205
            } catch (IllegalArgumentException iae) {
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   206
                fail(iae + ", Error updating buffers position");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   207
            }
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   208
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
        } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   210
            unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
            clientFinishedLatch.countDown();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
            try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
            catch (InterruptedException ie) { unexpected(ie); }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
            if (channel != null) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
                try { channel.close(); }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
                catch (IOException e) { unexpected (e);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
    class Server implements Runnable
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
    {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
        final InetSocketAddress serverAddr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
        private SctpMultiChannel serverChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
        public Server() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
            serverChannel = SctpMultiChannel.open().bind(null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
            java.util.Set<SocketAddress> addrs = serverChannel.getAllLocalAddresses();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
            if (addrs.isEmpty())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
                debug("addrs should not be empty");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   233
            serverAddr = (InetSocketAddress) addrs.iterator().next();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
        public void start() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
            (new Thread(this, "Server-"  + serverAddr.getPort())).start();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   239
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
        public InetSocketAddress address() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
            return serverAddr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   244
        @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   245
        public void run() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   246
            ByteBuffer buffer = ByteBuffer.allocateDirect(Util.LARGE_BUFFER);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   247
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   248
                MessageInfo info;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   249
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   250
                /* receive a small message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   251
                do {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   252
                    info = serverChannel.receive(buffer, null, null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   253
                    if (info == null) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   254
                        fail("Server: unexpected null from receive");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   255
                            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   256
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   257
                } while (!info.isComplete());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   258
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   259
                buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   260
                check(info != null, "info is null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   261
                check(info.streamNumber() == 0,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   262
                        "message not sent on the correct stream");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   263
                check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   264
                      length, "bytes received not equal to message length");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   265
                check(info.bytes() == buffer.remaining(), "bytes != remaining");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   266
                check(Util.compare(buffer, Util.SMALL_MESSAGE),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   267
                  "received message not the same as sent message");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   268
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   269
                check(info != null, "info is null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   270
                Set<Association> assocs = serverChannel.associations();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   271
                check(assocs.size() == 1, "there should be only one association");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   272
                Iterator<Association> it = assocs.iterator();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   273
                check(it.hasNext());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   274
                Association assoc = it.next();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   275
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   276
                /* echo the message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   277
                debug("Server: echoing first message");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   278
                buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   279
                int bytes = serverChannel.send(buffer, info);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   280
                debug("Server: sent " + bytes + "bytes");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   281
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   282
                /* receive a large message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   283
                buffer.clear();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   284
                do {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   285
                    info = serverChannel.receive(buffer, null, null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   286
                    if (info == null) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   287
                        fail("Server: unexpected null from receive");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   288
                            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   289
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   290
                } while (!info.isComplete());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   291
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   292
                buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   293
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   294
                check(info.streamNumber() == assoc.maxInboundStreams() - 1,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   295
                        "message not sent on the correct stream");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   296
                check(info.bytes() == Util.LARGE_MESSAGE.getBytes("ISO-8859-1").
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   297
                      length, "bytes received not equal to message length");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   298
                check(info.bytes() == buffer.remaining(), "bytes != remaining");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   299
                check(Util.compare(buffer, Util.LARGE_MESSAGE),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   300
                  "received message not the same as sent message");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   301
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   302
                /* echo the message */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   303
                debug("Server: echoing second message");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   304
                buffer.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   305
                bytes = serverChannel.send(buffer, info);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   306
                debug("Server: sent " + bytes + "bytes");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   307
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   308
                /* TEST 6 */
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   309
                ByteBuffer expected = ByteBuffer.allocate(Util.SMALL_BUFFER);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   310
                expected.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   311
                expected.flip();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   312
                final int offset = 1;
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   313
                expected.position(offset);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   314
                buffer.clear();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   315
                do {
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   316
                    info = serverChannel.receive(buffer, null, null);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   317
                    if (info == null) {
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   318
                        fail("Server: unexpected null from receive");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   319
                        return;
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   320
                    }
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   321
                } while (!info.isComplete());
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   322
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   323
                buffer.flip();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   324
                check(info != null, "info is null");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   325
                check(info.streamNumber() == 0, "message not sent on the correct stream");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   326
                check(info.bytes() == expected.remaining(),
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   327
                    "bytes received not equal to message length");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   328
                check(info.bytes() == buffer.remaining(), "bytes != remaining");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   329
                check(expected.equals(buffer),
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   330
                    "received message not the same as sent message");
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 2542
diff changeset
   331
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   332
                clientFinishedLatch.await(10L, TimeUnit.SECONDS);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   333
                serverFinishedLatch.countDown();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   334
            } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   335
                unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   336
            } catch (InterruptedException ie) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   337
                unexpected(ie);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   338
            } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   339
                try { if (serverChannel != null) serverChannel.close(); }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   340
                catch (IOException  unused) {}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   341
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   342
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   343
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   344
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   345
        //--------------------- Infrastructure ---------------------------
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   346
    boolean debug = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   347
    volatile int passed = 0, failed = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   348
    void pass() {passed++;}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   349
    void fail() {failed++; Thread.dumpStack();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   350
    void fail(String msg) {System.err.println(msg); fail();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   351
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   352
    void check(boolean cond) {if (cond) pass(); else fail();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   353
    void check(boolean cond, String failMessage) {if (cond) pass(); else fail(failMessage);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   354
    void debug(String message) {if(debug) { System.out.println(message); }  }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   355
    public static void main(String[] args) throws Throwable {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   356
        Class<?> k = new Object(){}.getClass().getEnclosingClass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   357
        try {k.getMethod("instanceMain",String[].class)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   358
                .invoke( k.newInstance(), (Object) args);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   359
        catch (Throwable e) {throw e.getCause();}}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   360
    public void instanceMain(String[] args) throws Throwable {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   361
        try {test(args);} catch (Throwable t) {unexpected(t);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   362
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   363
        if (failed > 0) throw new AssertionError("Some tests failed");}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   364
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   365
}