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