jdk/test/jdk/net/SocketFlow/SocketFlowBasic.java
author chegar
Wed, 27 Apr 2016 20:36:02 +0100
changeset 37676 24ef455da1b0
child 38579 477f5b3c9973
permissions -rw-r--r--
8044773: Refactor jdk.net API so that it can be moved out of the base module Reviewed-by: alanb, erikj, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     1
/*
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     4
 *
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     8
 *
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    13
 * accompanied this code).
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    14
 *
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    18
 *
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    21
 * questions.
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    22
 */
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    23
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    24
/*
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    25
 * @test
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    26
 * @bug 8765432
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    27
 * @summary Basic test for SocketFlow API
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    28
 * @run testng SocketFlowBasic
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    29
 */
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    30
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    31
import jdk.net.SocketFlow;
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    32
import org.testng.annotations.DataProvider;
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    33
import org.testng.annotations.Test;
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    34
import static jdk.net.SocketFlow.*;
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    35
import static org.testng.Assert.*;
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    36
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    37
public class SocketFlowBasic {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    38
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    39
    @DataProvider
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    40
    public Object[][] validPriorities() {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    41
        return new Object[][] { {HIGH_PRIORITY}, {NORMAL_PRIORITY} };
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    42
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    43
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    44
    @Test(dataProvider = "validPriorities")
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    45
    public void priority(long validPriority) {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    46
        SocketFlow flow = SocketFlow.create();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    47
        flow.bandwidth(validPriority);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    48
        long bandwidth = flow.bandwidth();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    49
        assertTrue(bandwidth == validPriority, "Expected " + validPriority + ", got" + bandwidth);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    50
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    51
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    52
    @DataProvider
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    53
    public Object[][] invalidPriorities() {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    54
        return new Object[][] { {HIGH_PRIORITY+10}, {NORMAL_PRIORITY-10000} };
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    55
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    56
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    57
    @Test(dataProvider = "invalidPriorities", expectedExceptions = IllegalArgumentException.class)
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    58
    public void priority(int invalidPriority) {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    59
        SocketFlow flow = SocketFlow.create();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    60
        flow.priority(invalidPriority);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    61
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    62
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    63
    @DataProvider
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    64
    public Object[][] positiveBandwidth() {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    65
        return new Object[][] { {0}, {100}, {Integer.MAX_VALUE}, {Long.MAX_VALUE} };
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    66
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    67
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    68
    @Test(dataProvider = "positiveBandwidth")
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    69
    public void bandwidth(long posBandwidth) {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    70
        SocketFlow flow = SocketFlow.create();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    71
        flow.bandwidth(posBandwidth);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    72
        long bandwidth = flow.bandwidth();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    73
        assertTrue(bandwidth == posBandwidth, "Expected " + posBandwidth + ", got" + bandwidth);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    74
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    75
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    76
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    77
    @DataProvider
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    78
    public Object[][] negativeBandwidth() {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    79
        return new Object[][] { {-1}, {-100}, {Integer.MIN_VALUE}, {Long.MIN_VALUE} };
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    80
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    81
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    82
    @Test(dataProvider = "negativeBandwidth", expectedExceptions = IllegalArgumentException.class)
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    83
    public void invalidBandwidth(long negBandwidth) {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    84
        SocketFlow flow = SocketFlow.create();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    85
        flow.bandwidth(negBandwidth);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    86
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    87
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    88
    @Test
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    89
    public void status() {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    90
        SocketFlow flow = SocketFlow.create();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    91
        assertTrue(flow.status() == Status.NO_STATUS);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    92
    }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
diff changeset
    93
}