PullMessageEncoder implements MessageEncoder { @Override public void encode( Message message, ValuePacker packer ) throws IOException { checkArgument( message, PullMessage.class ); packer.packStructHeader( 1, PullMessage.SIGNATURE ); packer.pack( ((PullMessage) message).metadata() ); }  @Override void encode( Message message, ValuePacker packer );  }
@Test void shouldSendPullAllCorrectly() throws Throwable { encoder.encode( PullMessage.PULL_ALL, packer ); Map<String,Value> meta = new HashMap<>(); meta.put( "n", value( -1 ) ); InOrder order = inOrder( packer ); order.verify( packer ).packStructHeader( 1, PullMessage.SIGNATURE ); order.verify( packer ).pack( meta ); }
@Test void shouldEncodePullMessage() throws Exception { encoder.encode( new PullMessage( 100, 200 ), packer ); Map<String,Value> meta = new HashMap<>(); meta.put( "n", value( 100 ) ); meta.put( "qid", value( 200 ) ); InOrder order = inOrder( packer ); order.verify( packer ).packStructHeader( 1, PullMessage.SIGNATURE ); order.verify( packer ).pack( meta ); }
@Test void shouldAvoidQueryId() throws Exception { encoder.encode( new PullMessage( 100, -1 ), packer ); Map<String,Value> meta = new HashMap<>(); meta.put( "n", value( 100 ) ); InOrder order = inOrder( packer ); order.verify( packer ).packStructHeader( 1, PullMessage.SIGNATURE ); order.verify( packer ).pack( meta ); }
@Test void shouldFailToEncodeWrongMessage() { assertThrows( IllegalArgumentException.class, () -> encoder.encode( PullAllMessage.PULL_ALL, packer ) ); }