NetworkConnection implements Connection { @Override public CompletionStage<Void> reset() { CompletableFuture<Void> result = new CompletableFuture<>(); ResetResponseHandler handler = new ResetResponseHandler( messageDispatcher, result ); writeResetMessageIfNeeded( handler, true ); return result; } 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 shouldSendResetMessageWhenReset() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); connection.reset(); channel.runPendingTasks(); assertEquals( 1, channel.outboundMessages().size() ); assertEquals( RESET, channel.readOutbound() ); }
@Test void shouldCompleteResetFutureWhenSuccessResponseArrives() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); CompletableFuture<Void> resetFuture = connection.reset().toCompletableFuture(); channel.runPendingTasks(); assertFalse( resetFuture.isDone() ); messageDispatcher( channel ).handleSuccessMessage( emptyMap() ); assertTrue( resetFuture.isDone() ); assertFalse( resetFuture.isCompletedExceptionally() ); }
@Test void shouldCompleteResetFutureWhenFailureResponseArrives() { EmbeddedChannel channel = newChannel(); NetworkConnection connection = newConnection( channel ); CompletableFuture<Void> resetFuture = connection.reset().toCompletableFuture(); channel.runPendingTasks(); assertFalse( resetFuture.isDone() ); messageDispatcher( channel ).handleFailureMessage( "Neo.TransientError.Transaction.Terminated", "Message" ); assertTrue( resetFuture.isDone() ); assertFalse( resetFuture.isCompletedExceptionally() ); }