From 2c46949ab0fc079946d0f8f9d4dbeb09a2f6d141 Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Mon, 15 Aug 2022 17:17:11 +0100 Subject: [PATCH] Delete deprecated routingDriver --- driver/clirr-ignored-differences.xml | 6 ++ .../java/org/neo4j/driver/GraphDatabase.java | 65 ------------------- .../org/neo4j/driver/GraphDatabaseTest.java | 51 --------------- 3 files changed, 6 insertions(+), 116 deletions(-) diff --git a/driver/clirr-ignored-differences.xml b/driver/clirr-ignored-differences.xml index 34e1f9fe6d..67f0465205 100644 --- a/driver/clirr-ignored-differences.xml +++ b/driver/clirr-ignored-differences.xml @@ -365,4 +365,10 @@ org.neo4j.driver.Value + + org/neo4j/driver/GraphDatabase + 7002 + org.neo4j.driver.Driver routingDriver(java.lang.Iterable, org.neo4j.driver.AuthToken, org.neo4j.driver.Config) + + diff --git a/driver/src/main/java/org/neo4j/driver/GraphDatabase.java b/driver/src/main/java/org/neo4j/driver/GraphDatabase.java index c77c6d8327..39d9a3fab3 100644 --- a/driver/src/main/java/org/neo4j/driver/GraphDatabase.java +++ b/driver/src/main/java/org/neo4j/driver/GraphDatabase.java @@ -18,10 +18,7 @@ */ package org.neo4j.driver; -import static org.neo4j.driver.internal.Scheme.NEO4J_URI_SCHEME; - import java.net.URI; -import org.neo4j.driver.exceptions.ServiceUnavailableException; import org.neo4j.driver.internal.DriverFactory; import org.neo4j.driver.internal.SecuritySettings; import org.neo4j.driver.internal.cluster.RoutingSettings; @@ -133,68 +130,6 @@ static Driver driver(URI uri, AuthToken authToken, Config config, DriverFactory return driverFactory.newInstance(uri, authToken, routingSettings, retrySettings, config, securityPlan); } - /** - * Try to create a neo4j driver from the first available address. - * This is wrapper for the {@link #driver} method that finds the first - * server to respond positively. - * - * @param routingUris an {@link Iterable} of server {@link URI}s for Neo4j instances. All given URIs should - * have 'neo4j' scheme. - * @param authToken authentication to use, see {@link AuthTokens} - * @param config user defined configuration - * @return a new driver instance - * @deprecated driver should be configured with initial address resolution as documented in the driver manual - */ - @Deprecated - public static Driver routingDriver(Iterable routingUris, AuthToken authToken, Config config) { - return routingDriver(routingUris, authToken, config, new DriverFactory()); - } - - static Driver routingDriver( - Iterable routingUris, AuthToken authToken, Config config, DriverFactory driverFactory) { - assertRoutingUris(routingUris); - Logger log = createLogger(config); - - for (URI uri : routingUris) { - final Driver driver = driver(uri, authToken, config, driverFactory); - try { - driver.verifyConnectivity(); - return driver; - } catch (ServiceUnavailableException e) { - log.warn("Unable to create routing driver for URI: " + uri, e); - closeDriver(driver, uri, log); - } catch (Throwable e) { - // for any other errors, we first close the driver and then rethrow the original error out. - closeDriver(driver, uri, log); - throw e; - } - } - - throw new ServiceUnavailableException("Failed to discover an available server"); - } - - private static void closeDriver(Driver driver, URI uri, Logger log) { - try { - driver.close(); - } catch (Throwable closeError) { - log.warn("Unable to close driver towards URI: " + uri, closeError); - } - } - - private static void assertRoutingUris(Iterable uris) { - for (URI uri : uris) { - if (!NEO4J_URI_SCHEME.equals(uri.getScheme())) { - throw new IllegalArgumentException( - "Illegal URI scheme, expected '" + NEO4J_URI_SCHEME + "' in '" + uri + "'"); - } - } - } - - private static Logger createLogger(Config config) { - Logging logging = getOrDefault(config).logging(); - return logging.getLog(GraphDatabase.class); - } - private static Config getOrDefault(Config config) { return config != null ? config : Config.defaultConfig(); } diff --git a/driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java b/driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java index f888d4d403..11c8f0a856 100644 --- a/driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java +++ b/driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java @@ -18,18 +18,11 @@ */ package org.neo4j.driver; -import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import static org.neo4j.driver.Logging.none; import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING; @@ -37,7 +30,6 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.URI; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.junit.jupiter.api.Test; @@ -62,49 +54,6 @@ void throwsWhenBoltSchemeUsedWithRoutingParams() { IllegalArgumentException.class, () -> GraphDatabase.driver("bolt://localhost:7687/?policy=my_policy")); } - @Test - void shouldLogWhenUnableToCreateRoutingDriver() { - Logging logging = mock(Logging.class); - Logger logger = mock(Logger.class); - when(logging.getLog(any(Class.class))).thenReturn(logger); - InternalDriver driver = mock(InternalDriver.class); - doThrow(ServiceUnavailableException.class).when(driver).verifyConnectivity(); - DriverFactory driverFactory = new MockSupplyingDriverFactory(Arrays.asList(driver, driver)); - Config config = Config.builder().withLogging(logging).build(); - - List routingUris = asList(URI.create("neo4j://localhost:9001"), URI.create("neo4j://localhost:9002")); - - assertThrows( - ServiceUnavailableException.class, - () -> GraphDatabase.routingDriver(routingUris, AuthTokens.none(), config, driverFactory)); - - verify(logger) - .warn(eq("Unable to create routing driver for URI: neo4j://localhost:9001"), any(Throwable.class)); - - verify(logger) - .warn(eq("Unable to create routing driver for URI: neo4j://localhost:9002"), any(Throwable.class)); - } - - @Test - void shouldNotFailRoutingDriverWhenThereIsWorkingUri() { - Logging logging = mock(Logging.class); - Logger logger = mock(Logger.class); - when(logging.getLog(any(Class.class))).thenReturn(logger); - InternalDriver failingDriver = mock(InternalDriver.class); - doThrow(ServiceUnavailableException.class).when(failingDriver).verifyConnectivity(); - InternalDriver workingDriver = mock(InternalDriver.class); - DriverFactory driverFactory = new MockSupplyingDriverFactory(Arrays.asList(failingDriver, workingDriver)); - Config config = Config.builder().withLogging(logging).build(); - - List routingUris = asList(URI.create("neo4j://localhost:9001"), URI.create("neo4j://localhost:9002")); - - Driver driver = GraphDatabase.routingDriver(routingUris, AuthTokens.none(), config, driverFactory); - - verify(logger) - .warn(eq("Unable to create routing driver for URI: neo4j://localhost:9001"), any(Throwable.class)); - assertEquals(driver, workingDriver); - } - @Test void shouldRespondToInterruptsWhenConnectingToUnresponsiveServer() throws Exception { try (ServerSocket serverSocket = new ServerSocket(0)) {