@@ -154,7 +154,7 @@ void shouldFailForIncorrectQuery()
154
154
ResultCursor cursor = await ( session .runAsync ( "RETURN" ) );
155
155
156
156
Exception e = assertThrows ( Exception .class , () -> await ( cursor .nextAsync () ) );
157
- assertThat ( e , is ( syntaxError ( "Unexpected end of input" ) ) );
157
+ assertThat ( e , is ( syntaxError () ) );
158
158
}
159
159
160
160
@ Test
@@ -446,9 +446,9 @@ void shouldFailForEachWhenActionFails()
446
446
447
447
IOException e = assertThrows ( IOException .class , () ->
448
448
await ( cursor .forEachAsync ( record ->
449
- {
450
- throw new CompletionException ( error );
451
- } ) ) );
449
+ {
450
+ throw new CompletionException ( error );
451
+ } ) ) );
452
452
assertEquals ( error , e );
453
453
}
454
454
@@ -462,7 +462,7 @@ void shouldConvertToListWithEmptyCursor()
462
462
void shouldConvertToListWithNonEmptyCursor ()
463
463
{
464
464
testList ( "UNWIND range(1, 100, 10) AS x RETURN x" ,
465
- Arrays .asList ( 1L , 11L , 21L , 31L , 41L , 51L , 61L , 71L , 81L , 91L ) );
465
+ Arrays .asList ( 1L , 11L , 21L , 31L , 41L , 51L , 61L , 71L , 81L , 91L ) );
466
466
}
467
467
468
468
@ Test
@@ -489,9 +489,9 @@ void shouldFailWhenListTransformationFunctionFails()
489
489
490
490
RuntimeException e = assertThrows ( RuntimeException .class , () ->
491
491
await ( cursor .listAsync ( record ->
492
- {
493
- throw error ;
494
- } ) ) );
492
+ {
493
+ throw error ;
494
+ } ) ) );
495
495
assertEquals ( error , e );
496
496
}
497
497
@@ -604,8 +604,8 @@ public CompletionStage<Integer> execute( AsyncTransaction tx )
604
604
throw new SessionExpiredException ( "Oh!" );
605
605
}
606
606
return tx .runAsync ( "UNWIND range(1, 10) AS x RETURN count(x)" )
607
- .thenCompose ( ResultCursor ::singleAsync )
608
- .thenApply ( record -> record .get ( 0 ).asInt () );
607
+ .thenCompose ( ResultCursor ::singleAsync )
608
+ .thenApply ( record -> record .get ( 0 ).asInt () );
609
609
}
610
610
} );
611
611
@@ -629,8 +629,8 @@ public CompletionStage<Integer> execute( AsyncTransaction tx )
629
629
throw new ServiceUnavailableException ( "Oh!" );
630
630
}
631
631
return tx .runAsync ( "CREATE (n1:TestNode), (n2:TestNode) RETURN 2" )
632
- .thenCompose ( ResultCursor ::singleAsync )
633
- .thenApply ( record -> record .get ( 0 ).asInt () );
632
+ .thenCompose ( ResultCursor ::singleAsync )
633
+ .thenApply ( record -> record .get ( 0 ).asInt () );
634
634
}
635
635
} );
636
636
@@ -651,16 +651,16 @@ void shouldExecuteReadTransactionUntilSuccessWhenWorkFails()
651
651
public CompletionStage <Integer > execute ( AsyncTransaction tx )
652
652
{
653
653
return tx .runAsync ( "RETURN 42" )
654
- .thenCompose ( ResultCursor ::singleAsync )
655
- .thenApply ( record -> record .get ( 0 ).asInt () )
656
- .thenCompose ( result ->
657
- {
658
- if ( failures .getAndIncrement () < maxFailures )
659
- {
660
- return failedFuture ( new TransientException ( "A" , "B" ) );
661
- }
662
- return completedFuture ( result );
663
- } );
654
+ .thenCompose ( ResultCursor ::singleAsync )
655
+ .thenApply ( record -> record .get ( 0 ).asInt () )
656
+ .thenCompose ( result ->
657
+ {
658
+ if ( failures .getAndIncrement () < maxFailures )
659
+ {
660
+ return failedFuture ( new TransientException ( "A" , "B" ) );
661
+ }
662
+ return completedFuture ( result );
663
+ } );
664
664
}
665
665
} );
666
666
@@ -680,16 +680,16 @@ void shouldExecuteWriteTransactionUntilSuccessWhenWorkFails()
680
680
public CompletionStage <String > execute ( AsyncTransaction tx )
681
681
{
682
682
return tx .runAsync ( "CREATE (:MyNode) RETURN 'Hello'" )
683
- .thenCompose ( ResultCursor ::singleAsync )
684
- .thenApply ( record -> record .get ( 0 ).asString () )
685
- .thenCompose ( result ->
686
- {
687
- if ( failures .getAndIncrement () < maxFailures )
688
- {
689
- return failedFuture ( new ServiceUnavailableException ( "Hi" ) );
690
- }
691
- return completedFuture ( result );
692
- } );
683
+ .thenCompose ( ResultCursor ::singleAsync )
684
+ .thenApply ( record -> record .get ( 0 ).asString () )
685
+ .thenCompose ( result ->
686
+ {
687
+ if ( failures .getAndIncrement () < maxFailures )
688
+ {
689
+ return failedFuture ( new ServiceUnavailableException ( "Hi" ) );
690
+ }
691
+ return completedFuture ( result );
692
+ } );
693
693
}
694
694
} );
695
695
@@ -779,7 +779,7 @@ void shouldPropagateFailureInCloseFromPreviousRun()
779
779
void shouldCloseCleanlyAfterFailure ()
780
780
{
781
781
CompletionStage <ResultCursor > runWithOpenTx = session .beginTransactionAsync ()
782
- .thenCompose ( tx -> session .runAsync ( "RETURN 1" ) );
782
+ .thenCompose ( tx -> session .runAsync ( "RETURN 1" ) );
783
783
784
784
ClientException e = assertThrows ( ClientException .class , () -> await ( runWithOpenTx ) );
785
785
assertThat ( e .getMessage (), startsWith ( "Queries cannot be run directly on a session with an open transaction" ) );
@@ -791,9 +791,9 @@ void shouldCloseCleanlyAfterFailure()
791
791
void shouldPropagateFailureFromFirstIllegalQuery ()
792
792
{
793
793
CompletionStage <ResultCursor > allQueries = session .runAsync ( "CREATE (:Node1)" )
794
- .thenCompose ( ignore -> session .runAsync ( "CREATE (:Node2)" ) )
795
- .thenCompose ( ignore -> session .runAsync ( "RETURN invalid" ) )
796
- .thenCompose ( ignore -> session .runAsync ( "CREATE (:Node3)" ) );
794
+ .thenCompose ( ignore -> session .runAsync ( "CREATE (:Node2)" ) )
795
+ .thenCompose ( ignore -> session .runAsync ( "RETURN invalid" ) )
796
+ .thenCompose ( ignore -> session .runAsync ( "CREATE (:Node3)" ) );
797
797
798
798
ClientException e = assertThrows ( ClientException .class , () -> await ( allQueries ) );
799
799
assertThat ( e , is ( syntaxError ( "Variable `invalid` not defined" ) ) );
@@ -820,59 +820,59 @@ private Future<List<CompletionStage<Record>>> runNestedQueries( ResultCursor inp
820
820
return resultFuture ;
821
821
}
822
822
823
- private void runNestedQueries (ResultCursor inputCursor , List <CompletionStage <Record >> stages ,
824
- CompletableFuture <List <CompletionStage <Record >>> resultFuture )
823
+ private void runNestedQueries ( ResultCursor inputCursor , List <CompletionStage <Record >> stages ,
824
+ CompletableFuture <List <CompletionStage <Record >>> resultFuture )
825
825
{
826
826
final CompletionStage <Record > recordResponse = inputCursor .nextAsync ();
827
827
stages .add ( recordResponse );
828
828
829
829
recordResponse .whenComplete ( ( record , error ) ->
830
- {
831
- if ( error != null )
832
- {
833
- resultFuture .completeExceptionally ( error );
834
- }
835
- else if ( record != null )
836
- {
837
- runNestedQuery ( inputCursor , record , stages , resultFuture );
838
- }
839
- else
840
- {
841
- resultFuture .complete ( stages );
842
- }
843
- } );
844
- }
845
-
846
- private void runNestedQuery (ResultCursor inputCursor , Record record ,
847
- List <CompletionStage <Record >> stages , CompletableFuture <List <CompletionStage <Record >>> resultFuture )
830
+ {
831
+ if ( error != null )
832
+ {
833
+ resultFuture .completeExceptionally ( error );
834
+ }
835
+ else if ( record != null )
836
+ {
837
+ runNestedQuery ( inputCursor , record , stages , resultFuture );
838
+ }
839
+ else
840
+ {
841
+ resultFuture .complete ( stages );
842
+ }
843
+ } );
844
+ }
845
+
846
+ private void runNestedQuery ( ResultCursor inputCursor , Record record ,
847
+ List <CompletionStage <Record >> stages , CompletableFuture <List <CompletionStage <Record >>> resultFuture )
848
848
{
849
849
Node node = record .get ( 0 ).asNode ();
850
850
long id = node .get ( "id" ).asLong ();
851
851
long age = id * 10 ;
852
852
853
853
CompletionStage <ResultCursor > response =
854
854
session .runAsync ( "MATCH (p:Person {id: $id}) SET p.age = $age RETURN p" ,
855
- parameters ( "id" , id , "age" , age ) );
855
+ parameters ( "id" , id , "age" , age ) );
856
856
857
857
response .whenComplete ( ( cursor , error ) ->
858
- {
859
- if ( error != null )
860
- {
861
- resultFuture .completeExceptionally ( Futures .completionExceptionCause ( error ) );
862
- }
863
- else
864
- {
865
- stages .add ( cursor .nextAsync () );
866
- runNestedQueries ( inputCursor , stages , resultFuture );
867
- }
868
- } );
858
+ {
859
+ if ( error != null )
860
+ {
861
+ resultFuture .completeExceptionally ( Futures .completionExceptionCause ( error ) );
862
+ }
863
+ else
864
+ {
865
+ stages .add ( cursor .nextAsync () );
866
+ runNestedQueries ( inputCursor , stages , resultFuture );
867
+ }
868
+ } );
869
869
}
870
870
871
871
private long countNodesByLabel ( String label )
872
872
{
873
873
CompletionStage <Long > countStage = session .runAsync ( "MATCH (n:" + label + ") RETURN count(n)" )
874
- .thenCompose ( ResultCursor ::singleAsync )
875
- .thenApply ( record -> record .get ( 0 ).asLong () );
874
+ .thenCompose ( ResultCursor ::singleAsync )
875
+ .thenApply ( record -> record .get ( 0 ).asLong () );
876
876
877
877
return await ( countStage );
878
878
}
@@ -960,13 +960,13 @@ public CompletionStage<Record> execute( AsyncTransaction tx )
960
960
CompletableFuture <Record > resultFuture = new CompletableFuture <>();
961
961
962
962
tx .runAsync ( query ).whenComplete ( ( cursor , error ) ->
963
- processQueryResult ( cursor , Futures .completionExceptionCause ( error ), resultFuture ) );
963
+ processQueryResult ( cursor , Futures .completionExceptionCause ( error ), resultFuture ) );
964
964
965
965
return resultFuture ;
966
966
}
967
967
968
- private void processQueryResult (ResultCursor cursor , Throwable error ,
969
- CompletableFuture <Record > resultFuture )
968
+ private void processQueryResult ( ResultCursor cursor , Throwable error ,
969
+ CompletableFuture <Record > resultFuture )
970
970
{
971
971
if ( error != null )
972
972
{
@@ -975,7 +975,7 @@ private void processQueryResult(ResultCursor cursor, Throwable error,
975
975
}
976
976
977
977
cursor .nextAsync ().whenComplete ( ( record , fetchError ) ->
978
- processFetchResult ( record , Futures .completionExceptionCause ( fetchError ), resultFuture ) );
978
+ processFetchResult ( record , Futures .completionExceptionCause ( fetchError ), resultFuture ) );
979
979
}
980
980
981
981
private void processFetchResult ( Record record , Throwable error , CompletableFuture <Record > resultFuture )
0 commit comments