Skip to content

Commit a19d468

Browse files
authored
Updating tests according to the server-side changes (#834)
1 parent f844d94 commit a19d468

File tree

7 files changed

+98
-93
lines changed

7 files changed

+98
-93
lines changed

driver/src/test/java/org/neo4j/driver/integration/async/AsyncSessionIT.java

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void shouldFailForIncorrectQuery()
154154
ResultCursor cursor = await( session.runAsync( "RETURN" ) );
155155

156156
Exception e = assertThrows( Exception.class, () -> await( cursor.nextAsync() ) );
157-
assertThat( e, is( syntaxError( "Unexpected end of input" ) ) );
157+
assertThat( e, is( syntaxError() ) );
158158
}
159159

160160
@Test
@@ -446,9 +446,9 @@ void shouldFailForEachWhenActionFails()
446446

447447
IOException e = assertThrows( IOException.class, () ->
448448
await( cursor.forEachAsync( record ->
449-
{
450-
throw new CompletionException( error );
451-
} ) ) );
449+
{
450+
throw new CompletionException( error );
451+
} ) ) );
452452
assertEquals( error, e );
453453
}
454454

@@ -462,7 +462,7 @@ void shouldConvertToListWithEmptyCursor()
462462
void shouldConvertToListWithNonEmptyCursor()
463463
{
464464
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 ) );
466466
}
467467

468468
@Test
@@ -489,9 +489,9 @@ void shouldFailWhenListTransformationFunctionFails()
489489

490490
RuntimeException e = assertThrows( RuntimeException.class, () ->
491491
await( cursor.listAsync( record ->
492-
{
493-
throw error;
494-
} ) ) );
492+
{
493+
throw error;
494+
} ) ) );
495495
assertEquals( error, e );
496496
}
497497

@@ -604,8 +604,8 @@ public CompletionStage<Integer> execute( AsyncTransaction tx )
604604
throw new SessionExpiredException( "Oh!" );
605605
}
606606
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() );
609609
}
610610
} );
611611

@@ -629,8 +629,8 @@ public CompletionStage<Integer> execute( AsyncTransaction tx )
629629
throw new ServiceUnavailableException( "Oh!" );
630630
}
631631
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() );
634634
}
635635
} );
636636

@@ -651,16 +651,16 @@ void shouldExecuteReadTransactionUntilSuccessWhenWorkFails()
651651
public CompletionStage<Integer> execute( AsyncTransaction tx )
652652
{
653653
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+
} );
664664
}
665665
} );
666666

@@ -680,16 +680,16 @@ void shouldExecuteWriteTransactionUntilSuccessWhenWorkFails()
680680
public CompletionStage<String> execute( AsyncTransaction tx )
681681
{
682682
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+
} );
693693
}
694694
} );
695695

@@ -779,7 +779,7 @@ void shouldPropagateFailureInCloseFromPreviousRun()
779779
void shouldCloseCleanlyAfterFailure()
780780
{
781781
CompletionStage<ResultCursor> runWithOpenTx = session.beginTransactionAsync()
782-
.thenCompose( tx -> session.runAsync( "RETURN 1" ) );
782+
.thenCompose( tx -> session.runAsync( "RETURN 1" ) );
783783

784784
ClientException e = assertThrows( ClientException.class, () -> await( runWithOpenTx ) );
785785
assertThat( e.getMessage(), startsWith( "Queries cannot be run directly on a session with an open transaction" ) );
@@ -791,9 +791,9 @@ void shouldCloseCleanlyAfterFailure()
791791
void shouldPropagateFailureFromFirstIllegalQuery()
792792
{
793793
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)" ) );
797797

798798
ClientException e = assertThrows( ClientException.class, () -> await( allQueries ) );
799799
assertThat( e, is( syntaxError( "Variable `invalid` not defined" ) ) );
@@ -820,59 +820,59 @@ private Future<List<CompletionStage<Record>>> runNestedQueries( ResultCursor inp
820820
return resultFuture;
821821
}
822822

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 )
825825
{
826826
final CompletionStage<Record> recordResponse = inputCursor.nextAsync();
827827
stages.add( recordResponse );
828828

829829
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 )
848848
{
849849
Node node = record.get( 0 ).asNode();
850850
long id = node.get( "id" ).asLong();
851851
long age = id * 10;
852852

853853
CompletionStage<ResultCursor> response =
854854
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 ) );
856856

857857
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+
} );
869869
}
870870

871871
private long countNodesByLabel( String label )
872872
{
873873
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() );
876876

877877
return await( countStage );
878878
}
@@ -960,13 +960,13 @@ public CompletionStage<Record> execute( AsyncTransaction tx )
960960
CompletableFuture<Record> resultFuture = new CompletableFuture<>();
961961

962962
tx.runAsync( query ).whenComplete( ( cursor, error ) ->
963-
processQueryResult( cursor, Futures.completionExceptionCause( error ), resultFuture ) );
963+
processQueryResult( cursor, Futures.completionExceptionCause( error ), resultFuture ) );
964964

965965
return resultFuture;
966966
}
967967

968-
private void processQueryResult(ResultCursor cursor, Throwable error,
969-
CompletableFuture<Record> resultFuture )
968+
private void processQueryResult( ResultCursor cursor, Throwable error,
969+
CompletableFuture<Record> resultFuture )
970970
{
971971
if ( error != null )
972972
{
@@ -975,7 +975,7 @@ private void processQueryResult(ResultCursor cursor, Throwable error,
975975
}
976976

977977
cursor.nextAsync().whenComplete( ( record, fetchError ) ->
978-
processFetchResult( record, Futures.completionExceptionCause( fetchError ), resultFuture ) );
978+
processFetchResult( record, Futures.completionExceptionCause( fetchError ), resultFuture ) );
979979
}
980980

981981
private void processFetchResult( Record record, Throwable error, CompletableFuture<Record> resultFuture )

driver/src/test/java/org/neo4j/driver/integration/async/AsyncTransactionIT.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.concurrent.CompletionStage;
3434
import java.util.concurrent.atomic.AtomicInteger;
3535

36+
import org.neo4j.driver.Bookmark;
3637
import org.neo4j.driver.Query;
3738
import org.neo4j.driver.Record;
3839
import org.neo4j.driver.Value;
@@ -41,11 +42,10 @@
4142
import org.neo4j.driver.async.ResultCursor;
4243
import org.neo4j.driver.exceptions.ClientException;
4344
import org.neo4j.driver.exceptions.NoSuchRecordException;
44-
import org.neo4j.driver.exceptions.ServiceUnavailableException;
45-
import org.neo4j.driver.Bookmark;
4645
import org.neo4j.driver.exceptions.ResultConsumedException;
47-
import org.neo4j.driver.summary.ResultSummary;
46+
import org.neo4j.driver.exceptions.ServiceUnavailableException;
4847
import org.neo4j.driver.summary.QueryType;
48+
import org.neo4j.driver.summary.ResultSummary;
4949
import org.neo4j.driver.types.Node;
5050
import org.neo4j.driver.util.DatabaseExtension;
5151
import org.neo4j.driver.util.ParallelizableIT;
@@ -63,8 +63,8 @@
6363
import static org.junit.jupiter.api.Assertions.assertNull;
6464
import static org.junit.jupiter.api.Assertions.assertThrows;
6565
import static org.junit.jupiter.api.Assertions.assertTrue;
66-
import static org.neo4j.driver.Values.parameters;
6766
import static org.neo4j.driver.SessionConfig.builder;
67+
import static org.neo4j.driver.Values.parameters;
6868
import static org.neo4j.driver.internal.InternalBookmark.parse;
6969
import static org.neo4j.driver.internal.util.Iterables.single;
7070
import static org.neo4j.driver.internal.util.Matchers.containsResultAvailableAfterAndResultConsumedAfter;
@@ -222,7 +222,7 @@ void shouldFailToCommitAfterSingleWrongQuery()
222222
ResultCursor cursor = await( tx.runAsync( "RETURN" ) );
223223

224224
Exception e = assertThrows( Exception.class, () -> await( cursor.consumeAsync() ) );
225-
assertThat( e, is( syntaxError( "Unexpected end of input" ) ) );
225+
assertThat( e, is( syntaxError() ) );
226226

227227
assertThrows( ClientException.class, () -> await( tx.commitAsync() ) );
228228
}
@@ -235,7 +235,7 @@ void shouldAllowRollbackAfterSingleWrongQuery()
235235
ResultCursor cursor = await( tx.runAsync( "RETURN" ) );
236236

237237
Exception e = assertThrows( Exception.class, () -> await( cursor.nextAsync() ) );
238-
assertThat( e, is( syntaxError( "Unexpected end of input" ) ) );
238+
assertThat( e, is( syntaxError() ) );
239239
assertThat( await( tx.rollbackAsync() ), is( nullValue() ) );
240240
}
241241

@@ -257,7 +257,7 @@ void shouldFailToCommitAfterCoupleCorrectAndSingleWrongQuery()
257257
ResultCursor cursor3 = await( tx.runAsync( "RETURN" ) );
258258

259259
Exception e = assertThrows( Exception.class, () -> await( cursor3.consumeAsync() ) );
260-
assertThat( e, is( syntaxError( "Unexpected end of input" ) ) );
260+
assertThat( e, is( syntaxError() ) );
261261

262262
assertThrows( ClientException.class, () -> await( tx.commitAsync() ) );
263263
}
@@ -280,7 +280,7 @@ void shouldAllowRollbackAfterCoupleCorrectAndSingleWrongQuery()
280280
ResultCursor cursor3 = await( tx.runAsync( "RETURN" ) );
281281

282282
Exception e = assertThrows( Exception.class, () -> await( cursor3.consumeAsync() ) );
283-
assertThat( e, is( syntaxError( "Unexpected end of input" ) ) );
283+
assertThat( e, is( syntaxError() ) );
284284
assertThat( await( tx.rollbackAsync() ), is( nullValue() ) );
285285
}
286286

@@ -292,7 +292,7 @@ void shouldNotAllowNewQueriesAfterAnIncorrectQuery()
292292
ResultCursor cursor = await( tx.runAsync( "RETURN" ) );
293293

294294
Exception e1 = assertThrows( Exception.class, () -> await( cursor.nextAsync() ) );
295-
assertThat( e1, is( syntaxError( "Unexpected end of input" ) ) );
295+
assertThat( e1, is( syntaxError() ) );
296296

297297
ClientException e2 = assertThrows( ClientException.class, () -> tx.runAsync( "CREATE ()" ) );
298298
assertThat( e2.getMessage(), startsWith( "Cannot run more queries in this transaction" ) );

driver/src/test/java/org/neo4j/driver/integration/reactive/RxTransactionIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
import java.util.stream.Stream;
3939

4040
import org.neo4j.driver.Bookmark;
41-
import org.neo4j.driver.Record;
4241
import org.neo4j.driver.Query;
42+
import org.neo4j.driver.Record;
4343
import org.neo4j.driver.Value;
4444
import org.neo4j.driver.exceptions.ClientException;
4545
import org.neo4j.driver.exceptions.ServiceUnavailableException;
4646
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
47-
import org.neo4j.driver.reactive.RxSession;
4847
import org.neo4j.driver.reactive.RxResult;
48+
import org.neo4j.driver.reactive.RxSession;
4949
import org.neo4j.driver.reactive.RxTransaction;
50-
import org.neo4j.driver.summary.ResultSummary;
5150
import org.neo4j.driver.summary.QueryType;
51+
import org.neo4j.driver.summary.ResultSummary;
5252
import org.neo4j.driver.types.Node;
5353
import org.neo4j.driver.util.DatabaseExtension;
5454
import org.neo4j.driver.util.ParallelizableIT;
@@ -899,7 +899,7 @@ private static void assertFailToRunWrongQuery(RxTransaction tx )
899899
{
900900
RxResult result = tx.run( "RETURN" );
901901
Exception e = assertThrows( Exception.class, () -> await( result.records() ) );
902-
assertThat( e, is( syntaxError( "Unexpected end of input" ) ) );
902+
assertThat( e, is( syntaxError() ) );
903903
}
904904

905905
private void assertCanRunReturnOne( RxTransaction tx )

0 commit comments

Comments
 (0)