Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 54727 invoked from network); 13 Aug 2010 09:24:10 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Aug 2010 09:24:10 -0000 Received: (qmail 56578 invoked by uid 500); 13 Aug 2010 09:24:10 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 56474 invoked by uid 500); 13 Aug 2010 09:24:08 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 56467 invoked by uid 99); 13 Aug 2010 09:24:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Aug 2010 09:24:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Aug 2010 09:24:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CFFE72388A38; Fri, 13 Aug 2010 09:22:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r985141 - /harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java Date: Fri, 13 Aug 2010 09:22:49 -0000 To: commits@harmony.apache.org From: odeakin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100813092249.CFFE72388A38@eris.apache.org> Author: odeakin Date: Fri Aug 13 09:22:49 2010 New Revision: 985141 URL: http://svn.apache.org/viewvc?rev=985141&view=rev Log: Commit partial patch for HARMONY-6621 ([classlib][nio] Minor testcase improvements to ServerSocketChannelTest and SocketChannelTest) Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java?rev=985141&r1=985140&r2=985141&view=diff ============================================================================== --- harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java (original) +++ harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest.java Fri Aug 13 09:22:49 2010 @@ -369,10 +369,11 @@ public class ServerSocketChannelTest ext } /** + * @throws InterruptedException * @tests ServerSocketChannel#accept().socket() */ public void test_read_LByteBuffer_Blocking_ReadWriteRealLargeData() - throws IOException { + throws IOException, InterruptedException { serverChannel.socket().bind(localAddr1); ByteBuffer buf = ByteBuffer.allocate(CAPACITY_64KB); for (int i = 0; i < CAPACITY_64KB; i++) { @@ -380,13 +381,38 @@ public class ServerSocketChannelTest ext } buf.flip(); clientChannel.connect(localAddr1); - clientChannel.write(buf); - clientChannel.close(); + WriteChannelThread writeThread = new WriteChannelThread(clientChannel, buf); + writeThread.start(); Socket socket = serverChannel.accept().socket(); InputStream in = socket.getInputStream(); assertReadResult(in,CAPACITY_64KB); + writeThread.join(); + // check if the thread threw any exceptions + if (writeThread.exception != null) { + throw writeThread.exception; + } } + class WriteChannelThread extends Thread { + SocketChannel channel; + ByteBuffer buffer; + IOException exception; + + public WriteChannelThread(SocketChannel channel, ByteBuffer buffer) { + this.channel = channel; + this.buffer = buffer; + } + + public void run() { + try { + channel.write(buffer); + channel.close(); + } catch (IOException e) { + exception = e; + } + } + } + /** * @tests ServerSocketChannel#accept().socket() */ @@ -400,11 +426,16 @@ public class ServerSocketChannelTest ext } buf.flip(); clientChannel.connect(localAddr1); - clientChannel.write(buf); - clientChannel.close(); + WriteChannelThread writeThread = new WriteChannelThread(clientChannel, buf); + writeThread.start(); Socket socket = serverChannel.accept().socket(); InputStream in = socket.getInputStream(); assertReadResult(in,CAPACITY_64KB); + writeThread.join(); + // check if the thread threw any exceptions + if (writeThread.exception != null) { + throw writeThread.exception; + } } /** @@ -420,10 +451,35 @@ public class ServerSocketChannelTest ext } clientChannel.connect(localAddr1); Socket socket = serverChannel.accept().socket(); - OutputStream out = socket.getOutputStream(); - out.write(writeContent); - socket.close(); + WriteSocketThread writeThread = new WriteSocketThread(socket, writeContent); + writeThread.start(); assertWriteResult(CAPACITY_64KB); + writeThread.join(); + // check if the thread threw any exceptions + if (writeThread.exception != null) { + throw writeThread.exception; + } + } + + class WriteSocketThread extends Thread { + Socket socket; + byte[] buffer; + IOException exception; + + public WriteSocketThread(Socket socket, byte[] buffer) { + this.socket = socket; + this.buffer = buffer; + } + + public void run() { + try { + OutputStream out = socket.getOutputStream(); + out.write(buffer); + socket.close(); + } catch (IOException e) { + exception = e; + } + } } /** @@ -438,10 +494,14 @@ public class ServerSocketChannelTest ext } clientChannel.connect(localAddr1); Socket socket = serverChannel.accept().socket(); - OutputStream out = socket.getOutputStream(); - out.write(writeContent); - socket.close(); + WriteSocketThread writeThread = new WriteSocketThread(socket, writeContent); + writeThread.start(); assertWriteResult(CAPACITY_64KB); + writeThread.join(); + // check if the thread threw any exceptions + if (writeThread.exception != null) { + throw writeThread.exception; + } } /**