InitResponseHandler implements ResponseHandler { @Override public void onFailure( Throwable error ) { channel.close().addListener( future -> connectionInitializedPromise.setFailure( error ) ); } InitResponseHandler( ChannelPromise connectionInitializedPromise ); @Override void onSuccess( Map<String,Value> metadata ); @Override void onFailure( Throwable error ); @Override void onRecord( Value[] fields );  }
@Test void shouldCloseChannelOnFailure() throws Exception { ChannelPromise channelPromise = channel.newPromise(); InitResponseHandler handler = new InitResponseHandler( channelPromise ); RuntimeException error = new RuntimeException( "Hi!" ); handler.onFailure( error ); ChannelFuture channelCloseFuture = channel.closeFuture(); channelCloseFuture.await( 5, TimeUnit.SECONDS ); assertTrue( channelCloseFuture.isSuccess() ); assertTrue( channelPromise.isDone() ); assertEquals( error, channelPromise.cause() ); }