private void testConnector( IoConnector connector, SocketAddress localAddress ) throws Exception
{
EchoConnectorHandler handler = new EchoConnectorHandler();
ByteBuffer readBuf = handler.readBuf;
IoSession session = connector.connect(
new InetSocketAddress( InetAddress.getLocalHost(), port ),
localAddress,
handler );
for( int i = 0; i < 10; i ++ )
{
ByteBuffer buf = ByteBuffer.allocate( 16 );
buf.limit( 16 );
fillWriteBuffer( buf, i );
buf.flip();
Object marker;
if( ( i & 1 ) == 0 )
{
marker = new Integer( i );
}
else
{
marker = null;
}
session.write( buf, marker );
// This will align message arrival order in UDP
for( int j = 0; j < 30; j ++ )
{
if( readBuf.position() == ( i + 1 ) * 16 )
{
break;
}
Thread.sleep( 10 );
}
}
for( int i = 0; i < 30; i++ ) {
if( readBuf.position() == 160 )
{
break;
}
else
{
Thread.sleep( 100 );
}
}
session.close( true );
Assert.assertEquals( 160, readBuf.position() );
readBuf.flip();
ByteBuffer expectedBuf = ByteBuffer.allocate( 160 );