NetworkConnection implements Connection { @Override public void write( Message message, ResponseHandler handler ) { if ( verifyOpen( handler, null ) ) { writeMessageInEventLoop( message, handler, false ); } } NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Clock clock, MetricsListener metricsListener ); @Override boolean isOpen(); @Override void enableAutoRead(); @Override void disableAutoRead(); @Override void flush(); @Override void write( Message message, ResponseHandler handler ); @Override void write( Message message1, ResponseHandler handler1, Message message2, ResponseHandler handler2 ); @Override void writeAndFlush( Message message, ResponseHandler handler ); @Override void writeAndFlush( Message message1, ResponseHandler handler1, Message message2, ResponseHandler handler2 ); @Override CompletionStage<Void> reset(); @Override CompletionStage<Void> release(); @Override void terminateAndRelease( String reason ); @Override BoltServerAddress serverAddress(); @Override ServerVersion serverVersion(); @Override BoltProtocol protocol();  }
@Test void shouldWriteInEventLoopThread() throws Exception { testWriteInEventLoop( "WriteSingleMessage", connection -> connection.write( new RunMessage( "RETURN 1" ), NO_OP_HANDLER ) ); testWriteInEventLoop( "WriteMultipleMessages", connection -> connection.write( new RunMessage( "RETURN 1" ), NO_OP_HANDLER, PULL_ALL, NO_OP_HANDLER ) ); }
@Test void shouldWriteSingleMessage() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); connection.write( PULL_ALL, NO_OP_HANDLER ); assertEquals( 0, channel.outboundMessages().size() ); channel.flushOutbound(); assertEquals( 1, channel.outboundMessages().size() ); assertEquals( PULL_ALL, single( channel.outboundMessages() ) ); }
@Test void shouldWriteMultipleMessage() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); connection.write( PULL_ALL, NO_OP_HANDLER, RESET, NO_OP_HANDLER ); assertEquals( 0, channel.outboundMessages().size() ); channel.flushOutbound(); assertEquals( 2, channel.outboundMessages().size() ); assertEquals( PULL_ALL, channel.outboundMessages().poll() ); assertEquals( RESET, channel.outboundMessages().poll() ); }