harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r627801 - /harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Date Thu, 14 Feb 2008 16:56:15 GMT
Author: tellison
Date: Thu Feb 14 08:56:02 2008
New Revision: 627801

URL: http://svn.apache.org/viewvc?rev=627801&view=rev
Log:
Regression test to accompany fix in r627731.

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java?rev=627801&r1=627800&r2=627801&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Thu Feb 14 08:56:02 2008
@@ -22,6 +22,7 @@
 import java.io.OutputStream;
 import java.net.BindException;
 import java.net.ConnectException;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -2028,6 +2029,42 @@
         }
     }
     
+    public void testReadByteBuffer_Direct2() throws IOException {
+        byte[] request = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+        ByteBuffer buffer = ByteBuffer.allocateDirect(128);
+
+        ServerSocketChannel server = ServerSocketChannel.open();
+        server.socket().bind(
+                new InetSocketAddress(InetAddress.getLocalHost(), 0), 5);
+        Socket client = new Socket(InetAddress.getLocalHost(), server.socket()
+                .getLocalPort());
+        client.setTcpNoDelay(false);
+        Socket worker = server.socket().accept();
+        SocketChannel workerChannel = worker.getChannel();
+
+        OutputStream out = client.getOutputStream();
+        out.write(request);
+        out.close();
+
+        buffer.limit(5);
+        int bytesRead = workerChannel.read(buffer);
+        assertEquals(5, bytesRead);
+        assertEquals(5, buffer.position());
+
+        buffer.limit(request.length);
+        bytesRead = workerChannel.read(buffer);
+        assertEquals(6, bytesRead);
+
+        buffer.flip();
+        assertEquals(request.length, buffer.limit());
+
+        assertEquals(ByteBuffer.wrap(request), buffer);
+
+        client.close();
+        worker.close();
+        server.close();
+    }
+
     public void testReadByteBuffer_BufNull() throws Exception {
         assertTrue(this.server1.isBound());
         java.nio.ByteBuffer readBuf = java.nio.ByteBuffer.allocate(0);



Mime
View raw message