AsyncResultCursorOnlyFactory implements ResultCursorFactory { public CompletionStage<AsyncResultCursor> asyncResult() { connection.write( runMessage, runHandler ); pullAllHandler.prePopulateRecords(); if ( waitForRunResponse ) { return runHandler.runFuture().thenApply( ignore -> new DisposableAsyncResultCursor( new AsyncResultCursorImpl( runHandler, pullAllHandler ) ) ); } else { return completedFuture( new DisposableAsyncResultCursor( new AsyncResultCursorImpl( runHandler, pullAllHandler ) ) ); } } AsyncResultCursorOnlyFactory(Connection connection, Message runMessage, RunResponseHandler runHandler,
                                        PullAllResponseHandler pullHandler, boolean waitForRunResponse ); CompletionStage<AsyncResultCursor> asyncResult(); CompletionStage<RxResultCursor> rxResult();  }
@Test void shouldFailAsyncResultWhenRunFailed() throws Throwable { Throwable error = new RuntimeException( "Hi there" ); ResultCursorFactory cursorFactory = newResultCursorFactory( failedFuture( error ), true ); CompletionStage<AsyncResultCursor> cursorFuture = cursorFactory.asyncResult(); CompletionException actual = assertThrows( CompletionException.class, () -> getNow( cursorFuture ) ); assertThat( actual.getCause(), equalTo( error ) ); }
@Test void shouldNotFailAsyncResultEvenWhenRunFailed() throws Throwable { Connection connection = mock( Connection.class ); Throwable error = new RuntimeException( "Hi there" ); ResultCursorFactory cursorFactory = newResultCursorFactory( connection, failedFuture( error ), false ); CompletionStage<AsyncResultCursor> cursorFuture = cursorFactory.asyncResult(); verifyRunCompleted( connection, cursorFuture ); }