public void testParseClientHandshake() throws Exception {
  for (int splitPos=1; splitPos < 5; splitPos++) {
    log.info("Checking split position: " + splitPos);
    ByteBuffer tmp=clientHandshakePacket();
    ByteBuffer[] split=split(tmp,splitPos);
    GridNioSession ses=new MockNioSession();
    ses.addMeta(MARSHALLER.ordinal(),new GridClientOptimizedMarshaller());
    GridTcpRestParser parser=new GridTcpRestParser(false);
    Collection<GridClientMessage> lst=new ArrayList<>(1);
    for (    ByteBuffer buf : split) {
      GridClientMessage r;
      while (buf.hasRemaining() && (r=parser.decode(ses,buf)) != null)       lst.add(r);
      assertTrue("Parser has left unparsed bytes.",buf.remaining() == 0);
    }
    assertEquals(1,lst.size());
    GridClientHandshakeRequest req=(GridClientHandshakeRequest)F.first(lst);
    assertNotNull(req);
    assertEquals(U.bytesToShort(new byte[]{5,0},0),req.version());
  }
}

public void testParseClientHandshake ( ) throws Exception { for ( int splitPos = 1 ; splitPos < 5 ; splitPos ++ ) { log . info ( "Checking split position: " + splitPos ) ; ByteBuffer tmp = clientHandshakePacket ( ) ; ByteBuffer [ ] split = split ( tmp , splitPos ) ; GridNioSession ses = new MockNioSession ( ) ; ses . addMeta ( MARSHALLER . ordinal ( ) , new GridClientOptimizedMarshaller ( ) ) ; GridTcpRestParser parser = new GridTcpRestParser ( false ) ; Collection < GridClientMessage > lst = new ArrayList < > ( 1 ) ; for ( ByteBuffer buf : split ) { GridClientMessage r ; while ( buf . hasRemaining ( ) && ( r = parser . decode ( ses , buf ) ) != null ) lst . add ( r ) ; assertTrue ( "Parser has left unparsed bytes." , buf . remaining ( ) == 0 ) ; } assertEquals ( 1 , lst . size ( ) ) ; GridClientHandshakeRequest req = ( GridClientHandshakeRequest ) F . first ( lst ) ; assertNotNull ( req ) ; assertEquals ( U . bytesToShort ( new byte [ ] { 5 , 0 } , 0 ) , req . version ( ) ) ; } }
tests correct parsing of client handshake packets .
