Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 87375 invoked from network); 24 Jun 2006 00:38:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Jun 2006 00:38:26 -0000 Received: (qmail 48375 invoked by uid 500); 24 Jun 2006 00:38:23 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 48324 invoked by uid 500); 24 Jun 2006 00:38:22 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 48307 invoked by uid 99); 24 Jun 2006 00:38:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jun 2006 17:38:22 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [143.182.124.21] (HELO azsmga101-1.ch.intel.com) (143.182.124.21) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jun 2006 17:38:21 -0700 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101-1.ch.intel.com with ESMTP; 23 Jun 2006 17:38:00 -0700 Received: from orsmsx334.jf.intel.com (HELO orsmsx334.amr.corp.intel.com) ([10.22.226.45]) by azsmga001.ch.intel.com with ESMTP; 23 Jun 2006 17:38:00 -0700 X-IronPort-AV: i="4.06,170,1149490800"; d="scan'208"; a="56711535:sNHT16446206" Received: from orsmsx409.amr.corp.intel.com ([192.168.65.58]) by orsmsx334.amr.corp.intel.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 23 Jun 2006 17:37:59 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: [classlib][LUNI | NIO] How to write stable tests for blocking write/read operations of Socket and SocketChannel Date: Fri, 23 Jun 2006 17:37:58 -0700 Message-ID: <8AEB79DC01BE994D8DE3FD02FA5B475B03E321F3@orsmsx409> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [classlib][LUNI | NIO] How to write stable tests for blocking write/read operations of Socket and SocketChannel thread-index: AcaXIt67BM0rFU7qQwyj5Fz9T4PBtgAA4Qsw From: "Magnusson, Geir" To: X-OriginalArrivalTime: 24 Jun 2006 00:37:59.0985 (UTC) FILETIME=[71C3DA10:01C69726] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N How about using mocks of some sort to control the sequences of activity? --=20 Geir Magnusson Jr SSG/MPD geir.magnusson@intel.com +1 203 665 6437 =20 > -----Original Message----- > From: Andrew Zhang [mailto:zhanghuangzhu@gmail.com]=20 > Sent: Friday, June 23, 2006 8:11 PM > To: harmony-dev@incubator.apache.org > Subject: [classlib][LUNI | NIO] How to write stable tests for=20 > blocking write/read operations of Socket and SocketChannel >=20 > Hi everybody, >=20 > I'm struggling to write a stable test for blocking write/read=20 > operation of > Socket and SocketChannel. >=20 > Could you anybody help me out? >=20 >=20 > On 6/23/06, Andrew Zhang wrote: > > > > Hi Alexander, > > > > Thanks for your kind reminder. > > > > Certainly I'll use sth. like=20 > Support_PortManager.getNextPort() to avoid > > such port conflict issue. > > > > Here I just want to describe the problem. > > > > The test still fails on my machine sometimes. Could anyone=20 > tell me how to > > write a stable test on this issue? > > > > Or is it a bug of RI? Or is it possible to write a=20 > theoretically stable > > test? > > > > Thanks a lot in advance! > > > > public void test_SocketChannel_BlockWriteRead() throws=20 > IOException { > > final int CAPACITY_NORMAL =3D 200; > > InetSocketAddress localAddr1 =3D new=20 > InetSocketAddress("127.0.0.1 > > ",1234); > > > > ServerSocket server =3D new ServerSocket(1234); > > > > SocketChannel channel =3D SocketChannel.open(); > > channel.connect(localAddr1); > > Socket client =3D server.accept (); > > client.setTcpNoDelay(true); > > client.setSendBufferSize(1); > > > > OutputStream out =3D client.getOutputStream(); > > > > byte[] sendBuf =3D new byte[CAPACITY_NORMAL * 2]; > > for (int i =3D 0; i < CAPACITY_NORMAL * 2; i++) { > > sendBuf[i] =3D (byte) i; > > } > > // send CAPACITY_NORMAL * 2 bytes data > > out.write(sendBuf); > > out.flush(); > > > > // no matter out.close() or client.shutdownOutput () is used > > // the test still fails sometimes. > > // out.close(); > > client.shutdownOutput(); > > > > > > ByteBuffer buf1 =3D ByteBuffer.allocate(CAPACITY_NORMAL); > > ByteBuffer buf2 =3D ByteBuffer.allocate(CAPACITY_NORMAL); > > ByteBuffer[] buf =3D{buf1, buf2}; > > > > // should receive CAPACITY_NORMAL * 2 bytes data > > long count =3D 0; > > do{ > > long ret =3D channel.read(buf); > > if(ret =3D=3D -1){ > > break; > > } > > count +=3D ret; > > }while(count < CAPACITY_NORMAL*2); > > assertEquals(CAPACITY_NORMAL * 2, count); > > } > > > > > > On 6/23/06, Alexander Kleymenov wrote: > > > > > > Hello Andrew, > > > > > > I ran the test on RI (1.4.2_04-b05 and 1.5.0-b64) and could not > > > reproduce the failure. Is it still an issue? > > > > > > Can I suggest a little improvement for your test? Try do not use > > > hardcoded port numbers in the test. > > > Let the ServerSocket choose the available port by specifying 0 as > > > parameter. > > > I.e. write the test as: > > > > > > ServerSocket server =3D new ServerSocket(0); > > > InetSocketAddress localAddr1 =3D new=20 > InetSocketAddress("127.0.0.1", > > > server.getLocalPort()); > > > > > > Such a way prevents the test from "Address in use" exception. > > > > > > Thank You, > > > Alexander > > > > > >=20 > --------------------------------------------------------------------- > > > Terms of use : http://incubator.apache.org/harmony/mailing.html > > > To unsubscribe, e-mail:=20 > harmony-dev-unsubscribe@incubator.apache.org > > > For additional commands, e-mail:=20 > harmony-dev-help@incubator.apache.org > > > > > > > > > > > > -- > > Andrew Zhang > > China Software Development Lab, IBM > > >=20 >=20 >=20 > --=20 > Andrew Zhang > China Software Development Lab, IBM >=20 --------------------------------------------------------------------- Terms of use : http://incubator.apache.org/harmony/mailing.html To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org For additional commands, e-mail: harmony-dev-help@incubator.apache.org