3939import org .neo4j .driver .v1 .Config ;
4040import org .neo4j .driver .v1 .Driver ;
4141import org .neo4j .driver .v1 .GraphDatabase ;
42+ import org .neo4j .driver .v1 .Logger ;
43+ import org .neo4j .driver .v1 .Logging ;
4244import org .neo4j .driver .v1 .Record ;
4345import org .neo4j .driver .v1 .Session ;
4446import org .neo4j .driver .v1 .StatementResult ;
6163import static org .junit .jupiter .api .Assertions .assertThrows ;
6264import static org .junit .jupiter .api .Assertions .assertTrue ;
6365import static org .mockito .ArgumentMatchers .any ;
66+ import static org .mockito .ArgumentMatchers .startsWith ;
6467import static org .mockito .Mockito .mock ;
68+ import static org .mockito .Mockito .times ;
6569import static org .mockito .Mockito .verify ;
6670import static org .mockito .Mockito .when ;
6771import static org .neo4j .driver .v1 .Logging .none ;
@@ -738,7 +742,9 @@ void shouldRetryWriteTransactionUntilSuccessWithWhenLeaderIsRemoved() throws Exc
738742 StubServer brokenWriter = StubServer .start ( "dead_write_server.script" , 9004 );
739743 StubServer writer = StubServer .start ( "write_server.script" , 9008 );
740744
741- try ( Driver driver = newDriverWithSleeplessClock ( "bolt+routing://127.0.0.1:9001" );
745+ Logger logger = mock ( Logger .class );
746+ Config config = Config .builder ().withoutEncryption ().withLogging ( mockedLogging ( logger ) ).build ();
747+ try ( Driver driver = newDriverWithSleeplessClock ( "bolt+routing://127.0.0.1:9001" , config );
742748 Session session = driver .session () )
743749 {
744750 AtomicInteger invocations = new AtomicInteger ();
@@ -753,6 +759,8 @@ void shouldRetryWriteTransactionUntilSuccessWithWhenLeaderIsRemoved() throws Exc
753759 assertEquals ( 0 , brokenWriter .exitStatus () );
754760 assertEquals ( 0 , writer .exitStatus () );
755761 }
762+ verify ( logger , times ( 3 ) ).warn ( startsWith ( "Transaction failed and will be retried in" ), any ( SessionExpiredException .class ) );
763+ verify ( logger ).warn ( startsWith ( "Failed to obtain a connection towards address 127.0.0.1:9004" ), any ( SessionExpiredException .class ) );
756764 }
757765
758766 @ Test
@@ -1188,19 +1196,24 @@ void useSessionAfterDriverIsClosed() throws Exception
11881196 }
11891197 }
11901198
1191- private static Driver newDriverWithSleeplessClock ( String uriString )
1199+ private static Driver newDriverWithSleeplessClock ( String uriString , Config config )
11921200 {
11931201 DriverFactory driverFactory = new DriverFactoryWithClock ( new SleeplessClock () );
1194- return newDriver ( uriString , driverFactory );
1202+ return newDriver ( uriString , driverFactory , config );
1203+ }
1204+
1205+ private static Driver newDriverWithSleeplessClock ( String uriString )
1206+ {
1207+ return newDriverWithSleeplessClock ( uriString , config );
11951208 }
11961209
11971210 private static Driver newDriverWithFixedRetries ( String uriString , int retries )
11981211 {
11991212 DriverFactory driverFactory = new DriverFactoryWithFixedRetryLogic ( retries );
1200- return newDriver ( uriString , driverFactory );
1213+ return newDriver ( uriString , driverFactory , config );
12011214 }
12021215
1203- private static Driver newDriver ( String uriString , DriverFactory driverFactory )
1216+ private static Driver newDriver ( String uriString , DriverFactory driverFactory , Config config )
12041217 {
12051218 URI uri = URI .create ( uriString );
12061219 RoutingSettings routingConf = new RoutingSettings ( 1 , 1 , null );
@@ -1230,4 +1243,11 @@ private static List<String> readStrings( final String query, Session session )
12301243 return names ;
12311244 } );
12321245 }
1246+
1247+ private static Logging mockedLogging ( Logger logger )
1248+ {
1249+ Logging logging = mock ( Logging .class );
1250+ when ( logging .getLog ( any () ) ).thenReturn ( logger );
1251+ return logging ;
1252+ }
12331253}
0 commit comments