//////////////////////////////////////////////////////////////////////////////////
// Data channel
ByteChannel channel = client_instance.createChannel( server_vmid, null );
// CLIENT - channel opened
pair = getNextMessage( client_listener, 2000 );
assertNotNull( pair );
assertEquals( CallType.VIRTUAL_CHANNEL_OPENED, pair.getOne() );
assertEquals( client_instance.getLocalVMID(), pair.getTwo().get( 0 ) );
assertEquals( server_instance.getLocalVMID(), pair.getTwo().get( 1 ) );
short client_channel_id = ( ( Short ) pair.getTwo().get( 2 ) ).shortValue();
// SERVER - channel opened
pair = getNextMessage( server_listener, 2000 );
assertNotNull( pair );
assertEquals( CallType.VIRTUAL_CHANNEL_OPENED, pair.getOne() );
assertEquals( server_instance.getLocalVMID(), pair.getTwo().get( 0 ) );
assertEquals( client_instance.getLocalVMID(), pair.getTwo().get( 1 ) );
assertEquals( Short.valueOf( client_channel_id ), pair.getTwo().get( 2 ) );
ByteBuffer buffer = ByteBuffer.allocate( 1024 );
byte[] to_write = new byte[ buffer.remaining() ];
new Random().nextBytes( to_write );
buffer.put( to_write );
buffer.flip();
channel.write( buffer );
// CLIENT - channel data sent
pair = getNextMessage( client_listener, 2000 );
assertNotNull( pair );
assertEquals( CallType.VIRTUAL_CHANNEL_DATA_SENT, pair.getOne() );
assertEquals( client_instance.getLocalVMID(), pair.getTwo().get( 0 ) );
assertEquals( server_instance.getLocalVMID(), pair.getTwo().get( 1 ) );
assertEquals( Short.valueOf( client_channel_id ), pair.getTwo().get( 2 ) );
assertEquals( Integer.valueOf( to_write.length ), pair.getTwo().get( 3 ) );
// SERVER - channel data received
pair = getNextMessage( server_listener, 2000 );
assertNotNull( pair );
assertEquals( CallType.VIRTUAL_CHANNEL_DATA_RECEIVED, pair.getOne() );
assertEquals( server_instance.getLocalVMID(), pair.getTwo().get( 0 ) );
assertEquals( client_instance.getLocalVMID(), pair.getTwo().get( 1 ) );
assertEquals( Short.valueOf( client_channel_id ), pair.getTwo().get( 2 ) );
assertEquals( Integer.valueOf( to_write.length ), pair.getTwo().get( 3 ) );
channel.close();
// CLIENT - channel close
pair = getNextMessage( client_listener, 2000 );
assertNotNull( pair );
assertEquals( CallType.VIRTUAL_CHANNEL_CLOSED, pair.getOne() );