From 5e57c9e2ffccc33e75a7e978fa6579de1acd34c6 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Wed, 12 Jan 2022 14:28:12 +0100 Subject: [PATCH 1/6] Allow tx timeout to be 0 or null. Adjust TestKit back end to accept * `null` timeout: send `null` to server (or omit as it's the default) * and integer: configure as timeout in milliseconds * omitted timeout: don't explicitly configure the timeout (user driver default) --- .../org/neo4j/driver/TransactionConfig.java | 15 +++-- .../testkit/backend/CustomDriverError.java | 5 ++ .../TestkitRequestProcessorHandler.java | 15 +++++ .../requests/SessionBeginTransaction.java | 55 ++++++++++++++----- .../backend/messages/requests/SessionRun.java | 51 +++++++++++++++-- 5 files changed, 117 insertions(+), 24 deletions(-) create mode 100644 testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java diff --git a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java index fee9943fb3..873b188a3c 100644 --- a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java +++ b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java @@ -183,26 +183,33 @@ public static class Builder private Duration timeout; private Map metadata = emptyMap(); + /** + * Value used to signal {@link #withTimeout(Duration)} to use the server-side configured default timeout. + */ + public static final Duration SERVER_DEFAULT_TIMEOUT = null; + private Builder() { } /** * Set the transaction timeout. Transactions that execute longer than the configured timeout will be terminated by the database. + * Use {@link #SERVER_DEFAULT_TIMEOUT SERVER_DEFAULT_TIMEOUT} (default) to rely on the server-side configured timeout. *

* This functionality allows to limit query/transaction execution time. Specified timeout overrides the default timeout configured in the database * using {@code dbms.transaction.timeout} setting. *

- * Provided value should not be {@code null} and should not represent a duration of zero or negative duration. + * Provided value should not represent a negative duration. * * @param timeout the timeout. * @return this builder. */ public Builder withTimeout( Duration timeout ) { - requireNonNull( timeout, "Transaction timeout should not be null" ); - checkArgument( !timeout.isZero(), "Transaction timeout should not be zero" ); - checkArgument( !timeout.isNegative(), "Transaction timeout should not be negative" ); + if (timeout != null) + { + checkArgument( !timeout.isNegative(), "Transaction timeout should not be negative" ); + } this.timeout = timeout; return this; diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java new file mode 100644 index 0000000000..4b647bd2fa --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java @@ -0,0 +1,5 @@ +package neo4j.org.testkit.backend; + +public class CustomDriverError extends java.lang.RuntimeException +{ +} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/channel/handler/TestkitRequestProcessorHandler.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/channel/handler/TestkitRequestProcessorHandler.java index 3d2ce940d0..5ea2d22b4e 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/channel/handler/TestkitRequestProcessorHandler.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/channel/handler/TestkitRequestProcessorHandler.java @@ -21,6 +21,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import neo4j.org.testkit.backend.CustomDriverError; import neo4j.org.testkit.backend.TestkitState; import neo4j.org.testkit.backend.messages.requests.TestkitRequest; import neo4j.org.testkit.backend.messages.responses.BackendError; @@ -145,6 +146,20 @@ else if ( isConnectionPoolClosedException( throwable ) || throwable instanceof U ) .build(); } + else if ( throwable instanceof CustomDriverError ) + { + throwable = throwable.getCause(); + String id = testkitState.newId(); + return DriverError.builder() + .data( + DriverError.DriverErrorBody.builder() + .id( id ) + .errorType( throwable.getClass().getName() ) + .msg( throwable.getMessage() ) + .build() + ) + .build(); + } else { return BackendError.builder().data( BackendError.BackendErrorBody.builder().msg( throwable.toString() ).build() ).build(); diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java index 0b10511fa2..5d848b1ac0 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java @@ -20,6 +20,7 @@ import lombok.Getter; import lombok.Setter; +import neo4j.org.testkit.backend.CustomDriverError; import neo4j.org.testkit.backend.TestkitState; import neo4j.org.testkit.backend.holder.AsyncTransactionHolder; import neo4j.org.testkit.backend.holder.RxTransactionHolder; @@ -45,6 +46,30 @@ public class SessionBeginTransaction implements TestkitRequest { private SessionBeginTransactionBody data; + private void configureTimeout( TransactionConfig.Builder builder ) + { + if ( data.getTimeoutPresent() ) + { + try + { + if ( data.getTimeout() != null ) + { + builder.withTimeout( Duration.ofMillis( data.getTimeout() ) ); + } + else + { + builder.withTimeout( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT ); + } + } + catch ( IllegalArgumentException e ) + { + CustomDriverError wrapped = new CustomDriverError(); + wrapped.initCause( e ); + throw wrapped; + } + } + } + @Override public TestkitResponse process( TestkitState testkitState ) { @@ -53,10 +78,7 @@ public TestkitResponse process( TestkitState testkitState ) TransactionConfig.Builder builder = TransactionConfig.builder(); Optional.ofNullable( data.txMeta ).ifPresent( builder::withMetadata ); - if ( data.getTimeout() != null ) - { - builder.withTimeout( Duration.ofMillis( data.getTimeout() ) ); - } + configureTimeout( builder ); org.neo4j.driver.Transaction transaction = session.beginTransaction( builder.build() ); return transaction( testkitState.addTransactionHolder( new TransactionHolder( sessionHolder, transaction ) ) ); @@ -72,10 +94,7 @@ public CompletionStage processAsync( TestkitState testkitState TransactionConfig.Builder builder = TransactionConfig.builder(); Optional.ofNullable( data.txMeta ).ifPresent( builder::withMetadata ); - if ( data.getTimeout() != null ) - { - builder.withTimeout( Duration.ofMillis( data.getTimeout() ) ); - } + configureTimeout( builder ); return session.beginTransactionAsync( builder.build() ).thenApply( tx -> transaction( testkitState.addAsyncTransactionHolder( new AsyncTransactionHolder( sessionHolder, tx ) ) ) ); @@ -92,10 +111,7 @@ public Mono processRx( TestkitState testkitState ) TransactionConfig.Builder builder = TransactionConfig.builder(); Optional.ofNullable( data.txMeta ).ifPresent( builder::withMetadata ); - if ( data.getTimeout() != null ) - { - builder.withTimeout( Duration.ofMillis( data.getTimeout() ) ); - } + configureTimeout( builder ); return Mono.fromDirect( session.beginTransaction( builder.build() ) ) .map( tx -> transaction( @@ -108,12 +124,23 @@ private Transaction transaction( String txId ) return Transaction.builder().data( Transaction.TransactionBody.builder().id( txId ).build() ).build(); } - @Getter - @Setter public static class SessionBeginTransactionBody { + @Getter + @Setter private String sessionId; + @Getter + @Setter private Map txMeta; + @Getter private Integer timeout; + @Getter + private Boolean timeoutPresent = false; + + public void setTimeout( Integer timeout ) + { + this.timeout = timeout; + timeoutPresent = true; + } } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java index e943726de7..4d6534497e 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Getter; import lombok.Setter; +import neo4j.org.testkit.backend.CustomDriverError; import neo4j.org.testkit.backend.TestkitState; import neo4j.org.testkit.backend.holder.ResultCursorHolder; import neo4j.org.testkit.backend.holder.ResultHolder; @@ -49,6 +50,30 @@ public class SessionRun implements TestkitRequest { private SessionRunBody data; + private void configureTimeout( TransactionConfig.Builder builder ) + { + if ( data.getTimeoutPresent() ) + { + try + { + if ( data.getTimeout() != null ) + { + builder.withTimeout( Duration.ofMillis( data.getTimeout() ) ); + } + else + { + builder.withTimeout( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT ); + } + } + catch ( IllegalArgumentException e ) + { + CustomDriverError wrapped = new CustomDriverError(); + wrapped.initCause( e ); + throw wrapped; + } + } + } + @Override public TestkitResponse process( TestkitState testkitState ) { @@ -59,7 +84,7 @@ public TestkitResponse process( TestkitState testkitState ) .orElseGet( () -> new Query( data.cypher ) ); TransactionConfig.Builder transactionConfig = TransactionConfig.builder(); Optional.ofNullable( data.getTxMeta() ).ifPresent( transactionConfig::withMetadata ); - Optional.ofNullable( data.getTimeout() ).ifPresent( to -> transactionConfig.withTimeout( Duration.ofMillis( to ) ) ); + configureTimeout( transactionConfig ); org.neo4j.driver.Result result = session.run( query, transactionConfig.build() ); String id = testkitState.addResultHolder( new ResultHolder( sessionHolder, result ) ); @@ -78,8 +103,7 @@ public CompletionStage processAsync( TestkitState testkitState .orElseGet( () -> new Query( data.cypher ) ); TransactionConfig.Builder transactionConfig = TransactionConfig.builder(); Optional.ofNullable( data.getTxMeta() ).ifPresent( transactionConfig::withMetadata ); - Optional.ofNullable( data.getTimeout() ) - .ifPresent( to -> transactionConfig.withTimeout( Duration.ofMillis( to ) ) ); + configureTimeout( transactionConfig ); return session.runAsync( query, transactionConfig.build() ) .thenApply( resultCursor -> @@ -103,7 +127,7 @@ public Mono processRx( TestkitState testkitState ) .orElseGet( () -> new Query( data.cypher ) ); TransactionConfig.Builder transactionConfig = TransactionConfig.builder(); Optional.ofNullable( data.getTxMeta() ).ifPresent( transactionConfig::withMetadata ); - Optional.ofNullable( data.getTimeout() ).ifPresent( to -> transactionConfig.withTimeout( Duration.ofMillis( to ) ) ); + configureTimeout( transactionConfig ); RxResult result = session.run( query, transactionConfig.build() ); String id = testkitState.addRxResultHolder( new RxResultHolder( sessionHolder, result ) ); @@ -120,17 +144,32 @@ private Result createResponse( String resultId ) return Result.builder().data( Result.ResultBody.builder().id( resultId ).build() ).build(); } - @Setter - @Getter public static class SessionRunBody { @JsonDeserialize( using = TestkitCypherParamDeserializer.class ) + @Setter + @Getter private Map params; + @Setter + @Getter private String sessionId; + @Setter + @Getter private String cypher; + @Setter + @Getter private Map txMeta; + @Getter private Integer timeout; + @Getter + private Boolean timeoutPresent = false; + + public void setTimeout( Integer timeout ) + { + this.timeout = timeout; + timeoutPresent = true; + } } } From 73e525bc878f04e6984aad33fdf103aafc71a110 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Wed, 12 Jan 2022 17:10:21 +0100 Subject: [PATCH 2/6] Adjust unit tests --- .../neo4j/driver/TransactionConfigTest.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java b/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java index 31740bdb82..88b3663c4d 100644 --- a/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java +++ b/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java @@ -51,18 +51,6 @@ void emptyConfigShouldHaveNoMetadata() assertEquals( emptyMap(), TransactionConfig.empty().metadata() ); } - @Test - void shouldDisallowNullTimeout() - { - assertThrows( NullPointerException.class, () -> TransactionConfig.builder().withTimeout( null ) ); - } - - @Test - void shouldDisallowZeroTimeout() - { - assertThrows( IllegalArgumentException.class, () -> TransactionConfig.builder().withTimeout( Duration.ZERO ) ); - } - @Test void shouldDisallowNegativeTimeout() { @@ -98,6 +86,26 @@ void shouldHaveTimeout() assertEquals( Duration.ofSeconds( 3 ), config.timeout() ); } + @Test + void shouldAllowDefaultTimeout() + { + TransactionConfig config = TransactionConfig.builder() + .withTimeout( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT ) + .build(); + + assertNull( config.timeout() ); + } + + @Test + void shouldAllowZeroTimeout() + { + TransactionConfig config = TransactionConfig.builder() + .withTimeout( Duration.ZERO ) + .build(); + + assertEquals( Duration.ZERO, config.timeout() ); + } + @Test void shouldHaveMetadata() { From feb3a7436029bcffeffcf75c731ef2b271678599 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Wed, 12 Jan 2022 17:39:58 +0100 Subject: [PATCH 3/6] Add header --- .../org/testkit/backend/CustomDriverError.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java index 4b647bd2fa..bc0183c324 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package neo4j.org.testkit.backend; public class CustomDriverError extends java.lang.RuntimeException From cfbc490a9901869b82335d44a7d58764b470ca4f Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Fri, 14 Jan 2022 10:59:45 +0100 Subject: [PATCH 4/6] Code review suggestions by Dmitriy Co-authored-by: Dmitriy Tverdiakov --- .../org/neo4j/driver/TransactionConfig.java | 8 ++++---- .../org/neo4j/driver/TransactionConfigTest.java | 1 + .../org/testkit/backend/CustomDriverError.java | 6 +++++- .../requests/SessionBeginTransaction.java | 12 +++--------- .../backend/messages/requests/SessionRun.java | 17 +++-------------- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java index 873b188a3c..1a524e8509 100644 --- a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java +++ b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java @@ -180,21 +180,21 @@ public String toString() */ public static class Builder { - private Duration timeout; - private Map metadata = emptyMap(); - /** * Value used to signal {@link #withTimeout(Duration)} to use the server-side configured default timeout. */ public static final Duration SERVER_DEFAULT_TIMEOUT = null; + private Duration timeout; + private Map metadata = emptyMap(); + private Builder() { } /** * Set the transaction timeout. Transactions that execute longer than the configured timeout will be terminated by the database. - * Use {@link #SERVER_DEFAULT_TIMEOUT SERVER_DEFAULT_TIMEOUT} (default) to rely on the server-side configured timeout. + * Use {@link #SERVER_DEFAULT_TIMEOUT} (default) to rely on the server-side configured timeout. *

* This functionality allows to limit query/transaction execution time. Specified timeout overrides the default timeout configured in the database * using {@code dbms.transaction.timeout} setting. diff --git a/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java b/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java index 88b3663c4d..c6dc4e3d51 100644 --- a/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java +++ b/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java @@ -94,6 +94,7 @@ void shouldAllowDefaultTimeout() .build(); assertNull( config.timeout() ); + assertEquals( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT,config.timeout() ); } @Test diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java index bc0183c324..3110446d6f 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CustomDriverError.java @@ -18,6 +18,10 @@ */ package neo4j.org.testkit.backend; -public class CustomDriverError extends java.lang.RuntimeException +public class CustomDriverError extends RuntimeException { + public CustomDriverError( Throwable cause ) + { + super( cause ); + } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java index 5d848b1ac0..04e17a630f 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java @@ -63,9 +63,7 @@ private void configureTimeout( TransactionConfig.Builder builder ) } catch ( IllegalArgumentException e ) { - CustomDriverError wrapped = new CustomDriverError(); - wrapped.initCause( e ); - throw wrapped; + throw new CustomDriverError( e ); } } } @@ -124,17 +122,13 @@ private Transaction transaction( String txId ) return Transaction.builder().data( Transaction.TransactionBody.builder().id( txId ).build() ).build(); } + @Getter + @Setter public static class SessionBeginTransactionBody { - @Getter - @Setter private String sessionId; - @Getter - @Setter private Map txMeta; - @Getter private Integer timeout; - @Getter private Boolean timeoutPresent = false; public void setTimeout( Integer timeout ) diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java index 4d6534497e..fda86bf10b 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java @@ -67,9 +67,7 @@ private void configureTimeout( TransactionConfig.Builder builder ) } catch ( IllegalArgumentException e ) { - CustomDriverError wrapped = new CustomDriverError(); - wrapped.initCause( e ); - throw wrapped; + throw new CustomDriverError( e ); } } } @@ -144,25 +142,16 @@ private Result createResponse( String resultId ) return Result.builder().data( Result.ResultBody.builder().id( resultId ).build() ).build(); } + @Setter + @Getter public static class SessionRunBody { @JsonDeserialize( using = TestkitCypherParamDeserializer.class ) - @Setter - @Getter private Map params; - - @Setter - @Getter private String sessionId; - @Setter - @Getter private String cypher; - @Setter - @Getter private Map txMeta; - @Getter private Integer timeout; - @Getter private Boolean timeoutPresent = false; public void setTimeout( Integer timeout ) From c96d403dcebb9e978290fa49f8e7f7be3e0c4d51 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Fri, 14 Jan 2022 10:59:45 +0100 Subject: [PATCH 5/6] Changed to Tx config builter `.withDefaultTimeout` + clean-up Co-authored-by: Dmitriy Tverdiakov --- .../org/neo4j/driver/TransactionConfig.java | 26 ++++++++++++------- .../neo4j/driver/TransactionConfigTest.java | 12 ++++----- .../requests/SessionBeginTransaction.java | 2 +- .../backend/messages/requests/SessionRun.java | 3 +-- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java index 1a524e8509..5b5caea2bf 100644 --- a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java +++ b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java @@ -180,11 +180,6 @@ public String toString() */ public static class Builder { - /** - * Value used to signal {@link #withTimeout(Duration)} to use the server-side configured default timeout. - */ - public static final Duration SERVER_DEFAULT_TIMEOUT = null; - private Duration timeout; private Map metadata = emptyMap(); @@ -194,7 +189,7 @@ private Builder() /** * Set the transaction timeout. Transactions that execute longer than the configured timeout will be terminated by the database. - * Use {@link #SERVER_DEFAULT_TIMEOUT} (default) to rely on the server-side configured timeout. + * See also {@link #withDefaultTimeout}. *

* This functionality allows to limit query/transaction execution time. Specified timeout overrides the default timeout configured in the database * using {@code dbms.transaction.timeout} setting. @@ -206,15 +201,26 @@ private Builder() */ public Builder withTimeout( Duration timeout ) { - if (timeout != null) - { - checkArgument( !timeout.isNegative(), "Transaction timeout should not be negative" ); - } + requireNonNull( timeout, "Transaction timeout should not be null" ); + checkArgument( !timeout.isNegative(), "Transaction timeout should not be negative" ); this.timeout = timeout; return this; } + /** + * Set the transaction timeout to ths server-side configured default timeout. This is the default behaviour if neiter + * {@link #withTimeout} has not been called. + * See also {@link #withTimeout}. + * + * @return this builder. + */ + public Builder withDefaultTimeout() + { + this.timeout = null; + return this; + } + /** * Set the transaction metadata. Specified metadata will be attached to the executing transaction and visible in the output of * {@code dbms.listQueries} and {@code dbms.listTransactions} procedures. It will also get logged to the {@code query.log}. diff --git a/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java b/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java index c6dc4e3d51..aebb5bac20 100644 --- a/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java +++ b/driver/src/test/java/org/neo4j/driver/TransactionConfigTest.java @@ -24,10 +24,10 @@ import java.util.HashMap; import java.util.Map; +import org.neo4j.driver.exceptions.ClientException; import org.neo4j.driver.internal.InternalNode; import org.neo4j.driver.internal.InternalPath; import org.neo4j.driver.internal.InternalRelationship; -import org.neo4j.driver.exceptions.ClientException; import org.neo4j.driver.util.TestUtil; import static java.util.Collections.emptyMap; @@ -80,8 +80,8 @@ void shouldDisallowMetadataWithIllegalValues() void shouldHaveTimeout() { TransactionConfig config = TransactionConfig.builder() - .withTimeout( Duration.ofSeconds( 3 ) ) - .build(); + .withTimeout( Duration.ofSeconds( 3 ) ) + .build(); assertEquals( Duration.ofSeconds( 3 ), config.timeout() ); } @@ -90,11 +90,11 @@ void shouldHaveTimeout() void shouldAllowDefaultTimeout() { TransactionConfig config = TransactionConfig.builder() - .withTimeout( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT ) - .build(); + .withTimeout( Duration.ofSeconds( 3 ) ) + .withDefaultTimeout() + .build(); assertNull( config.timeout() ); - assertEquals( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT,config.timeout() ); } @Test diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java index 04e17a630f..89c99424e6 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java @@ -58,7 +58,7 @@ private void configureTimeout( TransactionConfig.Builder builder ) } else { - builder.withTimeout( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT ); + builder.withDefaultTimeout(); } } catch ( IllegalArgumentException e ) diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java index fda86bf10b..eaa30ad575 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java @@ -62,7 +62,7 @@ private void configureTimeout( TransactionConfig.Builder builder ) } else { - builder.withTimeout( TransactionConfig.Builder.SERVER_DEFAULT_TIMEOUT ); + builder.withDefaultTimeout(); } } catch ( IllegalArgumentException e ) @@ -159,6 +159,5 @@ public void setTimeout( Integer timeout ) this.timeout = timeout; timeoutPresent = true; } - } } From 1b65debb65a86b460f8d75b57fae7decbcc2e8fd Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Tue, 18 Jan 2022 13:00:21 +0100 Subject: [PATCH 6/6] Fix typos --- driver/src/main/java/org/neo4j/driver/TransactionConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java index 5b5caea2bf..251f1a6071 100644 --- a/driver/src/main/java/org/neo4j/driver/TransactionConfig.java +++ b/driver/src/main/java/org/neo4j/driver/TransactionConfig.java @@ -209,7 +209,7 @@ public Builder withTimeout( Duration timeout ) } /** - * Set the transaction timeout to ths server-side configured default timeout. This is the default behaviour if neiter + * Set the transaction timeout to the server-side configured default timeout. This is the default behaviour if * {@link #withTimeout} has not been called. * See also {@link #withTimeout}. *