1818 */
1919package org .neo4j .driver ;
2020
21- import static java .util .Arrays .asList ;
2221import static java .util .concurrent .TimeUnit .MILLISECONDS ;
2322import static org .hamcrest .Matchers .containsString ;
2423import static org .hamcrest .junit .MatcherAssert .assertThat ;
2524import static org .junit .jupiter .api .Assertions .assertEquals ;
2625import static org .junit .jupiter .api .Assertions .assertThrows ;
27- import static org .mockito .ArgumentMatchers .any ;
28- import static org .mockito .ArgumentMatchers .eq ;
29- import static org .mockito .Mockito .doThrow ;
30- import static org .mockito .Mockito .mock ;
31- import static org .mockito .Mockito .verify ;
32- import static org .mockito .Mockito .when ;
3326import static org .neo4j .driver .Logging .none ;
3427import static org .neo4j .driver .internal .logging .DevNullLogging .DEV_NULL_LOGGING ;
3528
3629import io .netty .util .concurrent .EventExecutorGroup ;
3730import java .io .IOException ;
3831import java .net .ServerSocket ;
3932import java .net .URI ;
40- import java .util .Arrays ;
4133import java .util .Iterator ;
4234import java .util .List ;
4335import org .junit .jupiter .api .Test ;
@@ -62,49 +54,6 @@ void throwsWhenBoltSchemeUsedWithRoutingParams() {
6254 IllegalArgumentException .class , () -> GraphDatabase .driver ("bolt://localhost:7687/?policy=my_policy" ));
6355 }
6456
65- @ Test
66- void shouldLogWhenUnableToCreateRoutingDriver () {
67- Logging logging = mock (Logging .class );
68- Logger logger = mock (Logger .class );
69- when (logging .getLog (any (Class .class ))).thenReturn (logger );
70- InternalDriver driver = mock (InternalDriver .class );
71- doThrow (ServiceUnavailableException .class ).when (driver ).verifyConnectivity ();
72- DriverFactory driverFactory = new MockSupplyingDriverFactory (Arrays .asList (driver , driver ));
73- Config config = Config .builder ().withLogging (logging ).build ();
74-
75- List <URI > routingUris = asList (URI .create ("neo4j://localhost:9001" ), URI .create ("neo4j://localhost:9002" ));
76-
77- assertThrows (
78- ServiceUnavailableException .class ,
79- () -> GraphDatabase .routingDriver (routingUris , AuthTokens .none (), config , driverFactory ));
80-
81- verify (logger )
82- .warn (eq ("Unable to create routing driver for URI: neo4j://localhost:9001" ), any (Throwable .class ));
83-
84- verify (logger )
85- .warn (eq ("Unable to create routing driver for URI: neo4j://localhost:9002" ), any (Throwable .class ));
86- }
87-
88- @ Test
89- void shouldNotFailRoutingDriverWhenThereIsWorkingUri () {
90- Logging logging = mock (Logging .class );
91- Logger logger = mock (Logger .class );
92- when (logging .getLog (any (Class .class ))).thenReturn (logger );
93- InternalDriver failingDriver = mock (InternalDriver .class );
94- doThrow (ServiceUnavailableException .class ).when (failingDriver ).verifyConnectivity ();
95- InternalDriver workingDriver = mock (InternalDriver .class );
96- DriverFactory driverFactory = new MockSupplyingDriverFactory (Arrays .asList (failingDriver , workingDriver ));
97- Config config = Config .builder ().withLogging (logging ).build ();
98-
99- List <URI > routingUris = asList (URI .create ("neo4j://localhost:9001" ), URI .create ("neo4j://localhost:9002" ));
100-
101- Driver driver = GraphDatabase .routingDriver (routingUris , AuthTokens .none (), config , driverFactory );
102-
103- verify (logger )
104- .warn (eq ("Unable to create routing driver for URI: neo4j://localhost:9001" ), any (Throwable .class ));
105- assertEquals (driver , workingDriver );
106- }
107-
10857 @ Test
10958 void shouldRespondToInterruptsWhenConnectingToUnresponsiveServer () throws Exception {
11059 try (ServerSocket serverSocket = new ServerSocket (0 )) {
0 commit comments