6987116: (so) test/java/nio/channels/SocketChannel/VectorIO.java failed on Solaris 11
authoralanb
Tue, 05 Oct 2010 15:07:40 +0100
changeset 6845 0138b84aafdd
parent 6697 39929804f9d4
child 6846 2cfd1dfb014b
6987116: (so) test/java/nio/channels/SocketChannel/VectorIO.java failed on Solaris 11 Reviewed-by: forax
jdk/test/java/nio/channels/SocketChannel/VectorIO.java
--- a/jdk/test/java/nio/channels/SocketChannel/VectorIO.java	Mon Oct 04 13:04:09 2010 -0400
+++ b/jdk/test/java/nio/channels/SocketChannel/VectorIO.java	Tue Oct 05 15:07:40 2010 +0100
@@ -60,6 +60,7 @@
 
     static void bufferTest(int port) throws Exception {
         ByteBuffer[] bufs = new ByteBuffer[testSize];
+        long total = 0L;
         for(int i=0; i<testSize; i++) {
             String source = "buffer" + i;
             if (generator.nextBoolean())
@@ -69,6 +70,7 @@
 
             bufs[i].put(source.getBytes("8859_1"));
             bufs[i].flip();
+            total += bufs[i].remaining();
         }
 
         // Get a connection to the server
@@ -76,17 +78,20 @@
         InetSocketAddress isa = new InetSocketAddress(lh, port);
         SocketChannel sc = SocketChannel.open();
         sc.connect(isa);
-        sc.configureBlocking(false);
+        sc.configureBlocking(generator.nextBoolean());
 
         // Write the data out
-        long bytesWritten = 0;
-        do {
-            bytesWritten = sc.write(bufs);
-        } while (bytesWritten > 0);
-
-        try {
-            Thread.currentThread().sleep(500);
-        } catch (InterruptedException ie) { }
+        long rem = total;
+        while (rem > 0L) {
+            long bytesWritten = sc.write(bufs);
+            if (bytesWritten == 0) {
+                if (sc.isBlocking())
+                    throw new RuntimeException("write did not block");
+                Thread.sleep(50);
+            } else {
+                rem -= bytesWritten;
+            }
+        }
 
         // Clean up
         sc.close();
@@ -115,6 +120,7 @@
         }
 
         void bufferTest() throws Exception {
+            long total = 0L;
             ByteBuffer[] bufs = new ByteBuffer[testSize];
             for(int i=0; i<testSize; i++) {
                 String source = "buffer" + i;
@@ -122,6 +128,7 @@
                     bufs[i] = ByteBuffer.allocateDirect(source.length());
                 else
                     bufs[i] = ByteBuffer.allocate(source.length());
+                total += bufs[i].capacity();
             }
 
             // Get a connection from client
@@ -138,11 +145,21 @@
                     Thread.sleep(50);
                 }
 
+                sc.configureBlocking(generator.nextBoolean());
+
                 // Read data into multiple buffers
-                long bytesRead = 0;
-                do {
-                    bytesRead = sc.read(bufs);
-                } while (bytesRead > 0);
+                long avail = total;
+                while (avail > 0) {
+                    long bytesRead = sc.read(bufs);
+                    if (bytesRead < 0)
+                        break;
+                    if (bytesRead == 0) {
+                        if (sc.isBlocking())
+                            throw new RuntimeException("read did not block");
+                        Thread.sleep(50);
+                    }
+                    avail -= bytesRead;
+                }
 
                 // Check results
                 for(int i=0; i<testSize; i++) {