From e346cad3c1ca0f61fe81b7198aa7c5101e370722 Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Wed, 23 Feb 2022 12:11:50 +0000 Subject: [PATCH 1/2] Update mockito-core to 4.3.1 --- .../InternalMapAccessorWithDefaultValueTest.java | 14 +++++++------- .../async/pool/ConnectionPoolImplTest.java | 4 ++-- .../LeastConnectedLoadBalancingStrategyTest.java | 4 ++-- .../handlers/RoutingResponseHandlerTest.java | 14 +++++++------- .../retry/ExponentialBackoffRetryLogicTest.java | 8 ++++---- pom.xml | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/driver/src/test/java/org/neo4j/driver/internal/InternalMapAccessorWithDefaultValueTest.java b/driver/src/test/java/org/neo4j/driver/internal/InternalMapAccessorWithDefaultValueTest.java index aa36886831..406f2f6d1e 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/InternalMapAccessorWithDefaultValueTest.java +++ b/driver/src/test/java/org/neo4j/driver/internal/InternalMapAccessorWithDefaultValueTest.java @@ -26,6 +26,9 @@ import java.util.List; import java.util.Map; +import org.neo4j.driver.Record; +import org.neo4j.driver.Value; +import org.neo4j.driver.Values; import org.neo4j.driver.internal.value.BooleanValue; import org.neo4j.driver.internal.value.FloatValue; import org.neo4j.driver.internal.value.IntegerValue; @@ -36,9 +39,6 @@ import org.neo4j.driver.internal.value.PathValue; import org.neo4j.driver.internal.value.RelationshipValue; import org.neo4j.driver.internal.value.StringValue; -import org.neo4j.driver.Record; -import org.neo4j.driver.Value; -import org.neo4j.driver.Values; import org.neo4j.driver.types.Entity; import org.neo4j.driver.types.Node; import org.neo4j.driver.types.Path; @@ -115,8 +115,8 @@ void shouldGetObjectFromRecord() Record record = createRecord(); // IntegerValue.asObject returns Long - assertThat( record.get( "IntegerValue", (Object) 3 ), equalTo( (Object) new Long( 11 ) ) ); - assertThat( record.get( wrongKey, (Object) 3 ), equalTo( (Object) new Integer( 3 ) ) ); + assertThat( record.get( "IntegerValue", (Object) 3 ), equalTo( 11L ) ); + assertThat( record.get( wrongKey, (Object) 3 ), equalTo( 3 ) ); } @Test @@ -125,8 +125,8 @@ void shouldGetNumberFromRecord() Record record = createRecord(); // IntegerValue.asNumber returns Long - assertThat( record.get( "IntegerValue", (Number) 3 ), equalTo( (Object) new Long( 11 ) ) ); - assertThat( record.get( wrongKey, (Number) 3 ), equalTo( (Object) new Integer( 3 ) ) ); + assertThat( record.get( "IntegerValue", (Number) 3 ), equalTo( (Object) 11L ) ); + assertThat( record.get( wrongKey, (Number) 3 ), equalTo( (Object) 3 ) ); } @Test diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java index 676dfc532f..d18aa10395 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java +++ b/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java @@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static org.neo4j.driver.internal.BoltServerAddress.LOCAL_DEFAULT; import static org.neo4j.driver.internal.async.connection.ChannelAttributes.authorizationStateListener; @@ -57,7 +57,7 @@ void shouldDoNothingWhenRetainOnEmptyPool() pool.retainAll( singleton( LOCAL_DEFAULT ) ); - verifyZeroInteractions( nettyChannelTracker ); + verifyNoInteractions( nettyChannelTracker ); } @Test diff --git a/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LeastConnectedLoadBalancingStrategyTest.java b/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LeastConnectedLoadBalancingStrategyTest.java index 8643e8bf7c..092e46ea2b 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LeastConnectedLoadBalancingStrategyTest.java +++ b/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LeastConnectedLoadBalancingStrategyTest.java @@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING; import static org.neo4j.driver.internal.util.ClusterCompositionUtil.A; @@ -51,7 +51,7 @@ class LeastConnectedLoadBalancingStrategyTest @BeforeEach void setUp() { - initMocks( this ); + openMocks( this ); strategy = new LeastConnectedLoadBalancingStrategy( connectionPool, DEV_NULL_LOGGING ); } diff --git a/driver/src/test/java/org/neo4j/driver/internal/handlers/RoutingResponseHandlerTest.java b/driver/src/test/java/org/neo4j/driver/internal/handlers/RoutingResponseHandlerTest.java index e7249d07e2..6926e8da4c 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/handlers/RoutingResponseHandlerTest.java +++ b/driver/src/test/java/org/neo4j/driver/internal/handlers/RoutingResponseHandlerTest.java @@ -23,20 +23,20 @@ import java.util.concurrent.CompletionException; -import org.neo4j.driver.internal.RoutingErrorHandler; -import org.neo4j.driver.internal.spi.ResponseHandler; import org.neo4j.driver.AccessMode; import org.neo4j.driver.exceptions.ClientException; import org.neo4j.driver.exceptions.ServiceUnavailableException; import org.neo4j.driver.exceptions.SessionExpiredException; import org.neo4j.driver.exceptions.TransientException; +import org.neo4j.driver.internal.RoutingErrorHandler; +import org.neo4j.driver.internal.spi.ResponseHandler; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.neo4j.driver.internal.BoltServerAddress.LOCAL_DEFAULT; class RoutingResponseHandlerTest @@ -50,7 +50,7 @@ void shouldUnwrapCompletionException() Throwable handledError = handle( new CompletionException( error ), errorHandler ); assertEquals( error, handledError ); - verifyZeroInteractions( errorHandler ); + verifyNoInteractions( errorHandler ); } @Test @@ -86,7 +86,7 @@ void shouldHandleTransientException() Throwable handledError = handle( error, errorHandler ); assertEquals( error, handledError ); - verifyZeroInteractions( errorHandler ); + verifyNoInteractions( errorHandler ); } @Test @@ -122,7 +122,7 @@ void shouldHandleClientException() Throwable handledError = handle( error, errorHandler, AccessMode.READ ); assertEquals( error, handledError ); - verifyZeroInteractions( errorHandler ); + verifyNoInteractions( errorHandler ); } @Test @@ -158,7 +158,7 @@ private void testWriteFailureWithReadAccessMode( String code ) assertThat( handledError, instanceOf( ClientException.class ) ); assertEquals( "Write queries cannot be performed in READ access mode.", handledError.getMessage() ); - verifyZeroInteractions( errorHandler ); + verifyNoInteractions( errorHandler ); } private void testWriteFailureWithWriteAccessMode( String code ) diff --git a/driver/src/test/java/org/neo4j/driver/internal/retry/ExponentialBackoffRetryLogicTest.java b/driver/src/test/java/org/neo4j/driver/internal/retry/ExponentialBackoffRetryLogicTest.java index ba4817977b..0a2acb57b3 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/retry/ExponentialBackoffRetryLogicTest.java +++ b/driver/src/test/java/org/neo4j/driver/internal/retry/ExponentialBackoffRetryLogicTest.java @@ -75,7 +75,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING; import static org.neo4j.driver.internal.util.Futures.failedFuture; @@ -1090,7 +1090,7 @@ void nothingIsLoggedOnFatalFailure() throw new RuntimeException( "Fatal blocking" ); } ) ); assertEquals( "Fatal blocking", error.getMessage() ); - verifyZeroInteractions( logger ); + verifyNoInteractions( logger ); } @Test @@ -1106,7 +1106,7 @@ void nothingIsLoggedOnFatalFailureAsync() await( logic.retryAsync( () -> failedFuture( new RuntimeException( "Fatal async" ) ) ) ) ); assertEquals( "Fatal async", error.getMessage() ); - verifyZeroInteractions( logger ); + verifyNoInteractions( logger ); } @Test @@ -1122,7 +1122,7 @@ void nothingIsLoggedOnFatalFailureRx() RuntimeException error = assertThrows( RuntimeException.class, () -> await( retryRx ) ); assertEquals( "Fatal rx", error.getMessage() ); - verifyZeroInteractions( logger ); + verifyNoInteractions( logger ); } @Test diff --git a/pom.xml b/pom.xml index a12de376cc..0720f3c8d1 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 2.2.21 1.7.35 2.0.0.0 - 2.28.2 + 4.3.1 5.8.2 1.2.0 1.70 From 9f92687583fa9252e08cce337f3d281ff2a42a2a Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Wed, 23 Feb 2022 13:53:40 +0000 Subject: [PATCH 2/2] Update LoadBalancerTest and DriverIntroductionExample --- .../loadbalancing/LoadBalancerTest.java | 7 ++-- .../driver/DriverIntroductionExample.java | 35 +++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java b/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java index ab9d7e8281..3766c7b15d 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java +++ b/driver/src/test/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancerTest.java @@ -385,8 +385,11 @@ void expectsCompetedDatabaseNameAfterRoutingTableRegistry( boolean completed ) t new LoadBalancer( connectionPool, routingTables, rediscovery, new LeastConnectedLoadBalancingStrategy( connectionPool, DEV_NULL_LOGGING ), GlobalEventExecutor.INSTANCE, DEV_NULL_LOGGING ); ConnectionContext context = mock( ConnectionContext.class ); - CompletableFuture databaseNameFuture = - spy( completed ? CompletableFuture.completedFuture( DatabaseNameUtil.systemDatabase() ) : new CompletableFuture<>() ); + CompletableFuture databaseNameFuture = spy( new CompletableFuture<>() ); + if ( completed ) + { + databaseNameFuture.complete( DatabaseNameUtil.systemDatabase() ); + } when( context.databaseNameFuture() ).thenReturn( databaseNameFuture ); when( context.mode() ).thenReturn( WRITE ); diff --git a/examples/src/main/java/org/neo4j/docs/driver/DriverIntroductionExample.java b/examples/src/main/java/org/neo4j/docs/driver/DriverIntroductionExample.java index 067422382e..0197e1fbda 100644 --- a/examples/src/main/java/org/neo4j/docs/driver/DriverIntroductionExample.java +++ b/examples/src/main/java/org/neo4j/docs/driver/DriverIntroductionExample.java @@ -20,16 +20,21 @@ // tag::driver-introduction-example-import[] -import org.neo4j.driver.*; -import org.neo4j.driver.exceptions.Neo4jException; - import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import static org.neo4j.driver.Config.TrustStrategy.trustAllCertificates; +import org.neo4j.driver.AuthTokens; +import org.neo4j.driver.Config; +import org.neo4j.driver.Driver; +import org.neo4j.driver.GraphDatabase; +import org.neo4j.driver.Logging; +import org.neo4j.driver.Record; +import org.neo4j.driver.Result; +import org.neo4j.driver.Session; +import org.neo4j.driver.exceptions.Neo4jException; // end::driver-introduction-example-import[] // tag::driver-introduction-example[] @@ -61,17 +66,19 @@ public void createFriendship(final String person1Name, final String person2Name, params.put("person2_name", person2Name); params.put("knows_from", knowsFrom ); - try (Session session = driver.session()) { + try (Session session = driver.session()) + { // Write transactions allow the driver to handle retries and transient errors - Record record = session.writeTransaction(tx -> { - Result result = tx.run(createFriendshipQuery, params); - return result.single(); - }); - System.out.println(String.format("Created friendship between: %s, %s from %s", - record.get("p1").get("name").asString(), - record.get("p2").get("name").asString(), - record.get("k").get("from").asString())); - // You should capture any errors along with the query and data for traceability + Record record = session.writeTransaction( tx -> + { + Result result = tx.run( createFriendshipQuery, params ); + return result.single(); + } ); + System.out.println( String.format( "Created friendship between: %s, %s from %s", + record.get( "p1" ).get( "name" ).asString(), + record.get( "p2" ).get( "name" ).asString(), + record.get( "k" ).get( "from" ).asString() ) ); + // You should capture any errors along with the query and data for traceability } catch (Neo4jException ex) { LOGGER.log(Level.SEVERE, createFriendshipQuery + " raised an exception", ex); throw ex;