NetworkConnection implements Connection { @Override public void terminateAndRelease( String reason ) { if ( status.compareAndSet( Status.OPEN, Status.TERMINATED ) ) { setTerminationReason( channel, reason ); channel.close(); channelPool.release( channel ); releaseFuture.complete( null ); metricsListener.afterConnectionReleased( poolId( this.channel ), this.inUseEvent ); } } 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 shouldSetTerminationReasonOnChannelWhenTerminated() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); String reason = "Something really bad has happened"; connection.terminateAndRelease( reason ); assertEquals( reason, terminationReason( channel ) ); }
@Test void shouldCloseChannelWhenTerminated() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); assertTrue( channel.isActive() ); connection.terminateAndRelease( "test" ); assertFalse( channel.isActive() ); }