Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 18243 invoked from network); 24 Jun 2006 15:10:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Jun 2006 15:10:53 -0000 Received: (qmail 43397 invoked by uid 500); 24 Jun 2006 15:10:50 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 43335 invoked by uid 500); 24 Jun 2006 15:10:49 -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 43324 invoked by uid 99); 24 Jun 2006 15:10:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 Jun 2006 08:10:49 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: 64.74.244.71 is neither permitted nor denied by domain of geir@pobox.com) Received: from [64.74.244.71] (HELO chi.mobile-health-diary.com) (64.74.244.71) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 24 Jun 2006 08:10:48 -0700 Received: (qmail 27063 invoked from network); 24 Jun 2006 15:10:25 -0000 Received: from ool-43560edb.dyn.optonline.net (HELO ?192.168.1.106?) (geir@67.86.14.219) by b014.internal.mobile-health-diary.com with SMTP; 24 Jun 2006 15:10:25 -0000 Message-ID: <449D55E0.1070705@pobox.com> Date: Sat, 24 Jun 2006 11:10:24 -0400 From: Geir Magnusson Jr Reply-To: geir@pobox.com User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: harmony-dev@incubator.apache.org Subject: Re: [classlib][LUNI | NIO] How to write stable tests for blocking write/read operations of Socket and SocketChannel References: <8AEB79DC01BE994D8DE3FD02FA5B475B03E321F3@orsmsx409> <4d0b24970606240736w55b3ca3fs7a13e6e2afc6d35a@mail.gmail.com> In-Reply-To: <4d0b24970606240736w55b3ca3fs7a13e6e2afc6d35a@mail.gmail.com> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Andrew Zhang wrote: > Hi Geir, > > Please see my comments below. > > > On 6/24/06, Magnusson, Geir wrote: >> >> How about using mocks of some sort to control the sequences of activity? > > > But I couldn't find any API to guarantee to send all data without buffering > data (by OS). > At least, I tried all the way on RI , but still failed. > flush() only flushes the data to TCP stack. No API is provided to flush > TCP > stack data. > Any suggestions are highly appreciated! Thanks! You can't force a flush on the TCP stack, as it's pushing across the network, and has to handle retries, fragmentation, etc. What I meant was mock to keep the OS out of it. However, I don't understand the exact problem, so will re-read the thread... geir > > > -- >> Geir Magnusson Jr >> SSG/MPD >> geir.magnusson@intel.com >> +1 203 665 6437 >> >> > -----Original Message----- >> > From: Andrew Zhang [mailto:zhanghuangzhu@gmail.com] >> > Sent: Friday, June 23, 2006 8:11 PM >> > To: harmony-dev@incubator.apache.org >> > Subject: [classlib][LUNI | NIO] How to write stable tests for >> > blocking write/read operations of Socket and SocketChannel >> > >> > Hi everybody, >> > >> > I'm struggling to write a stable test for blocking write/read >> > operation of >> > Socket and SocketChannel. >> > >> > Could you anybody help me out? >> > >> > >> > On 6/23/06, Andrew Zhang wrote: >> > > >> > > Hi Alexander, >> > > >> > > Thanks for your kind reminder. >> > > >> > > Certainly I'll use sth. like >> > 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 >> > 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 >> > theoretically stable >> > > test? >> > > >> > > Thanks a lot in advance! >> > > >> > > public void test_SocketChannel_BlockWriteRead() throws >> > IOException { >> > > final int CAPACITY_NORMAL = 200; >> > > InetSocketAddress localAddr1 = new >> > InetSocketAddress("127.0.0.1 >> > > ",1234); >> > > >> > > ServerSocket server = new ServerSocket(1234); >> > > >> > > SocketChannel channel = SocketChannel.open(); >> > > channel.connect(localAddr1); >> > > Socket client = server.accept (); >> > > client.setTcpNoDelay(true); >> > > client.setSendBufferSize(1); >> > > >> > > OutputStream out = client.getOutputStream(); >> > > >> > > byte[] sendBuf = new byte[CAPACITY_NORMAL * 2]; >> > > for (int i = 0; i < CAPACITY_NORMAL * 2; i++) { >> > > sendBuf[i] = (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 = ByteBuffer.allocate(CAPACITY_NORMAL); >> > > ByteBuffer buf2 = ByteBuffer.allocate(CAPACITY_NORMAL); >> > > ByteBuffer[] buf ={buf1, buf2}; >> > > >> > > // should receive CAPACITY_NORMAL * 2 bytes data >> > > long count = 0; >> > > do{ >> > > long ret = channel.read(buf); >> > > if(ret == -1){ >> > > break; >> > > } >> > > count += 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 = new ServerSocket(0); >> > > > InetSocketAddress localAddr1 = new >> > InetSocketAddress("127.0.0.1", >> > > > server.getLocalPort()); >> > > > >> > > > Such a way prevents the test from "Address in use" exception. >> > > > >> > > > Thank You, >> > > > Alexander >> > > > >> > > > >> > --------------------------------------------------------------------- >> > > > 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 >> > > > >> > > > >> > > >> > > >> > > -- >> > > Andrew Zhang >> > > China Software Development Lab, IBM >> > > >> > >> > >> > >> > -- >> > Andrew Zhang >> > China Software Development Lab, IBM >> > >> >> --------------------------------------------------------------------- >> 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 >> >> > > --------------------------------------------------------------------- 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