From 439e105d05107f7220ee2a19aeb55af4c074ee55 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 21 Nov 2024 14:44:13 -0500 Subject: [PATCH 1/5] feat: introduce `java.time` variables and methods --- .../executor/spanner/CloudClientExecutor.java | 14 +- .../java/com/google/cloud/spanner/Clock.java | 2 +- .../google/cloud/spanner/CompositeTracer.java | 3 +- .../cloud/spanner/GrpcStreamIterator.java | 5 +- .../com/google/cloud/spanner/LatencyTest.java | 4 +- .../MultiplexedSessionDatabaseClient.java | 2 +- .../cloud/spanner/OpenTelemetryApiTracer.java | 16 +- .../com/google/cloud/spanner/Operation.java | 8 +- .../spanner/PartitionedDmlTransaction.java | 4 +- .../com/google/cloud/spanner/SessionImpl.java | 4 +- .../com/google/cloud/spanner/SessionPool.java | 6 +- .../cloud/spanner/SessionPoolOptions.java | 90 +++++-- .../cloud/spanner/SessionReference.java | 2 +- .../SpannerCloudMonitoringExporter.java | 6 +- .../com/google/cloud/spanner/SpannerImpl.java | 2 +- .../google/cloud/spanner/SpannerOptions.java | 236 ++++++++++++++---- .../cloud/spanner/SpannerRetryHelper.java | 6 +- .../connection/AbstractBaseUnitOfWork.java | 2 +- .../spanner/connection/ConnectionImpl.java | 2 +- .../connection/LocalConnectionChecker.java | 4 +- .../spanner/connection/StatementExecutor.java | 20 +- .../cloud/spanner/spi/v1/GapicSpannerRpc.java | 19 +- .../cloud/spanner/spi/v1/SpannerRpc.java | 2 +- .../spanner/BatchCreateSessionsSlowTest.java | 10 +- .../CloseSpannerWithOpenResultSetTest.java | 6 +- .../cloud/spanner/CompositeTracerTest.java | 12 +- .../spanner/DatabaseAdminClientTest.java | 44 ++-- .../cloud/spanner/DatabaseAdminGaxTest.java | 22 +- .../cloud/spanner/DatabaseClientImplTest.java | 46 ++-- .../cloud/spanner/DefaultBenchmark.java | 2 +- .../com/google/cloud/spanner/FakeClock.java | 2 +- .../cloud/spanner/GrpcResultSetTest.java | 4 +- .../cloud/spanner/InstanceAdminGaxTest.java | 22 +- .../spanner/LongRunningSessionsBenchmark.java | 4 +- .../MockDatabaseAdminServiceImplTest.java | 32 +-- .../cloud/spanner/MockSpannerServiceImpl.java | 2 +- ...edSessionDatabaseClientMockServerTest.java | 2 +- .../MultiplexedSessionDatabaseClientTest.java | 2 +- .../spanner/MultiplexedSessionsBenchmark.java | 2 +- .../spanner/OpenCensusApiTracerTest.java | 12 +- .../spanner/OpenTelemetryApiTracerTest.java | 12 +- ...OpenTelemetryBuiltInMetricsTracerTest.java | 10 +- .../cloud/spanner/OpenTelemetrySpanTest.java | 4 +- .../google/cloud/spanner/OperationTest.java | 10 +- .../PartitionedDmlTransactionTest.java | 2 +- ...yOnDifferentGrpcChannelMockServerTest.java | 16 +- .../cloud/spanner/SamplesMockServerTest.java | 12 +- .../SessionPoolMaintainerBenchmark.java | 4 +- .../SessionPoolMaintainerMockServerTest.java | 4 +- .../cloud/spanner/SessionPoolOptionsTest.java | 19 +- .../google/cloud/spanner/SessionPoolTest.java | 16 +- .../cloud/spanner/SpanExceptionTest.java | 4 +- .../com/google/cloud/spanner/SpanTest.java | 24 +- .../cloud/spanner/SpannerGaxRetryTest.java | 27 +- .../cloud/spanner/SpannerOptionsTest.java | 142 +++++------ .../connection/StatementTimeoutTest.java | 8 +- .../spanner/it/ITBuiltInMetricsTest.java | 4 +- .../spanner/it/ITCommitTimestampTest.java | 4 +- .../cloud/spanner/it/ITPgJsonbTest.java | 2 +- .../cloud/spanner/it/ITPgNumericTest.java | 2 +- .../spanner/it/ITPitrCreateDatabaseTest.java | 2 +- .../spanner/it/ITPitrUpdateDatabaseTest.java | 2 +- .../spanner/spi/v1/GapicSpannerRpcTest.java | 4 +- 63 files changed, 616 insertions(+), 403 deletions(-) diff --git a/google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudClientExecutor.java b/google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudClientExecutor.java index 481d95884ce..69c0d4d3ea9 100644 --- a/google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudClientExecutor.java +++ b/google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudClientExecutor.java @@ -170,6 +170,8 @@ import java.io.Serializable; import java.math.BigDecimal; import java.text.ParseException; +import java.time.Duration; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -186,8 +188,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; -import org.threeten.bp.Duration; -import org.threeten.bp.LocalDate; /** * Implementation of the SpannerExecutorProxy gRPC service that proxies action request through the @@ -818,13 +818,13 @@ private synchronized Spanner getClient(long timeoutSeconds, boolean useMultiplex } RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(Duration.ofSeconds(1)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofSeconds(32)) - .setInitialRpcTimeout(rpcTimeout) + .setMaxRetryDelayDuration(Duration.ofSeconds(32)) + .setInitialRpcTimeoutDuration(rpcTimeout) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(rpcTimeout) - .setTotalTimeout(rpcTimeout) + .setMaxRpcTimeoutDuration(rpcTimeout) + .setTotalTimeoutDuration(rpcTimeout) .build(); com.google.cloud.spanner.SessionPoolOptions.Builder poolOptionsBuilder = diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Clock.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Clock.java index 4fbe841cd84..567ccc1a043 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Clock.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Clock.java @@ -16,7 +16,7 @@ package com.google.cloud.spanner; -import org.threeten.bp.Instant; +import java.time.Instant; /** * Wrapper around current time so that we can fake it in tests. TODO(user): Replace with Java 8 diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java index 050116af8de..0ab12b4e99f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.threeten.bp.Duration; @InternalApi public class CompositeTracer extends BaseApiTracer { @@ -109,7 +108,7 @@ public void attemptCancelled() { } @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { for (ApiTracer child : children) { child.attemptFailed(error, delay); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/GrpcStreamIterator.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/GrpcStreamIterator.java index 79c02eab58c..60a52b78f25 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/GrpcStreamIterator.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/GrpcStreamIterator.java @@ -24,6 +24,7 @@ import com.google.common.collect.AbstractIterator; import com.google.common.util.concurrent.Uninterruptibles; import com.google.spanner.v1.PartialResultSet; +import java.time.Duration; import java.util.Optional; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -31,7 +32,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** Adapts a streaming read/query call into an iterator over partial result sets. */ @VisibleForTesting @@ -77,7 +77,8 @@ public void setCall(SpannerRpc.StreamingCall call, boolean withBeginTransaction) this.call = call; this.withBeginTransaction = withBeginTransaction; ApiCallContext callContext = call.getCallContext(); - Duration streamWaitTimeout = callContext == null ? null : callContext.getStreamWaitTimeout(); + Duration streamWaitTimeout = + callContext == null ? null : callContext.getStreamWaitTimeoutDuration(); if (streamWaitTimeout != null) { // Determine the timeout unit to use. This reduces the precision to seconds if the timeout // value is more than 1 second, which is lower than the precision that would normally be diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/LatencyTest.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/LatencyTest.java index 4f70c32d2b4..2ba2f8c5a62 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/LatencyTest.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/LatencyTest.java @@ -19,11 +19,11 @@ import com.google.cloud.spanner.SpannerOptions.FixedCloseableExecutorProvider; import java.nio.file.Files; import java.nio.file.Paths; +import java.time.Duration; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadLocalRandom; -import org.threeten.bp.Duration; public class LatencyTest { @@ -42,7 +42,7 @@ public static void main(String[] args) throws Exception { Paths.get("/Users/loite/Downloads/appdev-soda-spanner-staging.json")))) .setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) // .setUseMultiplexedSession(true) .build()) .setUseVirtualThreads(true) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java index 71e364bde83..a07819c07d0 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java @@ -275,7 +275,7 @@ public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount private static void maybeWaitForSessionCreation( SessionPoolOptions sessionPoolOptions, ApiFuture future) { - org.threeten.bp.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions(); + java.time.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions(); if (waitDuration != null && !waitDuration.isZero()) { long timeoutMillis = waitDuration.toMillis(); try { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java index 8d28a4b01ce..ea6e745f71f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java @@ -16,6 +16,9 @@ package com.google.cloud.spanner; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + +import com.google.api.core.ObsoleteApi; import com.google.api.gax.tracing.ApiTracer; import com.google.api.gax.tracing.ApiTracerFactory.OperationType; import com.google.common.base.Preconditions; @@ -27,7 +30,6 @@ import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * {@link com.google.api.gax.tracing.ApiTracer} for use with OpenTelemetry. Based on {@link @@ -163,8 +165,18 @@ public void attemptCancelled() { lastConnectionId = null; } + /** + * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} + * instead. + */ + @Override + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailedDuration(error, toJavaTimeDuration(delay)); + } + @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { AttributesBuilder builder = baseAttemptAttributesBuilder(); if (delay != null) { builder.put(RETRY_DELAY_KEY, delay.toMillis()); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java index f8f9d1e9779..66b1165f4a9 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java @@ -28,9 +28,9 @@ import com.google.longrunning.Operation.ResultCase; import com.google.protobuf.Any; import com.google.rpc.Status; +import java.time.Duration; import java.util.concurrent.ExecutionException; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Represents a long-running operation. @@ -43,11 +43,11 @@ public class Operation { private final RetrySettings DEFAULT_OPERATION_WAIT_SETTINGS = RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofHours(12L)) - .setInitialRetryDelay(Duration.ofMillis(500L)) + .setTotalTimeoutDuration(Duration.ofHours(12L)) + .setInitialRetryDelayDuration(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.0) .setJittered(false) - .setMaxRetryDelay(Duration.ofMinutes(500L)) + .setMaxRetryDelayDuration(Duration.ofMinutes(500L)) .build(); interface Parser { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java index 82b7f06b7d2..93cebb6333c 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java @@ -39,12 +39,12 @@ import com.google.spanner.v1.TransactionOptions; import com.google.spanner.v1.TransactionSelector; import io.grpc.Status; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -import org.threeten.bp.Duration; -import org.threeten.bp.temporal.ChronoUnit; @InternalApi public class PartitionedDmlTransaction implements SessionImpl.SessionTransaction { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java index 5bd31603685..2f0d86b6314 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java @@ -45,13 +45,13 @@ import com.google.spanner.v1.RequestOptions; import com.google.spanner.v1.Transaction; import com.google.spanner.v1.TransactionOptions; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** * Implementation of {@link Session}. Sessions are managed internally by the client library, and @@ -203,7 +203,7 @@ public long executePartitionedUpdate(Statement stmt, UpdateOption... options) { PartitionedDmlTransaction txn = new PartitionedDmlTransaction(this, spanner.getRpc(), Ticker.systemTicker()); return txn.executeStreamingPartitionedUpdate( - stmt, spanner.getOptions().getPartitionedDmlTimeout(), options); + stmt, spanner.getOptions().getPartitionedDmlTimeoutDuration(), options); } @Override diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java index cf50fa44c77..aba6aee1db8 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java @@ -91,6 +91,8 @@ import io.opentelemetry.api.metrics.Meter; import java.io.PrintWriter; import java.io.StringWriter; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -115,8 +117,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; /** * Maintains a pool of sessions. This class itself is thread safe and is meant to be used @@ -2079,7 +2079,7 @@ private void removeIdleSessions(Instant currTime) { // Determine the minimum last use time for a session to be deemed to still be alive. Remove // all sessions that have a lastUseTime before that time, unless it would cause us to go // below MinSessions. - Instant minLastUseTime = currTime.minus(options.getRemoveInactiveSessionAfter()); + Instant minLastUseTime = currTime.minus(options.getRemoveInactiveSessionAfterDuration()); Iterator iterator = sessions.descendingIterator(); while (iterator.hasNext()) { PooledSession session = iterator.next(); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java index 89de8df3ca9..14591ac1b80 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java @@ -16,13 +16,16 @@ package com.google.cloud.spanner; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.cloud.spanner.SessionPool.Position; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import java.util.Locale; import java.util.Objects; -import org.threeten.bp.Duration; /** Options for the session pool used by {@code DatabaseClient}. */ public class SessionPoolOptions { @@ -50,7 +53,7 @@ public class SessionPoolOptions { private final long loopFrequency; private final java.time.Duration multiplexedSessionMaintenanceLoopFrequency; private final int keepAliveIntervalMinutes; - private final Duration removeInactiveSessionAfter; + private final java.time.Duration removeInactiveSessionAfter; private final ActionOnSessionNotFound actionOnSessionNotFound; private final ActionOnSessionLeak actionOnSessionLeak; private final boolean trackStackTraceOfSessionCheckout; @@ -63,8 +66,8 @@ public class SessionPoolOptions { @Deprecated private final long initialWaitForSessionTimeoutMillis; private final boolean autoDetectDialect; - private final Duration waitForMinSessions; - private final Duration acquireSessionTimeout; + private final java.time.Duration waitForMinSessions; + private final java.time.Duration acquireSessionTimeout; private final Position releaseToPosition; private final long randomizePositionQPSThreshold; @@ -81,8 +84,7 @@ public class SessionPoolOptions { private final boolean useMultiplexedSessionForRW; - // TODO: Change to use java.time.Duration. - private final Duration multiplexedSessionMaintenanceDuration; + private final java.time.Duration multiplexedSessionMaintenanceDuration; private SessionPoolOptions(Builder builder) { // minSessions > maxSessions is only possible if the user has only set a value for maxSessions. @@ -244,7 +246,13 @@ public int getKeepAliveIntervalMinutes() { return keepAliveIntervalMinutes; } - public Duration getRemoveInactiveSessionAfter() { + /** This method is obsolete. Use {@link #getRemoveInactiveSessionAfterDuration()} instead. */ + @ObsoleteApi("Use getRemoveInactiveSessionAfterDuration() instead") + public org.threeten.bp.Duration getRemoveInactiveSessionAfter() { + return toThreetenDuration(getRemoveInactiveSessionAfterDuration()); + } + + public java.time.Duration getRemoveInactiveSessionAfterDuration() { return removeInactiveSessionAfter; } @@ -303,12 +311,12 @@ public boolean isTrackStackTraceOfSessionCheckout() { return trackStackTraceOfSessionCheckout; } - Duration getWaitForMinSessions() { + java.time.Duration getWaitForMinSessions() { return waitForMinSessions; } @VisibleForTesting - Duration getAcquireSessionTimeout() { + java.time.Duration getAcquireSessionTimeout() { return acquireSessionTimeout; } @@ -362,7 +370,7 @@ private static Boolean getUseMultiplexedSessionForRWFromEnvVariable() { return null; } - Duration getMultiplexedSessionMaintenanceDuration() { + java.time.Duration getMultiplexedSessionMaintenanceDuration() { return multiplexedSessionMaintenanceDuration; } @@ -402,7 +410,7 @@ static class InactiveTransactionRemovalOptions { * Frequency for closing inactive transactions. Between two consecutive task executions, it's * ensured that the duration is greater or equal to this duration. */ - private final Duration executionFrequency; + private final java.time.Duration executionFrequency; /** * Long-running transactions will be cleaned up if utilisation is greater than the below value. @@ -413,7 +421,7 @@ static class InactiveTransactionRemovalOptions { * A transaction is considered to be idle if it has not been used for a duration greater than * the below value. */ - private final Duration idleTimeThreshold; + private final java.time.Duration idleTimeThreshold; InactiveTransactionRemovalOptions(final Builder builder) { this.actionOnInactiveTransaction = builder.actionOnInactiveTransaction; @@ -443,7 +451,7 @@ public int hashCode() { this.usedSessionsRatioThreshold); } - Duration getExecutionFrequency() { + java.time.Duration getExecutionFrequency() { return executionFrequency; } @@ -451,7 +459,7 @@ Duration getExecutionFrequency() { return usedSessionsRatioThreshold; } - Duration getIdleTimeThreshold() { + java.time.Duration getIdleTimeThreshold() { return idleTimeThreshold; } @@ -462,9 +470,9 @@ static InactiveTransactionRemovalOptions.Builder newBuilder() { static class Builder { private ActionOnInactiveTransaction actionOnInactiveTransaction = ActionOnInactiveTransaction.WARN; - private Duration executionFrequency = Duration.ofMinutes(2); + private java.time.Duration executionFrequency = java.time.Duration.ofMinutes(2); private double usedSessionsRatioThreshold = 0.95; - private Duration idleTimeThreshold = Duration.ofMinutes(60L); + private java.time.Duration idleTimeThreshold = java.time.Duration.ofMinutes(60L); public Builder() {} @@ -493,7 +501,7 @@ InactiveTransactionRemovalOptions.Builder setActionOnInactiveTransaction( @VisibleForTesting InactiveTransactionRemovalOptions.Builder setExecutionFrequency( - final Duration executionFrequency) { + final java.time.Duration executionFrequency) { this.executionFrequency = executionFrequency; return this; } @@ -507,7 +515,7 @@ InactiveTransactionRemovalOptions.Builder setUsedSessionsRatioThreshold( @VisibleForTesting InactiveTransactionRemovalOptions.Builder setIdleTimeThreshold( - final Duration idleTimeThreshold) { + final java.time.Duration idleTimeThreshold) { this.idleTimeThreshold = idleTimeThreshold; return this; } @@ -551,10 +559,10 @@ public static class Builder { private java.time.Duration multiplexedSessionMaintenanceLoopFrequency = java.time.Duration.ofMinutes(10); private int keepAliveIntervalMinutes = 30; - private Duration removeInactiveSessionAfter = Duration.ofMinutes(55L); + private java.time.Duration removeInactiveSessionAfter = java.time.Duration.ofMinutes(55L); private boolean autoDetectDialect = false; - private Duration waitForMinSessions = Duration.ZERO; - private Duration acquireSessionTimeout = Duration.ofSeconds(60); + private java.time.Duration waitForMinSessions = java.time.Duration.ZERO; + private java.time.Duration acquireSessionTimeout = java.time.Duration.ofSeconds(60); private final Position releaseToPosition = getReleaseToPositionFromSystemProperty(); /** * The session pool will randomize the position of a session that is being returned when this @@ -577,7 +585,7 @@ public static class Builder { // default. private boolean useMultiplexedSessionForRW = false; - private Duration multiplexedSessionMaintenanceDuration = Duration.ofDays(7); + private java.time.Duration multiplexedSessionMaintenanceDuration = java.time.Duration.ofDays(7); private Clock poolMaintainerClock = Clock.INSTANCE; private static Position getReleaseToPositionFromSystemProperty() { @@ -689,7 +697,16 @@ Builder setInactiveTransactionRemovalOptions( return this; } - public Builder setRemoveInactiveSessionAfter(Duration duration) { + /** + * This method is obsolete. Use {@link + * #setRemoveInactiveSessionAfterDuration(java.time.Duration)} instead. + */ + @ObsoleteApi("Use setRemoveInactiveSessionAfterDuration(java.time.Duration) instead") + public Builder setRemoveInactiveSessionAfter(org.threeten.bp.Duration duration) { + return setRemoveInactiveSessionAfterDuration(toJavaTimeDuration(duration)); + } + + public Builder setRemoveInactiveSessionAfterDuration(java.time.Duration duration) { this.removeInactiveSessionAfter = duration; return this; } @@ -720,7 +737,8 @@ public Builder setFailIfPoolExhausted() { * *

By default the requests are blocked for 60s and will fail with a `SpannerException` with * error code `ResourceExhausted` if this timeout is exceeded. If you wish to block for a - * different period use the option {@link Builder#setAcquireSessionTimeout(Duration)} ()} + * different period use the option {@link + * Builder#setAcquireSessionTimeoutDuration(java.time.Duration)} ()} */ public Builder setBlockIfPoolExhausted() { this.actionOnExhaustion = ActionOnExhaustion.BLOCK; @@ -831,7 +849,7 @@ Builder setUseMultiplexedSessionForRW(boolean useMultiplexedSessionForRW) { @VisibleForTesting Builder setMultiplexedSessionMaintenanceDuration( - Duration multiplexedSessionMaintenanceDuration) { + java.time.Duration multiplexedSessionMaintenanceDuration) { this.multiplexedSessionMaintenanceDuration = multiplexedSessionMaintenanceDuration; return this; } @@ -908,6 +926,15 @@ public Builder setWriteSessionsFraction(float writeSessionsFraction) { return this; } + /** + * This method is obsolete. Use {@link #setWaitForMinSessionsDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use setWaitForMinSessionsDuration(java.time.Duration) instead") + public Builder setWaitForMinSessions(org.threeten.bp.Duration waitForMinSessions) { + return setWaitForMinSessionsDuration(toJavaTimeDuration(waitForMinSessions)); + } + /** * If greater than zero, waits for the session pool to have at least {@link * SessionPoolOptions#minSessions} before returning the database client to the caller. Note that @@ -918,16 +945,25 @@ public Builder setWriteSessionsFraction(float writeSessionsFraction) { * *

Defaults to zero (initialization is done asynchronously). */ - public Builder setWaitForMinSessions(Duration waitForMinSessions) { + public Builder setWaitForMinSessionsDuration(java.time.Duration waitForMinSessions) { this.waitForMinSessions = waitForMinSessions; return this; } + /** + * This method is obsolete. Use {@link #setAcquireSessionTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use setAcquireSessionTimeoutDuration(java.time.Duration) instead") + public Builder setAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionTimeout) { + return setAcquireSessionTimeoutDuration(toJavaTimeDuration(acquireSessionTimeout)); + } + /** * If greater than zero, we wait for said duration when no sessions are available in the {@link * SessionPool}. The default is a 60s timeout. Set the value to null to disable the timeout. */ - public Builder setAcquireSessionTimeout(Duration acquireSessionTimeout) { + public Builder setAcquireSessionTimeoutDuration(java.time.Duration acquireSessionTimeout) { try { if (acquireSessionTimeout != null) { Preconditions.checkArgument( diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionReference.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionReference.java index bc12cf8ee77..e96be9effaa 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionReference.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionReference.java @@ -20,9 +20,9 @@ import com.google.cloud.spanner.SessionClient.SessionId; import com.google.cloud.spanner.spi.v1.SpannerRpc; +import java.time.Instant; import java.util.Map; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** * A {@code Session} can be used to perform transactions that read and/or modify data in a Cloud diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerCloudMonitoringExporter.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerCloudMonitoringExporter.java index 3577c9f7b45..574d97071c6 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerCloudMonitoringExporter.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerCloudMonitoringExporter.java @@ -42,6 +42,7 @@ import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.metrics.export.MetricExporter; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -50,7 +51,6 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Spanner Cloud Monitoring OpenTelemetry Exporter. @@ -90,10 +90,10 @@ static SpannerCloudMonitoringExporter create(String projectId, @Nullable Credent settingsBuilder.setCredentialsProvider(credentialsProvider); settingsBuilder.setEndpoint(MONITORING_ENDPOINT); - org.threeten.bp.Duration timeout = Duration.ofMinutes(1); + Duration timeout = Duration.ofMinutes(1); // TODO: createServiceTimeSeries needs special handling if the request failed. Leaving // it as not retried for now. - settingsBuilder.createServiceTimeSeriesSettings().setSimpleTimeoutNoRetries(timeout); + settingsBuilder.createServiceTimeSeriesSettings().setSimpleTimeoutNoRetriesDuration(timeout); return new SpannerCloudMonitoringExporter( projectId, MetricServiceClient.create(settingsBuilder.build())); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java index dac1fc2c82b..1348d586e3a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java @@ -43,6 +43,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import java.io.IOException; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -55,7 +56,6 @@ import java.util.logging.Logger; import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Instant; /** Default implementation of the Cloud Spanner interface. */ class SpannerImpl extends BaseService implements Spanner { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java index af54515e7c6..0217f387f6c 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java @@ -16,6 +16,9 @@ package com.google.cloud.spanner; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; @@ -88,7 +91,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Duration; /** Options for the Cloud Spanner service. */ public class SpannerOptions extends ServiceOptions { @@ -130,7 +132,7 @@ public class SpannerOptions extends ServiceOptions { private final SpannerStubSettings spannerStubSettings; private final InstanceAdminStubSettings instanceAdminStubSettings; private final DatabaseAdminStubSettings databaseAdminStubSettings; - private final Duration partitionedDmlTimeout; + private final java.time.Duration partitionedDmlTimeout; private final boolean grpcGcpExtensionEnabled; private final GcpManagedChannelOptions grpcGcpOptions; private final boolean autoThrottleAdministrativeRequests; @@ -351,16 +353,16 @@ static SpannerMethod valueOf(ReqT request, MethodDescriptor */ public static class SpannerCallContextTimeoutConfigurator implements CallContextConfigurator { - private Duration commitTimeout; - private Duration rollbackTimeout; + private java.time.Duration commitTimeout; + private java.time.Duration rollbackTimeout; - private Duration executeQueryTimeout; - private Duration executeUpdateTimeout; - private Duration batchUpdateTimeout; - private Duration readTimeout; + private java.time.Duration executeQueryTimeout; + private java.time.Duration executeUpdateTimeout; + private java.time.Duration batchUpdateTimeout; + private java.time.Duration readTimeout; - private Duration partitionQueryTimeout; - private Duration partitionReadTimeout; + private java.time.Duration partitionQueryTimeout; + private java.time.Duration partitionReadTimeout; public static SpannerCallContextTimeoutConfigurator create() { return new SpannerCallContextTimeoutConfigurator(); @@ -379,117 +381,246 @@ public ApiCallContext configure( case BATCH_UPDATE: return batchUpdateTimeout == null ? null - : GrpcCallContext.createDefault().withTimeout(batchUpdateTimeout); + : GrpcCallContext.createDefault().withTimeoutDuration(batchUpdateTimeout); case COMMIT: return commitTimeout == null ? null - : GrpcCallContext.createDefault().withTimeout(commitTimeout); + : GrpcCallContext.createDefault().withTimeoutDuration(commitTimeout); case EXECUTE_QUERY: return executeQueryTimeout == null ? null : GrpcCallContext.createDefault() - .withTimeout(executeQueryTimeout) - .withStreamWaitTimeout(executeQueryTimeout); + .withTimeoutDuration(executeQueryTimeout) + .withStreamWaitTimeoutDuration(executeQueryTimeout); case EXECUTE_UPDATE: return executeUpdateTimeout == null ? null - : GrpcCallContext.createDefault().withTimeout(executeUpdateTimeout); + : GrpcCallContext.createDefault().withTimeoutDuration(executeUpdateTimeout); case PARTITION_QUERY: return partitionQueryTimeout == null ? null - : GrpcCallContext.createDefault().withTimeout(partitionQueryTimeout); + : GrpcCallContext.createDefault().withTimeoutDuration(partitionQueryTimeout); case PARTITION_READ: return partitionReadTimeout == null ? null - : GrpcCallContext.createDefault().withTimeout(partitionReadTimeout); + : GrpcCallContext.createDefault().withTimeoutDuration(partitionReadTimeout); case READ: return readTimeout == null ? null : GrpcCallContext.createDefault() - .withTimeout(readTimeout) - .withStreamWaitTimeout(readTimeout); + .withTimeoutDuration(readTimeout) + .withStreamWaitTimeoutDuration(readTimeout); case ROLLBACK: return rollbackTimeout == null ? null - : GrpcCallContext.createDefault().withTimeout(rollbackTimeout); + : GrpcCallContext.createDefault().withTimeoutDuration(rollbackTimeout); default: } return null; } - public Duration getCommitTimeout() { + /** This method is obsolete. Use {@link #getCommitTimeoutDuration()} instead. */ + @ObsoleteApi("Use getCommitTimeoutDuration() instead.") + public org.threeten.bp.Duration getCommitTimeout() { + return toThreetenDuration(getCommitTimeoutDuration()); + } + + public java.time.Duration getCommitTimeoutDuration() { return commitTimeout; } - public SpannerCallContextTimeoutConfigurator withCommitTimeout(Duration commitTimeout) { + /** + * This method is obsolete. Use {@link #withCommitTimeoutDuration(java.time.Duration)} instead. + */ + @ObsoleteApi("Use withCommitTimeoutDuration() instead.") + public SpannerCallContextTimeoutConfigurator withCommitTimeout( + org.threeten.bp.Duration commitTimeout) { + return withCommitTimeoutDuration(toJavaTimeDuration(commitTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withCommitTimeoutDuration( + java.time.Duration commitTimeout) { this.commitTimeout = commitTimeout; return this; } - public Duration getRollbackTimeout() { + /** This method is obsolete. Use {@link #getRollbackTimeoutDuration()} instead. */ + @ObsoleteApi("Use getRollbackTimeoutDuration() instead.") + public org.threeten.bp.Duration getRollbackTimeout() { + return toThreetenDuration(getRollbackTimeoutDuration()); + } + + public java.time.Duration getRollbackTimeoutDuration() { return rollbackTimeout; } - public SpannerCallContextTimeoutConfigurator withRollbackTimeout(Duration rollbackTimeout) { + /** + * This method is obsolete. Use {@link #withRollbackTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use withRollbackTimeoutDuration() instead.") + public SpannerCallContextTimeoutConfigurator withRollbackTimeout( + org.threeten.bp.Duration rollbackTimeout) { + return withRollbackTimeoutDuration(toJavaTimeDuration(rollbackTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withRollbackTimeoutDuration( + java.time.Duration rollbackTimeout) { this.rollbackTimeout = rollbackTimeout; return this; } - public Duration getExecuteQueryTimeout() { + /** This method is obsolete. Use {@link #getExecuteQueryTimeoutDuration()} instead. */ + @ObsoleteApi("Use getExecuteQueryTimeoutDuration() instead.") + public org.threeten.bp.Duration getExecuteQueryTimeout() { + return toThreetenDuration(getExecuteQueryTimeoutDuration()); + } + + public java.time.Duration getExecuteQueryTimeoutDuration() { return executeQueryTimeout; } + /** + * This method is obsolete. Use {@link #withExecuteQueryTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use withExecuteQueryTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withExecuteQueryTimeout( - Duration executeQueryTimeout) { + org.threeten.bp.Duration executeQueryTimeout) { + return withExecuteQueryTimeoutDuration(toJavaTimeDuration(executeQueryTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withExecuteQueryTimeoutDuration( + java.time.Duration executeQueryTimeout) { this.executeQueryTimeout = executeQueryTimeout; return this; } - public Duration getExecuteUpdateTimeout() { + /** This method is obsolete. Use {@link #getExecuteUpdateTimeoutDuration()} instead. */ + @ObsoleteApi("Use getExecuteUpdateTimeoutDuration() instead") + public org.threeten.bp.Duration getExecuteUpdateTimeout() { + return toThreetenDuration(getExecuteUpdateTimeoutDuration()); + } + + public java.time.Duration getExecuteUpdateTimeoutDuration() { return executeUpdateTimeout; } + /** + * This method is obsolete. Use {@link #withExecuteUpdateTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use withExecuteUpdateTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeout( - Duration executeUpdateTimeout) { + org.threeten.bp.Duration executeUpdateTimeout) { + return withExecuteUpdateTimeoutDuration(toJavaTimeDuration(executeUpdateTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeoutDuration( + java.time.Duration executeUpdateTimeout) { this.executeUpdateTimeout = executeUpdateTimeout; return this; } - public Duration getBatchUpdateTimeout() { + /** This method is obsolete. Use {@link #getBatchUpdateTimeoutDuration()} instead. */ + @ObsoleteApi("Use getBatchUpdateTimeoutDuration() instead") + public org.threeten.bp.Duration getBatchUpdateTimeout() { + return toThreetenDuration(getBatchUpdateTimeoutDuration()); + } + + public java.time.Duration getBatchUpdateTimeoutDuration() { return batchUpdateTimeout; } + /** + * This method is obsolete. Use {@link #withBatchUpdateTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use withBatchUpdateTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withBatchUpdateTimeout( - Duration batchUpdateTimeout) { + org.threeten.bp.Duration batchUpdateTimeout) { + return withBatchUpdateTimeoutDuration(toJavaTimeDuration(batchUpdateTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withBatchUpdateTimeoutDuration( + java.time.Duration batchUpdateTimeout) { this.batchUpdateTimeout = batchUpdateTimeout; return this; } - public Duration getReadTimeout() { + /** This method is obsolete. Use {@link #getReadTimeoutDuration()} instead. */ + @ObsoleteApi("Use getReadTimeoutDuration() instead") + public org.threeten.bp.Duration getReadTimeout() { + return toThreetenDuration(getReadTimeoutDuration()); + } + + public java.time.Duration getReadTimeoutDuration() { return readTimeout; } - public SpannerCallContextTimeoutConfigurator withReadTimeout(Duration readTimeout) { + /** + * This method is obsolete. Use {@link #withReadTimeoutDuration(java.time.Duration)} instead. + */ + @ObsoleteApi("Use withReadTimeoutDuration() instead") + public SpannerCallContextTimeoutConfigurator withReadTimeout( + org.threeten.bp.Duration readTimeout) { + return withReadTimeoutDuration(toJavaTimeDuration(readTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withReadTimeoutDuration( + java.time.Duration readTimeout) { this.readTimeout = readTimeout; return this; } - public Duration getPartitionQueryTimeout() { + /** This method is obsolete. Use {@link #getPartitionQueryTimeoutDuration()} instead. */ + @ObsoleteApi("Use getPartitionQueryTimeoutDuration() instead") + public org.threeten.bp.Duration getPartitionQueryTimeout() { + return toThreetenDuration(getPartitionQueryTimeoutDuration()); + } + + public java.time.Duration getPartitionQueryTimeoutDuration() { return partitionQueryTimeout; } + /** + * This method is obsolete. Use {@link #withPartitionQueryTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use withPartitionQueryTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withPartitionQueryTimeout( - Duration partitionQueryTimeout) { + org.threeten.bp.Duration partitionQueryTimeout) { + return withPartitionQueryTimeoutDuration(toJavaTimeDuration(partitionQueryTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withPartitionQueryTimeoutDuration( + java.time.Duration partitionQueryTimeout) { this.partitionQueryTimeout = partitionQueryTimeout; return this; } - public Duration getPartitionReadTimeout() { + /** This method is obsolete. Use {@link #getPartitionReadTimeoutDuration()} instead. */ + @ObsoleteApi("Use getPartitionReadTimeoutDuration() instead") + public org.threeten.bp.Duration getPartitionReadTimeout() { + return toThreetenDuration(getPartitionReadTimeoutDuration()); + } + + public java.time.Duration getPartitionReadTimeoutDuration() { return partitionReadTimeout; } + /** + * This method is obsolete. Use {@link #withPartitionReadTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use withPartitionReadTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withPartitionReadTimeout( - Duration partitionReadTimeout) { + org.threeten.bp.Duration partitionReadTimeout) { + return withPartitionReadTimeoutDuration(toJavaTimeDuration(partitionReadTimeout)); + } + + public SpannerCallContextTimeoutConfigurator withPartitionReadTimeoutDuration( + java.time.Duration partitionReadTimeout) { this.partitionReadTimeout = partitionReadTimeout; return this; } @@ -773,9 +904,9 @@ public static class Builder static final DecodeMode DEFAULT_DECODE_MODE = DecodeMode.DIRECT; static final RetrySettings DEFAULT_ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofSeconds(5L)) + .setInitialRetryDelayDuration(java.time.Duration.ofSeconds(5L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(Duration.ofSeconds(60L)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(60L)) .setMaxAttempts(10) .build(); private final ImmutableSet allowedClientLibTokens = @@ -807,7 +938,7 @@ public static class Builder InstanceAdminStubSettings.newBuilder(); private DatabaseAdminStubSettings.Builder databaseAdminStubSettingsBuilder = DatabaseAdminStubSettings.newBuilder(); - private Duration partitionedDmlTimeout = Duration.ofHours(2L); + private java.time.Duration partitionedDmlTimeout = java.time.Duration.ofHours(2L); private boolean grpcGcpExtensionEnabled = false; private GcpManagedChannelOptions grpcGcpOptions; private RetrySettings retryAdministrativeRequestsSettings = @@ -838,13 +969,13 @@ protected Builder() { OperationTimedPollAlgorithm longRunningPollingAlgorithm = OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofSeconds(60L)) - .setMaxRpcTimeout(Duration.ofSeconds(600L)) - .setInitialRetryDelay(Duration.ofSeconds(20L)) - .setMaxRetryDelay(Duration.ofSeconds(45L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofSeconds(60L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofSeconds(600L)) + .setInitialRetryDelayDuration(java.time.Duration.ofSeconds(20L)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(45L)) .setRetryDelayMultiplier(1.5) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeout(Duration.ofHours(48L)) + .setTotalTimeoutDuration(java.time.Duration.ofHours(48L)) .build()); databaseAdminStubSettingsBuilder .createDatabaseOperationSettings() @@ -1112,11 +1243,20 @@ public DatabaseAdminStubSettings.Builder getDatabaseAdminStubSettingsBuilder() { return databaseAdminStubSettingsBuilder; } + /** + * This method is obsolete. Use {@link #setPartitionedDmlTimeoutDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use setPartitionedDmlTimeoutDuration(java.time.Duration) instead") + public Builder setPartitionedDmlTimeout(org.threeten.bp.Duration timeout) { + return setPartitionedDmlTimeoutDuration(toJavaTimeDuration(timeout)); + } + /** * Sets a timeout specifically for Partitioned DML statements executed through {@link * DatabaseClient#executePartitionedUpdate(Statement, UpdateOption...)}. The default is 2 hours. */ - public Builder setPartitionedDmlTimeout(Duration timeout) { + public Builder setPartitionedDmlTimeoutDuration(java.time.Duration timeout) { this.partitionedDmlTimeout = timeout; return this; } @@ -1623,7 +1763,11 @@ public DatabaseAdminStubSettings getDatabaseAdminStubSettings() { return databaseAdminStubSettings; } - public Duration getPartitionedDmlTimeout() { + public org.threeten.bp.Duration getPartitionedDmlTimeout() { + return toThreetenDuration(getPartitionedDmlTimeoutDuration()); + } + + public java.time.Duration getPartitionedDmlTimeoutDuration() { return partitionedDmlTimeout; } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerRetryHelper.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerRetryHelper.java index a25c706e8a7..5fb35513222 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerRetryHelper.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerRetryHelper.java @@ -30,9 +30,9 @@ import com.google.common.base.Throwables; import com.google.spanner.v1.RollbackRequest; import io.grpc.Context; +import java.time.Duration; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; -import org.threeten.bp.Duration; /** * Util class for retrying aborted transactions. This class is a wrapper around {@link RetryHelper} @@ -60,7 +60,7 @@ class SpannerRetryHelper { .rollbackSettings() .getRetrySettings() .toBuilder() - .setTotalTimeout(Duration.ofHours(24L)) + .setTotalTimeoutDuration(Duration.ofHours(24L)) .setMaxAttempts(0) .build(); @@ -109,7 +109,7 @@ public TimedAttemptSettings createNextAttempt( if (retryDelay > -1L) { return prevSettings .toBuilder() - .setRandomizedRetryDelay(Duration.ofMillis(retryDelay)) + .setRandomizedRetryDelayDuration(Duration.ofMillis(retryDelay)) .build(); } } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractBaseUnitOfWork.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractBaseUnitOfWork.java index 9e431dbc0ba..e9ffc8b98c9 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractBaseUnitOfWork.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractBaseUnitOfWork.java @@ -354,7 +354,7 @@ public ApiCallContext configure( if (statementTimeout.hasTimeout() && applyStatementTimeoutToMethods.contains(method)) { return GrpcCallContext.createDefault() - .withTimeout(statementTimeout.asDuration()); + .withTimeoutDuration(statementTimeout.asDuration()); } return null; } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java index 37dcd3f9aac..5d07c4ecc8d 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java @@ -97,6 +97,7 @@ import java.io.FileInputStream; import java.io.InputStream; import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -114,7 +115,6 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** Implementation for {@link Connection}, the generic Spanner connection API (not JDBC). */ class ConnectionImpl implements Connection { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/LocalConnectionChecker.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/LocalConnectionChecker.java index 4271a8c2f0b..f9a12f5552a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/LocalConnectionChecker.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/LocalConnectionChecker.java @@ -24,7 +24,7 @@ import com.google.cloud.spanner.admin.instance.v1.stub.GrpcInstanceAdminStub; import com.google.cloud.spanner.admin.instance.v1.stub.InstanceAdminStubSettings; import com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest; -import org.threeten.bp.Duration; +import java.time.Duration; /** * Util class for quickly checking whether a local emulator or test server can be found. A common @@ -66,7 +66,7 @@ void checkLocalConnection(ConnectionOptions options) { .build()); testEmulatorSettings .listInstanceConfigsSettings() - .setSimpleTimeoutNoRetries(Duration.ofSeconds(10L)); + .setSimpleTimeoutNoRetriesDuration(Duration.ofSeconds(10L)); try (GrpcInstanceAdminStub stub = GrpcInstanceAdminStub.create(testEmulatorSettings.build())) { stub.listInstanceConfigsCallable() diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java index a126bd8ff37..b92e575a047 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java @@ -29,6 +29,7 @@ import com.google.common.util.concurrent.MoreExecutors; import com.google.protobuf.Duration; import io.opentelemetry.context.Context; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; @@ -37,7 +38,6 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.threeten.bp.temporal.ChronoUnit; /** * {@link StatementExecutor} is responsible for executing statements on a {@link Connection}. @@ -106,26 +106,26 @@ public boolean hasDuration() { }); } - org.threeten.bp.Duration asDuration() { + java.time.Duration asDuration() { if (!hasTimeout()) { - return org.threeten.bp.Duration.ZERO; + return java.time.Duration.ZERO; } TimeUnit unit = getAppropriateTimeUnit(); switch (unit) { case DAYS: - return org.threeten.bp.Duration.ofDays(getTimeoutValue(unit)); + return java.time.Duration.ofDays(getTimeoutValue(unit)); case HOURS: - return org.threeten.bp.Duration.ofHours(getTimeoutValue(unit)); + return java.time.Duration.ofHours(getTimeoutValue(unit)); case MICROSECONDS: - return org.threeten.bp.Duration.of(getTimeoutValue(unit), ChronoUnit.MICROS); + return java.time.Duration.of(getTimeoutValue(unit), ChronoUnit.MICROS); case MILLISECONDS: - return org.threeten.bp.Duration.ofMillis(getTimeoutValue(unit)); + return java.time.Duration.ofMillis(getTimeoutValue(unit)); case MINUTES: - return org.threeten.bp.Duration.ofMinutes(getTimeoutValue(unit)); + return java.time.Duration.ofMinutes(getTimeoutValue(unit)); case NANOSECONDS: - return org.threeten.bp.Duration.ofNanos(getTimeoutValue(unit)); + return java.time.Duration.ofNanos(getTimeoutValue(unit)); case SECONDS: - return org.threeten.bp.Duration.ofSeconds(getTimeoutValue(unit)); + return java.time.Duration.ofSeconds(getTimeoutValue(unit)); default: throw new IllegalStateException("invalid time unit: " + unit); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index fe23b097982..0e540ea7926 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -192,6 +192,7 @@ import java.net.URLDecoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -214,7 +215,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** Implementation of Cloud Spanner remote calls using Gapic libraries. */ @InternalApi @@ -347,7 +347,7 @@ public GapicSpannerRpc(final SpannerOptions options) { // Set a keepalive time of 120 seconds to help long running // commit GRPC calls succeed - .setKeepAliveTime(Duration.ofSeconds(GRPC_KEEPALIVE_SECONDS)) + .setKeepAliveTimeDuration(Duration.ofSeconds(GRPC_KEEPALIVE_SECONDS)) // Then check if SpannerOptions provides an InterceptorProvider. Create a default // SpannerInterceptorProvider if none is provided @@ -396,7 +396,7 @@ public GapicSpannerRpc(final SpannerOptions options) { WatchdogProvider watchdogProvider = InstantiatingWatchdogProvider.create() .withExecutor(spannerWatchdog) - .withCheckInterval(checkInterval) + .withCheckIntervalDuration(checkInterval) .withClock(NanoClock.getDefaultClock()); final String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST"); @@ -652,7 +652,7 @@ private static void checkEmulatorConnection( .setCredentialsProvider(credentialsProvider); testEmulatorSettings .listInstanceConfigsSettings() - .setSimpleTimeoutNoRetries(Duration.ofSeconds(10L)); + .setSimpleTimeoutNoRetriesDuration(Duration.ofSeconds(10L)); try (GrpcInstanceAdminStub stub = GrpcInstanceAdminStub.create(testEmulatorSettings.build())) { stub.listInstanceConfigsCallable() @@ -685,9 +685,9 @@ private static boolean isEmulatorEnabled(SpannerOptions options, String emulator private static final RetrySettings ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofSeconds(5L)) + .setInitialRetryDelayDuration(Duration.ofSeconds(5L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(Duration.ofSeconds(60L)) + .setMaxRetryDelayDuration(Duration.ofSeconds(60L)) .setMaxAttempts(10) .build(); @@ -1770,7 +1770,7 @@ public ServerStream executeStreamingPartitionedDml( SpannerGrpc.getExecuteStreamingSqlMethod(), true); // Override any timeout settings that might have been set on the call context. - context = context.withTimeout(timeout).withStreamWaitTimeout(timeout); + context = context.withTimeoutDuration(timeout).withStreamWaitTimeoutDuration(timeout); return partitionedDmlStub.executeStreamingSqlCallable().call(request, context); } @@ -2037,7 +2037,10 @@ GrpcCallContext newCallContext( context.withCallOptions(context.getCallOptions().withCallCredentials(callCredentials)); } } - context = context.withStreamWaitTimeout(waitTimeout).withStreamIdleTimeout(idleTimeout); + context = + context + .withStreamWaitTimeoutDuration(waitTimeout) + .withStreamIdleTimeoutDuration(idleTimeout); CallContextConfigurator configurator = SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY.get(); ApiCallContext apiCallContextFromContext = null; if (configurator != null) { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java index 0b040df4197..9ad94204743 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java @@ -56,11 +56,11 @@ import com.google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata; import com.google.spanner.admin.instance.v1.UpdateInstanceMetadata; import com.google.spanner.v1.*; +import java.time.Duration; import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Abstracts remote calls to the Cloud Spanner service. Typically end-consumer code will never use diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java index 4bcc5d07401..5b65dd8cf16 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java @@ -33,6 +33,7 @@ import io.grpc.Server; import io.grpc.inprocess.InProcessServerBuilder; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; @@ -46,7 +47,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(SlowTest.class) @RunWith(JUnit4.class) @@ -127,7 +127,7 @@ public void testBatchCreateSessionsTimesOut_whenDeadlineExceeded() throws Except builder .getSpannerStubSettingsBuilder() .batchCreateSessionsSettings() - .setSimpleTimeoutNoRetries(Duration.ofMillis(100)); + .setSimpleTimeoutNoRetriesDuration(Duration.ofMillis(100)); try (Spanner spanner = builder.build().getService()) { DatabaseId databaseId = DatabaseId.of("my-project", "my-instance", "my-database"); @@ -168,7 +168,9 @@ public void testBatchCreateSessionsTimesOut_whenResourceExhausted() throws Excep // Add a timeout for the max amount of time (60ms) that a request waits when a session is // unavailable. SessionPoolOptions sessionPoolOptions = - SessionPoolOptions.newBuilder().setAcquireSessionTimeout(Duration.ofMillis(60)).build(); + SessionPoolOptions.newBuilder() + .setAcquireSessionTimeoutDuration(Duration.ofMillis(60)) + .build(); SpannerOptions.Builder builder = SpannerOptions.newBuilder() .setProjectId("my-project") @@ -181,7 +183,7 @@ public void testBatchCreateSessionsTimesOut_whenResourceExhausted() throws Excep builder .getSpannerStubSettingsBuilder() .batchCreateSessionsSettings() - .setSimpleTimeoutNoRetries(Duration.ofMillis(1000)); + .setSimpleTimeoutNoRetriesDuration(Duration.ofMillis(1000)); try (Spanner spanner = builder.build().getService()) { DatabaseId databaseId = DatabaseId.of("my-project", "my-instance", "my-database"); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CloseSpannerWithOpenResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CloseSpannerWithOpenResultSetTest.java index 8d622579714..c8228e5ecf8 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CloseSpannerWithOpenResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CloseSpannerWithOpenResultSetTest.java @@ -30,6 +30,7 @@ import com.google.spanner.v1.ExecuteSqlRequest; import io.grpc.ManagedChannelBuilder; import io.grpc.Status; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; @@ -44,7 +45,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class CloseSpannerWithOpenResultSetTest extends AbstractMockServerTest { @@ -56,7 +56,9 @@ Spanner createSpanner() { .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( - SessionPoolOptions.newBuilder().setWaitForMinSessions(Duration.ofSeconds(5L)).build()) + SessionPoolOptions.newBuilder() + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) + .build()) .build() .getService(); } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java index dfb7b252268..7f2e7fffc6f 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableList; import com.google.spanner.v1.ReadRequest; import java.lang.reflect.Method; +import java.time.Duration; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -40,7 +41,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class CompositeTracerTest { @@ -150,11 +150,11 @@ public void testAttemptCancelled() { public void testAttemptFailed() { RuntimeException error = new RuntimeException(); Duration delay = Duration.ofMillis(10); - compositeTracer.attemptFailed(error, delay); - verify(child1, times(1)).attemptFailed(error, delay); - verify(child2, times(1)).attemptFailed(error, delay); - verify(child3, times(1)).attemptFailed(error, delay); - verify(child4, times(1)).attemptFailed(error, delay); + compositeTracer.attemptFailedDuration(error, delay); + verify(child1, times(1)).attemptFailedDuration(error, delay); + verify(child2, times(1)).attemptFailedDuration(error, delay); + verify(child3, times(1)).attemptFailedDuration(error, delay); + verify(child4, times(1)).attemptFailedDuration(error, delay); } @Test diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java index 8bb644e75ce..e93066f2683 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java @@ -55,6 +55,7 @@ import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import io.grpc.protobuf.lite.ProtoLiteUtils; import java.net.InetSocketAddress; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -68,7 +69,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class DatabaseAdminClientTest { @@ -107,13 +107,13 @@ public static void startStaticServer() throws Exception { SpannerOptions.Builder builder = SpannerOptions.newBuilder(); RetrySettings longRunningInitialRetrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(600L)) - .setMaxRpcTimeout(Duration.ofMillis(6000L)) - .setInitialRetryDelay(Duration.ofMillis(20L)) - .setMaxRetryDelay(Duration.ofMillis(45L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(600L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(6000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(20L)) + .setMaxRetryDelayDuration(Duration.ofMillis(45L)) .setRetryDelayMultiplier(1.5) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeout(Duration.ofMinutes(48L)) + .setTotalTimeoutDuration(Duration.ofMinutes(48L)) .build(); builder .getDatabaseAdminStubSettingsBuilder() @@ -128,12 +128,12 @@ public static void startStaticServer() throws Exception { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setMaxRetryDelay(Duration.ofMillis(150L)) - .setMaxRpcTimeout(Duration.ofMillis(150L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setInitialRetryDelayDuration(Duration.ofMillis(10L)) + .setMaxRetryDelayDuration(Duration.ofMillis(150L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(150L)) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(5000L)) + .setTotalTimeoutDuration(Duration.ofMillis(5000L)) .setRetryDelayMultiplier(1.3) .setRpcTimeoutMultiplier(1.3) .build())); @@ -152,12 +152,12 @@ public static void startStaticServer() throws Exception { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setMaxRetryDelay(Duration.ofMillis(150L)) - .setMaxRpcTimeout(Duration.ofMillis(150L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setInitialRetryDelayDuration(Duration.ofMillis(10L)) + .setMaxRetryDelayDuration(Duration.ofMillis(150L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(150L)) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(5000L)) + .setTotalTimeoutDuration(Duration.ofMillis(5000L)) .setRetryDelayMultiplier(1.3) .setRpcTimeoutMultiplier(1.3) .build())); @@ -175,19 +175,19 @@ public static void startStaticServer() throws Exception { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setMaxRetryDelay(Duration.ofMillis(150L)) - .setMaxRpcTimeout(Duration.ofMillis(150L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setInitialRetryDelayDuration(Duration.ofMillis(10L)) + .setMaxRetryDelayDuration(Duration.ofMillis(150L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(150L)) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(5000L)) + .setTotalTimeoutDuration(Duration.ofMillis(5000L)) .setRetryDelayMultiplier(1.3) .setRpcTimeoutMultiplier(1.3) .build())); builder.setRetryAdministrativeRequestsSettings( SpannerOptions.Builder.DEFAULT_ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofNanos(1L)) + .setInitialRetryDelayDuration(Duration.ofNanos(1L)) .build()); spanner = builder diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminGaxTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminGaxTest.java index 0af51744abd..be9f07d7f79 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminGaxTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminGaxTest.java @@ -37,6 +37,7 @@ import io.grpc.StatusRuntimeException; import io.grpc.inprocess.InProcessServerBuilder; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -56,7 +57,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import org.threeten.bp.Duration; @RunWith(Parameterized.class) public class DatabaseAdminGaxTest { @@ -214,22 +214,22 @@ public void setUp() throws Exception { mockDatabaseAdmin.reset(); RetrySettings retrySettingsWithLowTimeout = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setMaxRpcTimeout(Duration.ofMillis(1000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(1000L)) .setRetryDelayMultiplier(2.0) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(200L)) + .setTotalTimeoutDuration(Duration.ofMillis(200L)) .build(); RetrySettings retrySettingsWithHighTimeout = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(2000L)) - .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(2000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(5000L)) .setMaxAttempts(3) - .setTotalTimeout(Duration.ofMillis(15000L)) + .setTotalTimeoutDuration(Duration.ofMillis(15000L)) .build(); final RetrySettings retrySettingsToUse = exceptionType == ExceptionType.DELAYED diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java index 62a10c0adb4..cdb60bf1443 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java @@ -111,6 +111,8 @@ import io.opentelemetry.api.OpenTelemetry; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -135,8 +137,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class DatabaseClientImplTest { @@ -2852,10 +2852,10 @@ public void testPartitionedDmlDoesNotTimeout() { mockSpanner.setExecuteSqlExecutionTime(SimulatedExecutionTime.ofMinimumAndRandomTime(20, 0)); final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(1L)) - .setMaxRpcTimeout(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(1L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(1L)) .setMaxAttempts(1) - .setTotalTimeout(Duration.ofMillis(1L)) + .setTotalTimeoutDuration(Duration.ofMillis(1L)) .build(); SpannerOptions.Builder builder = SpannerOptions.newBuilder() @@ -2900,7 +2900,7 @@ public void testPartitionedDmlWithLowerTimeout() { .setChannelProvider(channelProvider) .setCredentials(NoCredentials.getInstance()); // Set PDML timeout value. - builder.setPartitionedDmlTimeout(Duration.ofMillis(10L)); + builder.setPartitionedDmlTimeoutDuration(Duration.ofMillis(10L)); try (Spanner spanner = builder.build().getService()) { DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); @@ -2933,7 +2933,7 @@ public void testPartitionedDmlWithHigherTimeout() { .setChannelProvider(channelProvider) .setCredentials(NoCredentials.getInstance()); // Set PDML timeout value to a value that should allow the statement to be executed. - builder.setPartitionedDmlTimeout(Duration.ofMillis(5000L)); + builder.setPartitionedDmlTimeoutDuration(Duration.ofMillis(5000L)); // Set the ExecuteSql RPC timeout value to a value lower than the time needed to execute the // statement. The higher timeout value that is set above should be respected, and the value for // the ExecuteSQL RPC should be ignored specifically for Partitioned DML. @@ -2946,10 +2946,10 @@ public void testPartitionedDmlWithHigherTimeout() { .executeSqlSettings() .getRetrySettings() .toBuilder() - .setInitialRpcTimeout(Duration.ofMillis(10L)) - .setMaxRpcTimeout(Duration.ofMillis(10L)) - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(10L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(10L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) .build()); try (Spanner spanner = builder.build().getService()) { DatabaseClient client = @@ -3051,7 +3051,7 @@ public void testDatabaseOrInstanceDoesNotExistOnCreate() { .setSessionPoolOption( SessionPoolOptions.newBuilder() .setMinSessions(0) - .setWaitForMinSessions(waitForMinSessions) + .setWaitForMinSessionsDuration(waitForMinSessions) .build()) .build() .getService()) { @@ -3737,7 +3737,9 @@ public void testBatchCreateSessionsPermissionDenied() { .setChannelProvider(channelProvider) .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( - SessionPoolOptions.newBuilder().setWaitForMinSessions(waitForMinSessions).build()) + SessionPoolOptions.newBuilder() + .setWaitForMinSessionsDuration(waitForMinSessions) + .build()) .build() .getService()) { DatabaseId databaseId = DatabaseId.of("my-project", "my-instance", "my-database"); @@ -3836,7 +3838,7 @@ public void testSpecificTimeout() { .withValue( SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY, SpannerCallContextTimeoutConfigurator.create() - .withExecuteQueryTimeout(Duration.ofNanos(1L))) + .withExecuteQueryTimeoutDuration(Duration.ofNanos(1L))) .run( () -> { // Query should fail with a timeout. @@ -4956,7 +4958,7 @@ public void testStreamWaitTimeout() { @Override public ApiCallContext configure( ApiCallContext context, ReqT request, MethodDescriptor method) { - return context.withStreamWaitTimeout(Duration.ofNanos(1L)); + return context.withStreamWaitTimeoutDuration(Duration.ofNanos(1L)); } }; Context context = @@ -4983,7 +4985,7 @@ public void testZeroStreamWaitTimeout() { @Override public ApiCallContext configure( ApiCallContext context, ReqT request, MethodDescriptor method) { - return context.withStreamWaitTimeout(Duration.ZERO); + return context.withStreamWaitTimeoutDuration(Duration.ZERO); } }; Context context = @@ -5002,12 +5004,12 @@ public ApiCallContext configure( public void testRetryOnResourceExhausted() { final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofSeconds(60L)) - .setMaxRpcTimeout(Duration.ofSeconds(60L)) - .setTotalTimeout(Duration.ofSeconds(60L)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(60L)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(60L)) + .setTotalTimeoutDuration(Duration.ofSeconds(60L)) .setRpcTimeoutMultiplier(1.0d) - .setInitialRetryDelay(Duration.ZERO) - .setMaxRetryDelay(Duration.ZERO) + .setInitialRetryDelayDuration(Duration.ZERO) + .setMaxRetryDelayDuration(Duration.ZERO) .setMaxAttempts(100) .build(); SpannerOptions.Builder builder = @@ -5096,7 +5098,7 @@ public void testSessionPoolExhaustedError_containsStackTraces() { .setFailIfPoolExhausted() .setMinSessions(2) .setMaxSessions(4) - .setWaitForMinSessions(Duration.ofSeconds(10L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10L)) .build()) .build() .getService()) { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java index 7579c4328d2..cdc62f83ef9 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java @@ -92,7 +92,7 @@ public void setup() throws Exception { SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(maxSessions) - .setWaitForMinSessions(org.threeten.bp.Duration.ofSeconds(20)) + .setWaitForMinSessionsDuration(java.time.Duration.ofSeconds(20)) .build()) .setHost(SERVER_URL) .setNumChannels(NUM_GRPC_CHANNELS) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/FakeClock.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/FakeClock.java index d46618ce2d0..ab2e859adff 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/FakeClock.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/FakeClock.java @@ -15,8 +15,8 @@ */ package com.google.cloud.spanner; +import java.time.Instant; import java.util.concurrent.atomic.AtomicLong; -import org.threeten.bp.Instant; /** * Class which allows to mock {@link Clock} in unit tests and return custom time values within the diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java index 59a18a3ab79..25c01560e92 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java @@ -44,6 +44,7 @@ import com.google.spanner.v1.Transaction; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -55,7 +56,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; /** Unit tests for {@link GrpcResultSet}. */ @RunWith(JUnit4.class) @@ -90,7 +90,7 @@ public void setUp() { new SpannerRpc.StreamingCall() { @Override public ApiCallContext getCallContext() { - return GrpcCallContext.createDefault().withStreamWaitTimeout(streamWaitTimeout); + return GrpcCallContext.createDefault().withStreamWaitTimeoutDuration(streamWaitTimeout); } @Override diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminGaxTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminGaxTest.java index c5a317ce5d7..f619d9b461f 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminGaxTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminGaxTest.java @@ -44,6 +44,7 @@ import io.grpc.StatusRuntimeException; import io.grpc.inprocess.InProcessServerBuilder; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -64,7 +65,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import org.threeten.bp.Duration; @RunWith(Parameterized.class) public class InstanceAdminGaxTest { @@ -221,23 +221,23 @@ public void setUp() throws Exception { mockInstanceAdmin.reset(); RetrySettings retrySettingsWithLowTimeout = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(10L)) - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setMaxRpcTimeout(Duration.ofMillis(200L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(10L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(200L)) .setRetryDelayMultiplier(1.3d) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(20000L)) + .setTotalTimeoutDuration(Duration.ofMillis(20000L)) .setJittered(false) .build(); RetrySettings retrySettingsWithHighTimeout = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(2000L)) - .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(2000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(5000L)) .setMaxAttempts(3) - .setTotalTimeout(Duration.ofMillis(15000L)) + .setTotalTimeoutDuration(Duration.ofMillis(15000L)) .build(); final RetrySettings retrySettingsToUse = exceptionType == ExceptionType.DELAYED diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/LongRunningSessionsBenchmark.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/LongRunningSessionsBenchmark.java index 19d614ded07..58eb423a5db 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/LongRunningSessionsBenchmark.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/LongRunningSessionsBenchmark.java @@ -28,6 +28,7 @@ import com.google.common.util.concurrent.ListeningScheduledExecutorService; import com.google.common.util.concurrent.MoreExecutors; import com.google.spanner.v1.BatchCreateSessionsRequest; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -48,7 +49,6 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; -import org.threeten.bp.Duration; /** * Benchmarks for long-running sessions scenarios. The simulated execution times are based on @@ -126,7 +126,7 @@ public void setup() throws Exception { SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(maxSessions) - .setWaitForMinSessions(Duration.ofSeconds(5)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5)) .setInactiveTransactionRemovalOptions(inactiveTransactionRemovalOptions) .build()) .build(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockDatabaseAdminServiceImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockDatabaseAdminServiceImplTest.java index 9c9f0e7f91a..637f97cb097 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockDatabaseAdminServiceImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockDatabaseAdminServiceImplTest.java @@ -58,6 +58,7 @@ import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -74,7 +75,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class MockDatabaseAdminServiceImplTest { @@ -150,12 +150,12 @@ public void setUp() throws IOException { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setMaxRetryDelay(Duration.ofMillis(150L)) - .setMaxRpcTimeout(Duration.ofMillis(150L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setInitialRetryDelayDuration(Duration.ofMillis(10L)) + .setMaxRetryDelayDuration(Duration.ofMillis(150L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(150L)) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(5000L)) + .setTotalTimeoutDuration(Duration.ofMillis(5000L)) .setRetryDelayMultiplier(1.3) .setRpcTimeoutMultiplier(1.3) .build())); @@ -164,12 +164,12 @@ public void setUp() throws IOException { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setMaxRetryDelay(Duration.ofMillis(150L)) - .setMaxRpcTimeout(Duration.ofMillis(150L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setInitialRetryDelayDuration(Duration.ofMillis(10L)) + .setMaxRetryDelayDuration(Duration.ofMillis(150L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(150L)) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(5000L)) + .setTotalTimeoutDuration(Duration.ofMillis(5000L)) .setRetryDelayMultiplier(1.3) .setRpcTimeoutMultiplier(1.3) .build())); @@ -178,12 +178,12 @@ public void setUp() throws IOException { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(20L)) - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setMaxRetryDelay(Duration.ofMillis(150L)) - .setMaxRpcTimeout(Duration.ofMillis(150L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(20L)) + .setInitialRetryDelayDuration(Duration.ofMillis(10L)) + .setMaxRetryDelayDuration(Duration.ofMillis(150L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(150L)) .setMaxAttempts(10) - .setTotalTimeout(Duration.ofMillis(5000L)) + .setTotalTimeoutDuration(Duration.ofMillis(5000L)) .setRetryDelayMultiplier(1.3) .setRpcTimeoutMultiplier(1.3) .build())); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java index 39f1ff180fa..676cb05eb07 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java @@ -86,6 +86,7 @@ import io.grpc.protobuf.lite.ProtoLiteUtils; import io.grpc.stub.StreamObserver; import java.math.BigDecimal; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -112,7 +113,6 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import java.util.stream.LongStream; -import org.threeten.bp.Instant; /** * In-process mock implementation of a Cloud Spanner server. The user must specify the results the diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java index 4dc1da62e7b..47e7a19d2cb 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java @@ -98,7 +98,7 @@ public void createSpannerInstance() { // Set the maintainer to loop once every 1ms .setMultiplexedSessionMaintenanceLoopFrequency(Duration.ofMillis(1L)) // Set multiplexed sessions to be replaced once every 1ms - .setMultiplexedSessionMaintenanceDuration(org.threeten.bp.Duration.ofMillis(1L)) + .setMultiplexedSessionMaintenanceDuration(java.time.Duration.ofMillis(1L)) .setFailOnSessionLeak() .build()) .build() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java index 287fdd0bd0b..a68928ee9b7 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java @@ -60,7 +60,7 @@ public void testMaintainer() { when(spanner.getOptions()).thenReturn(spannerOptions); when(spannerOptions.getSessionPoolOptions()).thenReturn(sessionPoolOptions); when(sessionPoolOptions.getMultiplexedSessionMaintenanceDuration()) - .thenReturn(org.threeten.bp.Duration.ofDays(7)); + .thenReturn(java.time.Duration.ofDays(7)); when(sessionPoolOptions.getMultiplexedSessionMaintenanceLoopFrequency()) .thenReturn(Duration.ofMinutes(10)); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java index ff976141d96..f4256ab6bf7 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java @@ -95,7 +95,7 @@ public void setup() throws Exception { SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(maxSessions) - .setWaitForMinSessions(org.threeten.bp.Duration.ofSeconds(20)) + .setWaitForMinSessionsDuration(java.time.Duration.ofSeconds(20)) .setUseMultiplexedSession(true) .build()) .setHost(SERVER_URL) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenCensusApiTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenCensusApiTracerTest.java index 5e7a58cdb23..ad27c775729 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenCensusApiTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenCensusApiTracerTest.java @@ -41,6 +41,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.trace.data.SpanData; import java.lang.reflect.Modifier; +import java.time.Duration; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -55,7 +56,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(TracerTest.class) @RunWith(JUnit4.class) @@ -121,10 +121,10 @@ public void createSpannerInstance() { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofNanos(1L)) - .setMaxRetryDelay(Duration.ofNanos(1L)) + .setInitialRetryDelayDuration(Duration.ofNanos(1L)) + .setMaxRetryDelayDuration(Duration.ofNanos(1L)) .setRetryDelayMultiplier(1.0) - .setTotalTimeout(Duration.ofMinutes(10L)) + .setTotalTimeoutDuration(Duration.ofMinutes(10L)) .build())); spanner = builder @@ -133,7 +133,7 @@ public void createSpannerInstance() { .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) .setFailOnSessionLeak() .build()) .setEnableApiTracing(true) @@ -359,7 +359,7 @@ public boolean isEnableApiTracing() { .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) .setFailOnSessionLeak() .build()) .build() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryApiTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryApiTracerTest.java index 123f0f486a7..e4d25f1d9b3 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryApiTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryApiTracerTest.java @@ -47,6 +47,7 @@ import io.opentelemetry.sdk.trace.data.EventData; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; +import java.time.Duration; import java.util.List; import java.util.Map.Entry; import java.util.Objects; @@ -58,7 +59,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class OpenTelemetryApiTracerTest extends AbstractMockServerTest { @@ -121,10 +121,10 @@ public void createSpannerInstance() { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofNanos(1L)) - .setMaxRetryDelay(Duration.ofNanos(1L)) + .setInitialRetryDelayDuration(Duration.ofNanos(1L)) + .setMaxRetryDelayDuration(Duration.ofNanos(1L)) .setRetryDelayMultiplier(1.0) - .setTotalTimeout(Duration.ofMinutes(10L)) + .setTotalTimeoutDuration(Duration.ofMinutes(10L)) .build())); spanner = builder @@ -133,7 +133,7 @@ public void createSpannerInstance() { .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) .setFailOnSessionLeak() .build()) .setEnableApiTracing(true) @@ -426,7 +426,7 @@ public boolean isEnableApiTracing() { .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) .setFailOnSessionLeak() .build()) .build() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java index 9f65402c31f..7a14681d525 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java @@ -43,6 +43,7 @@ import io.opentelemetry.sdk.metrics.data.LongPointData; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; +import java.time.Duration; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -55,7 +56,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class OpenTelemetryBuiltInMetricsTracerTest extends AbstractMockServerTest { @@ -130,10 +130,10 @@ public void createSpannerInstance() { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofNanos(1L)) - .setMaxRetryDelay(Duration.ofNanos(1L)) + .setInitialRetryDelayDuration(Duration.ofNanos(1L)) + .setMaxRetryDelayDuration(Duration.ofNanos(1L)) .setRetryDelayMultiplier(1.0) - .setTotalTimeout(Duration.ofMinutes(10L)) + .setTotalTimeoutDuration(Duration.ofMinutes(10L)) .build())); spanner = builder @@ -142,7 +142,7 @@ public void createSpannerInstance() { .setCredentials(NoCredentials.getInstance()) .setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) .setFailOnSessionLeak() .build()) // Setting this to false so that Spanner Options does not register Metrics Tracer diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java index a2aeb887733..f7f547ce357 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java @@ -47,6 +47,7 @@ import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import java.lang.reflect.Modifier; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -60,7 +61,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(TracerTest.class) @RunWith(JUnit4.class) @@ -237,7 +237,7 @@ public void setUp() throws Exception { .setSessionPoolOption( SessionPoolOptions.newBuilder() .setMinSessions(2) - .setWaitForMinSessions(Duration.ofSeconds(10)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10)) .build()); spanner = builder.build().getService(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OperationTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OperationTest.java index 20fa72252f5..55211de1980 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OperationTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OperationTest.java @@ -31,12 +31,12 @@ import com.google.rpc.Code; import com.google.rpc.Status; import com.google.spanner.admin.database.v1.CreateDatabaseMetadata; +import java.time.Duration; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mock; -import org.threeten.bp.Duration; /** Unit tests for {@link Operation}. */ @RunWith(JUnit4.class) @@ -160,8 +160,8 @@ public void waitForCompletes() { op = op.waitFor( - RetryOption.totalTimeout(Duration.ofSeconds(3)), - RetryOption.initialRetryDelay(Duration.ZERO)); + RetryOption.totalTimeoutDuration(Duration.ofSeconds(3)), + RetryOption.initialRetryDelayDuration(Duration.ZERO)); assertThat(op.getName()).isEqualTo("op1"); assertThat(op.isDone()).isTrue(); @@ -181,8 +181,8 @@ public void waitForTimeout() { SpannerException.class, () -> op.waitFor( - RetryOption.totalTimeout(Duration.ofMillis(100L)), - RetryOption.initialRetryDelay(Duration.ZERO))); + RetryOption.totalTimeoutDuration(Duration.ofMillis(100L)), + RetryOption.initialRetryDelayDuration(Duration.ZERO))); assertEquals(ErrorCode.DEADLINE_EXCEEDED, e.getErrorCode()); } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/PartitionedDmlTransactionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/PartitionedDmlTransactionTest.java index 93e0e3eb3d0..68bfcca6146 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/PartitionedDmlTransactionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/PartitionedDmlTransactionTest.java @@ -47,6 +47,7 @@ import com.google.spanner.v1.Transaction; import com.google.spanner.v1.TransactionSelector; import io.grpc.Status.Code; +import java.time.Duration; import java.util.Collections; import java.util.Iterator; import java.util.concurrent.TimeUnit; @@ -59,7 +60,6 @@ import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.threeten.bp.Duration; @SuppressWarnings("unchecked") @RunWith(JUnit4.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnDifferentGrpcChannelMockServerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnDifferentGrpcChannelMockServerTest.java index b5e3e2e54cf..267c6077add 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnDifferentGrpcChannelMockServerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnDifferentGrpcChannelMockServerTest.java @@ -42,6 +42,7 @@ import io.grpc.Status; import java.io.IOException; import java.net.InetSocketAddress; +import java.time.Duration; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -58,7 +59,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class RetryOnDifferentGrpcChannelMockServerTest extends AbstractMockServerTest { @@ -125,7 +125,9 @@ SpannerOptions.Builder createSpannerOptionsBuilder() { public void testReadWriteTransaction_retriesOnNewChannel() { SpannerOptions.Builder builder = createSpannerOptionsBuilder(); builder.setSessionPoolOption( - SessionPoolOptions.newBuilder().setWaitForMinSessions(Duration.ofSeconds(5L)).build()); + SessionPoolOptions.newBuilder() + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) + .build()); mockSpanner.setBeginTransactionExecutionTime( SimulatedExecutionTime.ofStickyException(Status.DEADLINE_EXCEEDED.asRuntimeException())); AtomicInteger attempts = new AtomicInteger(); @@ -159,7 +161,9 @@ public void testReadWriteTransaction_retriesOnNewChannel() { public void testReadWriteTransaction_stopsRetrying() { SpannerOptions.Builder builder = createSpannerOptionsBuilder(); builder.setSessionPoolOption( - SessionPoolOptions.newBuilder().setWaitForMinSessions(Duration.ofSeconds(5L)).build()); + SessionPoolOptions.newBuilder() + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) + .build()); mockSpanner.setBeginTransactionExecutionTime( SimulatedExecutionTime.ofStickyException(Status.DEADLINE_EXCEEDED.asRuntimeException())); @@ -200,7 +204,7 @@ public void testDenyListedChannelIsCleared() { SpannerOptions.Builder builder = createSpannerOptionsBuilder(); builder.setSessionPoolOption( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofSeconds(5)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5)) .setPoolMaintainerClock(clock) .build()); mockSpanner.setBeginTransactionExecutionTime( @@ -328,7 +332,9 @@ public void testSingleUseQuery_stopsRetrying() { public void testReadWriteTransaction_withGrpcContextDeadline_doesNotRetry() { SpannerOptions.Builder builder = createSpannerOptionsBuilder(); builder.setSessionPoolOption( - SessionPoolOptions.newBuilder().setWaitForMinSessions(Duration.ofSeconds(5L)).build()); + SessionPoolOptions.newBuilder() + .setWaitForMinSessionsDuration(Duration.ofSeconds(5L)) + .build()); mockSpanner.setBeginTransactionExecutionTime( SimulatedExecutionTime.ofMinimumAndRandomTime(500, 500)); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SamplesMockServerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SamplesMockServerTest.java index d8dcfc10e05..61c8d0573d7 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SamplesMockServerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SamplesMockServerTest.java @@ -23,10 +23,10 @@ import com.google.api.gax.rpc.StatusCode; import com.google.cloud.NoCredentials; import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult; +import java.time.Duration; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; /** Tests for samples that use an in-mem mock server instead of running on real Cloud Spanner. */ @RunWith(JUnit4.class) @@ -52,13 +52,13 @@ public void testSampleRetrySettings() { .setRetryableCodes(StatusCode.Code.UNAVAILABLE) .setRetrySettings( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(500)) - .setMaxRetryDelay(Duration.ofSeconds(16)) + .setInitialRetryDelayDuration(Duration.ofMillis(500)) + .setMaxRetryDelayDuration(Duration.ofSeconds(16)) .setRetryDelayMultiplier(1.5) - .setInitialRpcTimeout(Duration.ofNanos(1L)) - .setMaxRpcTimeout(Duration.ofNanos(1L)) + .setInitialRpcTimeoutDuration(Duration.ofNanos(1L)) + .setMaxRpcTimeoutDuration(Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1.0) - .setTotalTimeout(Duration.ofNanos(1L)) + .setTotalTimeoutDuration(Duration.ofNanos(1L)) .build()); // Create a Spanner client using the custom retry and timeout settings. try (Spanner spanner = builder.build().getService()) { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerBenchmark.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerBenchmark.java index 5f624cb6092..0370f5420e2 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerBenchmark.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerBenchmark.java @@ -27,6 +27,7 @@ import com.google.spanner.v1.BatchCreateSessionsRequest; import com.google.spanner.v1.BeginTransactionRequest; import com.google.spanner.v1.DeleteSessionRequest; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -46,7 +47,6 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; -import org.threeten.bp.Duration; /** * Benchmarks for the SessionPoolMaintainer. Run these benchmarks from the command line like this: @@ -111,7 +111,7 @@ public void setup() throws Exception { .setSessionPoolOption( SessionPoolOptions.newBuilder() // Set idle timeout and loop frequency to very low values. - .setRemoveInactiveSessionAfter(Duration.ofMillis(idleTimeout)) + .setRemoveInactiveSessionAfterDuration(Duration.ofMillis(idleTimeout)) .setLoopFrequency(idleTimeout / 10) .build()) .build(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerMockServerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerMockServerTest.java index c74806161f6..99a773eeb0f 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerMockServerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolMaintainerMockServerTest.java @@ -33,13 +33,13 @@ import com.google.spanner.v1.StructType.Field; import com.google.spanner.v1.Type; import com.google.spanner.v1.TypeCode; +import java.time.Duration; import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class SessionPoolMaintainerMockServerTest extends AbstractMockServerTest { @@ -80,7 +80,7 @@ public void createSpannerInstance() { .setSessionPoolOption( SessionPoolOptions.newBuilder() .setPoolMaintainerClock(clock) - .setWaitForMinSessions(Duration.ofSeconds(10L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10L)) .setFailOnSessionLeak() .build()) .build() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java index 2e3e2c85da3..9e16b3fb1c8 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java @@ -25,6 +25,7 @@ import static org.junit.Assume.assumeFalse; import com.google.cloud.spanner.SessionPoolOptions.InactiveTransactionRemovalOptions; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -34,7 +35,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import org.threeten.bp.Duration; /** Unit tests for {@link com.google.cloud.spanner.SessionPoolOptions} */ @RunWith(Parameterized.class) @@ -223,10 +223,12 @@ public void setNegativeIdleTimeThreshold() { @Test public void setAcquireSessionTimeout() { SessionPoolOptions sessionPoolOptions1 = - SessionPoolOptions.newBuilder().setAcquireSessionTimeout(Duration.ofSeconds(20)).build(); + SessionPoolOptions.newBuilder() + .setAcquireSessionTimeoutDuration(Duration.ofSeconds(20)) + .build(); SessionPoolOptions sessionPoolOptions2 = SessionPoolOptions.newBuilder() - .setAcquireSessionTimeout(Duration.ofMillis(Long.MAX_VALUE)) + .setAcquireSessionTimeoutDuration(Duration.ofMillis(Long.MAX_VALUE)) .build(); assertEquals(Duration.ofSeconds(20), sessionPoolOptions1.getAcquireSessionTimeout()); @@ -235,13 +237,13 @@ public void setAcquireSessionTimeout() { @Test(expected = IllegalArgumentException.class) public void setAcquireSessionTimeout_valueLessThanLowerBound() { - SessionPoolOptions.newBuilder().setAcquireSessionTimeout(Duration.ofMillis(0)).build(); + SessionPoolOptions.newBuilder().setAcquireSessionTimeoutDuration(Duration.ofMillis(0)).build(); } @Test(expected = IllegalArgumentException.class) public void setAcquireSessionTimeout_valueMoreThanUpperBound() { SessionPoolOptions.newBuilder() - .setAcquireSessionTimeout(Duration.ofSeconds(Long.MAX_VALUE)) + .setAcquireSessionTimeoutDuration(Duration.ofSeconds(Long.MAX_VALUE)) .build(); } @@ -418,7 +420,7 @@ public void testToBuilder() { .build()); assertToBuilderRoundtrip( SessionPoolOptions.newBuilder() - .setRemoveInactiveSessionAfter( + .setRemoveInactiveSessionAfterDuration( Duration.ofMillis(ThreadLocalRandom.current().nextLong(10000))) .build()); assertToBuilderRoundtrip( @@ -438,11 +440,12 @@ public void testToBuilder() { .build()); assertToBuilderRoundtrip( SessionPoolOptions.newBuilder() - .setWaitForMinSessions(Duration.ofMillis(ThreadLocalRandom.current().nextLong(10000))) + .setWaitForMinSessionsDuration( + Duration.ofMillis(ThreadLocalRandom.current().nextLong(10000))) .build()); assertToBuilderRoundtrip( SessionPoolOptions.newBuilder() - .setAcquireSessionTimeout( + .setAcquireSessionTimeoutDuration( Duration.ofMillis(ThreadLocalRandom.current().nextLong(1, 10000))) .build()); assertToBuilderRoundtrip( diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java index 00339fd2946..0389410064a 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java @@ -105,6 +105,9 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.time.Duration; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -133,9 +136,6 @@ import org.junit.runners.Parameterized.Parameters; import org.mockito.Mock; import org.mockito.Mockito; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; -import org.threeten.bp.temporal.ChronoUnit; /** Tests for SessionPool that mock out the underlying stub. */ @RunWith(Parameterized.class) @@ -314,7 +314,7 @@ public void poolLifo() { options .toBuilder() .setMinSessions(2) - .setWaitForMinSessions(Duration.ofSeconds(10L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10L)) .build(); pool = createPool(); pool.maybeWaitOnMinSessions(); @@ -350,7 +350,7 @@ public void poolFifo() throws Exception { options .toBuilder() .setMinSessions(2) - .setWaitForMinSessions(Duration.ofSeconds(10L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10L)) .build(); pool = createPool(); pool.maybeWaitOnMinSessions(); @@ -398,7 +398,7 @@ public void poolAllPositions() throws Exception { .toBuilder() .setMinSessions(numSessions) .setMaxSessions(numSessions) - .setWaitForMinSessions(Duration.ofSeconds(10L)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10L)) .build(); pool = createPool(); pool.maybeWaitOnMinSessions(); @@ -2212,7 +2212,7 @@ public void testWaitOnMinSessionsWhenSessionsAreCreatedBeforeTimeout() { SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(minSessions + 1) - .setWaitForMinSessions(Duration.ofSeconds(5)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(5)) .build(); doAnswer( invocation -> @@ -2241,7 +2241,7 @@ public void testWaitOnMinSessionsThrowsExceptionWhenTimeoutIsReached() { SessionPoolOptions.newBuilder() .setMinSessions(minSessions + 1) .setMaxSessions(minSessions + 1) - .setWaitForMinSessions(Duration.ofMillis(100)) + .setWaitForMinSessionsDuration(Duration.ofMillis(100)) .build(); pool = createPool(new FakeClock(), new FakeMetricRegistry(), SPANNER_DEFAULT_LABEL_VALUES); pool.maybeWaitOnMinSessions(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanExceptionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanExceptionTest.java index 2f16cd7c922..d09e65dfc0b 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanExceptionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanExceptionTest.java @@ -22,6 +22,7 @@ import com.google.cloud.NoCredentials; import com.google.cloud.spanner.connection.AbstractMockServerTest; import io.grpc.ManagedChannelBuilder; +import java.time.Duration; import java.util.ArrayList; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -31,7 +32,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class SpanExceptionTest extends AbstractMockServerTest { @@ -47,7 +47,7 @@ public void testReadOnlyTransaction() throws InterruptedException, ExecutionExce .setSessionPoolOption( SessionPoolOptions.newBuilder() .setMaxSessions(10) - .setAcquireSessionTimeout(Duration.ofMillis(10)) + .setAcquireSessionTimeoutDuration(Duration.ofMillis(10)) // .setAcquireSessionTimeout(null) .build()) .build() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java index ffe9e584de3..b87b7ba9752 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java @@ -45,6 +45,7 @@ import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import java.lang.reflect.Modifier; +import java.time.Duration; import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -58,7 +59,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(TracerTest.class) @RunWith(JUnit4.class) @@ -202,7 +202,7 @@ public void setUp() throws Exception { .setSessionPoolOption( SessionPoolOptions.newBuilder() .setMinSessions(2) - .setWaitForMinSessions(Duration.ofSeconds(10)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(10)) .build()); spanner = builder.build().getService(); @@ -211,21 +211,21 @@ public void setUp() throws Exception { final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(75L)) - .setMaxRpcTimeout(Duration.ofMillis(75L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(75L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(75L)) .setMaxAttempts(3) - .setTotalTimeout(Duration.ofMillis(200L)) + .setTotalTimeoutDuration(Duration.ofMillis(200L)) .build(); RetrySettings commitRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(5000L)) - .setMaxRpcTimeout(Duration.ofMillis(10000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(5000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(10000L)) .setMaxAttempts(1) - .setTotalTimeout(Duration.ofMillis(20000L)) + .setTotalTimeoutDuration(Duration.ofMillis(20000L)) .build(); builder .getSpannerStubSettingsBuilder() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerGaxRetryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerGaxRetryTest.java index 90d76c6a2bb..8ce858e77d7 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerGaxRetryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerGaxRetryTest.java @@ -41,6 +41,7 @@ import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.protobuf.ProtoUtils; import java.io.IOException; +import java.time.Duration; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -51,7 +52,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class SpannerGaxRetryTest { @@ -151,7 +151,10 @@ public void setUp() throws Exception { // wait time is for multiplexed sessions if (sessionPoolOptions.getUseMultiplexedSession()) { sessionPoolOptions = - sessionPoolOptions.toBuilder().setWaitForMinSessions(Duration.ofSeconds(5)).build(); + sessionPoolOptions + .toBuilder() + .setWaitForMinSessionsDuration(Duration.ofSeconds(5)) + .build(); } builder.setSessionPoolOption(sessionPoolOptions); // Create one client with default timeout values and one with short timeout values specifically @@ -161,21 +164,21 @@ public void setUp() throws Exception { final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(175L)) - .setMaxRpcTimeout(Duration.ofMillis(175L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(175L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(175L)) .setMaxAttempts(3) - .setTotalTimeout(Duration.ofMillis(200L)) + .setTotalTimeoutDuration(Duration.ofMillis(200L)) .build(); RetrySettings commitRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(5000L)) - .setMaxRpcTimeout(Duration.ofMillis(10000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(5000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(10000L)) .setMaxAttempts(1) - .setTotalTimeout(Duration.ofMillis(20000L)) + .setTotalTimeoutDuration(Duration.ofMillis(20000L)) .build(); builder .getSpannerStubSettingsBuilder() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java index e8421cd235c..832729e2df2 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java @@ -66,6 +66,7 @@ import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -82,7 +83,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; /** Unit tests for {@link com.google.cloud.spanner.SpannerOptions}. */ @RunWith(JUnit4.class) @@ -151,40 +151,40 @@ public void builder() { public void testSpannerDefaultRetrySettings() { RetrySettings witRetryPolicy1 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(250L)) + .setInitialRetryDelayDuration(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(3600000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(3600000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(3600000L)) - .setTotalTimeout(Duration.ofMillis(3600000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(3600000L)) + .setTotalTimeoutDuration(Duration.ofMillis(3600000L)) .build(); RetrySettings witRetryPolicy2 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(250L)) + .setInitialRetryDelayDuration(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(60000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(60000L)) - .setTotalTimeout(Duration.ofMillis(60000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(60000L)) + .setTotalTimeoutDuration(Duration.ofMillis(60000L)) .build(); RetrySettings witRetryPolicy3 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(250L)) + .setInitialRetryDelayDuration(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(30000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(30000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(30000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(Duration.ofMillis(30000L)) .build(); RetrySettings noRetry1 = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(3600000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(3600000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(3600000L)) - .setTotalTimeout(Duration.ofMillis(3600000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(3600000L)) + .setTotalTimeoutDuration(Duration.ofMillis(3600000L)) .build(); SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build(); SpannerStubSettings stubSettings = options.getSpannerStubSettings(); @@ -226,13 +226,13 @@ public void testSpannerDefaultRetrySettings() { public void testSpannerCustomRetrySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofSeconds(9999L)) + .setInitialRetryDelayDuration(Duration.ofSeconds(9999L)) .setRetryDelayMultiplier(9999.99D) - .setMaxRetryDelay(Duration.ofSeconds(9999L)) - .setInitialRpcTimeout(Duration.ofSeconds(9999L)) + .setMaxRetryDelayDuration(Duration.ofSeconds(9999L)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(9999L)) .setRpcTimeoutMultiplier(9999.99D) - .setMaxRpcTimeout(Duration.ofSeconds(9999L)) - .setTotalTimeout(Duration.ofSeconds(9999L)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(9999L)) + .setTotalTimeoutDuration(Duration.ofSeconds(9999L)) .build(); SpannerOptions.Builder builder = SpannerOptions.newBuilder().setProjectId("test-project"); SpannerStubSettings.Builder stubSettingsBuilder = builder.getSpannerStubSettingsBuilder(); @@ -294,30 +294,30 @@ public void testSpannerCustomRetrySettings() { public void testDatabaseAdminDefaultRetrySettings() { RetrySettings withRetryPolicy1 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1000L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(3600000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(3600000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(3600000L)) - .setTotalTimeout(Duration.ofMillis(3600000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(3600000L)) + .setTotalTimeoutDuration(Duration.ofMillis(3600000L)) .build(); RetrySettings withRetryPolicy2 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1000L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(30000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(30000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(30000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(Duration.ofMillis(30000L)) .build(); RetrySettings noRetryPolicy2 = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(30000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(30000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(30000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(Duration.ofMillis(30000L)) .build(); SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build(); DatabaseAdminStubSettings stubSettings = options.getDatabaseAdminStubSettings(); @@ -347,13 +347,13 @@ public void testDatabaseAdminDefaultRetrySettings() { public void testDatabaseAdminCustomRetrySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofSeconds(9999L)) + .setInitialRetryDelayDuration(Duration.ofSeconds(9999L)) .setRetryDelayMultiplier(9999.99D) - .setMaxRetryDelay(Duration.ofSeconds(9999L)) - .setInitialRpcTimeout(Duration.ofSeconds(9999L)) + .setMaxRetryDelayDuration(Duration.ofSeconds(9999L)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(9999L)) .setRpcTimeoutMultiplier(9999.99D) - .setMaxRpcTimeout(Duration.ofSeconds(9999L)) - .setTotalTimeout(Duration.ofSeconds(9999L)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(9999L)) + .setTotalTimeoutDuration(Duration.ofSeconds(9999L)) .build(); SpannerOptions.Builder builder = SpannerOptions.newBuilder().setProjectId("test-project"); DatabaseAdminStubSettings.Builder stubSettingsBuilder = @@ -384,37 +384,37 @@ public void testDatabaseAdminCustomRetrySettings() { public void testInstanceAdminDefaultRetrySettings() { RetrySettings withRetryPolicy1 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1000L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(3600000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(3600000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(3600000L)) - .setTotalTimeout(Duration.ofMillis(3600000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(3600000L)) + .setTotalTimeoutDuration(Duration.ofMillis(3600000L)) .build(); RetrySettings withRetryPolicy2 = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1000L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMillis(32000L)) - .setInitialRpcTimeout(Duration.ofMillis(30000L)) + .setMaxRetryDelayDuration(Duration.ofMillis(32000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(30000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(30000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(Duration.ofMillis(30000L)) .build(); RetrySettings noRetryPolicy1 = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(3600000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(3600000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(3600000L)) - .setTotalTimeout(Duration.ofMillis(3600000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(3600000L)) + .setTotalTimeoutDuration(Duration.ofMillis(3600000L)) .build(); RetrySettings noRetryPolicy2 = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(30000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(30000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(30000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(Duration.ofMillis(30000L)) .build(); SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build(); InstanceAdminStubSettings stubSettings = options.getInstanceAdminStubSettings(); @@ -451,13 +451,13 @@ public void testInstanceAdminDefaultRetrySettings() { public void testInstanceAdminCustomRetrySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofSeconds(9999L)) + .setInitialRetryDelayDuration(Duration.ofSeconds(9999L)) .setRetryDelayMultiplier(9999.99D) - .setMaxRetryDelay(Duration.ofSeconds(9999L)) - .setInitialRpcTimeout(Duration.ofSeconds(9999L)) + .setMaxRetryDelayDuration(Duration.ofSeconds(9999L)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(9999L)) .setRpcTimeoutMultiplier(9999.99D) - .setMaxRpcTimeout(Duration.ofSeconds(9999L)) - .setTotalTimeout(Duration.ofSeconds(9999L)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(9999L)) + .setTotalTimeoutDuration(Duration.ofSeconds(9999L)) .build(); SpannerOptions.Builder builder = SpannerOptions.newBuilder().setProjectId("test-project"); InstanceAdminStubSettings.Builder stubSettingsBuilder = @@ -866,14 +866,14 @@ public void testSpannerCallContextTimeoutConfigurator_NullValues() { public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { SpannerCallContextTimeoutConfigurator configurator = SpannerCallContextTimeoutConfigurator.create(); - configurator.withBatchUpdateTimeout(Duration.ofSeconds(1L)); - configurator.withCommitTimeout(Duration.ofSeconds(2L)); - configurator.withExecuteQueryTimeout(Duration.ofSeconds(3L)); - configurator.withExecuteUpdateTimeout(Duration.ofSeconds(4L)); - configurator.withPartitionQueryTimeout(Duration.ofSeconds(5L)); - configurator.withPartitionReadTimeout(Duration.ofSeconds(6L)); - configurator.withReadTimeout(Duration.ofSeconds(7L)); - configurator.withRollbackTimeout(Duration.ofSeconds(8L)); + configurator.withBatchUpdateTimeoutDuration(Duration.ofSeconds(1L)); + configurator.withCommitTimeoutDuration(Duration.ofSeconds(2L)); + configurator.withExecuteQueryTimeoutDuration(Duration.ofSeconds(3L)); + configurator.withExecuteUpdateTimeoutDuration(Duration.ofSeconds(4L)); + configurator.withPartitionQueryTimeoutDuration(Duration.ofSeconds(5L)); + configurator.withPartitionReadTimeoutDuration(Duration.ofSeconds(6L)); + configurator.withReadTimeoutDuration(Duration.ofSeconds(7L)); + configurator.withRollbackTimeoutDuration(Duration.ofSeconds(8L)); ApiCallContext inputCallContext = GrpcCallContext.createDefault(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/StatementTimeoutTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/StatementTimeoutTest.java index 24817c84450..f55c55c6c93 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/StatementTimeoutTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/StatementTimeoutTest.java @@ -46,6 +46,7 @@ import com.google.spanner.v1.CommitRequest; import com.google.spanner.v1.ExecuteSqlRequest; import io.grpc.Status; +import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -58,7 +59,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class StatementTimeoutTest extends AbstractMockServerTest { @@ -97,10 +97,10 @@ protected ITConnection createConnection() { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) - .setMaxRetryDelay(Duration.ofMillis(1L)) + .setInitialRetryDelayDuration(Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(Duration.ofMillis(1L)) .setRetryDelayMultiplier(1.0) - .setTotalTimeout(Duration.ofMinutes(10L)) + .setTotalTimeoutDuration(Duration.ofMinutes(10L)) .build()))) .build(); return createITConnection(options); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBuiltInMetricsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBuiltInMetricsTest.java index 9ff7e06e813..258c1230709 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBuiltInMetricsTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBuiltInMetricsTest.java @@ -31,6 +31,8 @@ import com.google.monitoring.v3.TimeInterval; import com.google.protobuf.util.Timestamps; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.concurrent.TimeUnit; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -39,8 +41,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITCommitTimestampTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITCommitTimestampTest.java index 5a3b5c14707..70c9cb3757a 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITCommitTimestampTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITCommitTimestampTest.java @@ -36,6 +36,8 @@ import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.RemoteSpannerHelper; import com.google.common.collect.ImmutableList; +import java.time.Duration; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.concurrent.ExecutionException; @@ -47,8 +49,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; /** Integration test for commit timestamp of Cloud Spanner. */ @Category(ParallelIntegrationTest.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgJsonbTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgJsonbTest.java index 7338c76f07e..634f7919658 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgJsonbTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgJsonbTest.java @@ -41,6 +41,7 @@ import com.google.common.collect.ImmutableList; import com.google.protobuf.ListValue; import com.google.protobuf.NullValue; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -57,7 +58,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgNumericTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgNumericTest.java index b5fc084a54c..bacb4718da0 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgNumericTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPgNumericTest.java @@ -35,6 +35,7 @@ import com.google.cloud.spanner.testing.RemoteSpannerHelper; import com.google.common.collect.ImmutableList; import java.math.BigDecimal; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -47,7 +48,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrCreateDatabaseTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrCreateDatabaseTest.java index f9fa081e413..6056b857b18 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrCreateDatabaseTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrCreateDatabaseTest.java @@ -30,6 +30,7 @@ import com.google.cloud.spanner.ParallelIntegrationTest; import com.google.cloud.spanner.SpannerException; import com.google.cloud.spanner.testing.RemoteSpannerHelper; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -42,7 +43,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrUpdateDatabaseTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrUpdateDatabaseTest.java index fa756b2f277..c730a7fa36c 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrUpdateDatabaseTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITPitrUpdateDatabaseTest.java @@ -35,6 +35,7 @@ import com.google.cloud.spanner.Statement; import com.google.cloud.spanner.testing.RemoteSpannerHelper; import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; +import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -45,7 +46,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @Category(ParallelIntegrationTest.class) @RunWith(JUnit4.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java index b3ff3b8f1c2..a0f236b0fd7 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java @@ -85,6 +85,7 @@ import io.opentelemetry.sdk.trace.samplers.Sampler; import java.io.IOException; import java.net.InetSocketAddress; +import java.time.Duration; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -96,7 +97,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import org.threeten.bp.Duration; @RunWith(Parameterized.class) public class GapicSpannerRpcTest { @@ -386,7 +386,7 @@ public ApiCallContext configure( // Sequence numbers are only assigned for DML statements, which means that // this is an update statement. if (sqlRequest.getSeqno() > 0L) { - return context.withTimeout(timeoutHolder.timeout); + return context.withTimeoutDuration(timeoutHolder.timeout); } } return null; From fafe22a3f2c2e39c534829115c39da5d2eeab445 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 21 Nov 2024 14:56:06 -0500 Subject: [PATCH 2/5] fix units --- .../cloud/spanner/BatchCreateSessionsSlowTest.java | 1 - .../cloud/spanner/DatabaseClientImplTest.java | 6 ++++-- .../google/cloud/spanner/SpannerOptionsTest.java | 14 +++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java index 5b65dd8cf16..72d04d94614 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsSlowTest.java @@ -194,7 +194,6 @@ public void testBatchCreateSessionsTimesOut_whenResourceExhausted() throws Excep List> futures = new ArrayList<>(5000); AtomicInteger counter = new AtomicInteger(); for (int i = 0; i < 5000; i++) { - final int index = i; futures.add( service.submit( () -> { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java index cdb60bf1443..86d0bfc2c94 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java @@ -2868,7 +2868,8 @@ public void testPartitionedDmlDoesNotTimeout() { DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); - assertThat(spanner.getOptions().getPartitionedDmlTimeout()).isEqualTo(Duration.ofHours(2L)); + assertThat(spanner.getOptions().getPartitionedDmlTimeoutDuration()) + .isEqualTo(Duration.ofHours(2L)); // PDML should not timeout with these settings. long updateCount = client.executePartitionedUpdate(UPDATE_STATEMENT); @@ -2904,7 +2905,8 @@ public void testPartitionedDmlWithLowerTimeout() { try (Spanner spanner = builder.build().getService()) { DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); - assertThat(spanner.getOptions().getPartitionedDmlTimeout()).isEqualTo(Duration.ofMillis(10L)); + assertThat(spanner.getOptions().getPartitionedDmlTimeoutDuration()) + .isEqualTo(Duration.ofMillis(10L)); // PDML should time out with these settings. mockSpanner.setExecuteSqlExecutionTime( SimulatedExecutionTime.ofMinimumAndRandomTime(1000, 0)); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java index 832729e2df2..a1632877eac 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java @@ -919,7 +919,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, CommitRequest.getDefaultInstance(), SpannerGrpc.getCommitMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(2L)); assertThat( configurator @@ -927,7 +927,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, RollbackRequest.getDefaultInstance(), SpannerGrpc.getRollbackMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(8L)); assertNull( @@ -941,7 +941,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, ExecuteSqlRequest.getDefaultInstance(), SpannerGrpc.getExecuteStreamingSqlMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(3L)); assertThat( configurator @@ -949,7 +949,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, ExecuteBatchDmlRequest.getDefaultInstance(), SpannerGrpc.getExecuteBatchDmlMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(1L)); assertNull( configurator.configure( @@ -960,7 +960,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, ReadRequest.getDefaultInstance(), SpannerGrpc.getStreamingReadMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(7L)); assertThat( @@ -969,7 +969,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, PartitionQueryRequest.getDefaultInstance(), SpannerGrpc.getPartitionQueryMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(5L)); assertThat( configurator @@ -977,7 +977,7 @@ public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() { inputCallContext, PartitionReadRequest.getDefaultInstance(), SpannerGrpc.getPartitionReadMethod()) - .getTimeout()) + .getTimeoutDuration()) .isEqualTo(Duration.ofSeconds(6L)); } From b42108407808067c87aa18a563ef92c8ef1890b3 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 21 Nov 2024 15:48:07 -0500 Subject: [PATCH 3/5] remove threeten from executor lib --- google-cloud-spanner-executor/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/google-cloud-spanner-executor/pom.xml b/google-cloud-spanner-executor/pom.xml index 6aaf0ad73c1..d3948f9996e 100644 --- a/google-cloud-spanner-executor/pom.xml +++ b/google-cloud-spanner-executor/pom.xml @@ -145,10 +145,6 @@ com.google.api gax-grpc - - org.threeten - threetenbp - com.google.code.findbugs jsr305 From ea066d9a999c16c38a2d3a0ec15fc34c88c33f03 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Mon, 25 Nov 2024 12:58:07 -0500 Subject: [PATCH 4/5] use javatime implementation in tracer --- .../main/java/com/google/cloud/spanner/CompositeTracer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java index 0ab12b4e99f..26b734f1cad 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java @@ -16,6 +16,8 @@ package com.google.cloud.spanner; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.InternalApi; import com.google.api.gax.tracing.ApiTracer; import com.google.api.gax.tracing.BaseApiTracer; @@ -110,7 +112,7 @@ public void attemptCancelled() { @Override public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { for (ApiTracer child : children) { - child.attemptFailed(error, delay); + child.attemptFailedDuration(error, toJavaTimeDuration(delay)); } } From 7b77a791e352a31e34627faa11d1985b891e7ed2 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 3 Dec 2024 12:05:28 -0500 Subject: [PATCH 5/5] use java.time as import --- .../google/cloud/spanner/CompositeTracer.java | 3 +- .../MultiplexedSessionDatabaseClient.java | 2 +- .../cloud/spanner/OpenTelemetryApiTracer.java | 10 +- .../cloud/spanner/SessionPoolOptions.java | 82 ++++++------- .../google/cloud/spanner/SpannerOptions.java | 116 +++++++----------- .../cloud/spanner/DefaultBenchmark.java | 10 +- ...edSessionDatabaseClientMockServerTest.java | 2 +- .../MultiplexedSessionDatabaseClientTest.java | 2 +- .../spanner/MultiplexedSessionsBenchmark.java | 8 +- 9 files changed, 102 insertions(+), 133 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java index 26b734f1cad..60d7081cc1e 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java @@ -23,6 +23,7 @@ import com.google.api.gax.tracing.BaseApiTracer; import com.google.api.gax.tracing.MetricsTracer; import com.google.common.collect.ImmutableList; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -117,7 +118,7 @@ public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { } @Override - public void attemptFailedDuration(Throwable error, java.time.Duration delay) { + public void attemptFailedDuration(Throwable error, Duration delay) { for (ApiTracer child : children) { child.attemptFailedDuration(error, delay); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java index a07819c07d0..bd709adbd99 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java @@ -275,7 +275,7 @@ public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount private static void maybeWaitForSessionCreation( SessionPoolOptions sessionPoolOptions, ApiFuture future) { - java.time.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions(); + Duration waitDuration = sessionPoolOptions.getWaitForMinSessions(); if (waitDuration != null && !waitDuration.isZero()) { long timeoutMillis = waitDuration.toMillis(); try { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java index ea6e745f71f..863c531de30 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/OpenTelemetryApiTracer.java @@ -27,6 +27,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.StatusCode; +import java.time.Duration; import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -165,18 +166,15 @@ public void attemptCancelled() { lastConnectionId = null; } - /** - * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} - * instead. - */ + /** This method is obsolete. Use {@link #attemptFailedDuration(Throwable, Duration)} instead. */ @Override - @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") + @ObsoleteApi("Use attemptFailedDuration(Throwable, Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { attemptFailedDuration(error, toJavaTimeDuration(delay)); } @Override - public void attemptFailedDuration(Throwable error, java.time.Duration delay) { + public void attemptFailedDuration(Throwable error, Duration delay) { AttributesBuilder builder = baseAttemptAttributesBuilder(); if (delay != null) { builder.put(RETRY_DELAY_KEY, delay.toMillis()); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java index 14591ac1b80..d4f3e598b11 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java @@ -24,6 +24,7 @@ import com.google.cloud.spanner.SessionPool.Position; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import java.time.Duration; import java.util.Locale; import java.util.Objects; @@ -51,9 +52,9 @@ public class SessionPoolOptions { private final ActionOnExhaustion actionOnExhaustion; private final long loopFrequency; - private final java.time.Duration multiplexedSessionMaintenanceLoopFrequency; + private final Duration multiplexedSessionMaintenanceLoopFrequency; private final int keepAliveIntervalMinutes; - private final java.time.Duration removeInactiveSessionAfter; + private final Duration removeInactiveSessionAfter; private final ActionOnSessionNotFound actionOnSessionNotFound; private final ActionOnSessionLeak actionOnSessionLeak; private final boolean trackStackTraceOfSessionCheckout; @@ -66,8 +67,8 @@ public class SessionPoolOptions { @Deprecated private final long initialWaitForSessionTimeoutMillis; private final boolean autoDetectDialect; - private final java.time.Duration waitForMinSessions; - private final java.time.Duration acquireSessionTimeout; + private final Duration waitForMinSessions; + private final Duration acquireSessionTimeout; private final Position releaseToPosition; private final long randomizePositionQPSThreshold; @@ -84,7 +85,7 @@ public class SessionPoolOptions { private final boolean useMultiplexedSessionForRW; - private final java.time.Duration multiplexedSessionMaintenanceDuration; + private final Duration multiplexedSessionMaintenanceDuration; private SessionPoolOptions(Builder builder) { // minSessions > maxSessions is only possible if the user has only set a value for maxSessions. @@ -238,7 +239,7 @@ long getLoopFrequency() { return loopFrequency; } - java.time.Duration getMultiplexedSessionMaintenanceLoopFrequency() { + Duration getMultiplexedSessionMaintenanceLoopFrequency() { return this.multiplexedSessionMaintenanceLoopFrequency; } @@ -252,7 +253,7 @@ public org.threeten.bp.Duration getRemoveInactiveSessionAfter() { return toThreetenDuration(getRemoveInactiveSessionAfterDuration()); } - public java.time.Duration getRemoveInactiveSessionAfterDuration() { + public Duration getRemoveInactiveSessionAfterDuration() { return removeInactiveSessionAfter; } @@ -311,12 +312,12 @@ public boolean isTrackStackTraceOfSessionCheckout() { return trackStackTraceOfSessionCheckout; } - java.time.Duration getWaitForMinSessions() { + Duration getWaitForMinSessions() { return waitForMinSessions; } @VisibleForTesting - java.time.Duration getAcquireSessionTimeout() { + Duration getAcquireSessionTimeout() { return acquireSessionTimeout; } @@ -370,7 +371,7 @@ private static Boolean getUseMultiplexedSessionForRWFromEnvVariable() { return null; } - java.time.Duration getMultiplexedSessionMaintenanceDuration() { + Duration getMultiplexedSessionMaintenanceDuration() { return multiplexedSessionMaintenanceDuration; } @@ -410,7 +411,7 @@ static class InactiveTransactionRemovalOptions { * Frequency for closing inactive transactions. Between two consecutive task executions, it's * ensured that the duration is greater or equal to this duration. */ - private final java.time.Duration executionFrequency; + private final Duration executionFrequency; /** * Long-running transactions will be cleaned up if utilisation is greater than the below value. @@ -421,7 +422,7 @@ static class InactiveTransactionRemovalOptions { * A transaction is considered to be idle if it has not been used for a duration greater than * the below value. */ - private final java.time.Duration idleTimeThreshold; + private final Duration idleTimeThreshold; InactiveTransactionRemovalOptions(final Builder builder) { this.actionOnInactiveTransaction = builder.actionOnInactiveTransaction; @@ -451,7 +452,7 @@ public int hashCode() { this.usedSessionsRatioThreshold); } - java.time.Duration getExecutionFrequency() { + Duration getExecutionFrequency() { return executionFrequency; } @@ -459,7 +460,7 @@ java.time.Duration getExecutionFrequency() { return usedSessionsRatioThreshold; } - java.time.Duration getIdleTimeThreshold() { + Duration getIdleTimeThreshold() { return idleTimeThreshold; } @@ -470,9 +471,9 @@ static InactiveTransactionRemovalOptions.Builder newBuilder() { static class Builder { private ActionOnInactiveTransaction actionOnInactiveTransaction = ActionOnInactiveTransaction.WARN; - private java.time.Duration executionFrequency = java.time.Duration.ofMinutes(2); + private Duration executionFrequency = Duration.ofMinutes(2); private double usedSessionsRatioThreshold = 0.95; - private java.time.Duration idleTimeThreshold = java.time.Duration.ofMinutes(60L); + private Duration idleTimeThreshold = Duration.ofMinutes(60L); public Builder() {} @@ -501,7 +502,7 @@ InactiveTransactionRemovalOptions.Builder setActionOnInactiveTransaction( @VisibleForTesting InactiveTransactionRemovalOptions.Builder setExecutionFrequency( - final java.time.Duration executionFrequency) { + final Duration executionFrequency) { this.executionFrequency = executionFrequency; return this; } @@ -515,7 +516,7 @@ InactiveTransactionRemovalOptions.Builder setUsedSessionsRatioThreshold( @VisibleForTesting InactiveTransactionRemovalOptions.Builder setIdleTimeThreshold( - final java.time.Duration idleTimeThreshold) { + final Duration idleTimeThreshold) { this.idleTimeThreshold = idleTimeThreshold; return this; } @@ -556,13 +557,12 @@ public static class Builder { private InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions = InactiveTransactionRemovalOptions.newBuilder().build(); private long loopFrequency = 10 * 1000L; - private java.time.Duration multiplexedSessionMaintenanceLoopFrequency = - java.time.Duration.ofMinutes(10); + private Duration multiplexedSessionMaintenanceLoopFrequency = Duration.ofMinutes(10); private int keepAliveIntervalMinutes = 30; - private java.time.Duration removeInactiveSessionAfter = java.time.Duration.ofMinutes(55L); + private Duration removeInactiveSessionAfter = Duration.ofMinutes(55L); private boolean autoDetectDialect = false; - private java.time.Duration waitForMinSessions = java.time.Duration.ZERO; - private java.time.Duration acquireSessionTimeout = java.time.Duration.ofSeconds(60); + private Duration waitForMinSessions = Duration.ZERO; + private Duration acquireSessionTimeout = Duration.ofSeconds(60); private final Position releaseToPosition = getReleaseToPositionFromSystemProperty(); /** * The session pool will randomize the position of a session that is being returned when this @@ -585,7 +585,7 @@ public static class Builder { // default. private boolean useMultiplexedSessionForRW = false; - private java.time.Duration multiplexedSessionMaintenanceDuration = java.time.Duration.ofDays(7); + private Duration multiplexedSessionMaintenanceDuration = Duration.ofDays(7); private Clock poolMaintainerClock = Clock.INSTANCE; private static Position getReleaseToPositionFromSystemProperty() { @@ -686,7 +686,7 @@ Builder setLoopFrequency(long loopFrequency) { return this; } - Builder setMultiplexedSessionMaintenanceLoopFrequency(java.time.Duration frequency) { + Builder setMultiplexedSessionMaintenanceLoopFrequency(Duration frequency) { this.multiplexedSessionMaintenanceLoopFrequency = frequency; return this; } @@ -698,15 +698,15 @@ Builder setInactiveTransactionRemovalOptions( } /** - * This method is obsolete. Use {@link - * #setRemoveInactiveSessionAfterDuration(java.time.Duration)} instead. + * This method is obsolete. Use {@link #setRemoveInactiveSessionAfterDuration(Duration)} + * instead. */ - @ObsoleteApi("Use setRemoveInactiveSessionAfterDuration(java.time.Duration) instead") + @ObsoleteApi("Use setRemoveInactiveSessionAfterDuration(Duration) instead") public Builder setRemoveInactiveSessionAfter(org.threeten.bp.Duration duration) { return setRemoveInactiveSessionAfterDuration(toJavaTimeDuration(duration)); } - public Builder setRemoveInactiveSessionAfterDuration(java.time.Duration duration) { + public Builder setRemoveInactiveSessionAfterDuration(Duration duration) { this.removeInactiveSessionAfter = duration; return this; } @@ -737,8 +737,8 @@ public Builder setFailIfPoolExhausted() { * *

By default the requests are blocked for 60s and will fail with a `SpannerException` with * error code `ResourceExhausted` if this timeout is exceeded. If you wish to block for a - * different period use the option {@link - * Builder#setAcquireSessionTimeoutDuration(java.time.Duration)} ()} + * different period use the option {@link Builder#setAcquireSessionTimeoutDuration(Duration)} + * ()} */ public Builder setBlockIfPoolExhausted() { this.actionOnExhaustion = ActionOnExhaustion.BLOCK; @@ -849,7 +849,7 @@ Builder setUseMultiplexedSessionForRW(boolean useMultiplexedSessionForRW) { @VisibleForTesting Builder setMultiplexedSessionMaintenanceDuration( - java.time.Duration multiplexedSessionMaintenanceDuration) { + Duration multiplexedSessionMaintenanceDuration) { this.multiplexedSessionMaintenanceDuration = multiplexedSessionMaintenanceDuration; return this; } @@ -926,11 +926,8 @@ public Builder setWriteSessionsFraction(float writeSessionsFraction) { return this; } - /** - * This method is obsolete. Use {@link #setWaitForMinSessionsDuration(java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use setWaitForMinSessionsDuration(java.time.Duration) instead") + /** This method is obsolete. Use {@link #setWaitForMinSessionsDuration(Duration)} instead. */ + @ObsoleteApi("Use setWaitForMinSessionsDuration(Duration) instead") public Builder setWaitForMinSessions(org.threeten.bp.Duration waitForMinSessions) { return setWaitForMinSessionsDuration(toJavaTimeDuration(waitForMinSessions)); } @@ -945,16 +942,13 @@ public Builder setWaitForMinSessions(org.threeten.bp.Duration waitForMinSessions * *

Defaults to zero (initialization is done asynchronously). */ - public Builder setWaitForMinSessionsDuration(java.time.Duration waitForMinSessions) { + public Builder setWaitForMinSessionsDuration(Duration waitForMinSessions) { this.waitForMinSessions = waitForMinSessions; return this; } - /** - * This method is obsolete. Use {@link #setAcquireSessionTimeoutDuration(java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use setAcquireSessionTimeoutDuration(java.time.Duration) instead") + /** This method is obsolete. Use {@link #setAcquireSessionTimeoutDuration(Duration)} instead. */ + @ObsoleteApi("Use setAcquireSessionTimeoutDuration(Duration) instead") public Builder setAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionTimeout) { return setAcquireSessionTimeoutDuration(toJavaTimeDuration(acquireSessionTimeout)); } @@ -963,7 +957,7 @@ public Builder setAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionT * If greater than zero, we wait for said duration when no sessions are available in the {@link * SessionPool}. The default is a 60s timeout. Set the value to null to disable the timeout. */ - public Builder setAcquireSessionTimeoutDuration(java.time.Duration acquireSessionTimeout) { + public Builder setAcquireSessionTimeoutDuration(Duration acquireSessionTimeout) { try { if (acquireSessionTimeout != null) { Preconditions.checkArgument( diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java index 0217f387f6c..371f76dbc3c 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java @@ -77,6 +77,7 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -132,7 +133,7 @@ public class SpannerOptions extends ServiceOptions { private final SpannerStubSettings spannerStubSettings; private final InstanceAdminStubSettings instanceAdminStubSettings; private final DatabaseAdminStubSettings databaseAdminStubSettings; - private final java.time.Duration partitionedDmlTimeout; + private final Duration partitionedDmlTimeout; private final boolean grpcGcpExtensionEnabled; private final GcpManagedChannelOptions grpcGcpOptions; private final boolean autoThrottleAdministrativeRequests; @@ -353,16 +354,16 @@ static SpannerMethod valueOf(ReqT request, MethodDescriptor */ public static class SpannerCallContextTimeoutConfigurator implements CallContextConfigurator { - private java.time.Duration commitTimeout; - private java.time.Duration rollbackTimeout; + private Duration commitTimeout; + private Duration rollbackTimeout; - private java.time.Duration executeQueryTimeout; - private java.time.Duration executeUpdateTimeout; - private java.time.Duration batchUpdateTimeout; - private java.time.Duration readTimeout; + private Duration executeQueryTimeout; + private Duration executeUpdateTimeout; + private Duration batchUpdateTimeout; + private Duration readTimeout; - private java.time.Duration partitionQueryTimeout; - private java.time.Duration partitionReadTimeout; + private Duration partitionQueryTimeout; + private Duration partitionReadTimeout; public static SpannerCallContextTimeoutConfigurator create() { return new SpannerCallContextTimeoutConfigurator(); @@ -425,21 +426,18 @@ public org.threeten.bp.Duration getCommitTimeout() { return toThreetenDuration(getCommitTimeoutDuration()); } - public java.time.Duration getCommitTimeoutDuration() { + public Duration getCommitTimeoutDuration() { return commitTimeout; } - /** - * This method is obsolete. Use {@link #withCommitTimeoutDuration(java.time.Duration)} instead. - */ + /** This method is obsolete. Use {@link #withCommitTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withCommitTimeoutDuration() instead.") public SpannerCallContextTimeoutConfigurator withCommitTimeout( org.threeten.bp.Duration commitTimeout) { return withCommitTimeoutDuration(toJavaTimeDuration(commitTimeout)); } - public SpannerCallContextTimeoutConfigurator withCommitTimeoutDuration( - java.time.Duration commitTimeout) { + public SpannerCallContextTimeoutConfigurator withCommitTimeoutDuration(Duration commitTimeout) { this.commitTimeout = commitTimeout; return this; } @@ -450,14 +448,11 @@ public org.threeten.bp.Duration getRollbackTimeout() { return toThreetenDuration(getRollbackTimeoutDuration()); } - public java.time.Duration getRollbackTimeoutDuration() { + public Duration getRollbackTimeoutDuration() { return rollbackTimeout; } - /** - * This method is obsolete. Use {@link #withRollbackTimeoutDuration(java.time.Duration)} - * instead. - */ + /** This method is obsolete. Use {@link #withRollbackTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withRollbackTimeoutDuration() instead.") public SpannerCallContextTimeoutConfigurator withRollbackTimeout( org.threeten.bp.Duration rollbackTimeout) { @@ -465,7 +460,7 @@ public SpannerCallContextTimeoutConfigurator withRollbackTimeout( } public SpannerCallContextTimeoutConfigurator withRollbackTimeoutDuration( - java.time.Duration rollbackTimeout) { + Duration rollbackTimeout) { this.rollbackTimeout = rollbackTimeout; return this; } @@ -476,14 +471,11 @@ public org.threeten.bp.Duration getExecuteQueryTimeout() { return toThreetenDuration(getExecuteQueryTimeoutDuration()); } - public java.time.Duration getExecuteQueryTimeoutDuration() { + public Duration getExecuteQueryTimeoutDuration() { return executeQueryTimeout; } - /** - * This method is obsolete. Use {@link #withExecuteQueryTimeoutDuration(java.time.Duration)} - * instead. - */ + /** This method is obsolete. Use {@link #withExecuteQueryTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withExecuteQueryTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withExecuteQueryTimeout( org.threeten.bp.Duration executeQueryTimeout) { @@ -491,7 +483,7 @@ public SpannerCallContextTimeoutConfigurator withExecuteQueryTimeout( } public SpannerCallContextTimeoutConfigurator withExecuteQueryTimeoutDuration( - java.time.Duration executeQueryTimeout) { + Duration executeQueryTimeout) { this.executeQueryTimeout = executeQueryTimeout; return this; } @@ -502,14 +494,11 @@ public org.threeten.bp.Duration getExecuteUpdateTimeout() { return toThreetenDuration(getExecuteUpdateTimeoutDuration()); } - public java.time.Duration getExecuteUpdateTimeoutDuration() { + public Duration getExecuteUpdateTimeoutDuration() { return executeUpdateTimeout; } - /** - * This method is obsolete. Use {@link #withExecuteUpdateTimeoutDuration(java.time.Duration)} - * instead. - */ + /** This method is obsolete. Use {@link #withExecuteUpdateTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withExecuteUpdateTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeout( org.threeten.bp.Duration executeUpdateTimeout) { @@ -517,7 +506,7 @@ public SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeout( } public SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeoutDuration( - java.time.Duration executeUpdateTimeout) { + Duration executeUpdateTimeout) { this.executeUpdateTimeout = executeUpdateTimeout; return this; } @@ -528,14 +517,11 @@ public org.threeten.bp.Duration getBatchUpdateTimeout() { return toThreetenDuration(getBatchUpdateTimeoutDuration()); } - public java.time.Duration getBatchUpdateTimeoutDuration() { + public Duration getBatchUpdateTimeoutDuration() { return batchUpdateTimeout; } - /** - * This method is obsolete. Use {@link #withBatchUpdateTimeoutDuration(java.time.Duration)} - * instead. - */ + /** This method is obsolete. Use {@link #withBatchUpdateTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withBatchUpdateTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withBatchUpdateTimeout( org.threeten.bp.Duration batchUpdateTimeout) { @@ -543,7 +529,7 @@ public SpannerCallContextTimeoutConfigurator withBatchUpdateTimeout( } public SpannerCallContextTimeoutConfigurator withBatchUpdateTimeoutDuration( - java.time.Duration batchUpdateTimeout) { + Duration batchUpdateTimeout) { this.batchUpdateTimeout = batchUpdateTimeout; return this; } @@ -554,21 +540,18 @@ public org.threeten.bp.Duration getReadTimeout() { return toThreetenDuration(getReadTimeoutDuration()); } - public java.time.Duration getReadTimeoutDuration() { + public Duration getReadTimeoutDuration() { return readTimeout; } - /** - * This method is obsolete. Use {@link #withReadTimeoutDuration(java.time.Duration)} instead. - */ + /** This method is obsolete. Use {@link #withReadTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withReadTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withReadTimeout( org.threeten.bp.Duration readTimeout) { return withReadTimeoutDuration(toJavaTimeDuration(readTimeout)); } - public SpannerCallContextTimeoutConfigurator withReadTimeoutDuration( - java.time.Duration readTimeout) { + public SpannerCallContextTimeoutConfigurator withReadTimeoutDuration(Duration readTimeout) { this.readTimeout = readTimeout; return this; } @@ -579,13 +562,12 @@ public org.threeten.bp.Duration getPartitionQueryTimeout() { return toThreetenDuration(getPartitionQueryTimeoutDuration()); } - public java.time.Duration getPartitionQueryTimeoutDuration() { + public Duration getPartitionQueryTimeoutDuration() { return partitionQueryTimeout; } /** - * This method is obsolete. Use {@link #withPartitionQueryTimeoutDuration(java.time.Duration)} - * instead. + * This method is obsolete. Use {@link #withPartitionQueryTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withPartitionQueryTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withPartitionQueryTimeout( @@ -594,7 +576,7 @@ public SpannerCallContextTimeoutConfigurator withPartitionQueryTimeout( } public SpannerCallContextTimeoutConfigurator withPartitionQueryTimeoutDuration( - java.time.Duration partitionQueryTimeout) { + Duration partitionQueryTimeout) { this.partitionQueryTimeout = partitionQueryTimeout; return this; } @@ -605,14 +587,11 @@ public org.threeten.bp.Duration getPartitionReadTimeout() { return toThreetenDuration(getPartitionReadTimeoutDuration()); } - public java.time.Duration getPartitionReadTimeoutDuration() { + public Duration getPartitionReadTimeoutDuration() { return partitionReadTimeout; } - /** - * This method is obsolete. Use {@link #withPartitionReadTimeoutDuration(java.time.Duration)} - * instead. - */ + /** This method is obsolete. Use {@link #withPartitionReadTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use withPartitionReadTimeoutDuration() instead") public SpannerCallContextTimeoutConfigurator withPartitionReadTimeout( org.threeten.bp.Duration partitionReadTimeout) { @@ -620,7 +599,7 @@ public SpannerCallContextTimeoutConfigurator withPartitionReadTimeout( } public SpannerCallContextTimeoutConfigurator withPartitionReadTimeoutDuration( - java.time.Duration partitionReadTimeout) { + Duration partitionReadTimeout) { this.partitionReadTimeout = partitionReadTimeout; return this; } @@ -904,9 +883,9 @@ public static class Builder static final DecodeMode DEFAULT_DECODE_MODE = DecodeMode.DIRECT; static final RetrySettings DEFAULT_ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelayDuration(java.time.Duration.ofSeconds(5L)) + .setInitialRetryDelayDuration(Duration.ofSeconds(5L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(60L)) + .setMaxRetryDelayDuration(Duration.ofSeconds(60L)) .setMaxAttempts(10) .build(); private final ImmutableSet allowedClientLibTokens = @@ -938,7 +917,7 @@ public static class Builder InstanceAdminStubSettings.newBuilder(); private DatabaseAdminStubSettings.Builder databaseAdminStubSettingsBuilder = DatabaseAdminStubSettings.newBuilder(); - private java.time.Duration partitionedDmlTimeout = java.time.Duration.ofHours(2L); + private Duration partitionedDmlTimeout = Duration.ofHours(2L); private boolean grpcGcpExtensionEnabled = false; private GcpManagedChannelOptions grpcGcpOptions; private RetrySettings retryAdministrativeRequestsSettings = @@ -969,13 +948,13 @@ protected Builder() { OperationTimedPollAlgorithm longRunningPollingAlgorithm = OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRpcTimeoutDuration(java.time.Duration.ofSeconds(60L)) - .setMaxRpcTimeoutDuration(java.time.Duration.ofSeconds(600L)) - .setInitialRetryDelayDuration(java.time.Duration.ofSeconds(20L)) - .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(45L)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(60L)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(600L)) + .setInitialRetryDelayDuration(Duration.ofSeconds(20L)) + .setMaxRetryDelayDuration(Duration.ofSeconds(45L)) .setRetryDelayMultiplier(1.5) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeoutDuration(java.time.Duration.ofHours(48L)) + .setTotalTimeoutDuration(Duration.ofHours(48L)) .build()); databaseAdminStubSettingsBuilder .createDatabaseOperationSettings() @@ -1243,11 +1222,8 @@ public DatabaseAdminStubSettings.Builder getDatabaseAdminStubSettingsBuilder() { return databaseAdminStubSettingsBuilder; } - /** - * This method is obsolete. Use {@link #setPartitionedDmlTimeoutDuration(java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use setPartitionedDmlTimeoutDuration(java.time.Duration) instead") + /** This method is obsolete. Use {@link #setPartitionedDmlTimeoutDuration(Duration)} instead. */ + @ObsoleteApi("Use setPartitionedDmlTimeoutDuration(Duration) instead") public Builder setPartitionedDmlTimeout(org.threeten.bp.Duration timeout) { return setPartitionedDmlTimeoutDuration(toJavaTimeDuration(timeout)); } @@ -1256,7 +1232,7 @@ public Builder setPartitionedDmlTimeout(org.threeten.bp.Duration timeout) { * Sets a timeout specifically for Partitioned DML statements executed through {@link * DatabaseClient#executePartitionedUpdate(Statement, UpdateOption...)}. The default is 2 hours. */ - public Builder setPartitionedDmlTimeoutDuration(java.time.Duration timeout) { + public Builder setPartitionedDmlTimeoutDuration(Duration timeout) { this.partitionedDmlTimeout = timeout; return this; } @@ -1767,7 +1743,7 @@ public org.threeten.bp.Duration getPartitionedDmlTimeout() { return toThreetenDuration(getPartitionedDmlTimeoutDuration()); } - public java.time.Duration getPartitionedDmlTimeoutDuration() { + public Duration getPartitionedDmlTimeoutDuration() { return partitionedDmlTimeout; } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java index cdc62f83ef9..35712cd5b4e 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DefaultBenchmark.java @@ -92,7 +92,7 @@ public void setup() throws Exception { SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(maxSessions) - .setWaitForMinSessionsDuration(java.time.Duration.ofSeconds(20)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(20)) .build()) .setHost(SERVER_URL) .setNumChannels(NUM_GRPC_CHANNELS) @@ -168,7 +168,7 @@ public void burstUpdates(final BenchmarkState server) throws Exception { collectResultsAndPrint(service, results, TOTAL_WRITES_PER_RUN); } - private List runBenchmarksForSingleUseQueries( + private List runBenchmarksForSingleUseQueries( final BenchmarkState server, int numberOfOperations) { List results = new ArrayList<>(numberOfOperations); // Execute one query to make sure everything has been warmed up. @@ -186,7 +186,7 @@ private void executeWarmup(final BenchmarkState server) { } } - private java.time.Duration executeSingleUseQuery(final BenchmarkState server) { + private Duration executeSingleUseQuery(final BenchmarkState server) { Stopwatch watch = Stopwatch.createStarted(); try (ResultSet rs = server.client.singleUse().executeQuery(getRandomisedReadStatement())) { @@ -198,7 +198,7 @@ private java.time.Duration executeSingleUseQuery(final BenchmarkState server) { return watch.elapsed(); } - private List runBenchmarkForUpdates( + private List runBenchmarkForUpdates( final BenchmarkState server, int numberOfOperations) { List results = new ArrayList<>(numberOfOperations); // Execute one query to make sure everything has been warmed up. @@ -237,7 +237,7 @@ void collectResultsAndPrint( List>> results, int numOperationsPerThread) throws Exception { - final List collectResults = + final List collectResults = collectResults( service, results, numOperationsPerThread * PARALLEL_THREADS, Duration.ofMinutes(60)); printResults(collectResults); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java index 47e7a19d2cb..9f3d0751471 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java @@ -98,7 +98,7 @@ public void createSpannerInstance() { // Set the maintainer to loop once every 1ms .setMultiplexedSessionMaintenanceLoopFrequency(Duration.ofMillis(1L)) // Set multiplexed sessions to be replaced once every 1ms - .setMultiplexedSessionMaintenanceDuration(java.time.Duration.ofMillis(1L)) + .setMultiplexedSessionMaintenanceDuration(Duration.ofMillis(1L)) .setFailOnSessionLeak() .build()) .build() diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java index a68928ee9b7..9a43ad07cdf 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java @@ -60,7 +60,7 @@ public void testMaintainer() { when(spanner.getOptions()).thenReturn(spannerOptions); when(spannerOptions.getSessionPoolOptions()).thenReturn(sessionPoolOptions); when(sessionPoolOptions.getMultiplexedSessionMaintenanceDuration()) - .thenReturn(java.time.Duration.ofDays(7)); + .thenReturn(Duration.ofDays(7)); when(sessionPoolOptions.getMultiplexedSessionMaintenanceLoopFrequency()) .thenReturn(Duration.ofMinutes(10)); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java index f4256ab6bf7..c6f7e22f280 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionsBenchmark.java @@ -95,7 +95,7 @@ public void setup() throws Exception { SessionPoolOptions.newBuilder() .setMinSessions(minSessions) .setMaxSessions(maxSessions) - .setWaitForMinSessionsDuration(java.time.Duration.ofSeconds(20)) + .setWaitForMinSessionsDuration(Duration.ofSeconds(20)) .setUseMultiplexedSession(true) .build()) .setHost(SERVER_URL) @@ -132,7 +132,7 @@ public void burstQueries(final BenchmarkState server) throws Exception { collectResultsAndPrint(service, results, TOTAL_READS_PER_RUN); } - private List runBenchmarksForSingleUseQueries( + private List runBenchmarksForSingleUseQueries( final BenchmarkState server, int numberOfOperations) { List results = new ArrayList<>(numberOfOperations); // Execute one query to make sure everything has been warmed up. @@ -150,7 +150,7 @@ private void executeWarmup(final BenchmarkState server) { } } - private java.time.Duration executeSingleUseQuery(final BenchmarkState server) { + private Duration executeSingleUseQuery(final BenchmarkState server) { Stopwatch watch = Stopwatch.createStarted(); try (ResultSet rs = server.client.singleUse().executeQuery(getRandomisedReadStatement())) { @@ -175,7 +175,7 @@ void collectResultsAndPrint( List>> results, int numOperationsPerThread) throws Exception { - final List collectResults = + final List collectResults = collectResults( service, results, numOperationsPerThread * PARALLEL_THREADS, Duration.ofMinutes(60)); printResults(collectResults);