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 * @run testng SocketFlowBasic 29 */ 30 31 import jdk.net.SocketFlow; 32 import org.testng.annotations.DataProvider; 33 import org.testng.annotations.Test; 34 import static jdk.net.SocketFlow.*; 35 import static org.testng.Assert.*; 36 37 public class SocketFlowBasic { 38 39 @DataProvider 40 public Object[][] validPriorities() { 41 return new Object[][] { {HIGH_PRIORITY}, {NORMAL_PRIORITY} }; 42 } 43 44 @Test(dataProvider = "validPriorities") 45 public void priority(long validPriority) { 46 SocketFlow flow = SocketFlow.create(); 47 flow.bandwidth(validPriority); 48 long bandwidth = flow.bandwidth(); 49 assertTrue(bandwidth == validPriority, "Expected " + validPriority + ", got" + bandwidth); 50 } 51 52 @DataProvider 53 public Object[][] invalidPriorities() { 54 return new Object[][] { {HIGH_PRIORITY+10}, {NORMAL_PRIORITY-10000} }; 55 } 56 57 @Test(dataProvider = "invalidPriorities", expectedExceptions = IllegalArgumentException.class) 58 public void priority(int invalidPriority) { 59 SocketFlow flow = SocketFlow.create(); 60 flow.priority(invalidPriority); 61 } 62 63 @DataProvider 64 public Object[][] positiveBandwidth() { 65 return new Object[][] { {0}, {100}, {Integer.MAX_VALUE}, {Long.MAX_VALUE} }; 66 } 67 68 @Test(dataProvider = "positiveBandwidth") 69 public void bandwidth(long posBandwidth) { 70 SocketFlow flow = SocketFlow.create(); 71 flow.bandwidth(posBandwidth); 72 long bandwidth = flow.bandwidth(); 73 assertTrue(bandwidth == posBandwidth, "Expected " + posBandwidth + ", got" + bandwidth); 74 } 75 76 77 @DataProvider 78 public Object[][] negativeBandwidth() { 79 return new Object[][] { {-1}, {-100}, {Integer.MIN_VALUE}, {Long.MIN_VALUE} }; 80 } 81 82 @Test(dataProvider = "negativeBandwidth", expectedExceptions = IllegalArgumentException.class) 83 public void invalidBandwidth(long negBandwidth) { 84 SocketFlow flow = SocketFlow.create(); 85 flow.bandwidth(negBandwidth); 86 } 87 88 @Test 89 public void status() { 90 SocketFlow flow = SocketFlow.create(); 91 assertTrue(flow.status() == Status.NO_STATUS); 92 } 93 }