harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <g...@pobox.com>
Subject Re: [classlib][LUNI | NIO] How to write stable tests for blocking write/read operations of Socket and SocketChannel
Date Sat, 24 Jun 2006 15:10:24 GMT


Andrew Zhang wrote:
> Hi Geir,
> 
> Please see my comments below.
> 
> 
> On 6/24/06, Magnusson, Geir <geir.magnusson@intel.com> 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 <zhanghuangzhu@gmail.com> 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 <kleymenov@gmail.com> 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


Mime
View raw message