1 /* 2 * Copyright (c) 2000, 2010, 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 /* @test 25 * @summary Test socketchannel vector IO 26 * @library .. 27 * @key randomness 28 */ 29 30 import java.io.*; 31 import java.net.*; 32 import java.nio.*; 33 import java.nio.channels.*; 34 import java.util.*; 35 36 37 public class VectorIO { 38 39 static Random generator = new Random(); 40 41 static int testSize; 42 43 public static void main(String[] args) throws Exception { 44 testSize = 1; 45 runTest(); 46 for(int i=15; i<18; i++) { 47 testSize = i; 48 runTest(); 49 } 50 } 51 52 static void runTest() throws Exception { 53 System.err.println("Length " + testSize); 54 Server sv = new Server(testSize); 55 sv.start(); 56 bufferTest(sv.port()); 57 if (sv.finish(8000) == 0) 58 throw new Exception("Failed: Length = " + testSize); 59 } 83 // Write the data out 84 long rem = total; 85 while (rem > 0L) { 86 long bytesWritten = sc.write(bufs); 87 if (bytesWritten == 0) { 88 if (sc.isBlocking()) 89 throw new RuntimeException("write did not block"); 90 Thread.sleep(50); 91 } else { 92 rem -= bytesWritten; 93 } 94 } 95 96 // Clean up 97 sc.close(); 98 } 99 100 static class Server 101 extends TestThread 102 { 103 static Random generator = new Random(); 104 105 final int testSize; 106 final ServerSocketChannel ssc; 107 108 Server(int testSize) throws IOException { 109 super("Server " + testSize); 110 this.testSize = testSize; 111 this.ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0)); 112 } 113 114 int port() { 115 return ssc.socket().getLocalPort(); 116 } 117 118 void go() throws Exception { 119 bufferTest(); 120 } 121 122 void bufferTest() throws Exception { 123 long total = 0L; 124 ByteBuffer[] bufs = new ByteBuffer[testSize]; | 1 /* 2 * Copyright (c) 2000, 2017, 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 /* @test 25 * @summary Test socketchannel vector IO (use -Dseed=X to set PRNG seed) 26 * @library .. /lib/testlibrary/ 27 * @build jdk.testlibrary.RandomFactory 28 * @run main VectorIO 29 * @key randomness 30 */ 31 32 import java.io.*; 33 import java.net.*; 34 import java.nio.*; 35 import java.nio.channels.*; 36 import java.util.*; 37 import jdk.testlibrary.RandomFactory; 38 39 public class VectorIO { 40 41 private static Random generator = RandomFactory.getRandom(); 42 43 static int testSize; 44 45 public static void main(String[] args) throws Exception { 46 testSize = 1; 47 runTest(); 48 for(int i=15; i<18; i++) { 49 testSize = i; 50 runTest(); 51 } 52 } 53 54 static void runTest() throws Exception { 55 System.err.println("Length " + testSize); 56 Server sv = new Server(testSize); 57 sv.start(); 58 bufferTest(sv.port()); 59 if (sv.finish(8000) == 0) 60 throw new Exception("Failed: Length = " + testSize); 61 } 85 // Write the data out 86 long rem = total; 87 while (rem > 0L) { 88 long bytesWritten = sc.write(bufs); 89 if (bytesWritten == 0) { 90 if (sc.isBlocking()) 91 throw new RuntimeException("write did not block"); 92 Thread.sleep(50); 93 } else { 94 rem -= bytesWritten; 95 } 96 } 97 98 // Clean up 99 sc.close(); 100 } 101 102 static class Server 103 extends TestThread 104 { 105 final int testSize; 106 final ServerSocketChannel ssc; 107 108 Server(int testSize) throws IOException { 109 super("Server " + testSize); 110 this.testSize = testSize; 111 this.ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0)); 112 } 113 114 int port() { 115 return ssc.socket().getLocalPort(); 116 } 117 118 void go() throws Exception { 119 bufferTest(); 120 } 121 122 void bufferTest() throws Exception { 123 long total = 0L; 124 ByteBuffer[] bufs = new ByteBuffer[testSize]; |