Skip to content

Commit 018f32b

Browse files
authored
Delete deprecated routingDriver (#1289)
1 parent fbf1c89 commit 018f32b

File tree

3 files changed

+6
-116
lines changed

3 files changed

+6
-116
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,10 @@
365365
<to>org.neo4j.driver.Value</to>
366366
</difference>
367367

368+
<difference>
369+
<className>org/neo4j/driver/GraphDatabase</className>
370+
<differenceType>7002</differenceType>
371+
<method>org.neo4j.driver.Driver routingDriver(java.lang.Iterable, org.neo4j.driver.AuthToken, org.neo4j.driver.Config)</method>
372+
</difference>
373+
368374
</differences>

driver/src/main/java/org/neo4j/driver/GraphDatabase.java

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
*/
1919
package org.neo4j.driver;
2020

21-
import static org.neo4j.driver.internal.Scheme.NEO4J_URI_SCHEME;
22-
2321
import java.net.URI;
24-
import org.neo4j.driver.exceptions.ServiceUnavailableException;
2522
import org.neo4j.driver.internal.DriverFactory;
2623
import org.neo4j.driver.internal.SecuritySettings;
2724
import org.neo4j.driver.internal.cluster.RoutingSettings;
@@ -133,68 +130,6 @@ static Driver driver(URI uri, AuthToken authToken, Config config, DriverFactory
133130
return driverFactory.newInstance(uri, authToken, routingSettings, retrySettings, config, securityPlan);
134131
}
135132

136-
/**
137-
* Try to create a neo4j driver from the <b>first</b> available address.
138-
* This is wrapper for the {@link #driver} method that finds the <b>first</b>
139-
* server to respond positively.
140-
*
141-
* @param routingUris an {@link Iterable} of server {@link URI}s for Neo4j instances. All given URIs should
142-
* have 'neo4j' scheme.
143-
* @param authToken authentication to use, see {@link AuthTokens}
144-
* @param config user defined configuration
145-
* @return a new driver instance
146-
* @deprecated driver should be configured with initial address resolution as documented in the driver manual
147-
*/
148-
@Deprecated
149-
public static Driver routingDriver(Iterable<URI> routingUris, AuthToken authToken, Config config) {
150-
return routingDriver(routingUris, authToken, config, new DriverFactory());
151-
}
152-
153-
static Driver routingDriver(
154-
Iterable<URI> routingUris, AuthToken authToken, Config config, DriverFactory driverFactory) {
155-
assertRoutingUris(routingUris);
156-
Logger log = createLogger(config);
157-
158-
for (URI uri : routingUris) {
159-
final Driver driver = driver(uri, authToken, config, driverFactory);
160-
try {
161-
driver.verifyConnectivity();
162-
return driver;
163-
} catch (ServiceUnavailableException e) {
164-
log.warn("Unable to create routing driver for URI: " + uri, e);
165-
closeDriver(driver, uri, log);
166-
} catch (Throwable e) {
167-
// for any other errors, we first close the driver and then rethrow the original error out.
168-
closeDriver(driver, uri, log);
169-
throw e;
170-
}
171-
}
172-
173-
throw new ServiceUnavailableException("Failed to discover an available server");
174-
}
175-
176-
private static void closeDriver(Driver driver, URI uri, Logger log) {
177-
try {
178-
driver.close();
179-
} catch (Throwable closeError) {
180-
log.warn("Unable to close driver towards URI: " + uri, closeError);
181-
}
182-
}
183-
184-
private static void assertRoutingUris(Iterable<URI> uris) {
185-
for (URI uri : uris) {
186-
if (!NEO4J_URI_SCHEME.equals(uri.getScheme())) {
187-
throw new IllegalArgumentException(
188-
"Illegal URI scheme, expected '" + NEO4J_URI_SCHEME + "' in '" + uri + "'");
189-
}
190-
}
191-
}
192-
193-
private static Logger createLogger(Config config) {
194-
Logging logging = getOrDefault(config).logging();
195-
return logging.getLog(GraphDatabase.class);
196-
}
197-
198133
private static Config getOrDefault(Config config) {
199134
return config != null ? config : Config.defaultConfig();
200135
}

driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,18 @@
1818
*/
1919
package org.neo4j.driver;
2020

21-
import static java.util.Arrays.asList;
2221
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2322
import static org.hamcrest.Matchers.containsString;
2423
import static org.hamcrest.junit.MatcherAssert.assertThat;
2524
import static org.junit.jupiter.api.Assertions.assertEquals;
2625
import 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;
3326
import static org.neo4j.driver.Logging.none;
3427
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
3528

3629
import io.netty.util.concurrent.EventExecutorGroup;
3730
import java.io.IOException;
3831
import java.net.ServerSocket;
3932
import java.net.URI;
40-
import java.util.Arrays;
4133
import java.util.Iterator;
4234
import java.util.List;
4335
import 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

Comments
 (0)