diff --git a/tarantool-client/src/main/java/io/tarantool/client/BaseOptions.java b/tarantool-client/src/main/java/io/tarantool/client/BaseOptions.java
index 5c72dd74..902006e8 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/BaseOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/BaseOptions.java
@@ -5,6 +5,8 @@
package io.tarantool.client;
+import java.time.Duration;
+
/**
* The class implements base options for operations.
*
@@ -13,15 +15,12 @@
*/
public class BaseOptions implements Options {
- /** Default {@link BaseOptions#timeout} value. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- *
Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*/
- private final long timeout;
+ private final Duration timeout;
/**
* Stream id for operation.
@@ -41,7 +40,7 @@ public class BaseOptions implements Options {
* @param streamId see also: {@link #streamId}.
* @see BaseOptions.Builder#build()
*/
- protected BaseOptions(long timeout, Long streamId) {
+ protected BaseOptions(Duration timeout, Long streamId) {
this.timeout = timeout;
this.streamId = streamId;
}
@@ -60,7 +59,13 @@ public static Builder builder() {
*
* @return {@link BaseOptions#timeout} value in milliseconds.
*/
+ @Deprecated
public long getTimeout() {
+ return this.timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return this.timeout;
}
@@ -80,7 +85,7 @@ public static class Builder {
/**
* @see BaseOptions#timeout
*/
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/**
* @see BaseOptions#streamId
@@ -116,8 +121,42 @@ public static class Builder {
* @return {@link BaseOptions.Builder} object.
* @throws IllegalArgumentException when {@code timeout <= 0}.
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets the {@link BaseOptions#timeout} parameter when constructing an instance of a builder
+ * class. The following example creates a {@link BaseOptions} object with a specified {@link
+ * BaseOptions#timeout} parameter:
+ *
+ *
{@code
+ * BaseOptions options = BaseOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(2)) // OK!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * {@code
+ * BaseOptions options = BaseOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(-1L)) // Wrong! Throws exception!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * @param timeout see {@link BaseOptions#timeout} field.
+ * @return {@link BaseOptions.Builder} object.
+ * @throws IllegalArgumentException when {@code timeout <= 0}.
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/OnlyKeyValueOptions.java b/tarantool-client/src/main/java/io/tarantool/client/OnlyKeyValueOptions.java
index f525b375..a73e4f84 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/OnlyKeyValueOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/OnlyKeyValueOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client;
+import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -17,19 +18,16 @@ public class OnlyKeyValueOptions implements OptionsMap {
private static final Logger LOGGER = LoggerFactory.getLogger(OnlyKeyValueOptions.class);
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
* The time after which the request is considered invalid (in milliseconds).
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT} milliseconds.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -53,7 +51,12 @@ public class OnlyKeyValueOptions implements OptionsMap {
* @param options {@link #options}
* @see OnlyKeyValueOptions
*/
+ @Deprecated
public OnlyKeyValueOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ public OnlyKeyValueOptions(Duration timeout, Long streamId, Map options) {
this.options = options;
this.timeout = timeout;
@@ -75,8 +78,14 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
- return timeout;
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
+ return this.timeout;
}
/**
@@ -110,7 +119,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link OnlyKeyValueOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link OnlyKeyValueOptions#streamId}. */
private Long streamId;
@@ -124,8 +133,22 @@ public static class Builder {
* @see OnlyKeyValueOptions#timeout
* @see OnlyKeyValueOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see OnlyKeyValueOptions#timeout
+ * @see OnlyKeyValueOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/Options.java b/tarantool-client/src/main/java/io/tarantool/client/Options.java
index 13137a60..b780d0c3 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/Options.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/Options.java
@@ -5,6 +5,8 @@
package io.tarantool.client;
+import java.time.Duration;
+
/**
* Provides a contract for basic client options.
*
@@ -13,13 +15,24 @@
*/
public interface Options {
+ /** Default request timeout. */
+ Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
+
/**
* Returns timeout of operation.
*
* @return timeout value in milliseconds.
*/
+ @Deprecated
long getTimeout();
+ /**
+ * Returns timeout of operation.
+ *
+ * @return timeout value.
+ */
+ Duration timeout();
+
/**
* Returns stream id of operation.
*
diff --git a/tarantool-client/src/main/java/io/tarantool/client/box/options/DeleteOptions.java b/tarantool-client/src/main/java/io/tarantool/client/box/options/DeleteOptions.java
index 272280da..16d4058c 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/box/options/DeleteOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/box/options/DeleteOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.box.options;
+import java.time.Duration;
import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -34,18 +35,15 @@
*/
public class DeleteOptions implements OptionsWithIndex {
- /** Default {@link DeleteOptions#timeout} value. */
- public static final long DEFAULT_TIMEOUT = 5_000L;
-
/** Default {@link DeleteOptions#indexId} value. Primary index id has always 0. */
public static final int PRIMARY = 0;
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*/
- private final long timeout;
+ private final Duration timeout;
/**
* Stream id for delete operation.
@@ -77,7 +75,7 @@ public class DeleteOptions implements OptionsWithIndex {
* @param indexName see also: {@link DeleteOptions#indexName}.
* @see Builder#build()
*/
- private DeleteOptions(long timeout, Long streamId, int indexId, String indexName) {
+ private DeleteOptions(Duration timeout, Long streamId, int indexId, String indexName) {
this.timeout = timeout;
this.streamId = streamId;
this.indexId = indexId;
@@ -98,7 +96,14 @@ public static Builder builder() {
*
* @return {@link DeleteOptions#timeout} value in milliseconds.
*/
+ @Override
+ @Deprecated
public long getTimeout() {
+ return this.timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return this.timeout;
}
@@ -108,6 +113,7 @@ public long getTimeout() {
* @return null - if {@link DeleteOptions#streamId} is null, otherwise - {@link
* DeleteOptions#streamId} value.
*/
+ @Override
public Long getStreamId() {
return this.streamId;
}
@@ -136,7 +142,7 @@ public static class Builder {
/**
* @see DeleteOptions#timeout
*/
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/**
* @see DeleteOptions#streamId
@@ -182,8 +188,42 @@ public static class Builder {
* @return {@link Builder} object.
* @throws IllegalArgumentException when {@code timeout <= 0}.
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets the {@link DeleteOptions#timeout} parameter when constructing an instance of a builder
+ * class. The following example creates a {@link DeleteOptions} object with a specified {@link
+ * DeleteOptions#timeout} parameter:
+ *
+ *
{@code
+ * DeleteOptions options = DeleteOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(5)) // OK!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * {@code
+ * DeleteOptions options = DeleteOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(-1L)) // Wrong! Throws exception!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * @param timeout see {@link DeleteOptions#timeout} field.
+ * @return {@link Builder} object.
+ * @throws IllegalArgumentException when {@code timeout <= 0}.
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/box/options/OptionsWithIndex.java b/tarantool-client/src/main/java/io/tarantool/client/box/options/OptionsWithIndex.java
index d9a084d5..73a13544 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/box/options/OptionsWithIndex.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/box/options/OptionsWithIndex.java
@@ -5,6 +5,8 @@
package io.tarantool.client.box.options;
+import java.time.Duration;
+
/**
* Represents a contract for classes that implement options that work with the index.
*
@@ -16,6 +18,9 @@
*/
public interface OptionsWithIndex {
+ /** Default request timeout. */
+ Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
+
/**
* Returns the id of the index.
*
@@ -29,4 +34,14 @@ public interface OptionsWithIndex {
* @return index name.
*/
String getIndexName();
+
+ /** Returns stream id of operation. */
+ Long getStreamId();
+
+ /** Returns timeout of operation im milliseconds. */
+ @Deprecated
+ long getTimeout();
+
+ /** Returns timeout of operation. */
+ Duration timeout();
}
diff --git a/tarantool-client/src/main/java/io/tarantool/client/box/options/SelectOptions.java b/tarantool-client/src/main/java/io/tarantool/client/box/options/SelectOptions.java
index 8775cadf..9a614201 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/box/options/SelectOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/box/options/SelectOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.box.options;
+import java.time.Duration;
import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -42,9 +43,6 @@ public class SelectOptions implements OptionsWithIndex {
/** Default {@link SelectOptions#offset} value. */
public static final int DEFAULT_OFFSET = 0;
- /** Default {@link SelectOptions#timeout} value. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/** Default {@link SelectOptions#iterator} value. */
public static final BoxIterator DEFAULT_BOX_ITERATOR = BoxIterator.EQ;
@@ -52,11 +50,11 @@ public class SelectOptions implements OptionsWithIndex {
public static final int PRIMARY = 0;
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*/
- private final long timeout;
+ private final Duration timeout;
/**
* Stream id for select operation.
@@ -153,7 +151,7 @@ public class SelectOptions implements OptionsWithIndex {
* @see Builder#build()
*/
private SelectOptions(
- long timeout,
+ Duration timeout,
Long streamId,
int indexId,
String indexName,
@@ -187,7 +185,14 @@ public static Builder builder() {
*
* @return {@link SelectOptions#timeout} value in milliseconds.
*/
+ @Override
+ @Deprecated
public long getTimeout() {
+ return this.timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return this.timeout;
}
@@ -197,6 +202,7 @@ public long getTimeout() {
* @return null - if {@link SelectOptions#streamId} is null, otherwise - {@link
* SelectOptions#streamId} value.
*/
+ @Override
public Long getStreamId() {
return this.streamId;
}
@@ -271,7 +277,7 @@ public static class Builder {
/**
* @see SelectOptions#timeout
*/
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/**
* @see SelectOptions#streamId
@@ -342,8 +348,42 @@ public static class Builder {
* @return {@link SelectOptions.Builder} object.
* @throws IllegalArgumentException when {@code timeout <= 0}.
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets the {@link SelectOptions#timeout} parameter when constructing an instance of a builder
+ * class. The following example creates a {@link SelectOptions} object with a specified {@link
+ * SelectOptions#timeout} parameter:
+ *
+ *
{@code
+ * SelectOptions options = SelectOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(2)) // OK!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * {@code
+ * SelectOptions options = SelectOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(-1L)) // Wrong! Throws exception!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * @param timeout see {@link SelectOptions#timeout} field.
+ * @return {@link SelectOptions.Builder} object.
+ * @throws IllegalArgumentException when {@code timeout <= 0}.
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/box/options/UpdateOptions.java b/tarantool-client/src/main/java/io/tarantool/client/box/options/UpdateOptions.java
index 6f0e6f4e..2f01fffb 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/box/options/UpdateOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/box/options/UpdateOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.box.options;
+import java.time.Duration;
import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -37,15 +38,12 @@ public class UpdateOptions implements OptionsWithIndex {
/** Default {@link UpdateOptions#indexId} value. Primary index id has always 0. */
public static final int PRIMARY = 0;
- /** Default {@link UpdateOptions#timeout} value. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*/
- private final long timeout;
+ private final Duration timeout;
/**
* Stream id for update operation.
@@ -76,7 +74,7 @@ public class UpdateOptions implements OptionsWithIndex {
* @param indexId see also: {@link UpdateOptions#indexId}.
* @param indexName see also: {@link UpdateOptions#indexName}.
*/
- private UpdateOptions(long timeout, Long streamId, int indexId, String indexName) {
+ private UpdateOptions(Duration timeout, Long streamId, int indexId, String indexName) {
this.timeout = timeout;
this.streamId = streamId;
this.indexId = indexId;
@@ -97,7 +95,14 @@ public static Builder builder() {
*
* @return {@link UpdateOptions#timeout} value in milliseconds.
*/
+ @Override
+ @Deprecated
public long getTimeout() {
+ return this.timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return this.timeout;
}
@@ -107,6 +112,7 @@ public long getTimeout() {
* @return null - if {@link UpdateOptions#streamId} is null, otherwise - {@link
* UpdateOptions#streamId} value.
*/
+ @Override
public Long getStreamId() {
return this.streamId;
}
@@ -135,7 +141,7 @@ public static class Builder {
/**
* @see UpdateOptions#timeout
*/
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/**
* @see UpdateOptions#streamId
@@ -181,8 +187,42 @@ public static class Builder {
* @return {@link UpdateOptions.Builder} instance.
* @throws IllegalArgumentException when {@code timeout <= 0}.
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets the {@link UpdateOptions#timeout} parameter when constructing an instance of a builder
+ * class. The following example creates a {@link UpdateOptions} object with a specified {@link
+ * UpdateOptions#timeout} parameter:
+ *
+ *
{@code
+ * UpdateOptions options = UpdateOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(1)) // OK!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * {@code
+ * UpdateOptions options = UpdateOptions
+ * .builder()
+ * .withTimeout(Duration.ofSeconds(-11L)) // Wrong! Throws exception!
+ * .build();
+ *
+ *
+ *
+ * }
+ *
+ * @param timeout see {@link UpdateOptions#timeout} field.
+ * @return {@link UpdateOptions.Builder} instance.
+ * @throws IllegalArgumentException when {@code timeout <= 0}.
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/CountOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/CountOptions.java
index d328d4e8..ba6505bb 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/CountOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/CountOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -51,7 +52,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("mode", Mode.WRITE);
* put("timeout", 2_000L);
@@ -75,7 +76,7 @@
*
* Condition condition = Condition.create("==", "pk", 1);
* CountOptions options = CountOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withStreamId(null)
* .withCrudTimeout(2_000L)
* .withMode(Mode.WRITE)
@@ -155,19 +156,16 @@ public class CountOptions implements CrudOptions {
*/
private static final String VSHARD_ROUTER = "vshard_router";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -191,7 +189,20 @@ public class CountOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see CountOptions
*/
+ @Deprecated
public CountOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link CountOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see CountOptions
+ */
+ public CountOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -213,7 +224,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -248,7 +265,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link CountOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link CountOptions#streamId}. */
private Long streamId;
@@ -266,8 +283,22 @@ public Builder() {
* @see CountOptions#timeout
* @see CountOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) throws IllegalArgumentException {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see CountOptions#timeout
+ * @see CountOptions
+ */
+ public Builder withTimeout(Duration timeout) throws IllegalArgumentException {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/DeleteOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/DeleteOptions.java
index d895e042..eca6cddf 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/DeleteOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/DeleteOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -49,7 +50,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* // Determine which fields will be returned
@@ -78,7 +79,7 @@
* space.insert(Arrays.asList(1, true, "Vanya"));
*
* DeleteOptions options = DeleteOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withCrudTimeout(2_000L)
* .withFields("id", "name")
* .build();
@@ -133,19 +134,16 @@ public class DeleteOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -169,7 +167,20 @@ public class DeleteOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see DeleteOptions
*/
+ @Deprecated
public DeleteOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link DeleteOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see DeleteOptions
+ */
+ public DeleteOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -191,7 +202,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -226,7 +243,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link DeleteOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link DeleteOptions#streamId}. */
private Long streamId;
@@ -240,8 +257,22 @@ public static class Builder {
* @see DeleteOptions#timeout
* @see DeleteOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link DeleteOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see DeleteOptions#timeout
+ * @see DeleteOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isZero() || timeout.isNegative()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/GetOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/GetOptions.java
index 515b0721..624f4011 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/GetOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/GetOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -51,7 +52,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* // Determine which fields will be returned
@@ -80,7 +81,7 @@
* space.insert(Arrays.asList(1, true, "Vanya"));
*
* GetOptions options = GetOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withCrudTimeout(2_000L)
* .withFields("id", "name")
* .build();
@@ -148,19 +149,16 @@ public class GetOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -184,7 +182,20 @@ public class GetOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see GetOptions
*/
+ @Deprecated
public GetOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link GetOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see GetOptions
+ */
+ public GetOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -206,7 +217,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -241,7 +258,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link GetOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link GetOptions#streamId}. */
private Long streamId;
@@ -259,8 +276,22 @@ public Builder() {
* @see GetOptions#timeout
* @see GetOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link GetOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see GetOptions#timeout
+ * @see GetOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isZero() || timeout.isNegative()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertManyOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertManyOptions.java
index 1028bdf5..c24f1451 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertManyOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertManyOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -52,7 +53,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* // Determine which fields will be returned
@@ -79,7 +80,7 @@
*
* InsertManyOptions options = InsertManyOptions.builder()
* .withTimeout(3_000L)
- * .withCrudTimeout(2_000L)
+ * .withCrudTimeout(Duration.ofSeconds(2))
* .withFields("id", "name")
* .build();
*
@@ -158,19 +159,16 @@ public class InsertManyOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -194,7 +192,20 @@ public class InsertManyOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see InsertManyOptions
*/
+ @Deprecated
public InsertManyOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link InsertManyOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see InsertManyOptions
+ */
+ public InsertManyOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -216,7 +227,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -251,7 +268,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link InsertManyOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link InsertManyOptions#streamId}. */
private Long streamId;
@@ -265,8 +282,22 @@ public static class Builder {
* @see InsertManyOptions#timeout
* @see InsertManyOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link InsertManyOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see InsertManyOptions#timeout
+ * @see InsertManyOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isZero() || timeout.isNegative()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertOptions.java
index cb40ee77..3bd56c9a 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/InsertOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -142,19 +143,16 @@ public class InsertOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -178,7 +176,20 @@ public class InsertOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see InsertOptions
*/
+ @Deprecated
public InsertOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link InsertOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see InsertOptions
+ */
+ public InsertOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -200,7 +211,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -235,7 +252,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link InsertOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link InsertOptions#streamId}. */
private Long streamId;
@@ -249,8 +266,22 @@ public static class Builder {
* @see InsertOptions#timeout
* @see InsertOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link InsertOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see InsertOptions#timeout
+ * @see InsertOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/LenOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/LenOptions.java
index 5401d9c4..afdafa8c 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/LenOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/LenOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -43,7 +44,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* }};
@@ -68,7 +69,7 @@
* TarantoolCrudSpace space = crudClient.space("spaceName");
*
* LenOptions options = LenOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withCrudTimeout(2_000L)
* .build();
*
@@ -106,19 +107,16 @@ public class LenOptions implements CrudOptions {
*/
private static final String VSHARD_ROUTER = "vshard_router";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -142,7 +140,20 @@ public class LenOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see LenOptions
*/
+ @Deprecated
public LenOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link LenOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see LenOptions
+ */
+ public LenOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -165,6 +176,11 @@ public static Builder builder() {
*/
@Override
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -199,7 +215,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link LenOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link LenOptions#streamId}. */
private Long streamId;
@@ -213,8 +229,22 @@ public static class Builder {
* @see LenOptions#timeout
* @see LenOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link LenOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see LenOptions#timeout
+ * @see LenOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/MinMaxOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/MinMaxOptions.java
index cadda50f..d963192c 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/MinMaxOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/MinMaxOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -46,7 +47,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* }};
@@ -73,7 +74,7 @@
* TarantoolCrudSpace space = crudClient.space("spaceName");
*
* MinMaxOptions option = MinMaxOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withCrudTimeout(2_000L)
* .build();
*
@@ -117,19 +118,16 @@ public class MinMaxOptions implements CrudOptions {
*/
private static final String VSHARD_ROUTER = "vshard_router";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -153,7 +151,20 @@ public class MinMaxOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see MinMaxOptions
*/
+ @Deprecated
public MinMaxOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link MinMaxOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see MinMaxOptions
+ */
+ public MinMaxOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -175,7 +186,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -210,7 +227,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link MinMaxOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link MinMaxOptions#streamId}. */
private Long streamId;
@@ -224,8 +241,22 @@ public static class Builder {
* @see MinMaxOptions#timeout
* @see MinMaxOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link MinMaxOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see MinMaxOptions#timeout
+ * @see MinMaxOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isZero() || timeout.isNegative()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/SelectOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/SelectOptions.java
index 6148894c..9060bd66 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/SelectOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/SelectOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -57,7 +58,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* // Determine which fields will be returned
@@ -83,7 +84,7 @@
* TarantoolCrudSpace space = crudClient.space("spaceName");
*
* SelectOptions option = SelectOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withCrudTimeout(2_000L)
* .withFields("id", "name")
* .build();
@@ -188,19 +189,16 @@ public class SelectOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -227,7 +225,20 @@ public class SelectOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see SelectOptions
*/
+ @Deprecated
public SelectOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link SelectOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see SelectOptions
+ */
+ public SelectOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -249,7 +260,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -281,10 +298,10 @@ public Map getOptions() {
public static class Builder {
/** See also: {@link SelectOptions#crudOptions}. */
- private final Map options = new HashMap();
+ private final Map options = new HashMap<>();
/** See also: {@link SelectOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link SelectOptions#streamId}. */
private Long streamId;
@@ -303,8 +320,22 @@ public Builder() {
* @see SelectOptions#timeout
* @see SelectOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link SelectOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see SelectOptions#timeout
+ * @see SelectOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isZero() || timeout.isNegative()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/TruncateOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/TruncateOptions.java
index a062ca54..309b2de1 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/TruncateOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/TruncateOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -43,7 +44,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* }};
@@ -63,7 +64,7 @@
* TarantoolCrudSpace space = crudClient.space("spaceName");
*
* CountOptions options = CountOptions.builder()
- * .withTimeout(3_000L)
+ * .withTimeout(Duration.ofSeconds(3))
* .withStreamId(null)
* .withCrudTimeout(2_000L)
* .build();
@@ -98,19 +99,16 @@ public class TruncateOptions implements CrudOptions {
*/
private static final String VSHARD_ROUTER = "vshard_router";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for truncate operation.
@@ -134,7 +132,20 @@ public class TruncateOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see TruncateOptions
*/
+ @Deprecated
public TruncateOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link TruncateOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see TruncateOptions
+ */
+ public TruncateOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -156,7 +167,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -191,7 +208,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link TruncateOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link TruncateOptions#streamId}. */
private Long streamId;
@@ -205,8 +222,22 @@ public static class Builder {
* @see TruncateOptions#timeout
* @see TruncateOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) throws IllegalArgumentException {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link TruncateOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see TruncateOptions#timeout
+ * @see TruncateOptions
+ */
+ public Builder withTimeout(Duration timeout) throws IllegalArgumentException {
+ if (timeout.isZero() || timeout.isNegative()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpdateOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpdateOptions.java
index 797d8825..3cc4c361 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpdateOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpdateOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -49,7 +50,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* // Determine which fields will be returned
@@ -77,7 +78,7 @@
*
* SelectOptions option = SelectOptions.builder()
* .withTimeout(3_000L)
- * .withCrudTimeout(2_000L)
+ * .withCrudTimeout(Duration.ofSeconds(2))
* .withFields("id", "name")
* .build();
*
@@ -135,19 +136,16 @@ public class UpdateOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -171,7 +169,20 @@ public class UpdateOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see UpdateOptions
*/
+ @Deprecated
public UpdateOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link UpdateOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see UpdateOptions
+ */
+ public UpdateOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -193,7 +204,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -228,7 +245,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link UpdateOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link UpdateOptions#streamId}. */
private Long streamId;
@@ -242,8 +259,22 @@ public static class Builder {
* @see UpdateOptions#timeout
* @see UpdateOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link UpdateOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see UpdateOptions#timeout
+ * @see UpdateOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpsertManyOptions.java b/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpsertManyOptions.java
index ecf23885..e0a2c00b 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpsertManyOptions.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/crud/options/UpsertManyOptions.java
@@ -5,6 +5,7 @@
package io.tarantool.client.crud.options;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -51,7 +52,7 @@
* <>
*
* TarantoolCrudSpace space = crudClient.space("spaceName");
- * long timeout = 3_000L;
+ * Duration timeout = Duration.ofSeconds(3);
* Map options = new HashMap(){{
* put("timeout", 2_000L);
* // Determine which fields will be returned
@@ -86,7 +87,7 @@
*
* UpsertManyOptions option = UpsertManyOptions.builder()
* .withTimeout(3_000L)
- * .withCrudTimeout(2_000L)
+ * .withCrudTimeout(Duration.ofSeconds(2))
* .withFields("id", "name")
* .build();
*
@@ -160,19 +161,16 @@ public class UpsertManyOptions implements CrudOptions {
*/
private static final String FETCH_LATEST_METADATA = "fetch_latest_metadata";
- /** Default value for {@link #timeout}. */
- public static final long DEFAULT_TIMEOUT = 5_000;
-
/**
- * The time after which the request is considered invalid (in milliseconds).
+ * The time after which the request is considered invalid.
*
- * Default value: {@value #DEFAULT_TIMEOUT} milliseconds.
+ *
Default value: {@link #DEFAULT_TIMEOUT}.
*
*
Note: The time indicated by this parameter is the time between sending a
* message from the connector to Tarantool and the time when the answer will come from Tarantool
* to connector.
*/
- private final Long timeout;
+ private final Duration timeout;
/**
* Stream id for count operation.
@@ -196,7 +194,20 @@ public class UpsertManyOptions implements CrudOptions {
* @param options {@link #crudOptions}
* @see UpsertManyOptions
*/
+ @Deprecated
public UpsertManyOptions(Long timeout, Long streamId, Map options) {
+ this(Duration.ofMillis(timeout), streamId, options);
+ }
+
+ /**
+ * Creates a {@link UpsertManyOptions} object with the given parameters.
+ *
+ * @param timeout {@link #timeout}
+ * @param streamId {@link #streamId}
+ * @param options {@link #crudOptions}
+ * @see UpsertManyOptions
+ */
+ public UpsertManyOptions(Duration timeout, Long streamId, Map options) {
this.crudOptions = options;
this.timeout = timeout;
@@ -218,7 +229,13 @@ public static Builder builder() {
* @return {@link #timeout} value.
*/
@Override
+ @Deprecated
public long getTimeout() {
+ return timeout.toMillis();
+ }
+
+ @Override
+ public Duration timeout() {
return timeout;
}
@@ -253,7 +270,7 @@ public static class Builder {
private final Map options = new HashMap<>();
/** See also: {@link UpsertManyOptions#timeout}. */
- private long timeout = DEFAULT_TIMEOUT;
+ private Duration timeout = DEFAULT_TIMEOUT;
/** See also: {@link UpsertManyOptions#streamId}. */
private Long streamId;
@@ -267,8 +284,22 @@ public static class Builder {
* @see UpsertManyOptions#timeout
* @see UpsertManyOptions
*/
+ @Deprecated
public Builder withTimeout(long timeout) {
- if (timeout <= 0) {
+ return withTimeout(Duration.ofMillis(timeout));
+ }
+
+ /**
+ * Sets value of {@link #timeout} option. Timeout parameter should be greater than 0.
+ *
+ * @param timeout value of timeout option.
+ * @return {@link UpsertManyOptions.Builder} object.
+ * @throws IllegalArgumentException when timeout ≤ 0.
+ * @see UpsertManyOptions#timeout
+ * @see UpsertManyOptions
+ */
+ public Builder withTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
this.timeout = timeout;
diff --git a/tarantool-client/src/main/java/io/tarantool/client/factory/IProtoCallClusterSpace.java b/tarantool-client/src/main/java/io/tarantool/client/factory/IProtoCallClusterSpace.java
index 02d4e6f6..e2e22a77 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/factory/IProtoCallClusterSpace.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/factory/IProtoCallClusterSpace.java
@@ -78,7 +78,7 @@ public CompletableFuture iprotoCall(
TarantoolJacksonMapping.toValue(withSpaceName(args)),
null,
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId())));
}
diff --git a/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolBoxSpaceImpl.java b/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolBoxSpaceImpl.java
index 7e3ebdbc..d8b1d051 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolBoxSpaceImpl.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolBoxSpaceImpl.java
@@ -441,7 +441,7 @@ private CompletableFuture iprotoUpsert(
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId());
int indexId;
@@ -496,7 +496,7 @@ private CompletableFuture iprotoUpdate(
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId());
Integer indexId;
@@ -548,7 +548,7 @@ private CompletableFuture iprotoDelete(List> key, DeleteOption
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId());
Integer indexId;
@@ -613,7 +613,7 @@ private CompletableFuture iprotoSelect(List> key, SelectOption
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId());
Integer indexId;
@@ -673,7 +673,7 @@ private CompletableFuture iprotoReplace(Object tuple, Options op
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId());
if (fetcher == null) {
@@ -715,7 +715,7 @@ private CompletableFuture iprotoInsert(Object tuple, Options opt
client -> {
final IProtoRequestOpts requestOpts =
IProtoRequestOpts.empty()
- .withRequestTimeout(options.getTimeout())
+ .withRequestTimeout(options.timeout())
.withStreamId(options.getStreamId());
if (fetcher == null) {
diff --git a/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolClientImpl.java b/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolClientImpl.java
index d4a1a679..aeb8c3e3 100644
--- a/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolClientImpl.java
+++ b/tarantool-client/src/main/java/io/tarantool/client/factory/TarantoolClientImpl.java
@@ -168,7 +168,7 @@ protected TarantoolClientImpl(
*/
private IProtoRequestOpts convertOptions(Options opts) {
return IProtoRequestOpts.empty()
- .withRequestTimeout(opts.getTimeout())
+ .withRequestTimeout(opts.timeout())
.withStreamId(opts.getStreamId());
}
diff --git a/tarantool-client/src/test/java/io/tarantool/client/OptionsTest.java b/tarantool-client/src/test/java/io/tarantool/client/OptionsTest.java
index dc4b7cac..9e4bf6cd 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/OptionsTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/OptionsTest.java
@@ -47,10 +47,10 @@ public void testDefaultIndexId() {
public static Stream dataForDefaultTimeout() {
return Stream.of(
- Arguments.of(BaseOptions.builder().build().getTimeout()),
- Arguments.of(SelectOptions.builder().build().getTimeout()),
- Arguments.of(DeleteOptions.builder().build().getTimeout()),
- Arguments.of(UpdateOptions.builder().build().getTimeout()));
+ Arguments.of(BaseOptions.builder().build().timeout()),
+ Arguments.of(SelectOptions.builder().build().timeout()),
+ Arguments.of(DeleteOptions.builder().build().timeout()),
+ Arguments.of(UpdateOptions.builder().build().timeout()));
}
@ParameterizedTest
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java
index 778c8055..b73a146e 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolBoxClientTest.java
@@ -7,6 +7,7 @@
import java.io.Serializable;
import java.lang.reflect.Field;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -331,7 +332,7 @@ public void testCallTimeoutWithIgnoredPacketsHandler() throws Exception {
})
.build();
- Options options = BaseOptions.builder().withTimeout(1_000L).build();
+ Options options = BaseOptions.builder().withTimeout(Duration.ofSeconds(1)).build();
Exception ex =
assertThrows(
CompletionException.class,
@@ -1871,7 +1872,7 @@ public void testOpenTelemetryTracingWithJaeger() throws Exception {
System.out.println("Sent successful request trace to Jaeger");
// Test timeout scenario
- Options timeoutOptions = BaseOptions.builder().withTimeout(100L).build();
+ Options timeoutOptions = BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build();
Exception ex =
assertThrows(
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java
index b87b724a..34b39f5f 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolClientTest.java
@@ -5,6 +5,7 @@
package io.tarantool.client.integration;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -139,7 +140,10 @@ public void testCallWithArgsAndOpts() {
List> input = Arrays.asList(2, null, "IvanD");
Object output =
client
- .call("echo_with_wrapping", input, BaseOptions.builder().withTimeout(100).build())
+ .call(
+ "echo_with_wrapping",
+ input,
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build())
.join()
.get();
assertEquals(Collections.singletonList(input), output);
@@ -150,7 +154,7 @@ public void testCallWithArgsAndOpts() {
.call(
"echo_with_wrapping",
input,
- BaseOptions.builder().withTimeout(100).build(),
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build(),
Person.class)
.join()
.get();
@@ -163,7 +167,7 @@ public void testCallWithArgsAndOpts() {
"echo_with_wrapping",
input,
null,
- BaseOptions.builder().withTimeout(100).build(),
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build(),
new TypeReference>() {})
.join()
.get();
@@ -175,7 +179,7 @@ public void testCallWithArgsAndOpts() {
"echo",
input,
null,
- BaseOptions.builder().withTimeout(100).build(),
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build(),
new TypeReference() {})
.join()
.get();
@@ -229,7 +233,10 @@ public void testEvalWithArgsAndOpts() {
List> input = Arrays.asList(2, null, "IvanD");
Object output =
client
- .eval("return {...}", input, BaseOptions.builder().withTimeout(100).build())
+ .eval(
+ "return {...}",
+ input,
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build())
.join()
.get();
assertEquals(Collections.singletonList(input), output);
@@ -238,7 +245,10 @@ public void testEvalWithArgsAndOpts() {
output =
client
.eval(
- "return {...}", input, BaseOptions.builder().withTimeout(100).build(), Person.class)
+ "return {...}",
+ input,
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build(),
+ Person.class)
.join()
.get();
assertEquals(Collections.singletonList(new Person(2, null, "IvanD")), output);
@@ -250,7 +260,7 @@ public void testEvalWithArgsAndOpts() {
"return {...}",
input,
null,
- BaseOptions.builder().withTimeout(100).build(),
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build(),
new TypeReference>() {})
.join()
.get();
@@ -262,7 +272,7 @@ public void testEvalWithArgsAndOpts() {
"return ...",
input,
null,
- BaseOptions.builder().withTimeout(100).build(),
+ BaseOptions.builder().withTimeout(Duration.ofMillis(100)).build(),
new TypeReference() {})
.join()
.get();
diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java
index 2763380e..47f07701 100644
--- a/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java
+++ b/tarantool-client/src/test/java/io/tarantool/client/integration/TarantoolCrudClientTest.java
@@ -224,7 +224,7 @@ public void truncateSpaces() throws Exception {
public void testCallTimeoutWithIgnoredPacketsHandler() throws Exception {
clusterContainer.executeCommand("return crud_aux.slow_api()");
TarantoolCrudSpace person = client.space("person");
- Options options = BaseOptions.builder().withTimeout(1_000L).build();
+ Options options = BaseOptions.builder().withTimeout(Duration.ofSeconds(1)).build();
Exception ex =
assertThrows(
CompletionException.class,
@@ -1052,7 +1052,7 @@ public static Stream prepareForTestUpsertObject(
Collections.singletonList(Arrays.asList("=", updField, newFieldValue));
final Operations operationsAsClass = Operations.create().set(updField, newFieldValue);
- final Options options = BaseOptions.builder().withTimeout(3_000L).build();
+ final Options options = BaseOptions.builder().withTimeout(Duration.ofSeconds(3)).build();
final UpdateOptions updateOptions = UpdateOptions.builder().build();
return Stream.of(
@@ -1128,7 +1128,7 @@ public static Stream dataForTestUpsertObjectMany() {
.collect(Collectors.toList());
final List> operations = Collections.singletonList(Arrays.asList("=", "name", "Kolya"));
- final Options options = BaseOptions.builder().withTimeout(3_000L).build();
+ final Options options = BaseOptions.builder().withTimeout(Duration.ofSeconds(3)).build();
final UpsertManyOptions upsertManyOptions = UpsertManyOptions.builder().build();
final Operations operationsAsClass = Operations.create().set("name", "Kolya");
final Supplier>> selectSupplier =
@@ -1422,7 +1422,7 @@ public void testUpsert() {
Person oldPerson = new Person(0, true, "1");
Person newPerson = new Person(1, true, "2");
- Options options = BaseOptions.builder().withTimeout(2_000).build();
+ Options options = BaseOptions.builder().withTimeout(Duration.ofSeconds(2)).build();
Executable checkPersons =
() -> {
@@ -1548,7 +1548,8 @@ public void testUpsertMany() {
new Person(2, true, "Second"),
new Person(3, true, "Third"),
new Person(4, true, "Fourth"));
- UpsertManyOptions options = UpsertManyOptions.builder().withTimeout(2_000).build();
+ UpsertManyOptions options =
+ UpsertManyOptions.builder().withTimeout(Duration.ofSeconds(2_000)).build();
List> batchOpsAsList =
persons.stream()
.map(
diff --git a/tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java b/tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java
index b248c732..2e5bc2e0 100644
--- a/tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java
+++ b/tarantool-core/src/main/java/io/tarantool/core/IProtoClientImpl.java
@@ -6,6 +6,7 @@
package io.tarantool.core;
import java.net.InetSocketAddress;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -78,7 +79,7 @@ public class IProtoClientImpl implements IProtoClient {
public static final IProtoAuth.AuthType DEFAULT_AUTH_TYPE = IProtoAuth.AuthType.CHAP_SHA1;
public static final IProtoRequestOpts DEFAULT_REQUEST_OPTS =
- IProtoRequestOpts.empty().withRequestTimeout(5000);
+ IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(5));
public static final WatcherOptions DEFAULT_WATCHER_OPTS = WatcherOptions.builder().build();
private static final Set FEATURES_SET_ENUM = EnumSet.allOf(IProtoFeature.class);
private static final List FEATURES_LIST_INT =
@@ -297,7 +298,7 @@ public CompletableFuture select(
offset,
iterator.getCode(),
key,
- opts.getStreamId(),
+ opts.streamId(),
fetchPosition,
after,
afterMode),
@@ -328,7 +329,7 @@ public CompletableFuture select(
offset,
iterator.getCode(),
key,
- opts.getStreamId(),
+ opts.streamId(),
fetchPosition,
after,
afterMode),
@@ -348,13 +349,13 @@ public CompletableFuture insert(int spaceId, byte[] tuple) {
@Override
public CompletableFuture insert(
Integer spaceId, String spaceName, ArrayValue tuple, IProtoRequestOpts opts) {
- return runRequest(new IProtoInsert(spaceId, spaceName, tuple, opts.getStreamId()), opts);
+ return runRequest(new IProtoInsert(spaceId, spaceName, tuple, opts.streamId()), opts);
}
@Override
public CompletableFuture insert(
Integer spaceId, String spaceName, byte[] tuple, IProtoRequestOpts opts) {
- return runRequest(new IProtoInsert(spaceId, spaceName, tuple, opts.getStreamId()), opts);
+ return runRequest(new IProtoInsert(spaceId, spaceName, tuple, opts.streamId()), opts);
}
@Override
@@ -370,13 +371,13 @@ public CompletableFuture replace(int spaceId, byte[] tuple) {
@Override
public CompletableFuture replace(
Integer spaceId, String spaceName, ArrayValue tuple, IProtoRequestOpts opts) {
- return runRequest(new IProtoReplace(spaceId, spaceName, tuple, opts.getStreamId()), opts);
+ return runRequest(new IProtoReplace(spaceId, spaceName, tuple, opts.streamId()), opts);
}
@Override
public CompletableFuture replace(
Integer spaceId, String spaceName, byte[] tuple, IProtoRequestOpts opts) {
- return runRequest(new IProtoReplace(spaceId, spaceName, tuple, opts.getStreamId()), opts);
+ return runRequest(new IProtoReplace(spaceId, spaceName, tuple, opts.streamId()), opts);
}
@Override
@@ -398,7 +399,7 @@ public CompletableFuture delete(
ArrayValue key,
IProtoRequestOpts opts) {
return runRequest(
- new IProtoDelete(spaceId, spaceName, indexId, indexName, key, opts.getStreamId()), opts);
+ new IProtoDelete(spaceId, spaceName, indexId, indexName, key, opts.streamId()), opts);
}
@Override
@@ -410,7 +411,7 @@ public CompletableFuture delete(
byte[] key,
IProtoRequestOpts opts) {
return runRequest(
- new IProtoDelete(spaceId, spaceName, indexId, indexName, key, opts.getStreamId()), opts);
+ new IProtoDelete(spaceId, spaceName, indexId, indexName, key, opts.streamId()), opts);
}
@Override
@@ -435,8 +436,7 @@ public CompletableFuture update(
ArrayValue operations,
IProtoRequestOpts opts) {
return runRequest(
- new IProtoUpdate(
- spaceId, spaceName, indexId, indexName, key, operations, opts.getStreamId()),
+ new IProtoUpdate(spaceId, spaceName, indexId, indexName, key, operations, opts.streamId()),
opts);
}
@@ -450,8 +450,7 @@ public CompletableFuture update(
byte[] operations,
IProtoRequestOpts opts) {
return runRequest(
- new IProtoUpdate(
- spaceId, spaceName, indexId, indexName, key, operations, opts.getStreamId()),
+ new IProtoUpdate(spaceId, spaceName, indexId, indexName, key, operations, opts.streamId()),
opts);
}
@@ -476,7 +475,7 @@ public CompletableFuture upsert(
ArrayValue operations,
IProtoRequestOpts opts) {
return runRequest(
- new IProtoUpsert(spaceId, spaceName, indexBaseId, tuple, operations, opts.getStreamId()),
+ new IProtoUpsert(spaceId, spaceName, indexBaseId, tuple, operations, opts.streamId()),
opts);
}
@@ -489,7 +488,7 @@ public CompletableFuture upsert(
byte[] operations,
IProtoRequestOpts opts) {
return runRequest(
- new IProtoUpsert(spaceId, spaceName, indexBaseId, tuple, operations, opts.getStreamId()),
+ new IProtoUpsert(spaceId, spaceName, indexBaseId, tuple, operations, opts.streamId()),
opts);
}
@@ -506,13 +505,13 @@ public CompletableFuture call(String function, byte[] args) {
@Override
public CompletableFuture call(
String function, ArrayValue args, IProtoRequestOpts opts) {
- return runRequest(new IProtoCall(function, args, opts.getStreamId()), opts);
+ return runRequest(new IProtoCall(function, args, opts.streamId()), opts);
}
@Override
public CompletableFuture call(
String function, byte[] args, byte[] formats, IProtoRequestOpts opts) {
- return runRequest(new IProtoCall(function, args, formats, opts.getStreamId()), opts);
+ return runRequest(new IProtoCall(function, args, formats, opts.streamId()), opts);
}
@Override
@@ -528,13 +527,13 @@ public CompletableFuture eval(String expression, byte[] args) {
@Override
public CompletableFuture eval(
String expression, ArrayValue args, IProtoRequestOpts opts) {
- return runRequest(new IProtoEval(expression, args, opts.getStreamId()), opts);
+ return runRequest(new IProtoEval(expression, args, opts.streamId()), opts);
}
@Override
public CompletableFuture eval(
String expression, byte[] args, byte[] formats, IProtoRequestOpts opts) {
- return runRequest(new IProtoEval(expression, args, formats, opts.getStreamId()), opts);
+ return runRequest(new IProtoEval(expression, args, formats, opts.streamId()), opts);
}
@Override
@@ -589,13 +588,13 @@ public CompletableFuture execute(
@Override
public CompletableFuture execute(
long statementId, ArrayValue sqlBind, ArrayValue options, IProtoRequestOpts opts) {
- return runRequest(new IProtoExecute(statementId, sqlBind, options, opts.getStreamId()), opts);
+ return runRequest(new IProtoExecute(statementId, sqlBind, options, opts.streamId()), opts);
}
@Override
public CompletableFuture execute(
long statementId, byte[] sqlBind, byte[] options, IProtoRequestOpts opts) {
- return runRequest(new IProtoExecute(statementId, sqlBind, options, opts.getStreamId()), opts);
+ return runRequest(new IProtoExecute(statementId, sqlBind, options, opts.streamId()), opts);
}
@Override
@@ -613,13 +612,13 @@ public CompletableFuture execute(
@Override
public CompletableFuture execute(
String statementText, ArrayValue sqlBind, ArrayValue options, IProtoRequestOpts opts) {
- return runRequest(new IProtoExecute(statementText, sqlBind, options, opts.getStreamId()), opts);
+ return runRequest(new IProtoExecute(statementText, sqlBind, options, opts.streamId()), opts);
}
@Override
public CompletableFuture execute(
String statementText, byte[] sqlBind, byte[] options, IProtoRequestOpts opts) {
- return runRequest(new IProtoExecute(statementText, sqlBind, options, opts.getStreamId()), opts);
+ return runRequest(new IProtoExecute(statementText, sqlBind, options, opts.streamId()), opts);
}
@Override
@@ -639,7 +638,7 @@ public CompletableFuture prepare(String statementText) {
@Override
public CompletableFuture prepare(String statementText, IProtoRequestOpts opts) {
- return runRequest(new IProtoPrepare(statementText, opts.getStreamId()), opts);
+ return runRequest(new IProtoPrepare(statementText, opts.streamId()), opts);
}
@Override
diff --git a/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoRequestOpts.java b/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoRequestOpts.java
index afde22ef..572d5500 100644
--- a/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoRequestOpts.java
+++ b/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoRequestOpts.java
@@ -5,28 +5,43 @@
package io.tarantool.core.protocol;
+import java.time.Duration;
import java.util.function.Consumer;
public class IProtoRequestOpts {
private Consumer pushHandler;
private Handlers handlers;
- private long requestTimeoutMs;
+ private Duration requestTimeout = Duration.ofSeconds(3);
private Long streamId;
- private IProtoRequestOpts() {
- requestTimeoutMs = 3_000L;
- }
+ private IProtoRequestOpts() {}
public static IProtoRequestOpts empty() {
return new IProtoRequestOpts();
}
+ /** Use {@link #withRequestTimeout(Duration)} instead this. */
+ @Deprecated
public IProtoRequestOpts withRequestTimeout(long timeoutMs) {
if (timeoutMs <= 0) {
throw new IllegalArgumentException("timeout should be greater than 0");
}
- this.requestTimeoutMs = timeoutMs;
+ this.requestTimeout = Duration.ofMillis(timeoutMs);
+ return this;
+ }
+
+ /**
+ * Set up request timeout.
+ *
+ * @param timeout request timeout. Not null.
+ */
+ public IProtoRequestOpts withRequestTimeout(Duration timeout) {
+ if (timeout.isNegative() || timeout.isZero()) {
+ throw new IllegalArgumentException("timeout should be positive and greater 0");
+ }
+
+ this.requestTimeout = timeout;
return this;
}
@@ -35,6 +50,11 @@ public IProtoRequestOpts withPushHandler(Consumer callback) {
return this;
}
+ /**
+ * Set up stream id.
+ *
+ * @param streamId stream id. Must be not null and greater or equal than 0.
+ */
public IProtoRequestOpts withStreamId(Long streamId) {
if (streamId != null && streamId < 0) {
throw new IllegalArgumentException("streamId should be greater or equal 0");
@@ -43,24 +63,48 @@ public IProtoRequestOpts withStreamId(Long streamId) {
return this;
}
+ public IProtoRequestOpts withHandlers(Handlers handlers) {
+ this.handlers = handlers;
+ return this;
+ }
+
+ /** Use {@link #requestTimeout()} instead this. */
+ @Deprecated
public long getRequestTimeout() {
- return this.requestTimeoutMs;
+ return this.requestTimeout.toMillis();
}
+ public Duration requestTimeout() {
+ return this.requestTimeout;
+ }
+
+ /** Use {@link #streamId()} instead this. */
+ @Deprecated
public Long getStreamId() {
return this.streamId;
}
+ public Long streamId() {
+ return this.streamId;
+ }
+
+ /** Use {@link #pushHandler()} instead this. */
+ @Deprecated
public Consumer getPushHandler() {
return this.pushHandler;
}
- public IProtoRequestOpts withHandlers(Handlers handlers) {
- this.handlers = handlers;
- return this;
+ public Consumer pushHandler() {
+ return this.pushHandler;
}
+ /** Use {@link #handlers()} instead this. */
+ @Deprecated
public Handlers getHandlers() {
return this.handlers;
}
+
+ public Handlers handlers() {
+ return this.handlers;
+ }
}
diff --git a/tarantool-core/src/main/java/io/tarantool/core/protocol/fsm/RequestStateMachine.java b/tarantool-core/src/main/java/io/tarantool/core/protocol/fsm/RequestStateMachine.java
index 0ce8f1f4..f0337ff6 100644
--- a/tarantool-core/src/main/java/io/tarantool/core/protocol/fsm/RequestStateMachine.java
+++ b/tarantool-core/src/main/java/io/tarantool/core/protocol/fsm/RequestStateMachine.java
@@ -5,6 +5,7 @@
package io.tarantool.core.protocol.fsm;
+import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -30,7 +31,7 @@ public class RequestStateMachine extends AbstractIProtoStateMachine {
private final Consumer pushConsumer;
private final Handlers handlers;
private final Timer timerService;
- private final long timeout;
+ private final Duration timeout;
private final CompletableFuture promise;
private Timeout timer;
@@ -45,10 +46,10 @@ public RequestStateMachine(
Handlers requestHandlers) {
super(connection, request, fsmRegistry);
request.setSyncId(syncId);
- this.pushConsumer = opts.getPushHandler();
+ this.pushConsumer = opts.pushHandler();
this.handlers = requestHandlers;
this.timerService = timerService;
- this.timeout = opts.getRequestTimeout();
+ this.timeout = opts.requestTimeout();
this.promise = promise;
fsmRegistry.put(syncId, this);
}
@@ -119,12 +120,13 @@ public void kill(Throwable ex) {
promise.completeExceptionally(ex);
}
- private Timeout runAfter(long after, Runnable cb) {
- if (after == 0) {
+ private Timeout runAfter(Duration after, Runnable cb) {
+ if (after.isZero()) {
cb.run();
return null;
}
- return timerService.newTimeout(timeoutHandler -> cb.run(), after, TimeUnit.MILLISECONDS);
+ return timerService.newTimeout(
+ timeoutHandler -> cb.run(), after.toNanos(), TimeUnit.NANOSECONDS);
}
}
diff --git a/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java b/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java
index f6ca2476..c1f57c8c 100644
--- a/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java
+++ b/tarantool-core/src/test/java/io/tarantool/core/integration/IProtoClientTest.java
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -82,7 +83,7 @@
public class IProtoClientTest extends BaseTest {
private static final IProtoRequestOpts DEFAULT_REQUEST_OPTS =
- IProtoRequestOpts.empty().withRequestTimeout(5000);
+ IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(5));
private static TarantoolContainer> tt;
private static int spaceAId;
private static int spaceBId;
@@ -1687,7 +1688,7 @@ public void testCallTimeout() throws Exception {
client.authorize(API_USER, CREDS.get(API_USER)).join();
ArrayValue args =
ValueFactory.newArray(ValueFactory.newString("one"), ValueFactory.newInteger(1));
- IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1));
CompletableFuture future = client.call("slow_echo", args, opts);
Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
@@ -1707,7 +1708,7 @@ public void testCallTimeoutWithIgnoredPacketsHandler() throws Exception {
client.onIgnoredPacket(packet -> ignoredPackets.put(packet.getSyncId(), packet));
ArrayValue args =
ValueFactory.newArray(ValueFactory.newString("one"), ValueFactory.newInteger(1));
- IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1));
CompletableFuture future = client.call("slow_echo", args, opts);
Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
@@ -1732,7 +1733,7 @@ public void testRawCallTimeout() throws Exception {
ArrayValue args =
ValueFactory.newArray(ValueFactory.newString("one"), ValueFactory.newInteger(1));
byte[] rawArgs = ArrayValueToBytes(args);
- IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1000));
CompletableFuture future = client.call("slow_echo", rawArgs, null, opts);
Exception ex = assertThrows(CompletionException.class, future::join);
Throwable cause = ex.getCause();
@@ -1745,7 +1746,7 @@ public void testCallNoTimeout() throws Exception {
client.authorize(API_USER, CREDS.get(API_USER)).join();
ArrayValue args =
ValueFactory.newArray(ValueFactory.newString("one"), ValueFactory.newInteger(1));
- IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1));
IProtoMessage message = client.call("nonslow_echo", args, opts).get();
checkMessageHeader(message, IPROTO_OK, 4);
assertEquals(args, message.getBodyArrayValue(IPROTO_DATA));
@@ -1758,7 +1759,7 @@ public void testRawCallNoTimeout() throws Exception {
ArrayValue args =
ValueFactory.newArray(ValueFactory.newString("one"), ValueFactory.newInteger(1));
byte[] rawArgs = ArrayValueToBytes(args);
- IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1000));
IProtoMessage message = client.call("nonslow_echo", rawArgs, null, opts).get();
checkMessageHeader(message, IPROTO_OK, 4);
assertEquals(args, message.getBodyArrayValue(IPROTO_DATA));
diff --git a/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/benchmark/CustomBenchmarkRunner.java b/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/benchmark/CustomBenchmarkRunner.java
index 18b3d52f..1069487e 100644
--- a/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/benchmark/CustomBenchmarkRunner.java
+++ b/tarantool-jackson-mapping/src/test/java/io/tarantool/mapping/benchmark/CustomBenchmarkRunner.java
@@ -6,6 +6,7 @@
package io.tarantool.mapping.benchmark;
import java.net.InetSocketAddress;
+import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
@@ -139,7 +140,7 @@ public static Boolean simpleCallAndJacksonMapping(
"return return_one_tuple()",
STUB_ARGS,
null,
- IProtoRequestOpts.empty().withRequestTimeout(2_000))
+ IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(2)))
.thenApply(TarantoolJacksonMapping::readResponse));
}
diff --git a/tarantool-pooling/src/main/java/io/tarantool/pool/PoolEntry.java b/tarantool-pooling/src/main/java/io/tarantool/pool/PoolEntry.java
index a1e0067f..2024357a 100644
--- a/tarantool-pooling/src/main/java/io/tarantool/pool/PoolEntry.java
+++ b/tarantool-pooling/src/main/java/io/tarantool/pool/PoolEntry.java
@@ -5,6 +5,7 @@
package io.tarantool.pool;
+import java.time.Duration;
import java.util.ArrayDeque;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -48,7 +49,7 @@ final class PoolEntry {
* @see io.tarantool.core.protocol.IProtoRequestOpts
*/
private static final IProtoRequestOpts firstPingOpts =
- IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1));
/** Logger instance. */
private static final Logger log = LoggerFactory.getLogger(PoolEntry.class);
@@ -262,7 +263,8 @@ public PoolEntry(
} else {
this.heartbeatOpts = heartbeatOpts;
this.heartbeatPingOpts =
- IProtoRequestOpts.empty().withRequestTimeout(heartbeatOpts.getPingInterval());
+ IProtoRequestOpts.empty()
+ .withRequestTimeout(Duration.ofSeconds(heartbeatOpts.getPingInterval()));
this.deathThreshold = heartbeatOpts.getDeathThreshold();
this.failedPingsThreshold = heartbeatOpts.getInvalidationThreshold();
this.windowSize = heartbeatOpts.getWindowSize();
diff --git a/tarantool-pooling/src/test/java/io/tarantool/pool/integration/ConnectionPoolTest.java b/tarantool-pooling/src/test/java/io/tarantool/pool/integration/ConnectionPoolTest.java
index b98015b5..2830bba1 100644
--- a/tarantool-pooling/src/test/java/io/tarantool/pool/integration/ConnectionPoolTest.java
+++ b/tarantool-pooling/src/test/java/io/tarantool/pool/integration/ConnectionPoolTest.java
@@ -5,6 +5,7 @@
package io.tarantool.pool.integration;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -584,7 +585,7 @@ public void testRequestsWithIgnoredPacketsHandler() throws Exception {
.withTag("node-b")
.build()));
- IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(1000);
+ IProtoRequestOpts opts = IProtoRequestOpts.empty().withRequestTimeout(Duration.ofSeconds(1));
ArrayValue args =
ValueFactory.newArray(ValueFactory.newString("one"), ValueFactory.newInteger(1));
List> futures = new ArrayList<>();