NetworkConnection implements Connection { @Override public CompletionStage<Void> release() { if ( status.compareAndSet( Status.OPEN, Status.RELEASED ) ) { ChannelReleasingResetResponseHandler handler = new ChannelReleasingResetResponseHandler( channel, channelPool, messageDispatcher, clock, releaseFuture ); writeResetMessageIfNeeded( handler, false ); metricsListener.afterConnectionReleased( poolId( this.channel ), this.inUseEvent ); } return releaseFuture; } 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 shouldSendResetOnRelease() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); connection.release(); channel.runPendingTasks(); assertEquals( 1, channel.outboundMessages().size() ); assertEquals( RESET, channel.readOutbound() ); }
@Test void shouldReturnSameCompletionStageFromRelease() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); CompletionStage<Void> releaseStage1 = connection.release(); CompletionStage<Void> releaseStage2 = connection.release(); CompletionStage<Void> releaseStage3 = connection.release(); channel.runPendingTasks(); assertEquals( 1, channel.outboundMessages().size() ); assertEquals( RESET, channel.outboundMessages().poll() ); assertEquals( releaseStage1, releaseStage2 ); assertEquals( releaseStage2, releaseStage3 ); }