From 212dcfad2bfa7058b52b1c8a90556bc029b41afd Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 18 Jul 2023 17:10:56 -0400 Subject: [PATCH 001/141] chore: initial conversion to java.time in gax production classes --- .../com/google/api/gax/grpc/ChannelPool.java | 3 +- .../google/api/gax/grpc/GrpcCallContext.java | 83 +++++++--- .../InstantiatingGrpcChannelProvider.java | 47 ++++-- .../stub/OperationsStubSettings.java | 11 +- .../api/gax/httpjson/HttpJsonCallContext.java | 113 ++++++++++--- .../api/gax/httpjson/HttpJsonCallOptions.java | 21 ++- .../api/gax/httpjson/HttpJsonClientCalls.java | 5 +- .../stub/OperationsStubSettings.java | 11 +- .../api/gax/batching/BatchingSettings.java | 16 +- .../api/gax/batching/ThresholdBatcher.java | 13 +- .../gax/retrying/DirectRetryingExecutor.java | 7 +- .../retrying/ExponentialRetryAlgorithm.java | 27 ++-- .../api/gax/retrying/RetrySettings.java | 148 +++++++++++++++--- .../gax/retrying/TimedAttemptSettings.java | 54 ++++++- .../google/api/gax/rpc/ApiCallContext.java | 52 ++++-- .../google/api/gax/rpc/AttemptCallable.java | 3 +- .../api/gax/rpc/CheckingAttemptCallable.java | 3 +- .../com/google/api/gax/rpc/ClientContext.java | 19 ++- .../google/api/gax/rpc/ClientSettings.java | 29 +++- .../api/gax/rpc/FixedWatchdogProvider.java | 8 +- .../rpc/InstantiatingWatchdogProvider.java | 19 ++- .../gax/rpc/ServerStreamingCallSettings.java | 92 ++++++++--- .../com/google/api/gax/rpc/StubSettings.java | 38 +++-- .../google/api/gax/rpc/UnaryCallSettings.java | 7 +- .../java/com/google/api/gax/rpc/Watchdog.java | 24 ++- .../google/api/gax/rpc/WatchdogProvider.java | 9 +- .../rpc/WatchdogServerStreamingCallable.java | 5 +- .../com/google/api/gax/tracing/ApiTracer.java | 3 +- .../google/api/gax/tracing/BaseApiTracer.java | 3 +- .../api/gax/tracing/OpencensusTracer.java | 3 +- 30 files changed, 667 insertions(+), 209 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java index 7f045cc44d..9e1740ff74 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java @@ -55,7 +55,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * A {@link ManagedChannel} that will send requests round-robin via a set of channels. @@ -69,7 +68,7 @@ */ class ChannelPool extends ManagedChannel { private static final Logger LOG = Logger.getLogger(ChannelPool.class.getName()); - private static final Duration REFRESH_PERIOD = Duration.ofMinutes(50); + private static final java.time.Duration REFRESH_PERIOD = java.time.Duration.ofMinutes(50); private final ChannelPoolSettings settings; private final ChannelFactory channelFactory; diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 5f33c36448..6351718b76 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -48,13 +48,14 @@ import io.grpc.Deadline; import io.grpc.Metadata; import io.grpc.auth.MoreCallCredentials; +import org.threeten.bp.Duration; + import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * GrpcCallContext encapsulates context data used to make a grpc call. @@ -70,9 +71,9 @@ public final class GrpcCallContext implements ApiCallContext { private final Channel channel; private final CallOptions callOptions; - @Nullable private final Duration timeout; - @Nullable private final Duration streamWaitTimeout; - @Nullable private final Duration streamIdleTimeout; + @Nullable private final java.time.Duration timeout; + @Nullable private final java.time.Duration streamWaitTimeout; + @Nullable private final java.time.Duration streamIdleTimeout; @Nullable private final Integer channelAffinity; @Nullable private final RetrySettings retrySettings; @Nullable private final ImmutableSet retryableCodes; @@ -112,9 +113,9 @@ public static GrpcCallContext of(Channel channel, CallOptions callOptions) { private GrpcCallContext( Channel channel, CallOptions callOptions, - @Nullable Duration timeout, - @Nullable Duration streamWaitTimeout, - @Nullable Duration streamIdleTimeout, + @Nullable java.time.Duration timeout, + @Nullable java.time.Duration streamWaitTimeout, + @Nullable java.time.Duration streamIdleTimeout, @Nullable Integer channelAffinity, ImmutableMap> extraHeaders, ApiCallContextOptions options, @@ -172,8 +173,16 @@ public GrpcCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } + /** + * Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + @Override + public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { + return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + } + @Override - public GrpcCallContext withTimeout(@Nullable Duration timeout) { + public GrpcCallContext withTimeout(@Nullable java.time.Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; @@ -199,15 +208,29 @@ public GrpcCallContext withTimeout(@Nullable Duration timeout) { @Nullable @Override - public Duration getTimeout() { + public org.threeten.bp.Duration getTimeout() { + return org.threeten.bp.Duration.ofNanos(getTimeoutDuration().toNanos()); + } + + @Nullable + @Override + public java.time.Duration getTimeoutDuration() { return timeout; } + /** + * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ @Override - public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout) { + public GrpcCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout) { + return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); + } + + @Override + public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout) { if (streamWaitTimeout != null) { Preconditions.checkArgument( - streamWaitTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); + streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new GrpcCallContext( @@ -223,11 +246,21 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeou retryableCodes); } + /** + * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * @param streamIdleTimeout + * @return + */ + @Override + public GrpcCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout) { + return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); + } + @Override - public GrpcCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout) { + public GrpcCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout) { if (streamIdleTimeout != null) { Preconditions.checkArgument( - streamIdleTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); + streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new GrpcCallContext( @@ -349,17 +382,17 @@ public ApiCallContext merge(ApiCallContext inputCallContext) { newTracer = callOptions.getOption(TRACER_KEY); } - Duration newTimeout = grpcCallContext.timeout; + java.time.Duration newTimeout = grpcCallContext.timeout; if (newTimeout == null) { newTimeout = timeout; } - Duration newStreamWaitTimeout = grpcCallContext.streamWaitTimeout; + java.time.Duration newStreamWaitTimeout = grpcCallContext.streamWaitTimeout; if (newStreamWaitTimeout == null) { newStreamWaitTimeout = streamWaitTimeout; } - Duration newStreamIdleTimeout = grpcCallContext.streamIdleTimeout; + java.time.Duration newStreamIdleTimeout = grpcCallContext.streamIdleTimeout; if (newStreamIdleTimeout == null) { newStreamIdleTimeout = streamIdleTimeout; } @@ -417,6 +450,15 @@ public CallOptions getCallOptions() { return callOptions; } + /** + * Backport of {@link #getStreamWaitTimeoutDuration()} + */ + @Override + @Nullable + public org.threeten.bp.Duration getStreamWaitTimeout() { + return org.threeten.bp.Duration.ofNanos(getStreamWaitTimeoutDuration().toNanos()); + } + /** * The stream wait timeout set for this context. * @@ -424,10 +466,15 @@ public CallOptions getCallOptions() { */ @Override @Nullable - public Duration getStreamWaitTimeout() { + public java.time.Duration getStreamWaitTimeoutDuration() { return streamWaitTimeout; } + @Override + @Nullable + public org.threeten.bp.Duration getStreamIdleTimeout() { + return org.threeten.bp.Duration.ofNanos(getStreamIdleTimeoutDuration().toNanos()); + } /** * The stream idle timeout set for this context. * @@ -435,7 +482,7 @@ public Duration getStreamWaitTimeout() { */ @Override @Nullable - public Duration getStreamIdleTimeout() { + public java.time.Duration getStreamIdleTimeoutDuration() { return streamIdleTimeout; } diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 06d0c18e51..5bf850f776 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -55,6 +55,8 @@ import io.grpc.TlsChannelCredentials; import io.grpc.alts.GoogleDefaultChannelCredentials; import io.grpc.auth.MoreCallCredentials; +import org.threeten.bp.Duration; + import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -66,7 +68,6 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import javax.net.ssl.KeyManagerFactory; -import org.threeten.bp.Duration; /** * InstantiatingGrpcChannelProvider is a TransportChannelProvider which constructs a gRPC @@ -101,8 +102,8 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP @Nullable private final GrpcInterceptorProvider interceptorProvider; @Nullable private final Integer maxInboundMessageSize; @Nullable private final Integer maxInboundMetadataSize; - @Nullable private final Duration keepAliveTime; - @Nullable private final Duration keepAliveTimeout; + @Nullable private final java.time.Duration keepAliveTime; + @Nullable private final java.time.Duration keepAliveTimeout; @Nullable private final Boolean keepAliveWithoutCalls; private final ChannelPoolSettings channelPoolSettings; @Nullable private final Credentials credentials; @@ -400,13 +401,21 @@ public String getEndpoint() { return endpoint; } + public org.threeten.bp.Duration getKeepAliveTime() { + return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeDuration().toNanos()); + } + /** The time without read activity before sending a keepalive ping. */ - public Duration getKeepAliveTime() { + public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } + public org.threeten.bp.Duration getKeepAliveTimeout() { + return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeoutDuration().toNanos()); + } + /** The time without read activity after sending a keepalive ping. */ - public Duration getKeepAliveTimeout() { + public java.time.Duration getKeepAliveTimeoutDuration() { return keepAliveTimeout; } @@ -444,8 +453,8 @@ public static final class Builder { @Nullable private GrpcInterceptorProvider interceptorProvider; @Nullable private Integer maxInboundMessageSize; @Nullable private Integer maxInboundMetadataSize; - @Nullable private Duration keepAliveTime; - @Nullable private Duration keepAliveTimeout; + @Nullable private java.time.Duration keepAliveTime; + @Nullable private java.time.Duration keepAliveTimeout; @Nullable private Boolean keepAliveWithoutCalls; @Nullable private ApiFunction channelConfigurator; @Nullable private Credentials credentials; @@ -583,25 +592,37 @@ public Integer getMaxInboundMetadataSize() { return maxInboundMetadataSize; } + /** + * Overload of {@link #setKeepAliveTime(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { + return setKeepAliveTime(java.time.Duration.ofNanos(duration.toNanos())) ; + } /** The time without read activity before sending a keepalive ping. */ - public Builder setKeepAliveTime(Duration duration) { + public Builder setKeepAliveTime(java.time.Duration duration) { this.keepAliveTime = duration; return this; } + /** + * Backport of {@link #getKeepAliveTimeDuration()} + */ + public org.threeten.bp.Duration getKeepAliveTime() { + return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeDuration().toNanos()); + } + /** The time without read activity before sending a keepalive ping. */ - public Duration getKeepAliveTime() { + public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } /** The time without read activity after sending a keepalive ping. */ - public Builder setKeepAliveTimeout(Duration duration) { - this.keepAliveTimeout = duration; - return this; + public org.threeten.bp.Duration getKeepAliveTimeout() { + return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeoutDuration().toNanos()); } /** The time without read activity after sending a keepalive ping. */ - public Duration getKeepAliveTimeout() { + public java.time.Duration getKeepAliveTimeoutDuration() { return keepAliveTimeout; } diff --git a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java index 85da6db5c1..853242eedd 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java @@ -63,7 +63,6 @@ import com.google.longrunning.WaitOperationRequest; import com.google.protobuf.Empty; import java.io.IOException; -import org.threeten.bp.Duration; /** Settings class to configure an instance of {@link OperationsStub}. */ public class OperationsStubSettings extends StubSettings { @@ -243,13 +242,13 @@ public static class Builder extends StubSettings.Builder> extraHeaders; private final ApiCallContextOptions options; private final ApiTracer tracer; @@ -103,9 +104,9 @@ public static HttpJsonCallContext of(HttpJsonChannel channel, HttpJsonCallOption private HttpJsonCallContext( HttpJsonChannel channel, HttpJsonCallOptions callOptions, - Duration timeout, - Duration streamWaitTimeout, - Duration streamIdleTimeout, + java.time.Duration timeout, + java.time.Duration streamWaitTimeout, + java.time.Duration streamIdleTimeout, ImmutableMap> extraHeaders, ApiCallContextOptions options, ApiTracer tracer, @@ -166,17 +167,17 @@ public HttpJsonCallContext merge(ApiCallContext inputCallContext) { // Do deep merge of callOptions HttpJsonCallOptions newCallOptions = callOptions.merge(httpJsonCallContext.callOptions); - Duration newTimeout = httpJsonCallContext.timeout; + java.time.Duration newTimeout = httpJsonCallContext.timeout; if (newTimeout == null) { newTimeout = this.timeout; } - Duration newStreamWaitTimeout = httpJsonCallContext.streamWaitTimeout; + java.time.Duration newStreamWaitTimeout = httpJsonCallContext.streamWaitTimeout; if (newStreamWaitTimeout == null) { newStreamWaitTimeout = streamWaitTimeout; } - Duration newStreamIdleTimeout = httpJsonCallContext.streamIdleTimeout; + java.time.Duration newStreamIdleTimeout = httpJsonCallContext.streamIdleTimeout; if (newStreamIdleTimeout == null) { newStreamIdleTimeout = streamIdleTimeout; } @@ -232,8 +233,16 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } + /** + * Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + @Override + public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { + return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + } + @Override - public HttpJsonCallContext withTimeout(Duration timeout) { + public HttpJsonCallContext withTimeout(java.time.Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; @@ -257,17 +266,34 @@ public HttpJsonCallContext withTimeout(Duration timeout) { this.retryableCodes); } + /** + * Backport of {@link #getTimeoutDuration()} + */ + @Nullable + @Override + public org.threeten.bp.Duration getTimeout() { + return org.threeten.bp.Duration.ofNanos(getTimeoutDuration().toNanos()); + } + @Nullable @Override - public Duration getTimeout() { + public java.time.Duration getTimeoutDuration() { return timeout; } + /** + * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + @Override + public HttpJsonCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout) { + return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); + } + @Override - public HttpJsonCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout) { + public HttpJsonCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout) { if (streamWaitTimeout != null) { Preconditions.checkArgument( - streamWaitTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); + streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new HttpJsonCallContext( @@ -283,6 +309,15 @@ public HttpJsonCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTi this.retryableCodes); } + /** + * Backport of {@link #getStreamWaitTimeoutDuration()} + */ + @Override + @Nullable + public org.threeten.bp.Duration getStreamWaitTimeout() { + return org.threeten.bp.Duration.ofNanos(getStreamWaitTimeoutDuration().toNanos()); + } + /** * The stream wait timeout set for this context. * @@ -290,15 +325,23 @@ public HttpJsonCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTi */ @Override @Nullable - public Duration getStreamWaitTimeout() { + public java.time.Duration getStreamWaitTimeoutDuration() { return streamWaitTimeout; } + /** + * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + @Override + public HttpJsonCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout) { + return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); + } + @Override - public HttpJsonCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout) { + public HttpJsonCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout) { if (streamIdleTimeout != null) { Preconditions.checkArgument( - streamIdleTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); + streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new HttpJsonCallContext( @@ -314,6 +357,15 @@ public HttpJsonCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTi this.retryableCodes); } + /** + * Backport of {@link #getStreamIdleTimeoutDuration()} + */ + @Override + @Nullable + public org.threeten.bp.Duration getStreamIdleTimeout() { + return org.threeten.bp.Duration.ofNanos(getStreamIdleTimeoutDuration().toNanos()); + } + /** * The stream idle timeout set for this context. * @@ -321,7 +373,7 @@ public HttpJsonCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTi */ @Override @Nullable - public Duration getStreamIdleTimeout() { + public java.time.Duration getStreamIdleTimeoutDuration() { return streamIdleTimeout; } @@ -381,10 +433,19 @@ public HttpJsonCallOptions getCallOptions() { return callOptions; } + /** + * Backport of {@link #getDeadlineInstant()} + */ + @Deprecated + @Nullable + public org.threeten.bp.Instant getDeadline() { + return org.threeten.bp.Instant.ofEpochMilli(getDeadlineInstant().toEpochMilli()); + } + @Deprecated @Nullable - public Instant getDeadline() { - return getCallOptions() != null ? getCallOptions().getDeadline() : null; + public java.time.Instant getDeadlineInstant() { + return getCallOptions() != null ? getCallOptions().getDeadlineInstant() : null; } @Deprecated @@ -461,8 +522,16 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { this.retryableCodes); } + /** + * Overload of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} + */ + @Deprecated + public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { + return withDeadline(java.time.Instant.ofEpochMilli(newDeadline.toEpochMilli())); + } + @Deprecated - public HttpJsonCallContext withDeadline(Instant newDeadline) { + public HttpJsonCallContext withDeadline(java.time.Instant newDeadline) { HttpJsonCallOptions.Builder builder = callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); return withCallOptions(builder.setDeadline(newDeadline).build()); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index df2ca03edc..30bf2fa11c 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -32,9 +32,10 @@ import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; +import org.threeten.bp.Instant; + import java.time.Duration; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** Options for an http-json call, including deadline and credentials. */ @AutoValue @@ -45,7 +46,12 @@ public abstract class HttpJsonCallOptions { public abstract Duration getTimeout(); @Nullable - public abstract Instant getDeadline(); + public final org.threeten.bp.Instant getDeadline() { + return org.threeten.bp.Instant.ofEpochMilli(getDeadlineInstant().toEpochMilli()); + } + + @Nullable + public abstract java.time.Instant getDeadlineInstant(); @Nullable public abstract Credentials getCredentials(); @@ -66,7 +72,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { Builder builder = this.toBuilder(); - Instant newDeadline = inputOptions.getDeadline(); + java.time.Instant newDeadline = inputOptions.getDeadlineInstant(); if (newDeadline != null) { builder.setDeadline(newDeadline); } @@ -95,7 +101,14 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { public abstract static class Builder { public abstract Builder setTimeout(java.time.Duration value); - public abstract Builder setDeadline(Instant value); + /** + * Overload of {@link #setDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} + */ + public final Builder setDeadline(org.threeten.bp.Instant value) { + return setDeadline(java.time.Instant.ofEpochMilli(value.toEpochMilli())); + } + + public abstract Builder setDeadline(java.time.Instant value); public abstract Builder setCredentials(Credentials value); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index ae1ae3ca84..8fb26065f0 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -34,7 +34,6 @@ import com.google.api.gax.rpc.ApiCallContext; import java.util.logging.Level; import java.util.logging.Logger; -import org.threeten.bp.Duration; /** * {@code HttpJsonClientCalls} creates a new {@code HttpJsonClientCall} from the given call context. @@ -60,8 +59,8 @@ public static HttpJsonClientCall newC // This is temporary here as we plan to migrate to java.util.Duration if (callOptions.getTimeout() == null || httpJsonContext - .getTimeout() - .compareTo(Duration.ofMillis(callOptions.getTimeout().toMillis())) + .getTimeoutDuration() + .compareTo(java.time.Duration.ofMillis(callOptions.getTimeout().toMillis())) < 0) { callOptions = callOptions diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java index 5f327a1091..b47755b714 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java @@ -65,7 +65,6 @@ import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; -import org.threeten.bp.Duration; // AUTO-GENERATED DOCUMENTATION AND CLASS. /** @@ -293,13 +292,13 @@ public static class Builder extends StubSettings.Builder 0, + || settings.getDelayThreshold().compareTo(org.threeten.bp.Duration.ZERO) > 0, "delayThreshold must be either unset or positive"); return settings; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 75d93ec148..db966fe9fa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -45,7 +45,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; -import org.threeten.bp.Duration; /** * Queues up elements until either a duration of time has passed or any threshold in a given set of @@ -77,7 +76,7 @@ public void run() { private final ArrayList> thresholds; private final ScheduledExecutorService executor; - private final Duration maxDelay; + private final java.time.Duration maxDelay; private final ThresholdBatchReceiver receiver; private final BatchingFlowController flowController; private final BatchMerger batchMerger; @@ -104,7 +103,7 @@ private ThresholdBatcher(Builder builder) { public static class Builder { private Collection> thresholds; private ScheduledExecutorService executor; - private Duration maxDelay; + private java.time.Duration maxDelay; private ThresholdBatchReceiver receiver; private BatchingFlowController flowController; private BatchMerger batchMerger; @@ -118,11 +117,17 @@ public Builder setExecutor(ScheduledExecutorService executor) { } /** Set the max delay for a batch. This is counted from the first item added to a batch. */ - public Builder setMaxDelay(Duration maxDelay) { + public Builder setMaxDelay(java.time.Duration maxDelay) { this.maxDelay = maxDelay; return this; } + /** Set the max delay for a batch. This is counted from the first item added to a batch. */ + public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { + this.maxDelay = java.time.Duration.ofNanos(maxDelay.toNanos()); + return this; + } + /** Set the thresholds for the ThresholdBatcher. */ public Builder setThresholds(Collection> thresholds) { this.thresholds = thresholds; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/DirectRetryingExecutor.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/DirectRetryingExecutor.java index 54b7750ca0..4ad2d27daa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/DirectRetryingExecutor.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/DirectRetryingExecutor.java @@ -36,7 +36,6 @@ import java.io.InterruptedIOException; import java.nio.channels.ClosedByInterruptException; import java.util.concurrent.Callable; -import org.threeten.bp.Duration; /** * The retry executor which executes attempts in the current thread, potentially causing the current @@ -99,7 +98,7 @@ public RetryingFuture createFuture( public ApiFuture submit(RetryingFuture retryingFuture) { while (!retryingFuture.isDone()) { try { - sleep(retryingFuture.getAttemptSettings().getRandomizedRetryDelay()); + sleep(retryingFuture.getAttemptSettings().getRandomizedRetryDelayDuration()); ResponseT response = retryingFuture.getCallable().call(); retryingFuture.setAttemptFuture(ApiFutures.immediateFuture(response)); } catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) { @@ -118,8 +117,8 @@ public ApiFuture submit(RetryingFuture retryingFuture) { * @param delay time to sleep * @throws InterruptedException if any thread has interrupted the current thread */ - protected void sleep(Duration delay) throws InterruptedException { - if (Duration.ZERO.compareTo(delay) < 0) { + protected void sleep(java.time.Duration delay) throws InterruptedException { + if (java.time.Duration.ZERO.compareTo(delay) < 0) { Thread.sleep(delay.toMillis()); } } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index b035246746..ed8823dc76 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -34,7 +34,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import java.util.concurrent.ThreadLocalRandom; -import org.threeten.bp.Duration; /** * The timed retry algorithm which uses jittered exponential backoff factor for calculating the next @@ -69,9 +68,9 @@ public ExponentialRetryAlgorithm(RetrySettings globalSettings, ApiClock clock) { public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) - .setRetryDelay(Duration.ZERO) + .setRetryDelay(java.time.Duration.ZERO) .setRpcTimeout(globalSettings.getInitialRpcTimeout()) - .setRandomizedRetryDelay(Duration.ZERO) + .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -99,8 +98,8 @@ public TimedAttemptSettings createFirstAttempt(RetryingContext context) { // retrySettings, but a new call will not (unless overridden again). .setGlobalSettings(retrySettings) .setRpcTimeout(retrySettings.getInitialRpcTimeout()) - .setRetryDelay(Duration.ZERO) - .setRandomizedRetryDelay(Duration.ZERO) + .setRetryDelay(java.time.Duration.ZERO) + .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -130,7 +129,7 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti (long) (settings.getRetryDelayMultiplier() * previousSettings.getRetryDelay().toMillis()); newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis()); } - Duration randomDelay = Duration.ofMillis(nextRandomLong(newRetryDelay)); + java.time.Duration randomDelay = java.time.Duration.ofMillis(nextRandomLong(newRetryDelay)); // The rpc timeout is determined as follows: // attempt #0 - use the initialRpcTimeout; @@ -144,10 +143,10 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti // If set, calculate time remaining in the totalTimeout since the start, taking into account the // next attempt's delay, in order to truncate the RPC timeout should it exceed the totalTimeout. if (!settings.getTotalTimeout().isZero()) { - Duration timeElapsed = - Duration.ofNanos(clock.nanoTime()) - .minus(Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); - Duration timeLeft = settings.getTotalTimeout().minus(timeElapsed).minus(randomDelay); + java.time.Duration timeElapsed = + java.time.Duration.ofNanos(clock.nanoTime()) + .minus(java.time.Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); + java.time.Duration timeLeft = settings.getTotalTimeoutDuration().minus(timeElapsed).minus(randomDelay); // If timeLeft at this point is < 0, the shouldRetry logic will prevent // the attempt from being made as it would exceed the totalTimeout. A negative RPC timeout @@ -158,8 +157,8 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti return TimedAttemptSettings.newBuilder() .setGlobalSettings(previousSettings.getGlobalSettings()) - .setRetryDelay(Duration.ofMillis(newRetryDelay)) - .setRpcTimeout(Duration.ofMillis(newRpcTimeout)) + .setRetryDelay(java.time.Duration.ofMillis(newRetryDelay)) + .setRpcTimeout(java.time.Duration.ofMillis(newRpcTimeout)) .setRandomizedRetryDelay(randomDelay) .setAttemptCount(previousSettings.getAttemptCount() + 1) .setOverallAttemptCount(previousSettings.getOverallAttemptCount() + 1) @@ -198,7 +197,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { RetrySettings globalSettings = nextAttemptSettings.getGlobalSettings(); int maxAttempts = globalSettings.getMaxAttempts(); - Duration totalTimeout = globalSettings.getTotalTimeout(); + java.time.Duration totalTimeout = globalSettings.getTotalTimeoutDuration(); // If total timeout and maxAttempts is not set then do not attempt retry. if (totalTimeout.isZero() && maxAttempts == 0) { @@ -210,7 +209,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { - nextAttemptSettings.getFirstAttemptStartTimeNanos() + nextAttemptSettings.getRandomizedRetryDelay().toNanos(); - Duration timeLeft = totalTimeout.minus(Duration.ofNanos(totalTimeSpentNanos)); + java.time.Duration timeLeft = totalTimeout.minus(java.time.Duration.ofNanos(totalTimeSpentNanos)); // Convert time spent to milliseconds to standardize the units being used for // retries. Otherwise, we would be using nanoseconds to determine if retries // should be attempted and milliseconds for retry delays and rpc timeouts diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index f5722f1ae9..c861e4f448 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -33,7 +33,6 @@ import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; -import org.threeten.bp.Duration; /** * Holds the parameters for retry or poll logic with jitter, timeout and exponential @@ -65,26 +64,36 @@ * *

Server streaming RPCs interpret RPC timeouts a bit differently. For server streaming RPCs, the * RPC timeout gets converted into a wait timeout {@link - * com.google.api.gax.rpc.ApiCallContext#withStreamWaitTimeout(Duration)}. + * com.google.api.gax.rpc.ApiCallContext#withStreamWaitTimeout(java.time.Duration)}. */ @AutoValue public abstract class RetrySettings implements Serializable { private static final long serialVersionUID = 8258475264439710899L; + /** + * Backport of {@link #getTotalTimeoutDuration()} + */ + public abstract org.threeten.bp.Duration getTotalTimeout(); + /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call * until it gives up completely. The higher the total timeout, the more retries can be attempted. * The default value is {@code Duration.ZERO}. */ - public abstract Duration getTotalTimeout(); + public abstract java.time.Duration getTotalTimeoutDuration(); + + /** + * Backport of {@link #getInitialRetryDelayDuration()} + */ + public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getInitialRetryDelay(); + public abstract java.time.Duration getInitialRetryDelayDuration(); /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -93,12 +102,17 @@ public abstract class RetrySettings implements Serializable { */ public abstract double getRetryDelayMultiplier(); + /** + * Backport of {@link #getMaxRetryDelayDuration()} + */ + public abstract org.threeten.bp.Duration getMaxRetryDelay(); + /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getMaxRetryDelay(); + public abstract java.time.Duration getMaxRetryDelayDuration(); /** * MaxAttempts defines the maximum number of attempts to perform. The default value is {@code 0}. @@ -121,12 +135,17 @@ public abstract class RetrySettings implements Serializable { @VisibleForTesting public abstract boolean isJittered(); + /** + * Backport of {@link #getInitialRpcTimeoutDuration()} + */ + public abstract org.threeten.bp.Duration getInitialRpcTimeout(); + /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getInitialRpcTimeout(); + public abstract java.time.Duration getInitialRpcTimeoutDuration(); /** * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is @@ -135,24 +154,29 @@ public abstract class RetrySettings implements Serializable { */ public abstract double getRpcTimeoutMultiplier(); + /** + * Backport of {@link #getMaxRpcTimeoutDuration()} + */ + public abstract org.threeten.bp.Duration getMaxRpcTimeout(); + /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier * can't increase the RPC timeout higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getMaxRpcTimeout(); + public abstract java.time.Duration getMaxRpcTimeoutDuration(); public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() - .setTotalTimeout(Duration.ZERO) - .setInitialRetryDelay(Duration.ZERO) + .setTotalTimeout(java.time.Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(0) .setJittered(true) - .setInitialRpcTimeout(Duration.ZERO) + .setInitialRpcTimeout(java.time.Duration.ZERO) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ZERO); + .setMaxRpcTimeout(java.time.Duration.ZERO); } public abstract Builder toBuilder(); @@ -164,19 +188,33 @@ public static Builder newBuilder() { @AutoValue.Builder public abstract static class Builder { + /** + * Overload of {@link #setTotalTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { + return setTotalTimeout(java.time.Duration.ofNanos(totalTimeout.toNanos())); + } + /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call * until it gives up completely. The higher the total timeout, the more retries can be * attempted. The default value is {@code Duration.ZERO}. */ - public abstract Builder setTotalTimeout(Duration totalTimeout); + public abstract Builder setTotalTimeout(java.time.Duration totalTimeout); + + /** + * Overload of {@link #setInitialRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { + return setInitialRetryDelay(java.time.Duration.ofNanos(initialDelay.toNanos())); + } /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setInitialRetryDelay(Duration initialDelay); + public abstract Builder setInitialRetryDelay(java.time.Duration initialDelay); /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -185,12 +223,19 @@ public abstract static class Builder { */ public abstract Builder setRetryDelayMultiplier(double multiplier); + /** + * Overload of {@link #setMaxRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { + return setMaxRetryDelay(java.time.Duration.ofNanos(maxDelay.toNanos())); + } + /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setMaxRetryDelay(Duration maxDelay); + public abstract Builder setMaxRetryDelay(java.time.Duration maxDelay); /** * MaxAttempts defines the maximum number of attempts to perform. The default value is {@code @@ -213,12 +258,19 @@ public abstract static class Builder { @VisibleForTesting public abstract Builder setJittered(boolean jittered); + /** + * Overload of {@link #setInitialRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { + return setInitialRpcTimeout(java.time.Duration.ofNanos(initialTimeout.toNanos())); + } + /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setInitialRpcTimeout(Duration initialTimeout); + public abstract Builder setInitialRpcTimeout(java.time.Duration initialTimeout); /** * See the class documentation of {@link RetrySettings} for a description of what this value @@ -226,26 +278,47 @@ public abstract static class Builder { */ public abstract Builder setRpcTimeoutMultiplier(double multiplier); + /** + * Overload of {@link #setMaxRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { + return setMaxRpcTimeout(java.time.Duration.ofNanos(maxTimeout.toNanos())); + } + /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier * can't increase the RPC timeout higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setMaxRpcTimeout(Duration maxTimeout); + public abstract Builder setMaxRpcTimeout(java.time.Duration maxTimeout); + + /** + * Backport of {@link #getTotalTimeoutDuration()} + */ + public final org.threeten.bp.Duration getTotalTimeout() { + return org.threeten.bp.Duration.ofNanos(getTotalTimeoutDuration().toNanos()); + } /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call * until it gives up completely. The higher the total timeout, the more retries can be * attempted. The default value is {@code Duration.ZERO}. */ - public abstract Duration getTotalTimeout(); + public abstract java.time.Duration getTotalTimeoutDuration(); + + /** + * Backport of {@link #getInitialRetryDelay()} + */ + public final org.threeten.bp.Duration getInitialRetryDelay() { + return org.threeten.bp.Duration.ofNanos(getInitialRetryDelayDuration().toNanos()); + } /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getInitialRetryDelay(); + public abstract java.time.Duration getInitialRetryDelayDuration(); /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -271,19 +344,33 @@ public abstract static class Builder { */ public abstract boolean isJittered(); + /** + * Backport of {@link #getMaxRetryDelayDuration()} + */ + public final org.threeten.bp.Duration getMaxRetryDelay() { + return org.threeten.bp.Duration.ofNanos(getMaxRetryDelayDuration().toNanos()); + } + /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getMaxRetryDelay(); + public abstract java.time.Duration getMaxRetryDelayDuration(); + + /** + * Backport of {@link #getInitialRpcTimeoutDuration()} + */ + public final org.threeten.bp.Duration getInitialRpcTimeout() { + return org.threeten.bp.Duration.ofNanos((getInitialRpcTimeoutDuration().toNanos())); + } /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Duration getInitialRpcTimeout(); + public abstract java.time.Duration getInitialRpcTimeoutDuration(); /** * See the class documentation of {@link RetrySettings} for a description of what this value @@ -291,11 +378,26 @@ public abstract static class Builder { */ public abstract double getRpcTimeoutMultiplier(); + /** + * Backport of {@link #getMaxRpcTimeoutDuration()} + */ + public final org.threeten.bp.Duration getMaxRpcTimeout() { + return org.threeten.bp.Duration.ofNanos((getMaxRpcTimeoutDuration().toNanos())); + } + /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier * can't increase the RPC timeout higher than this amount. */ - public abstract Duration getMaxRpcTimeout(); + public abstract java.time.Duration getMaxRpcTimeoutDuration(); + + /** + * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + @BetaApi + public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { + return setLogicalTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + } /** * Configures the timeout settings with the given timeout such that the logical call will take @@ -307,7 +409,7 @@ public abstract static class Builder { * setter is respected. */ @BetaApi - public Builder setLogicalTimeout(Duration timeout) { + public Builder setLogicalTimeout(java.time.Duration timeout) { return setRpcTimeoutMultiplier(1) .setInitialRpcTimeout(timeout) .setMaxRpcTimeout(timeout) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index 2f9028a2ef..092b224cbc 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -40,20 +40,41 @@ public abstract class TimedAttemptSettings { /** Returns global (attempt-independent) retry settings. */ public abstract RetrySettings getGlobalSettings(); + /** + * Backport of {@link #getRetryDelayDuration()} + */ + public final org.threeten.bp.Duration getRetryDelay() { + return org.threeten.bp.Duration.ofNanos(getRetryDelayDuration().toNanos()); + } + /** * Returns the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public abstract Duration getRetryDelay(); + public abstract java.time.Duration getRetryDelayDuration(); + + /** + * Backport of {@link #getRpcTimeoutDuration()} + */ + public final org.threeten.bp.Duration getRpcTimeout() { + return org.threeten.bp.Duration.ofNanos(getRpcTimeoutDuration().toNanos()); + } /** Returns rpc timeout used for this attempt. */ - public abstract Duration getRpcTimeout(); + public abstract java.time.Duration getRpcTimeoutDuration(); + + /** + * Backport of {@link #getRandomizedRetryDelayDuration()} + */ + public final org.threeten.bp.Duration getRandomizedRetryDelay() { + return org.threeten.bp.Duration.ofNanos(getRandomizedRetryDelayDuration().toNanos()); + } /** * Returns randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public abstract Duration getRandomizedRetryDelay(); + public abstract java.time.Duration getRandomizedRetryDelayDuration(); /** * The attempt count. It is a zero-based value (first attempt will have this value set to 0). For @@ -85,20 +106,41 @@ public abstract static class Builder { /** Sets global (attempt-independent) retry settings. */ public abstract Builder setGlobalSettings(RetrySettings value); + /** + * Overload of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setRetryDelay(org.threeten.bp.Duration value) { + return setRetryDelay(java.time.Duration.ofNanos(value.toNanos())); + } + /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public abstract Builder setRetryDelay(Duration value); + public abstract Builder setRetryDelay(java.time.Duration value); + + /** + * Overload of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setRpcTimeout(org.threeten.bp.Duration value) { + return setRpcTimeout(java.time.Duration.ofNanos(value.toNanos())); + } /** Sets rpc timeout used for this attempt. */ - public abstract Builder setRpcTimeout(Duration value); + public abstract Builder setRpcTimeout(java.time.Duration value); + + /** + * Overload of {@link #setRandomizedRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public final Builder setRandomizedRetryDelay(Duration value) { + return setRandomizedRetryDelay(java.time.Duration.ofNanos(value.toNanos())); + } /** * Sets randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public abstract Builder setRandomizedRetryDelay(Duration value); + public abstract Builder setRandomizedRetryDelay(java.time.Duration value); /** * Set the attempt count. It is a zero-based value (first attempt will have this value set to diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 5a34b58e39..35c0090e26 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -37,12 +37,13 @@ import com.google.api.gax.tracing.ApiTracer; import com.google.auth.Credentials; import com.google.common.base.Preconditions; +import org.threeten.bp.Duration; + import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Context for an API call. @@ -63,6 +64,11 @@ public interface ApiCallContext extends RetryingContext { /** Returns a new ApiCallContext with the given channel set. */ ApiCallContext withTransportChannel(TransportChannel channel); + /** + * Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); + /** * Returns a new ApiCallContext with the given timeout set. * @@ -75,11 +81,20 @@ public interface ApiCallContext extends RetryingContext { *

If a method has default {@link com.google.api.gax.retrying.RetrySettings}, the max attempts * and/or total timeout is still respected when scheduling each RPC attempt. */ - ApiCallContext withTimeout(@Nullable Duration timeout); + ApiCallContext withTimeout(@Nullable java.time.Duration timeout); + + /** Backport of {@link #getTimeoutDuration()} */ + @Nullable + org.threeten.bp.Duration getTimeout(); /** Returns the configured per-RPC timeout. */ @Nullable - Duration getTimeout(); + java.time.Duration getTimeoutDuration(); + + /** + * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration } + */ + ApiCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout); /** * Returns a new ApiCallContext with the given stream timeout set. @@ -92,21 +107,32 @@ public interface ApiCallContext extends RetryingContext { * server or connection stalls. When the timeout has been reached, the stream will be closed with * a retryable {@link WatchdogTimeoutException} and a status of {@link StatusCode.Code#ABORTED}. * - *

A value of {@link Duration#ZERO}, disables the streaming wait timeout and a null value will + *

A value of {@link java.time.Duration#ZERO}, disables the streaming wait timeout and a null value will * use the default in the callable. * *

Please note that this timeout is best effort and the maximum resolution is configured in * {@link StubSettings#getStreamWatchdogCheckInterval()}. */ - ApiCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout); + ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout); + + /** + * Backport of {@link #getStreamWaitTimeoutDuration()} + */ + @Nullable + org.threeten.bp.Duration getStreamWaitTimeout(); /** * Return the stream wait timeout set for this context. * - * @see #withStreamWaitTimeout(Duration) + * @see #withStreamWaitTimeout(java.time.Duration) */ @Nullable - Duration getStreamWaitTimeout(); + java.time.Duration getStreamWaitTimeoutDuration(); + + /** + * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + ApiCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout); /** * Returns a new ApiCallContext with the given stream idle timeout set. @@ -120,13 +146,19 @@ public interface ApiCallContext extends RetryingContext { * reached, the stream will be closed with a nonretryable {@link WatchdogTimeoutException} and a * status of {@link StatusCode.Code#ABORTED}. * - *

A value of {@link Duration#ZERO}, disables the streaming idle timeout and a null value will + *

A value of {@link java.time.Duration#ZERO}, disables the streaming idle timeout and a null value will * use the default in the callable. * *

Please note that this timeout is best effort and the maximum resolution is configured in * {@link StubSettings#getStreamWatchdogCheckInterval()}. */ - ApiCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout); + ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout); + + /** + * Backport of {@link #getStreamIdleTimeoutDuration()} + */ + @Nullable + org.threeten.bp.Duration getStreamIdleTimeout(); /** * The stream idle timeout set for this context. @@ -134,7 +166,7 @@ public interface ApiCallContext extends RetryingContext { * @see #withStreamIdleTimeout(Duration) */ @Nullable - Duration getStreamIdleTimeout(); + java.time.Duration getStreamIdleTimeoutDuration(); /** * The {@link ApiTracer} that was previously set for this context. diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java index 6b419f1d49..10a68117c0 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java @@ -35,7 +35,6 @@ import com.google.api.gax.retrying.RetryingFuture; import com.google.common.base.Preconditions; import java.util.concurrent.Callable; -import org.threeten.bp.Duration; /** * A callable representing an attempt to make an RPC call. This class is used from {@link @@ -70,7 +69,7 @@ public ResponseT call() { try { // Set the RPC timeout if the caller did not provide their own. - Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); + java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero() && callContext.getTimeout() == null) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java index 17670a5e7a..53c20b911b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java @@ -35,7 +35,6 @@ import com.google.api.gax.retrying.RetryingFuture; import com.google.common.base.Preconditions; import java.util.concurrent.Callable; -import org.threeten.bp.Duration; /** * A callable representing an attempt to check the status of something by issuing a call to a @@ -66,7 +65,7 @@ public ResponseT call() { ApiCallContext callContext = originalCallContext; try { - Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); + java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero()) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index c26d4a0f4d..b481d0db1e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -57,7 +57,6 @@ import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Encapsulates client state, including executor, credentials, and transport channel. @@ -98,8 +97,17 @@ public abstract class ClientContext { @Nullable public abstract Watchdog getStreamWatchdog(); + /** + * Backport of {@link #getStreamWatchdogCheckIntervalDuration()} + * @return + */ + @Nonnull + public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { + return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); + } + @Nonnull - public abstract Duration getStreamWatchdogCheckInterval(); + public abstract java.time.Duration getStreamWatchdogCheckIntervalDuration(); @Nullable public abstract String getEndpoint(); @@ -127,7 +135,7 @@ public static Builder newBuilder() { .setInternalHeaders(Collections.emptyMap()) .setClock(NanoClock.getDefaultClock()) .setStreamWatchdog(null) - .setStreamWatchdogCheckInterval(Duration.ZERO) + .setStreamWatchdogCheckInterval(java.time.Duration.ZERO) .setTracerFactory(BaseApiTracerFactory.getInstance()) .setQuotaProjectId(null) .setGdchApiAudience(null); @@ -350,7 +358,10 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); - public abstract Builder setStreamWatchdogCheckInterval(Duration duration); + public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { + return setStreamWatchdogCheckInterval(java.time.Duration.ofNanos(duration.toNanos())); + } + public abstract Builder setStreamWatchdogCheckInterval(java.time.Duration duration); /** * Set the {@link ApiTracerFactory} that will be used to generate traces for operations. diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 04b2c9f55b..24cde0f7b7 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -38,7 +38,6 @@ import java.util.concurrent.Executor; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * A base settings class to configure a client class. @@ -106,9 +105,18 @@ public final WatchdogProvider getWatchdogProvider() { return stubSettings.getStreamWatchdogProvider(); } + /** + * Backport of {@link #getWatchdogCheckIntervalDuration()} + * @return + */ @Nonnull - public final Duration getWatchdogCheckInterval() { - return stubSettings.getStreamWatchdogCheckInterval(); + public final org.threeten.bp.Duration getWatchdogCheckInterval() { + return org.threeten.bp.Duration.ofNanos(getWatchdogCheckIntervalDuration().toNanos()); + } + + @Nonnull + public final java.time.Duration getWatchdogCheckIntervalDuration() { + return stubSettings.getStreamWatchdogCheckIntervalDuration(); } /** Gets the GDCH API audience that was previously set in this Builder */ @@ -256,7 +264,11 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { return self(); } - public B setWatchdogCheckInterval(@Nullable Duration checkInterval) { + public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { + return setWatchdogCheckInterval(java.time.Duration.ofNanos(checkInterval.toNanos())); + } + + public B setWatchdogCheckInterval(@Nullable java.time.Duration checkInterval) { stubSettings.setStreamWatchdogCheckInterval(checkInterval); return self(); } @@ -336,8 +348,13 @@ public WatchdogProvider getWatchdogProvider() { } @Nullable - public Duration getWatchdogCheckInterval() { - return stubSettings.getStreamWatchdogCheckInterval(); + public org.threeten.bp.Duration getWatchdogCheckInterval() { + return org.threeten.bp.Duration.ofNanos(getWatchdogCheckIntervalDuration().toNanos()); + } + + @Nullable + public java.time.Duration getWatchdogCheckIntervalDuration() { + return stubSettings.getStreamWatchdogCheckIntervalDuration(); } /** Gets the GDCH API audience that was previously set in this Builder */ diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java index a1fd245b5f..9d8054ab1d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java @@ -34,7 +34,6 @@ import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * A watchdog provider which always returns the same watchdog instance provided to the provider @@ -71,7 +70,12 @@ public boolean needsCheckInterval() { } @Override - public WatchdogProvider withCheckInterval(Duration checkInterval) { + public WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval) { + throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); + } + + @Override + public WatchdogProvider withCheckInterval(java.time.Duration checkInterval) { throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index a069c49c84..3a981f343c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -32,10 +32,11 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.common.base.Preconditions; + +import java.time.Duration; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * A watchdog provider which instantiates a new provider on every request. @@ -47,7 +48,7 @@ public final class InstantiatingWatchdogProvider implements WatchdogProvider { @Nullable private final ApiClock clock; @Nullable private final ScheduledExecutorService executor; - @Nullable private final Duration checkInterval; + @Nullable private final java.time.Duration checkInterval; public static WatchdogProvider create() { return new InstantiatingWatchdogProvider(null, null, null); @@ -56,7 +57,7 @@ public static WatchdogProvider create() { private InstantiatingWatchdogProvider( @Nullable ApiClock clock, @Nullable ScheduledExecutorService executor, - @Nullable Duration checkInterval) { + @Nullable java.time.Duration checkInterval) { this.clock = clock; this.executor = executor; this.checkInterval = checkInterval; @@ -78,8 +79,18 @@ public boolean needsCheckInterval() { return checkInterval == null; } + /** + * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link org.threeten.bp.Duration} + * @param checkInterval + * @return + */ + @Override + public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { + return withCheckInterval(java.time.Duration.ofNanos(Preconditions.checkNotNull(checkInterval).toNanos())); + } + @Override - public WatchdogProvider withCheckInterval(@Nonnull Duration checkInterval) { + public WatchdogProvider withCheckInterval(@Nonnull java.time.Duration checkInterval) { return new InstantiatingWatchdogProvider( clock, executor, Preconditions.checkNotNull(checkInterval)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 48e5242b80..171472ce1a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -37,9 +37,10 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; +import org.threeten.bp.Duration; + import java.util.Set; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; /** * A settings class to configure a {@link ServerStreamingCallable}. @@ -51,7 +52,7 @@ * will terminate any stream that has not has seen any demand (via {@link * StreamController#request(int)}) in the configured interval or has not seen a message from the * server in {@code waitTimeout}. To turn off idle checks, set the interval to {@link - * Duration#ZERO}. + * java.time.Duration#ZERO}. * *

Retry configuration allows for the stream to be restarted and resumed. It is composed of 3 * parts: the retryable codes, the retry settings and the stream resumption strategy. The retryable @@ -80,8 +81,8 @@ public final class ServerStreamingCallSettings @Nonnull private final RetrySettings retrySettings; @Nonnull private final StreamResumptionStrategy resumptionStrategy; - @Nonnull private final Duration idleTimeout; - @Nonnull private final Duration waitTimeout; + @Nonnull private final java.time.Duration idleTimeout; + @Nonnull private final java.time.Duration waitTimeout; private ServerStreamingCallSettings(Builder builder) { this.retryableCodes = ImmutableSet.copyOf(builder.retryableCodes); @@ -118,21 +119,37 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } + /** + * Backport of {@link #getIdleTimeoutDuration()} + */ + @Nonnull + public org.threeten.bp.Duration getIdleTimeout() { + return org.threeten.bp.Duration.ofNanos(getIdleTimeoutDuration().toNanos()); + } + /** * See the class documentation of {@link ServerStreamingCallSettings} for a description of what * the {@link #idleTimeout} does. */ @Nonnull - public Duration getIdleTimeout() { + public java.time.Duration getIdleTimeoutDuration() { return idleTimeout; } + /** + * Backport of {@link #getWaitTimeoutDuration()} + */ + @Nonnull + public org.threeten.bp.Duration getWaitTimeout() { + return org.threeten.bp.Duration.ofNanos(getWaitTimeoutDuration().toNanos()); + } + /** * See the class documentation of {@link ServerStreamingCallSettings} for a description of what * the {@link #waitTimeout} does. */ @Nonnull - public Duration getWaitTimeout() { + public java.time.Duration getWaitTimeoutDuration() { return waitTimeout; } @@ -160,9 +177,9 @@ public static class Builder @Nonnull private RetrySettings.Builder retrySettingsBuilder; @Nonnull private StreamResumptionStrategy resumptionStrategy; - @Nonnull private Duration idleTimeout; + @Nonnull private java.time.Duration idleTimeout; - @Nonnull private Duration waitTimeout; + @Nonnull private java.time.Duration waitTimeout; /** Initialize the builder with default settings */ private Builder() { @@ -170,8 +187,8 @@ private Builder() { this.retrySettingsBuilder = RetrySettings.newBuilder(); this.resumptionStrategy = new SimpleStreamResumptionStrategy<>(); - this.idleTimeout = Duration.ZERO; - this.waitTimeout = Duration.ZERO; + this.idleTimeout = java.time.Duration.ZERO; + this.waitTimeout = java.time.Duration.ZERO; } private Builder(ServerStreamingCallSettings settings) { @@ -242,15 +259,22 @@ public RetrySettings getRetrySettings() { return retrySettingsBuilder.build(); } + /** + * Overload of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public Builder setSimpleTimeoutNoRetries(@Nonnull org.threeten.bp.Duration timeout) { + return setSimpleTimeoutNoRetries(java.time.Duration.ofNanos(timeout.toNanos())); + } + /** Disables retries and sets the overall timeout. */ - public Builder setSimpleTimeoutNoRetries(@Nonnull Duration timeout) { + public Builder setSimpleTimeoutNoRetries(@Nonnull java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() .setTotalTimeout(timeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setInitialRpcTimeout(timeout) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(timeout) @@ -276,30 +300,60 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } + /** + * Backport of {@link #getIdleTimeoutDuration()} + */ @Nonnull - public Duration getIdleTimeout() { + public org.threeten.bp.Duration getIdleTimeout() { + return org.threeten.bp.Duration.ofNanos(getIdleTimeoutDuration().toNanos()); + } + + @Nonnull + public java.time.Duration getIdleTimeoutDuration() { return idleTimeout; } + /** + * Overlad of {@link #setIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public Builder setIdleTimeout(@Nonnull org.threeten.bp.Duration idleTimeout) { + return setIdleTimeout(java.time.Duration.ofNanos(idleTimeout.toNanos())); + } + /** * Set how long to wait before considering the stream orphaned by the user and closing it. - * {@link Duration#ZERO} disables the check for abandoned streams. + * {@link java.time.Duration#ZERO} disables the check for abandoned streams. */ - public Builder setIdleTimeout(@Nonnull Duration idleTimeout) { + public Builder setIdleTimeout(@Nonnull java.time.Duration idleTimeout) { this.idleTimeout = Preconditions.checkNotNull(idleTimeout); return this; } + /** + * Backport of {@link #getWaitTimeoutDuration()} + */ + @Nonnull + public org.threeten.bp.Duration getWaitTimeout() { + return org.threeten.bp.Duration.ofNanos(getWaitTimeoutDuration().toNanos()); + } + @Nonnull - public Duration getWaitTimeout() { + public java.time.Duration getWaitTimeoutDuration() { return waitTimeout; } + /** + * Overload of {@link #setWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public Builder setWaitTimeout(@Nonnull org.threeten.bp.Duration waitTimeout) { + return setWaitTimeout(java.time.Duration.ofNanos(waitTimeout.toNanos())); + } + /** * Set the maximum amount of time to wait for the next message from the server. {@link - * Duration#ZERO} disables the check for abandoned streams. + * java.time.Duration#ZERO} disables the check for abandoned streams. */ - public Builder setWaitTimeout(@Nonnull Duration waitTimeout) { + public Builder setWaitTimeout(@Nonnull java.time.Duration waitTimeout) { this.waitTimeout = waitTimeout; return this; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index 7ebbe327c8..13b4cff5e9 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -44,11 +44,12 @@ import com.google.auth.oauth2.QuotaProjectIdProvider; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; +import org.threeten.bp.Duration; + import java.io.IOException; import java.util.concurrent.Executor; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * A base settings class to configure a client stub class. @@ -75,7 +76,7 @@ public abstract class StubSettings> { private final String quotaProjectId; @Nullable private final String gdchApiAudience; @Nullable private final WatchdogProvider streamWatchdogProvider; - @Nonnull private final Duration streamWatchdogCheckInterval; + @Nonnull private final java.time.Duration streamWatchdogCheckInterval; @Nonnull private final ApiTracerFactory tracerFactory; // Track if deprecated setExecutorProvider is called private boolean deprecatedExecutorProviderSet; @@ -159,8 +160,16 @@ public final WatchdogProvider getStreamWatchdogProvider() { return streamWatchdogProvider; } + /** + * Backport of {@link #getStreamWatchdogCheckIntervalDuration()} + */ + @Nonnull + public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { + return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); + } + @Nonnull - public final Duration getStreamWatchdogCheckInterval() { + public final java.time.Duration getStreamWatchdogCheckIntervalDuration() { return streamWatchdogCheckInterval; } @@ -216,7 +225,7 @@ public abstract static class Builder< private String quotaProjectId; @Nullable private String gdchApiAudience; @Nullable private WatchdogProvider streamWatchdogProvider; - @Nonnull private Duration streamWatchdogCheckInterval; + @Nonnull private java.time.Duration streamWatchdogCheckInterval; @Nonnull private ApiTracerFactory tracerFactory; private boolean deprecatedExecutorProviderSet; @@ -276,7 +285,7 @@ protected Builder(ClientContext clientContext) { this.mtlsEndpoint = null; this.quotaProjectId = null; this.streamWatchdogProvider = InstantiatingWatchdogProvider.create(); - this.streamWatchdogCheckInterval = Duration.ofSeconds(10); + this.streamWatchdogCheckInterval = java.time.Duration.ofSeconds(10); this.tracerFactory = BaseApiTracerFactory.getInstance(); this.deprecatedExecutorProviderSet = false; this.gdchApiAudience = null; @@ -298,7 +307,7 @@ protected Builder(ClientContext clientContext) { } this.streamWatchdogProvider = FixedWatchdogProvider.create(clientContext.getStreamWatchdog()); - this.streamWatchdogCheckInterval = clientContext.getStreamWatchdogCheckInterval(); + this.streamWatchdogCheckInterval = clientContext.getStreamWatchdogCheckIntervalDuration(); this.tracerFactory = clientContext.getTracerFactory(); this.quotaProjectId = getQuotaProjectIdFromClientContext(clientContext); this.gdchApiAudience = clientContext.getGdchApiAudience(); @@ -438,11 +447,18 @@ public B setQuotaProjectId(String quotaProjectId) { return self(); } + /** + * Overload of {@link #setStreamWatchdogCheckInterval(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { + return setStreamWatchdogCheckInterval(java.time.Duration.ofNanos(checkInterval.toNanos())); + } + /** * Sets how often the {@link Watchdog} will check ongoing streaming RPCs. Defaults to 10 secs. - * Use {@link Duration#ZERO} to disable. + * Use {@link java.time.Duration#ZERO} to disable. */ - public B setStreamWatchdogCheckInterval(@Nonnull Duration checkInterval) { + public B setStreamWatchdogCheckInterval(@Nonnull java.time.Duration checkInterval) { Preconditions.checkNotNull(checkInterval); this.streamWatchdogCheckInterval = checkInterval; return self(); @@ -527,8 +543,12 @@ public String getQuotaProjectId() { return quotaProjectId; } + public org.threeten.bp.Duration getStreamWatchdogCheckInterval() { + return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); + } + @Nonnull - public Duration getStreamWatchdogCheckInterval() { + public java.time.Duration getStreamWatchdogCheckIntervalDuration() { return streamWatchdogCheckInterval; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index c8f2811449..8866103d89 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import java.util.Set; -import org.threeten.bp.Duration; /** * A base settings class to configure a UnaryCallable. An instance of UnaryCallSettings is not @@ -196,14 +195,14 @@ public UnaryCallSettings.Builder setRetrySettings( /** Disables retries and sets the RPC timeout. */ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( - Duration timeout) { + java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() .setTotalTimeout(timeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setInitialRpcTimeout(timeout) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(timeout) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 8ca97876ca..842ee9bdd7 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -32,6 +32,8 @@ import com.google.api.core.ApiClock; import com.google.api.gax.core.BackgroundResource; import com.google.common.base.Preconditions; + +import java.time.Duration; import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.CancellationException; @@ -45,7 +47,6 @@ import java.util.logging.Logger; import javax.annotation.Nonnull; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Duration; /** * Prevents the streams from hanging indefinitely. This middleware garbage collects idle streams in @@ -71,19 +72,19 @@ public final class Watchdog implements Runnable, BackgroundResource { private final ConcurrentHashMap openStreams = new ConcurrentHashMap<>(); private final ApiClock clock; - private final Duration scheduleInterval; + private final java.time.Duration scheduleInterval; private final ScheduledExecutorService executor; private ScheduledFuture future; /** returns a Watchdog which is scheduled at the provided interval. */ public static Watchdog create( - ApiClock clock, Duration scheduleInterval, ScheduledExecutorService executor) { + ApiClock clock, java.time.Duration scheduleInterval, ScheduledExecutorService executor) { Watchdog watchdog = new Watchdog(clock, scheduleInterval, executor); watchdog.start(); return watchdog; } - private Watchdog(ApiClock clock, Duration scheduleInterval, ScheduledExecutorService executor) { + private Watchdog(ApiClock clock, java.time.Duration scheduleInterval, ScheduledExecutorService executor) { this.clock = Preconditions.checkNotNull(clock, "clock can't be null"); this.scheduleInterval = scheduleInterval; this.executor = executor; @@ -95,11 +96,22 @@ private void start() { this, scheduleInterval.toMillis(), scheduleInterval.toMillis(), TimeUnit.MILLISECONDS); } + /** + * Overload of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + public ResponseObserver watch( + ResponseObserver innerObserver, + @Nonnull org.threeten.bp.Duration waitTimeout, + @Nonnull org.threeten.bp.Duration idleTimeout) { + return watch(innerObserver, + java.time.Duration.ofNanos(waitTimeout.toNanos()), + java.time.Duration.ofNanos(idleTimeout.toNanos())); + } /** Wraps the target observer with timing constraints. */ public ResponseObserver watch( ResponseObserver innerObserver, - @Nonnull Duration waitTimeout, - @Nonnull Duration idleTimeout) { + @Nonnull java.time.Duration waitTimeout, + @Nonnull java.time.Duration idleTimeout) { Preconditions.checkNotNull(innerObserver, "innerObserver can't be null"); Preconditions.checkNotNull(waitTimeout, "waitTimeout can't be null"); Preconditions.checkNotNull(idleTimeout, "idleTimeout can't be null"); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index db3fb20bb7..c1942e4fa7 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -30,9 +30,9 @@ package com.google.api.gax.rpc; import com.google.api.core.ApiClock; + import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; public interface WatchdogProvider { boolean needsClock(); @@ -41,7 +41,12 @@ public interface WatchdogProvider { boolean needsCheckInterval(); - WatchdogProvider withCheckInterval(Duration checkInterval); + /** + * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link org.threeten.bp.Duration} + */ + WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); + + WatchdogProvider withCheckInterval(java.time.Duration checkInterval); boolean needsExecutor(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java index cc3dfec829..61a16118e6 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java @@ -31,7 +31,6 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.threeten.bp.Duration; /** * A callable that uses a {@link Watchdog} to monitor streams. @@ -62,8 +61,8 @@ public void call( RequestT request, ResponseObserver responseObserver, ApiCallContext context) { // If the caller never configured the timeouts, disable them - Duration waitTimeout = MoreObjects.firstNonNull(context.getStreamWaitTimeout(), Duration.ZERO); - Duration idleTimeout = MoreObjects.firstNonNull(context.getStreamIdleTimeout(), Duration.ZERO); + java.time.Duration waitTimeout = MoreObjects.firstNonNull(context.getStreamWaitTimeoutDuration(), java.time.Duration.ZERO); + java.time.Duration idleTimeout = MoreObjects.firstNonNull(context.getStreamIdleTimeoutDuration(), java.time.Duration.ZERO); responseObserver = watchdog.watch(responseObserver, waitTimeout, idleTimeout); inner.call(request, responseObserver, context); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index 3176be4b92..b964ac8449 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -30,7 +30,6 @@ package com.google.api.gax.tracing; import com.google.api.core.InternalApi; -import org.threeten.bp.Duration; /** * Implementations of this class trace the logical flow of a google cloud client. @@ -110,7 +109,7 @@ public interface ApiTracer { * @param error the transient error that caused the attempt to fail. * @param delay the amount of time to wait before the next attempt will start. */ - void attemptFailed(Throwable error, Duration delay); + void attemptFailed(Throwable error, java.time.Duration delay); /** * Adds an annotation that the attempt failed and that no further attempts will be made because diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index 538708b879..334fe33dbc 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -30,7 +30,6 @@ package com.google.api.gax.tracing; import com.google.api.core.InternalApi; -import org.threeten.bp.Duration; /** * A base implementation of {@link ApiTracer} that does nothing. @@ -101,7 +100,7 @@ public void attemptCancelled() { } @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailed(Throwable error, java.time.Duration delay) { // noop } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java index ea4c5f9039..e8bd6c56aa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java @@ -47,7 +47,6 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; /** * Implementation of {@link ApiTracer} that uses OpenCensus. @@ -342,7 +341,7 @@ public void attemptCancelled() { /** {@inheritDoc} */ @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailed(Throwable error, java.time.Duration delay) { Map attributes = baseAttemptAttributes(); attributes.put("delay ms", AttributeValue.longAttributeValue(delay.toMillis())); populateError(attributes, error); From 62ae4efd5b4b8631aae64c7d68a92a419af0cd56 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 19 Jul 2023 22:42:03 -0400 Subject: [PATCH 002/141] chore: initial conversion to java.time in gax test classes --- .../common/RetrySettingsComposerTest.java | 26 ++-- .../SampleBodyJavaFormatterTest.java | 4 +- ...ServiceClientHeaderSampleComposerTest.java | 6 +- .../SettingsSampleComposerTest.java | 4 +- .../gapic/model/GapicServiceConfigTest.java | 4 +- .../protoparser/ServiceConfigParserTest.java | 6 +- .../google/api/gax/grpc/GrpcCallContext.java | 24 ++-- .../InstantiatingGrpcChannelProvider.java | 20 +-- .../api/gax/grpc/GrpcCallContextTest.java | 60 ++++---- .../api/gax/grpc/GrpcCallableFactoryTest.java | 5 +- .../api/gax/grpc/GrpcClientCallsTest.java | 7 +- .../grpc/GrpcDirectStreamControllerTest.java | 11 +- .../api/gax/grpc/GrpcLongRunningTest.java | 11 +- .../InstantiatingGrpcChannelProviderTest.java | 11 +- .../com/google/api/gax/grpc/SettingsTest.java | 19 ++- .../com/google/api/gax/grpc/TimeoutTest.java | 48 ++++--- .../api/gax/httpjson/HttpJsonCallContext.java | 40 ++---- .../api/gax/httpjson/HttpJsonCallOptions.java | 17 ++- .../gax/httpjson/HttpJsonCallContextTest.java | 37 +++-- .../HttpJsonClientInterceptorTest.java | 3 +- .../httpjson/HttpJsonDirectCallableTest.java | 19 +-- ...JsonDirectServerStreamingCallableTest.java | 3 +- .../google/api/gax/httpjson/RetryingTest.java | 15 +- .../gax/httpjson/testing/MockHttpService.java | 9 +- .../api/gax/batching/BatchingSettings.java | 21 ++- .../api/gax/retrying/BasicRetryingFuture.java | 2 +- .../retrying/ExponentialRetryAlgorithm.java | 6 +- .../api/gax/retrying/RetrySettings.java | 136 +++++++++++------- .../gax/retrying/TimedAttemptSettings.java | 62 +++++--- .../google/api/gax/rpc/ApiCallContext.java | 29 ++-- .../com/google/api/gax/rpc/Callables.java | 2 +- .../com/google/api/gax/rpc/ClientContext.java | 10 +- .../google/api/gax/rpc/ClientSettings.java | 1 + .../rpc/InstantiatingWatchdogProvider.java | 9 +- .../gax/rpc/ServerStreamingCallSettings.java | 36 +++-- .../com/google/api/gax/rpc/StubSettings.java | 9 +- .../java/com/google/api/gax/rpc/Watchdog.java | 20 +-- .../google/api/gax/rpc/WatchdogProvider.java | 4 +- .../rpc/WatchdogServerStreamingCallable.java | 6 +- .../api/gax/batching/AssertByPolling.java | 5 +- .../api/gax/batching/AssertByPollingTest.java | 9 +- .../api/gax/batching/BatcherImplTest.java | 22 ++- .../batching/BatchingCallSettingsTest.java | 5 +- .../api/gax/batching/FlowControllerTest.java | 7 +- .../gax/batching/ThresholdBatcherTest.java | 7 +- .../api/gax/core/RecordingScheduler.java | 10 +- .../AbstractRetryingExecutorTest.java | 25 ++-- .../gax/retrying/BasicRetryingFutureTest.java | 4 +- .../ExponentialRetryAlgorithmTest.java | 65 +++++---- .../api/gax/retrying/FailingCallable.java | 21 ++- .../api/gax/retrying/RetrySettingsTest.java | 13 +- .../ScheduledRetryingExecutorTest.java | 25 ++-- .../api/gax/rpc/AttemptCallableTest.java | 15 +- .../api/gax/rpc/BatcherFactoryTest.java | 3 +- .../api/gax/rpc/BatchingCallSettingsTest.java | 17 ++- .../api/gax/rpc/BatchingCallableTest.java | 3 +- .../com/google/api/gax/rpc/BatchingTest.java | 9 +- .../com/google/api/gax/rpc/CallableTest.java | 19 ++- .../google/api/gax/rpc/CancellationTest.java | 21 ++- .../gax/rpc/CheckingAttemptCallableTest.java | 11 +- .../google/api/gax/rpc/ClientContextTest.java | 7 +- .../api/gax/rpc/ClientSettingsTest.java | 15 +- .../gax/rpc/FixedWatchdogProviderTest.java | 7 +- .../InstantiatingWatchdogProviderTest.java | 3 +- .../gax/rpc/OperationCallableImplTest.java | 57 ++++---- .../api/gax/rpc/PagedCallSettingsTest.java | 17 ++- .../com/google/api/gax/rpc/RetryingTest.java | 29 ++-- .../ServerStreamingAttemptCallableTest.java | 29 ++-- .../rpc/ServerStreamingCallSettingsTest.java | 30 ++-- .../gax/rpc/StreamingRetryAlgorithmTest.java | 21 ++- .../api/gax/rpc/UnaryCallSettingsTest.java | 33 ++--- .../com/google/api/gax/rpc/WatchdogTest.java | 7 +- .../api/gax/rpc/testing/FakeCallContext.java | 66 ++++++--- .../api/gax/tracing/OpencensusTracerTest.java | 13 +- .../api/gax/tracing/TracedCallableTest.java | 3 +- .../java/com/google/cloud/RetryOption.java | 28 +++- .../cloud/testing/BaseEmulatorHelper.java | 13 +- .../com/google/cloud/RetryOptionTest.java | 25 ++-- .../com/google/cloud/SerializationTest.java | 3 +- .../cloud/testing/BaseEmulatorHelperTest.java | 11 +- 80 files changed, 809 insertions(+), 686 deletions(-) diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java index 0d567f409d..ecce73d810 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java @@ -121,18 +121,18 @@ public void paramDefinitionsBlock_basic() { "settings =" + " RetrySettings.newBuilder().setInitialRetryDelay(" + "Duration.ofMillis(100L)).setRetryDelayMultiplier(2.0)" - + ".setMaxRetryDelay(Duration.ofMillis(3000L))" - + ".setInitialRpcTimeout(Duration.ofMillis(10000L))" + + ".setMaxRetryDelayjava.time.Duration.ofMillis(3000L))" + + ".setInitialRpcTimeoutjava.time.Duration.ofMillis(10000L))" + ".setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeout(Duration.ofMillis(10000L))" - + ".setTotalTimeout(Duration.ofMillis(10000L)).build();\n", + + ".setMaxRpcTimeoutjava.time.Duration.ofMillis(10000L))" + + ".setTotalTimeoutjava.time.Duration.ofMillis(10000L)).build();\n", "definitions.put(\"retry_policy_1_params\", settings);\n", "settings =" + " RetrySettings.newBuilder()" - + ".setInitialRpcTimeout(Duration.ofMillis(5000L))" + + ".setInitialRpcTimeoutjava.time.Duration.ofMillis(5000L))" + ".setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeout(Duration.ofMillis(5000L))" - + ".setTotalTimeout(Duration.ofMillis(5000L)).build();\n", + + ".setMaxRpcTimeoutjava.time.Duration.ofMillis(5000L))" + + ".setTotalTimeoutjava.time.Duration.ofMillis(5000L)).build();\n", "definitions.put(\"no_retry_0_params\", settings);\n", "RETRY_PARAM_DEFINITIONS = definitions.build();\n", "}\n"); @@ -341,10 +341,10 @@ public void lroBuilderExpr() { + "WaitResponse.class))" + ".setMetadataTransformer(ProtoOperationTransformers.MetadataTransformer.create(" + "WaitMetadata.class)).setPollingAlgorithm(OperationTimedPollAlgorithm.create(" - + "RetrySettings.newBuilder().setInitialRetryDelay(Duration.ofMillis(5000L))" - + ".setRetryDelayMultiplier(1.5).setMaxRetryDelay(Duration.ofMillis(45000L))" - + ".setInitialRpcTimeout(Duration.ZERO).setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeout(Duration.ZERO).setTotalTimeout(Duration.ofMillis(300000L))" + + "RetrySettings.newBuilder().setInitialRetryDelayjava.time.Duration.ofMillis(5000L))" + + ".setRetryDelayMultiplier(1.5).setMaxRetryDelayjava.time.Duration.ofMillis(45000L))" + + ".setInitialRpcTimeoutjava.time.Duration.ZERO).setRpcTimeoutMultiplier(1.0)" + + ".setMaxRpcTimeoutjava.time.Duration.ZERO).setTotalTimeoutjava.time.Duration.ofMillis(300000L))" + ".build()))"); assertEquals(expected, writerVisitor.write()); } @@ -394,7 +394,7 @@ public void batchingSettings_minimalFlowControlSettings() { + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(100L)" + ".setRequestByteThreshold(1048576L)" - + ".setDelayThreshold(Duration.ofMillis(10L))" + + ".setDelayThresholdjava.time.Duration.ofMillis(10L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore)" @@ -451,7 +451,7 @@ public void batchingSettings_fullFlowControlSettings() { + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(1000L)" + ".setRequestByteThreshold(1048576L)" - + ".setDelayThreshold(Duration.ofMillis(50L))" + + ".setDelayThresholdjava.time.Duration.ofMillis(50L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setMaxOutstandingElementCount(100000L)" diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java index af58e7a30c..8c256930fa 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java @@ -49,7 +49,7 @@ public void validFormatSampleCode_longChainMethod() { String sampleCode = "echoSettingsBuilder.echoSettings().setRetrySettings(" + "echoSettingsBuilder.echoSettings().getRetrySettings().toBuilder()" - + ".setTotalTimeout(Duration.ofSeconds(30)).build());"; + + ".setTotalTimeoutjava.time.Duration.ofSeconds(30)).build());"; String result = SampleBodyJavaFormatter.format(sampleCode); String expected = LineFormatter.lines( @@ -60,7 +60,7 @@ public void validFormatSampleCode_longChainMethod() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeout(Duration.ofSeconds(30))\n", + " .setTotalTimeoutjava.time.Duration.ofSeconds(30))\n", " .build());"); assertEquals(expected, result); } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java index bf33f30e26..92294cd2f0 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java @@ -163,7 +163,7 @@ public void composeClassHeaderSample_firstMethodIsNotUnaryRpc() { String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", - " Duration ttl = Duration.newBuilder().build();\n", + " java.time.Duration ttl =java.time.Duration.newBuilder().build();\n", " WaitResponse response = echoClient.waitAsync(ttl).get();\n", "}"); Assert.assertEquals(results, expected); @@ -806,7 +806,7 @@ public void valid_composeShowcaseMethodSample_lroRpcWithReturnResponseType() { String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", - " Duration ttl = Duration.newBuilder().build();\n", + " java.time.Duration ttl =java.time.Duration.newBuilder().build();\n", " WaitResponse response = echoClient.waitAsync(ttl).get();\n", "}"); Assert.assertEquals(results, expected); @@ -888,7 +888,7 @@ public void valid_composeShowcaseMethodSample_lroRpcWithReturnVoid() { String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", - " Duration ttl = Duration.newBuilder().build();\n", + " java.time.Duration ttl =java.time.Duration.newBuilder().build();\n", " echoClient.waitAsync(ttl).get();\n", "}"); Assert.assertEquals(results, expected); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java index 00f319b0ce..35bbd07cd5 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java @@ -61,7 +61,7 @@ public void composeSettingsSample_serviceSettingsClass() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeout(Duration.ofSeconds(30))\n", + " .setTotalTimeoutjava.time.Duration.ofSeconds(30))\n", " .build());\n", "EchoSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); @@ -89,7 +89,7 @@ public void composeSettingsSample_serviceStubClass() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeout(Duration.ofSeconds(30))\n", + " .setTotalTimeoutjava.time.Duration.ofSeconds(30))\n", " .build());\n", "EchoStubSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java index ca4cd84418..e19c6c71cc 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java @@ -97,8 +97,8 @@ public void serviceConfig_basic() { MethodConfig.RetryPolicy retryPolicy = settings.retryPolicy(); assertEquals(3, retryPolicy.getMaxAttempts()); - assertEquals(100, Durations.toMillis(retryPolicy.getInitialBackoff())); - assertEquals(3000, Durations.toMillis(retryPolicy.getMaxBackoff())); + assertEquals(100,Durations.toMillis(retryPolicy.getInitialBackoff())); + assertEquals(3000,Durations.toMillis(retryPolicy.getMaxBackoff())); assertEquals(2.0, retryPolicy.getBackoffMultiplier(), EPSILON); String retryCodeName = serviceConfig.getRetryCodeName(service, method); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java index 8a27f7fd4f..956ec8cbe4 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java @@ -51,8 +51,8 @@ public void parseServiceConfig_basic() { MethodConfig.RetryPolicy retryPolicy = methodConfig.getRetryPolicy(); assertEquals(5, retryPolicy.getMaxAttempts()); - assertEquals(500, Durations.toMillis(retryPolicy.getInitialBackoff())); - assertEquals(30000, Durations.toMillis(retryPolicy.getMaxBackoff())); + assertEquals(500,Durations.toMillis(retryPolicy.getInitialBackoff())); + assertEquals(30000,Durations.toMillis(retryPolicy.getMaxBackoff())); assertEquals(2.0, retryPolicy.getBackoffMultiplier(), EPSILON); assertEquals(1, retryPolicy.getRetryableStatusCodesList().size()); @@ -72,7 +72,7 @@ public void parseServiceConfig_showcase() { MethodConfig methodConfig = config.getMethodConfigList().get(0); assertEquals(2, methodConfig.getNameList().size()); assertTrue(methodConfig.getNameList().get(0).getMethod().isEmpty()); - assertEquals(5000, Durations.toMillis(methodConfig.getTimeout())); + assertEquals(5000,Durations.toMillis(methodConfig.getTimeout())); methodConfig = config.getMethodConfigList().get(1); assertEquals(9, methodConfig.getNameList().size()); diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 6351718b76..14b44a2c6e 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -48,14 +48,13 @@ import io.grpc.Deadline; import io.grpc.Metadata; import io.grpc.auth.MoreCallCredentials; -import org.threeten.bp.Duration; - import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.threeten.bp.Duration; /** * GrpcCallContext encapsulates context data used to make a grpc call. @@ -173,9 +172,7 @@ public GrpcCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } - /** - * Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} - */ + /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @Override public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); @@ -219,10 +216,12 @@ public java.time.Duration getTimeoutDuration() { } /** - * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @Override - public GrpcCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout) { + public GrpcCallContext withStreamWaitTimeout( + @Nullable org.threeten.bp.Duration streamWaitTimeout) { return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); } @@ -247,12 +246,15 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration stream } /** - * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + * * @param streamIdleTimeout * @return */ @Override - public GrpcCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout) { + public GrpcCallContext withStreamIdleTimeout( + @Nullable org.threeten.bp.Duration streamIdleTimeout) { return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); } @@ -450,9 +452,7 @@ public CallOptions getCallOptions() { return callOptions; } - /** - * Backport of {@link #getStreamWaitTimeoutDuration()} - */ + /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Override @Nullable public org.threeten.bp.Duration getStreamWaitTimeout() { diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 5bf850f776..659736c5bb 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -55,8 +55,6 @@ import io.grpc.TlsChannelCredentials; import io.grpc.alts.GoogleDefaultChannelCredentials; import io.grpc.auth.MoreCallCredentials; -import org.threeten.bp.Duration; - import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -593,10 +591,11 @@ public Integer getMaxInboundMetadataSize() { } /** - * Overload of {@link #setKeepAliveTime(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setKeepAliveTime(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { - return setKeepAliveTime(java.time.Duration.ofNanos(duration.toNanos())) ; + return setKeepAliveTime(java.time.Duration.ofNanos(duration.toNanos())); } /** The time without read activity before sending a keepalive ping. */ public Builder setKeepAliveTime(java.time.Duration duration) { @@ -604,9 +603,7 @@ public Builder setKeepAliveTime(java.time.Duration duration) { return this; } - /** - * Backport of {@link #getKeepAliveTimeDuration()} - */ + /** Backport of {@link #getKeepAliveTimeDuration()} */ public org.threeten.bp.Duration getKeepAliveTime() { return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeDuration().toNanos()); } @@ -616,9 +613,14 @@ public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } + public Builder setKeepAliveTimeout(org.threeten.bp.Duration duration) { + return setKeepAliveTimeout(java.time.Duration.ofNanos(duration.toNanos())); + } + /** The time without read activity after sending a keepalive ping. */ - public org.threeten.bp.Duration getKeepAliveTimeout() { - return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeoutDuration().toNanos()); + public Builder setKeepAliveTimeout(java.time.Duration duration) { + this.keepAliveTimeout = duration; + return this; } /** The time without read activity after sending a keepalive ping. */ diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 4e563225e5..ec0018b85a 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -57,7 +57,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class GrpcCallContextTest { @@ -129,61 +128,70 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { - assertNull(GrpcCallContext.createDefault().withTimeout(null).getTimeout()); + org.threeten.bp.Duration timeout = null; + assertNull(GrpcCallContext.createDefault().withTimeout(timeout).getTimeout()); } @Test public void testWithNegativeTimeout() { - assertNull(GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(-1L)).getTimeout()); + assertNull( + GrpcCallContext.createDefault() + .withTimeout(java.time.Duration.ofSeconds(-1L)) + .getTimeout()); } @Test public void testWithZeroTimeout() { - assertNull(GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(0L)).getTimeout()); + assertNull( + GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(0L)).getTimeout()); } @Test public void testWithShorterTimeout() { GrpcCallContext ctxWithLongTimeout = - GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(10)); + GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); // Sanity check - Truth.assertThat(ctxWithLongTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(10)); + Truth.assertThat(ctxWithLongTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(10)); // Shorten the timeout and make sure it changed - GrpcCallContext ctxWithShorterTimeout = ctxWithLongTimeout.withTimeout(Duration.ofSeconds(5)); - Truth.assertThat(ctxWithShorterTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(5)); + GrpcCallContext ctxWithShorterTimeout = + ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShorterTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); } @Test public void testWithLongerTimeout() { GrpcCallContext ctxWithShortTimeout = - GrpcCallContext.createDefault().withTimeout(Duration.ofSeconds(5)); + GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); // Sanity check - Truth.assertThat(ctxWithShortTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShortTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); // Try to extend the timeout and verify that it was ignored GrpcCallContext ctxWithUnchangedTimeout = - ctxWithShortTimeout.withTimeout(Duration.ofSeconds(10)); - Truth.assertThat(ctxWithUnchangedTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(5)); + ctxWithShortTimeout.withTimeout(java.time.Duration.ofSeconds(10)); + Truth.assertThat(ctxWithUnchangedTimeout.getTimeout()) + .isEqualTo(java.time.Duration.ofSeconds(5)); } @Test public void testMergeWithNullTimeout() { - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); GrpcCallContext baseContext = GrpcCallContext.createDefault().withTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeout()).isEqualTo(timeout); - GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withTimeout(null); + org.threeten.bp.Duration callContextTimeout = null; + GrpcCallContext explicitNullOverlay = + GrpcCallContext.createDefault().withTimeout(callContextTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeout()).isEqualTo(timeout); } @Test public void testMergeWithTimeout() { - Duration timeout = Duration.ofSeconds(19); + java.time.Duration timeout = java.time.Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withTimeout(timeout); @@ -192,28 +200,29 @@ public void testMergeWithTimeout() { @Test public void testWithStreamingWaitTimeout() { - Duration timeout = Duration.ofSeconds(15); + java.time.Duration timeout = java.time.Duration.ofSeconds(15); GrpcCallContext context = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(timeout); } @Test public void testMergeWithNullStreamingWaitTimeout() { - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeout()).isEqualTo(timeout); + org.threeten.bp.Duration streamWaitTimeout = null; GrpcCallContext explicitNullOverlay = - GrpcCallContext.createDefault().withStreamWaitTimeout(null); + GrpcCallContext.createDefault().withStreamWaitTimeout(streamWaitTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamWaitTimeout()) .isEqualTo(timeout); } @Test public void testWithZeroStreamingWaitTimeout() { - Duration timeout = Duration.ZERO; + java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( GrpcCallContext.createDefault().withStreamWaitTimeout(timeout).getStreamWaitTimeout()) .isEqualTo(timeout); @@ -221,7 +230,7 @@ public void testWithZeroStreamingWaitTimeout() { @Test public void testMergeWithStreamingWaitTimeout() { - Duration timeout = Duration.ofSeconds(19); + java.time.Duration timeout = java.time.Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); @@ -230,28 +239,29 @@ public void testMergeWithStreamingWaitTimeout() { @Test public void testWithStreamingIdleTimeout() { - Duration timeout = Duration.ofSeconds(15); + java.time.Duration timeout = java.time.Duration.ofSeconds(15); GrpcCallContext context = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(timeout); } @Test public void testMergeWithNullStreamingIdleTimeout() { - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeout()).isEqualTo(timeout); + org.threeten.bp.Duration idleTimeout = null; GrpcCallContext explicitNullOverlay = - GrpcCallContext.createDefault().withStreamIdleTimeout(null); + GrpcCallContext.createDefault().withStreamIdleTimeout(idleTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamIdleTimeout()) .isEqualTo(timeout); } @Test public void testWithZeroStreamingIdleTimeout() { - Duration timeout = Duration.ZERO; + java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( GrpcCallContext.createDefault().withStreamIdleTimeout(timeout).getStreamIdleTimeout()) .isEqualTo(timeout); @@ -259,7 +269,7 @@ public void testWithZeroStreamingIdleTimeout() { @Test public void testMergeWithStreamingIdleTimeout() { - Duration timeout = Duration.ofSeconds(19); + java.time.Duration timeout = java.time.Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java index 2ebe93b7f7..131f25dcb1 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java @@ -58,7 +58,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class GrpcCallableFactoryTest { @@ -97,7 +96,7 @@ public void createServerStreamingCallableRetryableExceptions() { ServerStreamingCallSettings.newBuilder() .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofSeconds(1)) + .setTotalTimeout(java.time.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); @@ -123,7 +122,7 @@ public void createServerStreamingCallableRetryableExceptions() { .setRetryableCodes(Code.INVALID_ARGUMENT) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofSeconds(1)) + .setTotalTimeout(java.time.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java index fcdea5afe9..d99865a2f5 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java @@ -54,7 +54,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.threeten.bp.Duration; public class GrpcClientCallsTest { @Test @@ -149,7 +148,7 @@ public void testTimeoutToDeadlineConversion() { Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())) .thenReturn(mockClientCall); - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); GrpcCallContext context = @@ -182,7 +181,7 @@ public void testTimeoutAfterDeadline() { // Configure a timeout that occurs after the grpc deadline Deadline priorDeadline = Deadline.after(5, TimeUnit.SECONDS); - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); GrpcCallContext context = GrpcCallContext.createDefault() @@ -214,7 +213,7 @@ public void testTimeoutBeforeDeadline() { .thenReturn(mockClientCall); // Configure a timeout that occurs before the grpc deadline - Duration timeout = Duration.ofSeconds(5); + java.time.Duration timeout = java.time.Duration.ofSeconds(5); Deadline subsequentDeadline = Deadline.after(10, TimeUnit.SECONDS); Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java index 96d7cf1063..082b2a15ef 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java @@ -57,7 +57,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 GrpcDirectStreamControllerTest { @@ -101,11 +100,11 @@ public boolean canResume() { .setRetryableCodes(StatusCode.Code.DEADLINE_EXCEEDED) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofMinutes(1)) - .setInitialRpcTimeout(Duration.ofMillis(1)) - .setMaxRpcTimeout(Duration.ofMillis(1)) - .setInitialRetryDelay(Duration.ofMillis(1)) - .setMaxRetryDelay(Duration.ofMillis(1)) + .setTotalTimeout(java.time.Duration.ofMinutes(1)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(1)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1)) .build()) .build(); // Store a list of resources to manually close at the end of the test diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java index 7149f23ba7..07d8af8272 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java @@ -68,22 +68,21 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class GrpcLongRunningTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(1L)) - .setInitialRpcTimeout(Duration.ofMillis(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(1L)) - .setTotalTimeout(Duration.ofMillis(5L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(1L)) + .setTotalTimeout(java.time.Duration.ofMillis(5L)) .build(); private ManagedChannel channel; diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index d58a3b56b6..fcab281538 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -62,7 +62,6 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class InstantiatingGrpcChannelProviderTest extends AbstractMtlsTransportChannelTest { @@ -91,8 +90,8 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { - Duration keepaliveTime = Duration.ofSeconds(1); - Duration keepaliveTimeout = Duration.ofSeconds(2); + java.time.Duration keepaliveTime = java.time.Duration.ofSeconds(1); + java.time.Duration keepaliveTimeout = java.time.Duration.ofSeconds(2); boolean keepaliveWithoutCalls = true; InstantiatingGrpcChannelProvider provider = @@ -153,8 +152,8 @@ public void testWithPoolSize() throws IOException { @Test public void testToBuilder() { - Duration keepaliveTime = Duration.ofSeconds(1); - Duration keepaliveTimeout = Duration.ofSeconds(2); + java.time.Duration keepaliveTime = java.time.Duration.ofSeconds(1); + java.time.Duration keepaliveTimeout = java.time.Duration.ofSeconds(2); ApiFunction channelConfigurator = builder -> { throw new UnsupportedOperationException(); @@ -181,7 +180,7 @@ public void testToBuilder() { assertThat(builder.getMaxInboundMessageSize()).isEqualTo(12345678); assertThat(builder.getMaxInboundMetadataSize()).isEqualTo(4096); assertThat(builder.getKeepAliveTime()).isEqualTo(keepaliveTime); - assertThat(builder.getKeepAliveTimeout()).isEqualTo(keepaliveTimeout); + assertThat(builder.getKeepAliveTimeoutDuration()).isEqualTo(keepaliveTimeout); assertThat(builder.getChannelConfigurator()).isEqualTo(channelConfigurator); assertThat(builder.getPoolSize()).isEqualTo(5); assertThat(builder.build().directPathServiceConfig).isEqualTo(directPathServiceConfig); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index e24e36c686..514838de88 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -62,7 +62,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class SettingsTest { @@ -112,13 +111,13 @@ private static class FakeStubSettings extends StubSettings { RetrySettings settings = null; settings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(100L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(100L)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(Duration.ofMillis(1000L)) - .setInitialRpcTimeout(Duration.ofMillis(2000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1000L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2000L)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(45000L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(30000L)) + .setTotalTimeout(java.time.Duration.ofMillis(45000L)) .build(); definitions.put("default", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -224,7 +223,7 @@ private static Builder createDefault() { BatchingSettings.newBuilder() .setElementCountThreshold(800L) .setRequestByteThreshold(8388608L) - .setDelayThreshold(Duration.ofMillis(100)) + .setDelayThreshold(java.time.Duration.ofMillis(100)) .build()); builder .fakeMethodBatching() @@ -337,7 +336,7 @@ public void unaryCallSettingsBuilderBuildDoesNotFailUnsetProperties() { @Test public void callSettingsBuildFromTimeoutNoRetries() { - Duration timeout = Duration.ofMillis(60000); + java.time.Duration timeout = java.time.Duration.ofMillis(60000); UnaryCallSettings.Builder builderA = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -351,9 +350,9 @@ public void callSettingsBuildFromTimeoutNoRetries() { .setRetrySettings( RetrySettings.newBuilder() .setTotalTimeout(timeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setInitialRpcTimeout(timeout) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(timeout) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java index 9de95c1752..01245cf9a1 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java @@ -63,7 +63,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class TimeoutTest { @@ -74,9 +73,12 @@ public class TimeoutTest { private static final ImmutableSet emptyRetryCodes = ImmutableSet.of(); private static final ImmutableSet retryUnknownCode = ImmutableSet.of(StatusCode.Code.UNKNOWN); - private static final Duration totalTimeout = Duration.ofDays(DEADLINE_IN_DAYS); - private static final Duration maxRpcTimeout = Duration.ofMinutes(DEADLINE_IN_MINUTES); - private static final Duration initialRpcTimeout = Duration.ofSeconds(DEADLINE_IN_SECONDS); + private static final java.time.Duration totalTimeout = + java.time.Duration.ofDays(DEADLINE_IN_DAYS); + private static final java.time.Duration maxRpcTimeout = + java.time.Duration.ofMinutes(DEADLINE_IN_MINUTES); + private static final java.time.Duration initialRpcTimeout = + java.time.Duration.ofSeconds(DEADLINE_IN_SECONDS); private static final GrpcCallContext defaultCallContext = GrpcCallContext.createDefault(); @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); @@ -89,9 +91,9 @@ public void testNonRetryUnarySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) @@ -115,16 +117,16 @@ public void testNonRetryUnarySettingsContextWithRetry() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(maxRpcTimeout) .build(); - Duration newTimeout = Duration.ofSeconds(5); + java.time.Duration newTimeout = java.time.Duration.ofSeconds(5); RetrySettings contextRetrySettings = retrySettings .toBuilder() @@ -155,9 +157,9 @@ public void testNonRetryUnarySettingsWithoutInitialRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) @@ -180,9 +182,9 @@ public void testNonRetryUnarySettingsWithoutIndividualRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) @@ -205,9 +207,9 @@ public void testNonRetryServerStreamingSettings() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) @@ -231,16 +233,16 @@ public void testNonRetryServerStreamingSettingsContextWithRetry() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(maxRpcTimeout) .build(); - Duration newTimeout = Duration.ofSeconds(5); + java.time.Duration newTimeout = java.time.Duration.ofSeconds(5); RetrySettings contextRetrySettings = retrySettings .toBuilder() @@ -271,9 +273,9 @@ public void testNonRetryServerStreamingSettingsWithoutInitialRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) @@ -296,9 +298,9 @@ public void testNonRetryServerStreamingSettingsWithoutIndividualRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) @@ -443,7 +445,7 @@ private CallOptions setupServerStreamingCallable( * codebase must continue to support Java 7 and up, in alignment with client libraries that depend * on gax-java. */ - private int toSecondsPart(Duration duration) { + private int toSecondsPart(java.time.Duration duration) { return (int) (duration.getSeconds() - TimeUnit.MINUTES.toSeconds(1) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 3b1691e7db..67899eacfe 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -42,15 +42,13 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.threeten.bp.Duration; - -import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.threeten.bp.Duration; /** * HttpJsonCallContext encapsulates context data used to make an http-json call. @@ -233,9 +231,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } - /** - * Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} - */ + /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @Override public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); @@ -266,9 +262,7 @@ public HttpJsonCallContext withTimeout(java.time.Duration timeout) { this.retryableCodes); } - /** - * Backport of {@link #getTimeoutDuration()} - */ + /** Backport of {@link #getTimeoutDuration()} */ @Nullable @Override public org.threeten.bp.Duration getTimeout() { @@ -282,10 +276,12 @@ public java.time.Duration getTimeoutDuration() { } /** - * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @Override - public HttpJsonCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout) { + public HttpJsonCallContext withStreamWaitTimeout( + @Nullable org.threeten.bp.Duration streamWaitTimeout) { return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); } @@ -309,9 +305,7 @@ public HttpJsonCallContext withStreamWaitTimeout(@Nullable java.time.Duration st this.retryableCodes); } - /** - * Backport of {@link #getStreamWaitTimeoutDuration()} - */ + /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Override @Nullable public org.threeten.bp.Duration getStreamWaitTimeout() { @@ -330,10 +324,12 @@ public java.time.Duration getStreamWaitTimeoutDuration() { } /** - * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @Override - public HttpJsonCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout) { + public HttpJsonCallContext withStreamIdleTimeout( + @Nullable org.threeten.bp.Duration streamIdleTimeout) { return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); } @@ -357,9 +353,7 @@ public HttpJsonCallContext withStreamIdleTimeout(@Nullable java.time.Duration st this.retryableCodes); } - /** - * Backport of {@link #getStreamIdleTimeoutDuration()} - */ + /** Backport of {@link #getStreamIdleTimeoutDuration()} */ @Override @Nullable public org.threeten.bp.Duration getStreamIdleTimeout() { @@ -433,9 +427,7 @@ public HttpJsonCallOptions getCallOptions() { return callOptions; } - /** - * Backport of {@link #getDeadlineInstant()} - */ + /** Backport of {@link #getDeadlineInstant()} */ @Deprecated @Nullable public org.threeten.bp.Instant getDeadline() { @@ -522,9 +514,7 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { this.retryableCodes); } - /** - * Overload of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} - */ + /** Overload of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} */ @Deprecated public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { return withDeadline(java.time.Instant.ofEpochMilli(newDeadline.toEpochMilli())); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index 30bf2fa11c..b40adf1829 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -32,8 +32,6 @@ import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; -import org.threeten.bp.Instant; - import java.time.Duration; import javax.annotation.Nullable; @@ -102,13 +100,22 @@ public abstract static class Builder { public abstract Builder setTimeout(java.time.Duration value); /** - * Overload of {@link #setDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} + * Overload of {@link #setDeadlineInstant(java.time.Instant)} using {@link + * org.threeten.bp.Instant} */ public final Builder setDeadline(org.threeten.bp.Instant value) { - return setDeadline(java.time.Instant.ofEpochMilli(value.toEpochMilli())); + return setDeadlineInstant(java.time.Instant.ofEpochMilli(value.toEpochMilli())); + } + + /** + * Overload of {@link #setDeadlineInstant(java.time.Instant)} using {@link + * org.threeten.bp.Instant} This is a convenience public method to keep name conformity + */ + public final Builder setDeadline(java.time.Instant value) { + return setDeadlineInstant(value); } - public abstract Builder setDeadline(java.time.Instant value); + public abstract Builder setDeadlineInstant(java.time.Instant value); public abstract Builder setCredentials(Credentials value); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index fc872d3529..a06d439040 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -54,7 +54,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class HttpJsonCallContextTest { @@ -117,64 +116,72 @@ public void testMergeWrongType() { @Test public void testWithTimeout() { - assertNull(HttpJsonCallContext.createDefault().withTimeout(null).getTimeout()); + org.threeten.bp.Duration timeout = null; + assertNull(HttpJsonCallContext.createDefault().withTimeout(timeout).getTimeout()); } @Test public void testWithNegativeTimeout() { assertNull( - HttpJsonCallContext.createDefault().withTimeout(Duration.ofSeconds(-1L)).getTimeout()); + HttpJsonCallContext.createDefault() + .withTimeout(java.time.Duration.ofSeconds(-1L)) + .getTimeout()); } @Test public void testWithZeroTimeout() { assertNull( - HttpJsonCallContext.createDefault().withTimeout(Duration.ofSeconds(0L)).getTimeout()); + HttpJsonCallContext.createDefault() + .withTimeout(java.time.Duration.ofSeconds(0L)) + .getTimeout()); } @Test public void testWithShorterTimeout() { HttpJsonCallContext ctxWithLongTimeout = - HttpJsonCallContext.createDefault().withTimeout(Duration.ofSeconds(10)); + HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); // Sanity check - Truth.assertThat(ctxWithLongTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(10)); + Truth.assertThat(ctxWithLongTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(10)); // Shorten the timeout and make sure it changed HttpJsonCallContext ctxWithShorterTimeout = - ctxWithLongTimeout.withTimeout(Duration.ofSeconds(5)); - Truth.assertThat(ctxWithShorterTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(5)); + ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShorterTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); } @Test public void testWithLongerTimeout() { HttpJsonCallContext ctxWithShortTimeout = - HttpJsonCallContext.createDefault().withTimeout(Duration.ofSeconds(5)); + HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); // Sanity check - Truth.assertThat(ctxWithShortTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShortTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); // Try to extend the timeout and verify that it was ignored HttpJsonCallContext ctxWithUnchangedTimeout = - ctxWithShortTimeout.withTimeout(Duration.ofSeconds(10)); - Truth.assertThat(ctxWithUnchangedTimeout.getTimeout()).isEqualTo(Duration.ofSeconds(5)); + ctxWithShortTimeout.withTimeout(java.time.Duration.ofSeconds(10)); + Truth.assertThat(ctxWithUnchangedTimeout.getTimeout()) + .isEqualTo(java.time.Duration.ofSeconds(5)); } @Test public void testMergeWithNullTimeout() { - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); HttpJsonCallContext baseContext = HttpJsonCallContext.createDefault().withTimeout(timeout); HttpJsonCallContext defaultOverlay = HttpJsonCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeout()).isEqualTo(timeout); - HttpJsonCallContext explicitNullOverlay = HttpJsonCallContext.createDefault().withTimeout(null); + org.threeten.bp.Duration callContextTimeout = null; + HttpJsonCallContext explicitNullOverlay = + HttpJsonCallContext.createDefault().withTimeout(callContextTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeout()).isEqualTo(timeout); } @Test public void testMergeWithTimeout() { - Duration timeout = Duration.ofSeconds(19); + java.time.Duration timeout = java.time.Duration.ofSeconds(19); HttpJsonCallContext ctx1 = HttpJsonCallContext.createDefault(); HttpJsonCallContext ctx2 = HttpJsonCallContext.createDefault().withTimeout(timeout); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java index 6e081fb75f..9d99342dad 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java @@ -51,7 +51,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 HttpJsonClientInterceptorTest { @@ -185,7 +184,7 @@ public void testCustomInterceptor() throws ExecutionException, InterruptedExcept HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); Field request; Field expectedResponse; diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java index fa666dc69c..95d60a6ef0 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java @@ -53,7 +53,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 HttpJsonDirectCallableTest { @@ -135,7 +134,7 @@ public void testSuccessfulUnaryResponse() throws ExecutionException, Interrupted HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); Field request; Field expectedResponse; @@ -170,7 +169,7 @@ public void testSuccessfulMultipleResponsesForUnaryCall() HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); Field request = createTestMessage(2); Field expectedResponse = createTestMessage(2); @@ -205,7 +204,7 @@ public void testErrorMultipleResponsesForUnaryCall() HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); Field request = createTestMessage(2); Field expectedResponse = createTestMessage(2); @@ -237,7 +236,7 @@ public void testErrorUnaryResponse() throws InterruptedException { HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); ApiException exception = ApiExceptionFactory.createException( @@ -269,7 +268,7 @@ public void testErrorNullContentSuccessfulResponse() throws InterruptedException HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); MOCK_SERVICE.addNullResponse(); @@ -298,7 +297,7 @@ public void testErrorNullContentFailedResponse() throws InterruptedException { HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); MOCK_SERVICE.addNullResponse(400); try { @@ -324,7 +323,7 @@ public void testErrorNon2xxOr4xxResponse() throws InterruptedException { HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)); + .withTimeout(java.time.Duration.ofSeconds(30)); ApiException exception = ApiExceptionFactory.createException( @@ -354,7 +353,9 @@ public void testDeadlineExceededResponse() throws InterruptedException { new HttpJsonDirectCallable<>(FAKE_METHOD_DESCRIPTOR); HttpJsonCallContext callContext = - HttpJsonCallContext.createDefault().withChannel(channel).withTimeout(Duration.ofSeconds(3)); + HttpJsonCallContext.createDefault() + .withChannel(channel) + .withTimeout(java.time.Duration.ofSeconds(3)); Field response = createTestMessage(10); MOCK_SERVICE.addResponse(response, java.time.Duration.ofSeconds(5)); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java index 8781ad00d4..cb8fa9c089 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java @@ -66,7 +66,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 HttpJsonDirectServerStreamingCallableTest { @@ -149,7 +148,7 @@ public void setUp() { .setTransportChannel(HttpJsonTransportChannel.create(channel)) .setDefaultCallContext( HttpJsonCallContext.of(channel, HttpJsonCallOptions.DEFAULT) - .withTimeout(Duration.ofSeconds(3))) + .withTimeout(java.time.Duration.ofSeconds(3))) .build(); streamingCallSettings = ServerStreamingCallSettings.newBuilder().build(); streamingCallable = diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/RetryingTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/RetryingTest.java index d03d7e57f0..d6badb5eef 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/RetryingTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/RetryingTest.java @@ -60,7 +60,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class RetryingTest { @@ -83,13 +82,13 @@ public class RetryingTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(2L)) - .setInitialRpcTimeout(Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(2L)) - .setTotalTimeout(Duration.ofMillis(10L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); @Before @@ -147,8 +146,8 @@ public void retryTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); UnaryCallSettings callSettings = createSettings(retryable, retrySettings); UnaryCallable callable = diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java index 86cc78fd7d..931041201d 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/testing/MockHttpService.java @@ -43,7 +43,6 @@ import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; -import java.time.Duration; import java.util.LinkedList; import java.util.List; import java.util.Queue; @@ -88,7 +87,7 @@ public synchronized void addResponse(Object response) { responseHandlers.add(new MessageResponseFactory(endpoint, serviceMethodDescriptors, response)); } - public synchronized void addResponse(Object response, Duration delay) { + public synchronized void addResponse(Object response, java.time.Duration delay) { responseHandlers.add( new MessageResponseFactory(endpoint, serviceMethodDescriptors, response, delay)); } @@ -188,18 +187,18 @@ private static class MessageResponseFactory implements HttpResponseFactory { private final List serviceMethodDescriptors; private final Object response; private final String endpoint; - private final Duration delay; + private final java.time.Duration delay; public MessageResponseFactory( String endpoint, List serviceMethodDescriptors, Object response) { - this(endpoint, serviceMethodDescriptors, response, Duration.ofNanos(0)); + this(endpoint, serviceMethodDescriptors, response, java.time.Duration.ofNanos(0)); } public MessageResponseFactory( String endpoint, List serviceMethodDescriptors, Object response, - Duration delay) { + java.time.Duration delay) { this.endpoint = endpoint; this.serviceMethodDescriptors = ImmutableList.copyOf(serviceMethodDescriptors); this.response = response; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index e3b4c62f00..f82311c52b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -33,7 +33,6 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import javax.annotation.Nullable; -import java.time.Duration; /** * Represents the batching settings to use for an API method that is capable of batching. @@ -106,7 +105,7 @@ public final org.threeten.bp.Duration getDelayThreshold() { /** Get the delay threshold to use for batching. */ @Nullable - public abstract Duration getDelayThresholdDuration(); + public abstract java.time.Duration getDelayThresholdDuration(); /** Returns the Boolean object to indicate if the batching is enabled. Default to true */ public abstract Boolean getIsEnabled(); @@ -148,13 +147,29 @@ public abstract static class Builder { */ public abstract Builder setRequestByteThreshold(Long requestByteThreshold); + /** + * Overload of {@link #setDelayThresholdDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) { + return setDelayThresholdDuration(java.time.Duration.ofNanos(delayThreshold.toNanos())); + } + + /** + * Overload of {@link #setDelayThresholdDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} This is a convenience public method to keep name conformity + */ + public final Builder setDelayThreshold(java.time.Duration delayThreshold) { + return setDelayThresholdDuration(java.time.Duration.ofNanos(delayThreshold.toNanos())); + } + /** * Set the delay threshold to use for batching. After this amount of time has elapsed (counting * from the first element added), the elements will be wrapped up in a batch and sent. This * value should not be set too high, usually on the order of milliseconds. Otherwise, calls * might appear to never complete. */ - public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); + public abstract Builder setDelayThresholdDuration(java.time.Duration delayThreshold); /** * Set if the batch should be enabled. If set to false, the batch logic will be disabled and the diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java index de7b5b5acb..a07242a436 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java @@ -187,7 +187,7 @@ void handleAttempt(Throwable throwable, ResponseT response) { "retriableException: " + throwable }); } - tracer.attemptFailed(throwable, nextAttemptSettings.getRandomizedRetryDelay()); + tracer.attemptFailed(throwable, nextAttemptSettings.getRandomizedRetryDelayDuration()); attemptSettings = nextAttemptSettings; setAttemptResult(throwable, response, true); // a new attempt will be (must be) scheduled by an external executor diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index ed8823dc76..8d54579e8e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -146,7 +146,8 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti java.time.Duration timeElapsed = java.time.Duration.ofNanos(clock.nanoTime()) .minus(java.time.Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); - java.time.Duration timeLeft = settings.getTotalTimeoutDuration().minus(timeElapsed).minus(randomDelay); + java.time.Duration timeLeft = + settings.getTotalTimeoutDuration().minus(timeElapsed).minus(randomDelay); // If timeLeft at this point is < 0, the shouldRetry logic will prevent // the attempt from being made as it would exceed the totalTimeout. A negative RPC timeout @@ -209,7 +210,8 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { - nextAttemptSettings.getFirstAttemptStartTimeNanos() + nextAttemptSettings.getRandomizedRetryDelay().toNanos(); - java.time.Duration timeLeft = totalTimeout.minus(java.time.Duration.ofNanos(totalTimeSpentNanos)); + java.time.Duration timeLeft = + totalTimeout.minus(java.time.Duration.ofNanos(totalTimeSpentNanos)); // Convert time spent to milliseconds to standardize the units being used for // retries. Otherwise, we would be using nanoseconds to determine if retries // should be attempted and milliseconds for retry delays and rpc timeouts diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index c861e4f448..bc810c3c84 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -71,10 +71,10 @@ public abstract class RetrySettings implements Serializable { private static final long serialVersionUID = 8258475264439710899L; - /** - * Backport of {@link #getTotalTimeoutDuration()} - */ - public abstract org.threeten.bp.Duration getTotalTimeout(); + /** Backport of {@link #getTotalTimeoutDuration()} */ + public final org.threeten.bp.Duration getTotalTimeout() { + return org.threeten.bp.Duration.ofNanos(getTotalTimeoutDuration().toNanos()); + } /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call @@ -83,10 +83,10 @@ public abstract class RetrySettings implements Serializable { */ public abstract java.time.Duration getTotalTimeoutDuration(); - /** - * Backport of {@link #getInitialRetryDelayDuration()} - */ - public abstract org.threeten.bp.Duration getInitialRetryDelay(); + /** Backport of {@link #getInitialRetryDelayDuration()} */ + public final org.threeten.bp.Duration getInitialRetryDelay() { + return org.threeten.bp.Duration.ofNanos(getInitialRetryDelayDuration().toNanos()); + } /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this @@ -102,10 +102,10 @@ public abstract class RetrySettings implements Serializable { */ public abstract double getRetryDelayMultiplier(); - /** - * Backport of {@link #getMaxRetryDelayDuration()} - */ - public abstract org.threeten.bp.Duration getMaxRetryDelay(); + /** Backport of {@link #getMaxRetryDelayDuration()} */ + public final org.threeten.bp.Duration getMaxRetryDelay() { + return org.threeten.bp.Duration.ofNanos(getMaxRetryDelayDuration().toNanos()); + } /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier @@ -135,10 +135,10 @@ public abstract class RetrySettings implements Serializable { @VisibleForTesting public abstract boolean isJittered(); - /** - * Backport of {@link #getInitialRpcTimeoutDuration()} - */ - public abstract org.threeten.bp.Duration getInitialRpcTimeout(); + /** Backport of {@link #getInitialRpcTimeoutDuration()} */ + public final org.threeten.bp.Duration getInitialRpcTimeout() { + return org.threeten.bp.Duration.ofNanos(getInitialRpcTimeoutDuration().toNanos()); + } /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this @@ -154,10 +154,10 @@ public abstract class RetrySettings implements Serializable { */ public abstract double getRpcTimeoutMultiplier(); - /** - * Backport of {@link #getMaxRpcTimeoutDuration()} - */ - public abstract org.threeten.bp.Duration getMaxRpcTimeout(); + /** Backport of {@link #getMaxRpcTimeoutDuration()} */ + public final org.threeten.bp.Duration getMaxRpcTimeout() { + return org.threeten.bp.Duration.ofNanos(getMaxRpcTimeoutDuration().toNanos()); + } /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier @@ -189,10 +189,19 @@ public static Builder newBuilder() { public abstract static class Builder { /** - * Overload of {@link #setTotalTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setTotalTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { - return setTotalTimeout(java.time.Duration.ofNanos(totalTimeout.toNanos())); + return setTotalTimeoutDuration(java.time.Duration.ofNanos(totalTimeout.toNanos())); + } + + /** + * Overload of {@link #setTotalTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} This is a convenience public method to keep name conformity + */ + public final Builder setTotalTimeout(java.time.Duration totalTimeout) { + return setTotalTimeoutDuration(java.time.Duration.ofNanos(totalTimeout.toNanos())); } /** @@ -200,21 +209,30 @@ public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { * until it gives up completely. The higher the total timeout, the more retries can be * attempted. The default value is {@code Duration.ZERO}. */ - public abstract Builder setTotalTimeout(java.time.Duration totalTimeout); + public abstract Builder setTotalTimeoutDuration(java.time.Duration totalTimeout); /** - * Overload of {@link #setInitialRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setInitialRetryDelay(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { return setInitialRetryDelay(java.time.Duration.ofNanos(initialDelay.toNanos())); } + /** + * Overload of {@link #setInitialRetryDelay(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { + return setInitialRetryDelayDuration(initialDelay); + } + /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setInitialRetryDelay(java.time.Duration initialDelay); + public abstract Builder setInitialRetryDelayDuration(java.time.Duration initialDelay); /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -224,10 +242,19 @@ public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) public abstract Builder setRetryDelayMultiplier(double multiplier); /** - * Overload of {@link #setMaxRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setMaxRetryDelayDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { - return setMaxRetryDelay(java.time.Duration.ofNanos(maxDelay.toNanos())); + return setMaxRetryDelayDuration(java.time.Duration.ofNanos(maxDelay.toNanos())); + } + + /** + * Overload of {@link #setMaxRetryDelayDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { + return setMaxRetryDelayDuration(maxDelay); } /** @@ -235,7 +262,7 @@ public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setMaxRetryDelay(java.time.Duration maxDelay); + abstract Builder setMaxRetryDelayDuration(java.time.Duration maxDelay); /** * MaxAttempts defines the maximum number of attempts to perform. The default value is {@code @@ -259,10 +286,19 @@ public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { public abstract Builder setJittered(boolean jittered); /** - * Overload of {@link #setInitialRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { - return setInitialRpcTimeout(java.time.Duration.ofNanos(initialTimeout.toNanos())); + return setInitialRpcTimeoutDuration(java.time.Duration.ofNanos(initialTimeout.toNanos())); + } + + /** + * Overload of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { + return setInitialRpcTimeoutDuration(initialTimeout); } /** @@ -270,7 +306,7 @@ public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeou * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setInitialRpcTimeout(java.time.Duration initialTimeout); + abstract Builder setInitialRpcTimeoutDuration(java.time.Duration initialTimeout); /** * See the class documentation of {@link RetrySettings} for a description of what this value @@ -279,10 +315,19 @@ public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeou public abstract Builder setRpcTimeoutMultiplier(double multiplier); /** - * Overload of {@link #setMaxRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { - return setMaxRpcTimeout(java.time.Duration.ofNanos(maxTimeout.toNanos())); + return setMaxRpcTimeoutDuration(java.time.Duration.ofNanos(maxTimeout.toNanos())); + } + + /** + * Overload of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} using {@link + * java.time..Duration} This is a convenience public method to keep name conformity + */ + public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { + return setMaxRpcTimeoutDuration(maxTimeout); } /** @@ -290,11 +335,9 @@ public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { * can't increase the RPC timeout higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setMaxRpcTimeout(java.time.Duration maxTimeout); + abstract Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout); - /** - * Backport of {@link #getTotalTimeoutDuration()} - */ + /** Backport of {@link #getTotalTimeoutDuration()} */ public final org.threeten.bp.Duration getTotalTimeout() { return org.threeten.bp.Duration.ofNanos(getTotalTimeoutDuration().toNanos()); } @@ -306,9 +349,7 @@ public final org.threeten.bp.Duration getTotalTimeout() { */ public abstract java.time.Duration getTotalTimeoutDuration(); - /** - * Backport of {@link #getInitialRetryDelay()} - */ + /** Backport of {@link #getInitialRetryDelay()} */ public final org.threeten.bp.Duration getInitialRetryDelay() { return org.threeten.bp.Duration.ofNanos(getInitialRetryDelayDuration().toNanos()); } @@ -344,9 +385,7 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { */ public abstract boolean isJittered(); - /** - * Backport of {@link #getMaxRetryDelayDuration()} - */ + /** Backport of {@link #getMaxRetryDelayDuration()} */ public final org.threeten.bp.Duration getMaxRetryDelay() { return org.threeten.bp.Duration.ofNanos(getMaxRetryDelayDuration().toNanos()); } @@ -358,9 +397,7 @@ public final org.threeten.bp.Duration getMaxRetryDelay() { */ public abstract java.time.Duration getMaxRetryDelayDuration(); - /** - * Backport of {@link #getInitialRpcTimeoutDuration()} - */ + /** Backport of {@link #getInitialRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getInitialRpcTimeout() { return org.threeten.bp.Duration.ofNanos((getInitialRpcTimeoutDuration().toNanos())); } @@ -378,9 +415,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { */ public abstract double getRpcTimeoutMultiplier(); - /** - * Backport of {@link #getMaxRpcTimeoutDuration()} - */ + /** Backport of {@link #getMaxRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getMaxRpcTimeout() { return org.threeten.bp.Duration.ofNanos((getMaxRpcTimeoutDuration().toNanos())); } @@ -392,7 +427,8 @@ public final org.threeten.bp.Duration getMaxRpcTimeout() { public abstract java.time.Duration getMaxRpcTimeoutDuration(); /** - * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @BetaApi public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index 092b224cbc..b72d284093 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -31,7 +31,6 @@ import com.google.api.core.ApiClock; import com.google.auto.value.AutoValue; -import org.threeten.bp.Duration; /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ @AutoValue @@ -40,9 +39,7 @@ public abstract class TimedAttemptSettings { /** Returns global (attempt-independent) retry settings. */ public abstract RetrySettings getGlobalSettings(); - /** - * Backport of {@link #getRetryDelayDuration()} - */ + /** Backport of {@link #getRetryDelayDuration()} */ public final org.threeten.bp.Duration getRetryDelay() { return org.threeten.bp.Duration.ofNanos(getRetryDelayDuration().toNanos()); } @@ -53,9 +50,7 @@ public final org.threeten.bp.Duration getRetryDelay() { */ public abstract java.time.Duration getRetryDelayDuration(); - /** - * Backport of {@link #getRpcTimeoutDuration()} - */ + /** Backport of {@link #getRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getRpcTimeout() { return org.threeten.bp.Duration.ofNanos(getRpcTimeoutDuration().toNanos()); } @@ -63,9 +58,7 @@ public final org.threeten.bp.Duration getRpcTimeout() { /** Returns rpc timeout used for this attempt. */ public abstract java.time.Duration getRpcTimeoutDuration(); - /** - * Backport of {@link #getRandomizedRetryDelayDuration()} - */ + /** Backport of {@link #getRandomizedRetryDelayDuration()} */ public final org.threeten.bp.Duration getRandomizedRetryDelay() { return org.threeten.bp.Duration.ofNanos(getRandomizedRetryDelayDuration().toNanos()); } @@ -107,40 +100,67 @@ public abstract static class Builder { public abstract Builder setGlobalSettings(RetrySettings value); /** - * Overload of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setRetryDelayDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setRetryDelay(org.threeten.bp.Duration value) { - return setRetryDelay(java.time.Duration.ofNanos(value.toNanos())); + return setRetryDelayDuration(java.time.Duration.ofNanos(value.toNanos())); + } + + /** + * Overload of {@link #setRetryDelayDuration(java.time.Duration)} using {@link + * java.time.Duration} This is a convenience public method to keep name conformity + */ + public final Builder setRetryDelay(java.time.Duration value) { + return setRetryDelayDuration(value); } /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public abstract Builder setRetryDelay(java.time.Duration value); + public abstract Builder setRetryDelayDuration(java.time.Duration value); /** - * Overload of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public final Builder setRpcTimeout(org.threeten.bp.Duration value) { - return setRpcTimeout(java.time.Duration.ofNanos(value.toNanos())); + return setRpcTimeoutDuration(java.time.Duration.ofNanos(value.toNanos())); + } + + /** + * Overload of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link + * java.time.Duration} This is a convenience public method to keep name conformity + */ + public final Builder setRpcTimeout(java.time.Duration value) { + return setRpcTimeoutDuration(value); } /** Sets rpc timeout used for this attempt. */ - public abstract Builder setRpcTimeout(java.time.Duration value); + public abstract Builder setRpcTimeoutDuration(java.time.Duration value); /** - * Overload of {@link #setRandomizedRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} - */ - public final Builder setRandomizedRetryDelay(Duration value) { - return setRandomizedRetryDelay(java.time.Duration.ofNanos(value.toNanos())); + * Overload of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + public final Builder setRandomizedRetryDelay(org.threeten.bp.Duration value) { + return setRandomizedRetryDelayDuration(java.time.Duration.ofNanos(value.toNanos())); + } + + /** + * Overload of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link + * java.time.Duration} This is a convenience public method to keep name conformity + */ + public final Builder setRandomizedRetryDelay(java.time.Duration value) { + return setRandomizedRetryDelayDuration(value); } /** * Sets randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public abstract Builder setRandomizedRetryDelay(java.time.Duration value); + public abstract Builder setRandomizedRetryDelayDuration(java.time.Duration value); /** * Set the attempt count. It is a zero-based value (first attempt will have this value set to diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 35c0090e26..ac2e60a075 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -37,13 +37,12 @@ import com.google.api.gax.tracing.ApiTracer; import com.google.auth.Credentials; import com.google.common.base.Preconditions; -import org.threeten.bp.Duration; - import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.threeten.bp.Duration; /** * Context for an API call. @@ -64,9 +63,7 @@ public interface ApiCallContext extends RetryingContext { /** Returns a new ApiCallContext with the given channel set. */ ApiCallContext withTransportChannel(TransportChannel channel); - /** - * Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} - */ + /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); /** @@ -92,7 +89,8 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getTimeoutDuration(); /** - * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration } + * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration } */ ApiCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout); @@ -107,17 +105,15 @@ public interface ApiCallContext extends RetryingContext { * server or connection stalls. When the timeout has been reached, the stream will be closed with * a retryable {@link WatchdogTimeoutException} and a status of {@link StatusCode.Code#ABORTED}. * - *

A value of {@link java.time.Duration#ZERO}, disables the streaming wait timeout and a null value will - * use the default in the callable. + *

A value of {@link java.time.Duration#ZERO}, disables the streaming wait timeout and a null + * value will use the default in the callable. * *

Please note that this timeout is best effort and the maximum resolution is configured in * {@link StubSettings#getStreamWatchdogCheckInterval()}. */ ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout); - /** - * Backport of {@link #getStreamWaitTimeoutDuration()} - */ + /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Nullable org.threeten.bp.Duration getStreamWaitTimeout(); @@ -130,7 +126,8 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getStreamWaitTimeoutDuration(); /** - * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ ApiCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout); @@ -146,17 +143,15 @@ public interface ApiCallContext extends RetryingContext { * reached, the stream will be closed with a nonretryable {@link WatchdogTimeoutException} and a * status of {@link StatusCode.Code#ABORTED}. * - *

A value of {@link java.time.Duration#ZERO}, disables the streaming idle timeout and a null value will - * use the default in the callable. + *

A value of {@link java.time.Duration#ZERO}, disables the streaming idle timeout and a null + * value will use the default in the callable. * *

Please note that this timeout is best effort and the maximum resolution is configured in * {@link StubSettings#getStreamWatchdogCheckInterval()}. */ ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout); - /** - * Backport of {@link #getStreamIdleTimeoutDuration()} - */ + /** Backport of {@link #getStreamIdleTimeoutDuration()} */ @Nullable org.threeten.bp.Duration getStreamIdleTimeout(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 28a76fe721..3cab37fee2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -63,7 +63,7 @@ public static UnaryCallable retrying( settings = settings .toBuilder() - .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeout()) + .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index b481d0db1e..338db8c806 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -99,6 +99,7 @@ public abstract class ClientContext { /** * Backport of {@link #getStreamWatchdogCheckIntervalDuration()} + * * @return */ @Nonnull @@ -359,9 +360,14 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { - return setStreamWatchdogCheckInterval(java.time.Duration.ofNanos(duration.toNanos())); + return setStreamWatchdogCheckIntervalDuration(java.time.Duration.ofNanos(duration.toNanos())); } - public abstract Builder setStreamWatchdogCheckInterval(java.time.Duration duration); + + public final Builder setStreamWatchdogCheckInterval(java.time.Duration duration) { + return setStreamWatchdogCheckIntervalDuration(duration); + } + + public abstract Builder setStreamWatchdogCheckIntervalDuration(java.time.Duration duration); /** * Set the {@link ApiTracerFactory} that will be used to generate traces for operations. diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 24cde0f7b7..c2d75b8d88 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -107,6 +107,7 @@ public final WatchdogProvider getWatchdogProvider() { /** * Backport of {@link #getWatchdogCheckIntervalDuration()} + * * @return */ @Nonnull diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index 3a981f343c..44a726e27e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -32,8 +32,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.common.base.Preconditions; - -import java.time.Duration; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -80,13 +78,16 @@ public boolean needsCheckInterval() { } /** - * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + * * @param checkInterval * @return */ @Override public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { - return withCheckInterval(java.time.Duration.ofNanos(Preconditions.checkNotNull(checkInterval).toNanos())); + return withCheckInterval( + java.time.Duration.ofNanos(Preconditions.checkNotNull(checkInterval).toNanos())); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 171472ce1a..f04eb49bf6 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -37,8 +37,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import org.threeten.bp.Duration; - import java.util.Set; import javax.annotation.Nonnull; @@ -119,9 +117,7 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } - /** - * Backport of {@link #getIdleTimeoutDuration()} - */ + /** Backport of {@link #getIdleTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getIdleTimeout() { return org.threeten.bp.Duration.ofNanos(getIdleTimeoutDuration().toNanos()); @@ -136,9 +132,7 @@ public java.time.Duration getIdleTimeoutDuration() { return idleTimeout; } - /** - * Backport of {@link #getWaitTimeoutDuration()} - */ + /** Backport of {@link #getWaitTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getWaitTimeout() { return org.threeten.bp.Duration.ofNanos(getWaitTimeoutDuration().toNanos()); @@ -260,14 +254,17 @@ public RetrySettings getRetrySettings() { } /** - * Overload of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ - public Builder setSimpleTimeoutNoRetries(@Nonnull org.threeten.bp.Duration timeout) { + public Builder setSimpleTimeoutNoRetries( + @Nonnull org.threeten.bp.Duration timeout) { return setSimpleTimeoutNoRetries(java.time.Duration.ofNanos(timeout.toNanos())); } /** Disables retries and sets the overall timeout. */ - public Builder setSimpleTimeoutNoRetries(@Nonnull java.time.Duration timeout) { + public Builder setSimpleTimeoutNoRetries( + @Nonnull java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() @@ -300,9 +297,7 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } - /** - * Backport of {@link #getIdleTimeoutDuration()} - */ + /** Backport of {@link #getIdleTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getIdleTimeout() { return org.threeten.bp.Duration.ofNanos(getIdleTimeoutDuration().toNanos()); @@ -316,7 +311,8 @@ public java.time.Duration getIdleTimeoutDuration() { /** * Overlad of {@link #setIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ - public Builder setIdleTimeout(@Nonnull org.threeten.bp.Duration idleTimeout) { + public Builder setIdleTimeout( + @Nonnull org.threeten.bp.Duration idleTimeout) { return setIdleTimeout(java.time.Duration.ofNanos(idleTimeout.toNanos())); } @@ -329,9 +325,7 @@ public Builder setIdleTimeout(@Nonnull java.time.Duration i return this; } - /** - * Backport of {@link #getWaitTimeoutDuration()} - */ + /** Backport of {@link #getWaitTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getWaitTimeout() { return org.threeten.bp.Duration.ofNanos(getWaitTimeoutDuration().toNanos()); @@ -343,9 +337,11 @@ public java.time.Duration getWaitTimeoutDuration() { } /** - * Overload of {@link #setWaitTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setWaitTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ - public Builder setWaitTimeout(@Nonnull org.threeten.bp.Duration waitTimeout) { + public Builder setWaitTimeout( + @Nonnull org.threeten.bp.Duration waitTimeout) { return setWaitTimeout(java.time.Duration.ofNanos(waitTimeout.toNanos())); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index 13b4cff5e9..cda0bd3a19 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -44,8 +44,6 @@ import com.google.auth.oauth2.QuotaProjectIdProvider; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.threeten.bp.Duration; - import java.io.IOException; import java.util.concurrent.Executor; import javax.annotation.Nonnull; @@ -160,9 +158,7 @@ public final WatchdogProvider getStreamWatchdogProvider() { return streamWatchdogProvider; } - /** - * Backport of {@link #getStreamWatchdogCheckIntervalDuration()} - */ + /** Backport of {@link #getStreamWatchdogCheckIntervalDuration()} */ @Nonnull public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); @@ -448,7 +444,8 @@ public B setQuotaProjectId(String quotaProjectId) { } /** - * Overload of {@link #setStreamWatchdogCheckInterval(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #setStreamWatchdogCheckInterval(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { return setStreamWatchdogCheckInterval(java.time.Duration.ofNanos(checkInterval.toNanos())); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 842ee9bdd7..b186b210c8 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -32,7 +32,6 @@ import com.google.api.core.ApiClock; import com.google.api.gax.core.BackgroundResource; import com.google.common.base.Preconditions; - import java.time.Duration; import java.util.Iterator; import java.util.Map.Entry; @@ -84,7 +83,8 @@ public static Watchdog create( return watchdog; } - private Watchdog(ApiClock clock, java.time.Duration scheduleInterval, ScheduledExecutorService executor) { + private Watchdog( + ApiClock clock, java.time.Duration scheduleInterval, ScheduledExecutorService executor) { this.clock = Preconditions.checkNotNull(clock, "clock can't be null"); this.scheduleInterval = scheduleInterval; this.executor = executor; @@ -97,15 +97,17 @@ private void start() { } /** - * Overload of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using + * {@link org.threeten.bp.Duration} */ public ResponseObserver watch( - ResponseObserver innerObserver, - @Nonnull org.threeten.bp.Duration waitTimeout, - @Nonnull org.threeten.bp.Duration idleTimeout) { - return watch(innerObserver, - java.time.Duration.ofNanos(waitTimeout.toNanos()), - java.time.Duration.ofNanos(idleTimeout.toNanos())); + ResponseObserver innerObserver, + @Nonnull org.threeten.bp.Duration waitTimeout, + @Nonnull org.threeten.bp.Duration idleTimeout) { + return watch( + innerObserver, + java.time.Duration.ofNanos(waitTimeout.toNanos()), + java.time.Duration.ofNanos(idleTimeout.toNanos())); } /** Wraps the target observer with timing constraints. */ public ResponseObserver watch( diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index c1942e4fa7..89dc58abef 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -30,7 +30,6 @@ package com.google.api.gax.rpc; import com.google.api.core.ApiClock; - import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; @@ -42,7 +41,8 @@ public interface WatchdogProvider { boolean needsCheckInterval(); /** - * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java index 61a16118e6..c5b5d1a6cc 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java @@ -61,8 +61,10 @@ public void call( RequestT request, ResponseObserver responseObserver, ApiCallContext context) { // If the caller never configured the timeouts, disable them - java.time.Duration waitTimeout = MoreObjects.firstNonNull(context.getStreamWaitTimeoutDuration(), java.time.Duration.ZERO); - java.time.Duration idleTimeout = MoreObjects.firstNonNull(context.getStreamIdleTimeoutDuration(), java.time.Duration.ZERO); + java.time.Duration waitTimeout = + MoreObjects.firstNonNull(context.getStreamWaitTimeoutDuration(), java.time.Duration.ZERO); + java.time.Duration idleTimeout = + MoreObjects.firstNonNull(context.getStreamIdleTimeoutDuration(), java.time.Duration.ZERO); responseObserver = watchdog.watch(responseObserver, waitTimeout, idleTimeout); inner.call(request, responseObserver, context); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPolling.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPolling.java index d392a7393d..778610eee9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPolling.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPolling.java @@ -32,7 +32,6 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import com.google.common.base.Stopwatch; -import java.time.Duration; import java.util.Objects; /** @@ -40,12 +39,12 @@ * timeout is exceeded. Expected usage: * *

{@code
- * assertByPolling(Duration.ofSeconds(2), () -> assertThat(...));
+ * assertByPolling(java.time.Duration.ofSeconds(2), () -> assertThat(...));
  * }
*/ public class AssertByPolling { - public static void assertByPolling(Duration timeout, Runnable assertion) + public static void assertByPolling(java.time.Duration timeout, Runnable assertion) throws InterruptedException { Objects.requireNonNull(timeout, "Timeout must not be null"); Stopwatch stopwatch = Stopwatch.createStarted(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPollingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPollingTest.java index bc1949f871..5033162a35 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPollingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/AssertByPollingTest.java @@ -32,7 +32,6 @@ import static com.google.api.gax.batching.AssertByPolling.assertByPolling; import com.google.common.truth.Truth; -import java.time.Duration; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Assert; @@ -45,7 +44,9 @@ public void testFailsWhenTimeoutExceeded() { AssertionError error = Assert.assertThrows( AssertionError.class, - () -> assertByPolling(Duration.ofNanos(2), () -> Truth.assertThat(1).isAtLeast(2))); + () -> + assertByPolling( + java.time.Duration.ofNanos(2), () -> Truth.assertThat(1).isAtLeast(2))); Throwable cause = error.getCause(); Truth.assertThat(cause).isInstanceOf(AssertionError.class); @@ -63,7 +64,7 @@ public void testImmediateSuccessSucceedsRegardlessOfTimeout() throws Interrupted throw new RuntimeException(ex); } }; - Duration timeout = Duration.ofNanos(0); + java.time.Duration timeout = java.time.Duration.ofNanos(0); assertByPolling(timeout, succeedsAfter1ms); } @@ -79,7 +80,7 @@ public void testSucceedsAfterInitialFailure() throws InterruptedException { } }; - Duration timeout = Duration.ofMillis(300); + java.time.Duration timeout = java.time.Duration.ofMillis(300); assertByPolling(timeout, succeedsSecondTime); Truth.assertThat(numFailures.get()).isEqualTo(1); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index 47454563a1..5f43047126 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -79,7 +79,6 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BatcherImplTest { @@ -93,7 +92,7 @@ public class BatcherImplTest { BatchingSettings.newBuilder() .setElementCountThreshold(1000L) .setRequestByteThreshold(1000L) - .setDelayThreshold(Duration.ofSeconds(1000)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1000)) .build(); @After @@ -372,7 +371,7 @@ public void testWhenThresholdIsDisabled() throws Exception { BatchingSettings.newBuilder() .setElementCountThreshold(null) .setRequestByteThreshold(null) - .setDelayThreshold(null) + .setDelayThresholdDuration(null) .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(2); @@ -384,7 +383,10 @@ public void testWhenThresholdIsDisabled() throws Exception { @Test public void testWhenDelayThresholdExceeds() throws Exception { BatchingSettings settings = - batchingSettings.toBuilder().setDelayThreshold(Duration.ofMillis(100)).build(); + batchingSettings + .toBuilder() + .setDelayThresholdDuration(java.time.Duration.ofMillis(100)) + .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(6); assertThat(result.isDone()).isFalse(); @@ -415,7 +417,10 @@ public ApiFuture> futureCall( } }; BatchingSettings settings = - batchingSettings.toBuilder().setDelayThreshold(Duration.ofMillis(50)).build(); + batchingSettings + .toBuilder() + .setDelayThresholdDuration(java.time.Duration.ofMillis(50)) + .build(); try (final BatcherImpl> batcherTest = new BatcherImpl<>(SQUARER_BATCHING_DESC_V2, callable, labeledIntList, settings, EXECUTOR)) { @@ -459,7 +464,10 @@ public Void call() throws InterruptedException { public void testPushCurrentBatchRunnable() throws Exception { long DELAY_TIME = 50L; BatchingSettings settings = - batchingSettings.toBuilder().setDelayThreshold(Duration.ofMillis(DELAY_TIME)).build(); + batchingSettings + .toBuilder() + .setDelayThresholdDuration(java.time.Duration.ofMillis(DELAY_TIME)) + .build(); BatcherImpl> batcher = createDefaultBatcherImpl(settings, null); @@ -984,7 +992,7 @@ public ApiFuture futureCall(Object o, ApiCallContext apiCallContext) { Object prototype = new Object(); BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(100L) .setRequestByteThreshold(100L) .setFlowControlSettings(FlowControlSettings.getDefaultInstance()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java index 51339dfa15..51e8a1a8be 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java @@ -41,7 +41,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 BatchingCallSettingsTest { @@ -50,7 +49,7 @@ public class BatchingCallSettingsTest { BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(20L) - .setDelayThreshold(Duration.ofMillis(5)) + .setDelayThreshold(java.time.Duration.ofMillis(5)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100L) @@ -91,7 +90,7 @@ public void testBuilderFromSettings() { BatchingCallSettings.Builder> builder = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC_V2); RetrySettings retrySettings = - RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build(); + RetrySettings.newBuilder().setTotalTimeout(java.time.Duration.ofMinutes(1)).build(); builder .setBatchingSettings(BATCHING_SETTINGS) .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/FlowControllerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/FlowControllerTest.java index 534ad3c137..85ce0665d0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/FlowControllerTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/FlowControllerTest.java @@ -42,7 +42,6 @@ import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.common.util.concurrent.SettableFuture; import java.lang.Thread.State; -import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -608,7 +607,8 @@ public void testNumberOfBytesOutOfBoundaryWontDeadlock() throws Exception { t.start(); // wait for thread to start, and check it should be blocked - assertByPolling(Duration.ofMillis(200), () -> assertEquals(State.WAITING, t.getState())); + assertByPolling( + java.time.Duration.ofMillis(200), () -> assertEquals(State.WAITING, t.getState())); // increase and decrease should not be blocked int increase = 5, decrease = 20; @@ -652,7 +652,8 @@ public void testElementCountsOutOfBoundaryWontDeadlock() throws Exception { t.start(); // wait for thread to start, and check it should be blocked - assertByPolling(Duration.ofMillis(200), () -> assertEquals(State.WAITING, t.getState())); + assertByPolling( + java.time.Duration.ofMillis(200), () -> assertEquals(State.WAITING, t.getState())); // increase and decrease should not be blocked int increase = 5, decrease = 20; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 45eaa84b7f..901aab9bf9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -42,7 +42,6 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import org.junit.Assert; import org.junit.Test; -import org.threeten.bp.Duration; public class ThresholdBatcherTest { @@ -134,7 +133,7 @@ private static ThresholdBatcher.Builder createSimpleBatcherBuidler( return ThresholdBatcher.newBuilder() .setThresholds(BatchingThresholds.create(100)) .setExecutor(EXECUTOR) - .setMaxDelay(Duration.ofMillis(10000)) + .setMaxDelay(java.time.Duration.ofMillis(10000)) .setReceiver(receiver) .setFlowController(ThresholdBatcherTest.getDisabledBatchingFlowController()) .setBatchMerger(new SimpleBatchMerger()); @@ -194,7 +193,7 @@ public void testBatchingWithDelay() throws Exception { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); ThresholdBatcher batcher = - createSimpleBatcherBuidler(receiver).setMaxDelay(Duration.ofMillis(100)).build(); + createSimpleBatcherBuidler(receiver).setMaxDelay(java.time.Duration.ofMillis(100)).build(); batcher.add(SimpleBatch.fromInteger(3)); batcher.add(SimpleBatch.fromInteger(5)); @@ -220,7 +219,7 @@ public void testExceptionWithNullFlowController() { ThresholdBatcher.newBuilder() .setThresholds(BatchingThresholds.create(100)) .setExecutor(EXECUTOR) - .setMaxDelay(Duration.ofMillis(10000)) + .setMaxDelay(java.time.Duration.ofMillis(10000)) .setReceiver( new AccumulatingBatchReceiver(ApiFutures.immediateFuture(null))) .setBatchMerger(new SimpleBatchMerger()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java b/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java index 6d8cf9119b..cb29dda299 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java @@ -43,11 +43,10 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.threeten.bp.Duration; public abstract class RecordingScheduler implements ScheduledExecutorService { - public abstract List getSleepDurations(); + public abstract List getSleepDurations(); public abstract int getIterationsCount(); @@ -56,7 +55,7 @@ public static RecordingScheduler create(final FakeApiClock clock) { // mock class fields: final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); - final List sleepDurations = new ArrayList<>(); + final List sleepDurations = new ArrayList<>(); final AtomicInteger iterationsCount = new AtomicInteger(0); // mock class methods: @@ -71,7 +70,8 @@ public ScheduledFuture answer(InvocationOnMock invocation) throws Throwable { Long delay = (Long) args[1]; TimeUnit unit = (TimeUnit) args[2]; iterationsCount.incrementAndGet(); - sleepDurations.add(Duration.ofMillis(TimeUnit.MILLISECONDS.convert(delay, unit))); + sleepDurations.add( + java.time.Duration.ofMillis(TimeUnit.MILLISECONDS.convert(delay, unit))); clock.incrementNanoTime(TimeUnit.NANOSECONDS.convert(delay, unit)); return executor.schedule(runnable, 0, TimeUnit.NANOSECONDS); } @@ -87,7 +87,7 @@ public List answer(InvocationOnMock invocation) throws Throwable { } }); - // List getSleepDurations() + // Listjava.time.Duration> getSleepDurations() when(mock.getSleepDurations()).thenReturn(sleepDurations); // int getIterationsCount() diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java index 2a914ee06f..9f354afb24 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java @@ -67,7 +67,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.threeten.bp.Duration; @RunWith(Parameterized.class) public abstract class AbstractRetryingExecutorTest { @@ -90,7 +89,7 @@ protected abstract RetryingExecutorWithContext getExecutor( protected abstract RetryAlgorithm getAlgorithm( RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException); - protected void busyWaitForInitialResult(RetryingFuture future, Duration timeout) + protected void busyWaitForInitialResult(RetryingFuture future, java.time.Duration timeout) throws TimeoutException { Stopwatch watch = Stopwatch.createStarted(); while (future.peekAttemptResult() == null) { @@ -144,7 +143,7 @@ public void testSuccessWithFailures() throws Exception { assertEquals(5, future.getAttemptSettings().getAttemptCount()); verify(tracer, times(6)).attemptStarted(eq("request"), anyInt()); - verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(Duration.class)); + verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); verify(tracer, times(1)).attemptSucceeded(); verifyNoMoreInteractions(tracer); } @@ -189,7 +188,7 @@ public void testMaxRetriesExceeded() throws Exception { assertEquals(5, future.getAttemptSettings().getAttemptCount()); verify(tracer, times(6)).attemptStarted(eq("request"), anyInt()); - verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(Duration.class)); + verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); verify(tracer, times(1)).attemptFailedRetriesExhausted(any(Throwable.class)); verifyNoMoreInteractions(tracer); } @@ -199,8 +198,8 @@ public void testTotalTimeoutExceeded() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); boolean useContextRetrySettings = retryingContext.getRetrySettings() != null; RetryingExecutorWithContext executor = @@ -233,9 +232,9 @@ public void testCancelOuterFutureBeforeStart() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(1_000L)) - .setMaxRetryDelay(Duration.ofMillis(1_000L)) - .setTotalTimeout(Duration.ofMillis(10_000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_000L)) .build(); RetryingExecutorWithContext executor = getExecutor(getAlgorithm(retrySettings, 0, null)); @@ -267,7 +266,7 @@ public void testCancelByRetryingAlgorithm() throws Exception { verify(tracer, times(5)).attemptStarted(eq("request"), anyInt()); // Pre-apocalypse failures - verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(Duration.class)); + verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); // Apocalypse failure verify(tracer, times(1)).attemptFailedRetriesExhausted(any(CancellationException.class)); verifyNoMoreInteractions(tracer); @@ -287,7 +286,7 @@ public void testUnexpectedExceptionFromRetryAlgorithm() throws Exception { verify(tracer, times(5)).attemptStarted(eq("request"), anyInt()); // Pre-apocalypse failures - verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(Duration.class)); + verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); // Apocalypse failure verify(tracer, times(1)).attemptPermanentFailure(any(RuntimeException.class)); verifyNoMoreInteractions(tracer); @@ -298,8 +297,8 @@ public void testPollExceptionByPollAlgorithm() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); boolean useContextRetrySettings = retryingContext.getRetrySettings() != null; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java index c95cda7ebf..68bb2457fc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java @@ -43,7 +43,6 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BasicRetryingFutureTest { @@ -96,7 +95,8 @@ public void testHandleAttemptDoesNotThrowNPEWhenLogLevelLowerThanFiner() throws future.handleAttempt(null, null); Mockito.verify(tracer) - .attemptFailed(ArgumentMatchers.any(), ArgumentMatchers.any()); + .attemptFailed( + ArgumentMatchers.any(), ArgumentMatchers.any()); Mockito.verifyNoMoreInteractions(tracer); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index d0c1ee3ed9..63cbdebd71 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -39,7 +39,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 ExponentialRetryAlgorithmTest { @@ -47,26 +46,26 @@ public class ExponentialRetryAlgorithmTest { private final RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(Duration.ofMillis(8L)) - .setInitialRpcTimeout(Duration.ofMillis(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) .setRpcTimeoutMultiplier(2.0) - .setMaxRpcTimeout(Duration.ofMillis(8L)) - .setTotalTimeout(Duration.ofMillis(200L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) + .setTotalTimeout(java.time.Duration.ofMillis(200L)) .build(); private final ExponentialRetryAlgorithm algorithm = new ExponentialRetryAlgorithm(retrySettings, clock); private final RetrySettings retrySettingsOverride = RetrySettings.newBuilder() .setMaxAttempts(3) - .setInitialRetryDelay(Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(3.0) - .setMaxRetryDelay(Duration.ofMillis(18L)) - .setInitialRpcTimeout(Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(18L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(3.0) - .setMaxRpcTimeout(Duration.ofMillis(18L)) - .setTotalTimeout(Duration.ofMillis(300L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(18L)) + .setTotalTimeout(java.time.Duration.ofMillis(300L)) .build(); private final RetryingContext retryingContext = FakeCallContext.createDefault().withRetrySettings(retrySettingsOverride); @@ -78,10 +77,10 @@ public void testCreateFirstAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(Duration.ZERO, attempt.getRetryDelay()); - assertEquals(Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(Duration.ofMillis(1L), attempt.getRpcTimeout()); - assertEquals(Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelay()); + assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeout()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); } @Test @@ -91,10 +90,10 @@ public void testCreateFirstAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(Duration.ZERO, attempt.getRetryDelay()); - assertEquals(Duration.ZERO, attempt.getRandomizedRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelay()); assertEquals(retrySettingsOverride.getInitialRpcTimeout(), attempt.getRpcTimeout()); - assertEquals(Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); } @Test @@ -105,13 +104,13 @@ public void testCreateNextAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(Duration.ofMillis(1L), secondAttempt.getRetryDelay()); - assertEquals(Duration.ofMillis(2L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelay()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeout()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(Duration.ofMillis(2L), thirdAttempt.getRetryDelay()); - assertEquals(Duration.ofMillis(4L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelay()); + assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeout()); } @Test @@ -122,13 +121,13 @@ public void testCreateNextAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(Duration.ofMillis(2L), secondAttempt.getRetryDelay()); - assertEquals(Duration.ofMillis(6L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelay()); + assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeout()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(Duration.ofMillis(6L), thirdAttempt.getRetryDelay()); - assertEquals(Duration.ofMillis(18L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelay()); + assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeout()); } @Test @@ -136,19 +135,19 @@ public void testTruncateToTotalTimeout() { RetrySettings timeoutSettings = retrySettings .toBuilder() - .setInitialRpcTimeout(Duration.ofSeconds(4L)) - .setMaxRpcTimeout(Duration.ofSeconds(4L)) - .setTotalTimeout(Duration.ofSeconds(4L)) + .setInitialRpcTimeout(java.time.Duration.ofSeconds(4L)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(4L)) + .setTotalTimeout(java.time.Duration.ofSeconds(4L)) .build(); ExponentialRetryAlgorithm timeoutAlg = new ExponentialRetryAlgorithm(timeoutSettings, clock); TimedAttemptSettings firstAttempt = timeoutAlg.createFirstAttempt(); TimedAttemptSettings secondAttempt = timeoutAlg.createNextAttempt(firstAttempt); assertThat(secondAttempt.getRpcTimeout()).isAtLeast(firstAttempt.getRpcTimeout()); - assertThat(secondAttempt.getRpcTimeout()).isAtMost(Duration.ofSeconds(4L)); + assertThat(secondAttempt.getRpcTimeoutDuration()).isAtMost(java.time.Duration.ofSeconds(4L)); TimedAttemptSettings thirdAttempt = timeoutAlg.createNextAttempt(secondAttempt); - assertThat(thirdAttempt.getRpcTimeout()).isAtMost(Duration.ofSeconds(4L)); + assertThat(thirdAttempt.getRpcTimeoutDuration()).isAtMost(java.time.Duration.ofSeconds(4L)); } @Test @@ -186,11 +185,11 @@ public void testShouldRetryFalseOnMaxTimeout() { // Simulate each attempt with 60ms of clock time. // "attempt" = RPC Timeout + createNextAttempt() and shouldRetry() TimedAttemptSettings attempt = algorithm.createFirstAttempt(); - clock.incrementNanoTime(Duration.ofMillis(60L).toNanos()); + clock.incrementNanoTime(java.time.Duration.ofMillis(60L).toNanos()); for (int i = 0; i < 3; i++) { assertTrue(algorithm.shouldRetry(attempt)); attempt = algorithm.createNextAttempt(attempt); - clock.incrementNanoTime(Duration.ofMillis(60L).toNanos()); + clock.incrementNanoTime(java.time.Duration.ofMillis(60L).toNanos()); } assertFalse(algorithm.shouldRetry(attempt)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java index 5360312bbc..de5804c6cc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java @@ -34,30 +34,29 @@ import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; -import org.threeten.bp.Duration; class FailingCallable implements Callable { static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(Duration.ofMillis(8L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(8L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(8L)) - .setInitialRpcTimeout(Duration.ofMillis(8L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(8L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(8L)) - .setTotalTimeout(Duration.ofMillis(400L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) + .setTotalTimeout(java.time.Duration.ofMillis(400L)) .build(); static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(Duration.ofNanos(1L)) + .setInitialRetryDelay(java.time.Duration.ofNanos(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofNanos(1L)) - .setInitialRpcTimeout(Duration.ofNanos(1L)) + .setMaxRetryDelay(java.time.Duration.ofNanos(1L)) + .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofNanos(1L)) - .setTotalTimeout(Duration.ofNanos(1L)) + .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) + .setTotalTimeout(java.time.Duration.ofNanos(1L)) .build(); private AtomicInteger attemptsCount = new AtomicInteger(0); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index 8bcdea4cc8..5901e9bfb1 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -31,13 +31,12 @@ import com.google.common.truth.Truth; import org.junit.Test; -import org.threeten.bp.Duration; public class RetrySettingsTest { @Test public void retrySettingsSetLogicalTimeout() { - Duration timeout = Duration.ofMillis(60000); + java.time.Duration timeout = java.time.Duration.ofMillis(60000); RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); @@ -50,13 +49,13 @@ public void retrySettingsSetLogicalTimeout() { public void retrySettingsMerge() { RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofMillis(45000)) - .setInitialRpcTimeout(Duration.ofMillis(2000)) + .setTotalTimeout(java.time.Duration.ofMillis(45000)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2000)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(Duration.ofMillis(30000)) - .setInitialRetryDelay(Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(30000)) + .setInitialRetryDelay(java.time.Duration.ofMillis(100)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(Duration.ofMillis(1000)); + .setMaxRetryDelay(java.time.Duration.ofMillis(1000)); RetrySettings.Builder mergedBuilder = RetrySettings.newBuilder(); mergedBuilder.merge(builder); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java index cd3079ec33..e86f794f22 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java @@ -50,7 +50,6 @@ import org.junit.After; import org.junit.Test; import org.mockito.Mockito; -import org.threeten.bp.Duration; // @RunWith(MockitoJUnitRunner.class) public class ScheduledRetryingExecutorTest extends AbstractRetryingExecutorTest { @@ -93,7 +92,7 @@ public void testSuccessWithFailuresPeekAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -144,7 +143,7 @@ public void testSuccessWithFailuresGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -198,7 +197,7 @@ public void testCancelGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -256,9 +255,9 @@ public void testCancelOuterFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(1_000L)) - .setMaxRetryDelay(Duration.ofMillis(1_000L)) - .setTotalTimeout(Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); @@ -284,9 +283,9 @@ public void testCancelIsTraced() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(1_000L)) - .setMaxRetryDelay(Duration.ofMillis(1_000L)) - .setTotalTimeout(Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); @@ -314,9 +313,9 @@ public void testCancelProxiedFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(1_000L)) - .setMaxRetryDelay(Duration.ofMillis(1_000L)) - .setTotalTimeout(Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 3b16b568d0..044484d9dd 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -45,7 +45,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; -import org.threeten.bp.Duration; @RunWith(MockitoJUnitRunner.class) public class AttemptCallableTest { @@ -66,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(Duration.ofSeconds(1)) - .setRandomizedRetryDelay(Duration.ofSeconds(1)) - .setRpcTimeout(Duration.ZERO) + .setRetryDelay(java.time.Duration.ofSeconds(1)) + .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) + .setRpcTimeout(java.time.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) @@ -88,7 +87,7 @@ public void testRpcTimeout() { callable.setExternalFuture(mockExternalFuture); // Make sure that the rpc timeout is set - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); callable.call(); @@ -96,7 +95,7 @@ public void testRpcTimeout() { assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out - Duration longerTimeout = Duration.ofSeconds(20); + java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); @@ -105,10 +104,10 @@ public void testRpcTimeout() { @Test public void testRpcTimeoutIsNotErased() { - Duration callerTimeout = Duration.ofMillis(10); + java.time.Duration callerTimeout = java.time.Duration.ofMillis(10); ApiCallContext callerCallContext = FakeCallContext.createDefault().withTimeout(callerTimeout); - Duration timeout = Duration.ofMillis(5); + java.time.Duration timeout = java.time.Duration.ofMillis(5); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); AttemptCallable callable = diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java index 254ba2831c..3ea1ecf3ca 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java @@ -47,7 +47,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 BatcherFactoryTest { @@ -67,7 +66,7 @@ public void tearDown() { public void testGetPushingBatcher() { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java index baafb1044e..47d39731fe 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java @@ -40,7 +40,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BatchingCallSettingsTest { @@ -85,11 +84,11 @@ public void testBuilder() { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -129,11 +128,11 @@ public void testBuilderFromSettings() throws Exception { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java index a0234a441a..8ac84bade4 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java @@ -47,7 +47,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 BatchingCallableTest { @@ -68,7 +67,7 @@ public void testBatchedCall() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(10)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(10)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java index 2b4a075963..30c992b8c0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java @@ -54,7 +54,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 BatchingTest { @@ -82,7 +81,7 @@ public void teardown() { public void batching() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -102,7 +101,7 @@ public void batching() throws Exception { public void batchingWithFlowControl() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(4L) .setRequestByteThreshold(null) .setFlowControlSettings( @@ -180,7 +179,7 @@ public void batchingDisabled() throws Exception { public void batchingWithBlockingCallThreshold() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -209,7 +208,7 @@ public ApiFuture> futureCall(LabeledIntList request, ApiCallContex public void batchingException() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 04e025fecb..5b1d61220e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -45,7 +45,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; -import org.threeten.bp.Duration; public class CallableTest { @@ -59,9 +58,9 @@ public class CallableTest { private RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(Duration.ofMillis(5L)) - .setMaxRpcTimeout(Duration.ofMillis(5L)) - .setTotalTimeout(Duration.ofMillis(10L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(5L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(5L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); @Spy private ApiCallContext callContext = FakeCallContext.createDefault(); @@ -77,7 +76,7 @@ public class CallableTest { public void testNonRetriedCallable() throws Exception { innerResult = SettableApiFuture.create(); when(innerCallable.futureCall(anyString(), any(ApiCallContext.class))).thenReturn(innerResult); - Duration timeout = Duration.ofMillis(5L); + java.time.Duration timeout = java.time.Duration.ofMillis(5L); UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(timeout).build(); @@ -98,13 +97,13 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) .build(); UnaryCallable callable = Callables.retrying(innerCallable, callSettings, clientContext); innerResult.set("No, my refrigerator is not running!"); - Duration timeout = retrySettings.getInitialRpcTimeout(); + java.time.Duration timeout = retrySettings.getInitialRpcTimeoutDuration(); callable.futureCall("Is your refrigerator running?", callContextWithRetrySettings); @@ -115,7 +114,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { @Test public void testNonRetriedServerStreamingCallable() throws Exception { - Duration timeout = Duration.ofMillis(5L); + java.time.Duration timeout = java.time.Duration.ofMillis(5L); ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder().setSimpleTimeoutNoRetries(timeout).build(); ServerStreamingCallable callable = @@ -132,12 +131,12 @@ public void testNonRetriedServerStreamingCallable() throws Exception { public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exception { ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder() - .setSimpleTimeoutNoRetries(Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) .build(); ServerStreamingCallable callable = Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); - Duration timeout = retrySettings.getInitialRpcTimeout(); + java.time.Duration timeout = retrySettings.getInitialRpcTimeoutDuration(); callable.call("Is your refrigerator running?", callContextWithRetrySettings); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java index bb36d863cd..7914ab876d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java @@ -53,7 +53,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class CancellationTest { @@ -63,24 +62,24 @@ public class CancellationTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(2L)) - .setInitialRpcTimeout(Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(2L)) - .setTotalTimeout(Duration.ofMillis(20L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(20L)) .build(); private static final RetrySettings SLOW_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(3000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(3000L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(3000L)) - .setInitialRpcTimeout(Duration.ofMillis(3000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(3000L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(3000L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(3000L)) - .setTotalTimeout(Duration.ofMillis(3000L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(3000L)) + .setTotalTimeout(java.time.Duration.ofMillis(3000L)) .build(); private FakeApiClock fakeClock; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index 92554616bc..f763b891c5 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -45,7 +45,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; -import org.threeten.bp.Duration; @RunWith(MockitoJUnitRunner.class) public class CheckingAttemptCallableTest { @@ -66,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(Duration.ofSeconds(1)) - .setRandomizedRetryDelay(Duration.ofSeconds(1)) - .setRpcTimeout(Duration.ZERO) + .setRetryDelay(java.time.Duration.ofSeconds(1)) + .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) + .setRpcTimeout(java.time.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) @@ -88,7 +87,7 @@ public void testRpcTimeout() { callable.setExternalFuture(mockExternalFuture); // Make sure that the rpc timeout is set - Duration timeout = Duration.ofSeconds(10); + java.time.Duration timeout = java.time.Duration.ofSeconds(10); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); callable.call(); @@ -96,7 +95,7 @@ public void testRpcTimeout() { assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out - Duration longerTimeout = Duration.ofSeconds(20); + java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index ebe7a66712..124726b1bc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -72,7 +72,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class ClientContextTest { @@ -258,9 +257,9 @@ private void runTest( Watchdog watchdog = Watchdog.create( Mockito.mock(ApiClock.class), - Duration.ZERO, + java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); - Duration watchdogCheckInterval = Duration.ofSeconds(11); + java.time.Duration watchdogCheckInterval = java.time.Duration.ofSeconds(11); builder.setExecutorProvider(executorProvider); builder.setTransportChannelProvider(transportProvider); @@ -335,7 +334,7 @@ public void testWatchdogProvider() throws IOException { builder.setExecutorProvider(new FakeExecutorProvider(executor, true)); builder.setTransportChannelProvider(transportProvider); - Duration watchdogCheckInterval = Duration.ofSeconds(11); + java.time.Duration watchdogCheckInterval = java.time.Duration.ofSeconds(11); builder.setWatchdogProvider( InstantiatingWatchdogProvider.create() .withClock(clock) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java index b39d59cbd5..1b287ef05b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java @@ -58,7 +58,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class ClientSettingsTest { @@ -119,7 +118,8 @@ public void testEmptyBuilder() throws Exception { Truth.assertThat(builder.getInternalHeaderProvider()).isInstanceOf(NoHeaderProvider.class); Truth.assertThat(builder.getWatchdogProvider()) .isInstanceOf(InstantiatingWatchdogProvider.class); - Truth.assertThat(builder.getWatchdogCheckInterval()).isGreaterThan(Duration.ZERO); + Truth.assertThat(builder.getWatchdogCheckIntervalDuration()) + .isGreaterThan(java.time.Duration.ZERO); Truth.assertThat(builder.getQuotaProjectId()).isNull(); FakeClientSettings settings = builder.build(); @@ -137,7 +137,8 @@ public void testEmptyBuilder() throws Exception { .isSameInstanceAs(builder.getInternalHeaderProvider()); Truth.assertThat(settings.getWatchdogProvider()) .isInstanceOf(InstantiatingWatchdogProvider.class); - Truth.assertThat(settings.getWatchdogCheckInterval()).isGreaterThan(Duration.ZERO); + Truth.assertThat(settings.getWatchdogCheckIntervalDuration()) + .isGreaterThan(java.time.Duration.ZERO); Truth.assertThat((settings.getQuotaProjectId())).isSameInstanceAs(builder.getQuotaProjectId()); String settingsString = settings.toString(); @@ -163,7 +164,7 @@ public void testBuilder() throws Exception { HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class); WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class); - Duration watchdogCheckInterval = Duration.ofSeconds(13); + java.time.Duration watchdogCheckInterval = java.time.Duration.ofSeconds(13); String quotaProjectId = "test_quota_project_id"; builder.setExecutorProvider(executorProvider); @@ -210,9 +211,9 @@ public void testBuilderFromClientContext() throws Exception { Watchdog watchdog = Watchdog.create( Mockito.mock(ApiClock.class), - Duration.ZERO, + java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); - Duration watchdogCheckInterval = Duration.ofSeconds(12); + java.time.Duration watchdogCheckInterval = java.time.Duration.ofSeconds(12); ClientContext clientContext = ClientContext.newBuilder() @@ -257,7 +258,7 @@ public void testBuilderFromSettings() throws Exception { HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class); WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class); - Duration watchdogCheckInterval = Duration.ofSeconds(14); + java.time.Duration watchdogCheckInterval = java.time.Duration.ofSeconds(14); String quotaProjectId = "test_builder_from_settings_quotaProjectId"; builder.setExecutorProvider(executorProvider); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index 9fb9659371..88206d9f28 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -37,7 +37,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class FixedWatchdogProviderTest { @@ -52,7 +51,7 @@ public void testSameInstance() { Watchdog watchdog = Watchdog.create( Mockito.mock(ApiClock.class), - Duration.ZERO, + java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); WatchdogProvider provider = FixedWatchdogProvider.create(watchdog); @@ -64,7 +63,7 @@ public void testNoModifications() { Watchdog watchdog = Watchdog.create( Mockito.mock(ApiClock.class), - Duration.ZERO, + java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); WatchdogProvider provider = FixedWatchdogProvider.create(watchdog); @@ -75,7 +74,7 @@ public void testNoModifications() { Throwable actualError = null; try { - provider.withCheckInterval(Duration.ofSeconds(10)); + provider.withCheckInterval(java.time.Duration.ofSeconds(10)); } catch (Throwable t) { actualError = t; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java index 0607dc7179..e0464b3d0e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java @@ -39,13 +39,12 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.threeten.bp.Duration; @RunWith(MockitoJUnitRunner.class) public class InstantiatingWatchdogProviderTest { @Mock private ScheduledExecutorService executor; @Mock private ApiClock clock; - private Duration checkInterval = Duration.ofSeconds(11); + private java.time.Duration checkInterval = java.time.Duration.ofSeconds(11); @Test public void happyPath() { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 5779f72f71..f307d0c4b8 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -73,36 +73,37 @@ import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class OperationCallableImplTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(2L)) - .setInitialRpcTimeout(Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(2L)) - .setTotalTimeout(Duration.ofMillis(10L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAST_RECHECKING_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) .setInitialRpcTimeout( - Duration.ZERO) // supposed to be ignored, but are not actually, so we set to zero + java.time.Duration + .ZERO) // supposed to be ignored, but are not actually, so we set to zero .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier( 1) // supposed to be ignored, but are not actually, so we set to one .setMaxRpcTimeout( - Duration.ZERO) // supposed to be ignored, but are not actually, so we set to zero - .setTotalTimeout(Duration.ofMillis(5L)) + java.time.Duration + .ZERO) // supposed to be ignored, but are not actually, so we set to zero + .setTotalTimeout(java.time.Duration.ofMillis(5L)) .build(); private FakeChannel initialChannel; @@ -484,10 +485,10 @@ public void testFutureCallPollRPCTimeout() throws Exception { // for LRO polling. They are not actually ignored in code, so they changing them // here has an actual affect. This test verifies that they work as such, but in // practice generated clients set the RPC timeouts to 0 to be ignored. - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofSeconds(1)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(2) - .setTotalTimeout(Duration.ofSeconds(5L)) + .setTotalTimeout(java.time.Duration.ofSeconds(5L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -521,14 +522,17 @@ public void testFutureCallPollRPCTimeout() throws Exception { callable.futureCall(2, FakeCallContext.createDefault()).get(10, TimeUnit.SECONDS); - List actualTimeouts = Lists.newArrayList(); + List actualTimeouts = Lists.newArrayList(); for (ApiCallContext callContext : callContextCaptor.getAllValues()) { - actualTimeouts.add(callContext.getTimeout()); + actualTimeouts.add(callContext.getTimeoutDuration()); } - List expectedTimeouts = - Lists.newArrayList(Duration.ofMillis(100), Duration.ofMillis(200), Duration.ofMillis(400)); + List expectedTimeouts = + Lists.newArrayList( + java.time.Duration.ofMillis(100), + java.time.Duration.ofMillis(200), + java.time.Duration.ofMillis(400)); assertThat(actualTimeouts).isEqualTo(expectedTimeouts); } @@ -558,11 +562,13 @@ public void testFutureCallContextPropagation() throws Exception { FakeCallableFactory.createOperationCallable( initialCallable, callSettings, initialContext, longRunningClient); - ApiCallContext callContext = FakeCallContext.createDefault().withTimeout(Duration.ofMillis(10)); + ApiCallContext callContext = + FakeCallContext.createDefault().withTimeout(java.time.Duration.ofMillis(10)); callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); - assertThat(callContextCaptor.getValue().getTimeout()).isEqualTo(Duration.ofMillis(10)); + assertThat(callContextCaptor.getValue().getTimeout()) + .isEqualTo(java.time.Duration.ofMillis(10)); } @Test @@ -587,7 +593,7 @@ public void testFutureCallPollDoneOnMany() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(Duration.ofMillis(iterationsCount)) + .setTotalTimeout(java.time.Duration.ofMillis(iterationsCount)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -695,7 +701,10 @@ public void testFutureCallPollCancelOnLongTimeoutExceeded() throws Exception { pollingAlgorithm = OperationTimedPollAlgorithm.create( - FAST_RECHECKING_SETTINGS.toBuilder().setTotalTimeout(Duration.ofMillis(1000L)).build(), + FAST_RECHECKING_SETTINGS + .toBuilder() + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -1165,8 +1174,8 @@ private UnaryCallable mockGetOpSnapshotC public ApiFuture futureCall(RequestT request, ApiCallContext context) { FakeCallContext fakeCallContext = (FakeCallContext) context; if (fakeCallContext != null - && fakeCallContext.getTimeout() != null - && fakeCallContext.getTimeout().isZero()) { + && fakeCallContext.getTimeoutDuration() != null + && fakeCallContext.getTimeoutDuration().isZero()) { throw new DeadlineExceededException( "Invalid timeout of 0 s", null, diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java index 25c6b8064f..687b2895cb 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java @@ -38,7 +38,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class PagedCallSettingsTest { @@ -75,11 +74,11 @@ public void testBuilder() { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -108,11 +107,11 @@ public void testBuilderFromSettings() throws Exception { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java index b58bd2c2c4..da6639cb54 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java @@ -55,7 +55,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class RetryingTest { @@ -69,24 +68,24 @@ public class RetryingTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(2L)) - .setInitialRpcTimeout(Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofMillis(2L)) - .setTotalTimeout(Duration.ofMillis(10L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(Duration.ofNanos(0L)) + .setInitialRetryDelay(java.time.Duration.ofNanos(0L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(Duration.ofMillis(0L)) - .setInitialRpcTimeout(Duration.ofNanos(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(0L)) + .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofNanos(1L)) - .setTotalTimeout(Duration.ofNanos(1L)) + .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) + .setTotalTimeout(java.time.Duration.ofNanos(1L)) .build(); @Before @@ -152,8 +151,8 @@ public void retryTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); assertRetrying(retrySettings); @@ -170,8 +169,8 @@ public void retryUsingContextTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); try { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index acc70467bf..70128775f7 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -53,7 +53,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class ServerStreamingAttemptCallableTest { @@ -61,8 +60,8 @@ public class ServerStreamingAttemptCallableTest { private AccumulatingObserver observer; private FakeRetryingFuture fakeRetryingFuture; private StreamResumptionStrategy resumptionStrategy; - private static Duration totalTimeout = Duration.ofHours(1); - private static final Duration attemptTimeout = Duration.ofMinutes(1); + private static java.time.Duration totalTimeout = java.time.Duration.ofHours(1); + private static final java.time.Duration attemptTimeout = java.time.Duration.ofMinutes(1); private FakeCallContext mockedCallContext; @Before @@ -92,17 +91,19 @@ private ServerStreamingAttemptCallable createCallable(ApiCallCon public void testUserProvidedContextTimeout() { // Mock up the ApiCallContext as if the user provided a timeout and streamWaitTimeout. Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer(); - Mockito.doReturn(Duration.ofHours(5)).when(mockedCallContext).getTimeout(); - Mockito.doReturn(Duration.ofHours(5)).when(mockedCallContext).getStreamWaitTimeout(); + Mockito.doReturn(java.time.Duration.ofHours(5)).when(mockedCallContext).getTimeoutDuration(); + Mockito.doReturn(java.time.Duration.ofHours(5)) + .when(mockedCallContext) + .getStreamWaitTimeoutDuration(); ServerStreamingAttemptCallable callable = createCallable(mockedCallContext); callable.start(); // Ensure that the callable did not overwrite the user provided timeouts - Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeout(); + Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeoutDuration(); Mockito.verify(mockedCallContext, Mockito.never()).withTimeout(totalTimeout); Mockito.verify(mockedCallContext, Mockito.never()) - .withStreamWaitTimeout(Mockito.any(Duration.class)); + .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); // Should notify outer observer Truth.assertThat(observer.controller).isNotNull(); @@ -126,19 +127,19 @@ public void testUserProvidedContextTimeout() { public void testNoUserProvidedContextTimeout() { // Mock up the ApiCallContext as if the user did not provide custom timeouts. Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer(); - Mockito.doReturn(null).when(mockedCallContext).getTimeout(); - Mockito.doReturn(null).when(mockedCallContext).getStreamWaitTimeout(); + Mockito.doReturn(null).when(mockedCallContext).getTimeoutDuration(); + Mockito.doReturn(null).when(mockedCallContext).getStreamWaitTimeoutDuration(); Mockito.doReturn(mockedCallContext).when(mockedCallContext).withTimeout(attemptTimeout); Mockito.doReturn(mockedCallContext) .when(mockedCallContext) - .withStreamWaitTimeout(Mockito.any(Duration.class)); + .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); ServerStreamingAttemptCallable callable = createCallable(mockedCallContext); callable.start(); // Ensure that the callable configured the timeouts via the Settings in the // absence of user-defined timeouts. - Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeout(); + Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeoutDuration(); Mockito.verify(mockedCallContext, Mockito.times(1)).withTimeout(attemptTimeout); // Should notify outer observer @@ -477,9 +478,9 @@ private static class FakeRetryingFuture extends AbstractApiFuture .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) - .setRandomizedRetryDelay(Duration.ofMillis(1)) - .setRetryDelay(Duration.ofMillis(1)) - .setRpcTimeout(Duration.ofMinutes(1)) + .setRandomizedRetryDelay(java.time.Duration.ofMillis(1)) + .setRetryDelay(java.time.Duration.ofMillis(1)) + .setRpcTimeout(java.time.Duration.ofMinutes(1)) .build(); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java index bcd5a9272e..4d2fd595fd 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java @@ -38,7 +38,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 ServerStreamingCallSettingsTest { @@ -66,11 +65,11 @@ public void retryableCodesVarArgs() { public void retryableSettingsAreNotLost() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -87,7 +86,7 @@ public void retryableSettingsAreNotLost() { @Test public void idleTimeoutIsNotLost() { - Duration idleTimeout = Duration.ofSeconds(5); + java.time.Duration idleTimeout = java.time.Duration.ofSeconds(5); ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); @@ -100,7 +99,7 @@ public void idleTimeoutIsNotLost() { @Test public void waitTimeoutIsNotLost() { - Duration waitTimeout = Duration.ofSeconds(5); + java.time.Duration waitTimeout = java.time.Duration.ofSeconds(5); ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); @@ -116,11 +115,11 @@ public void waitTimeoutIsNotLost() { public void testRetrySettingsBuilder() { RetrySettings initialSettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -129,18 +128,19 @@ public void testRetrySettingsBuilder() { ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder().setRetrySettings(initialSettings); - builder.retrySettings().setMaxRetryDelay(Duration.ofMinutes(1)); + builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); - assertThat(builder.getRetrySettings().getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1)); + assertThat(builder.getRetrySettings().getMaxRetryDelay()) + .isEqualTo(java.time.Duration.ofMinutes(1)); assertThat(builder.build().getRetrySettings().getMaxRetryDelay()) - .isEqualTo(Duration.ofMinutes(1)); + .isEqualTo(java.time.Duration.ofMinutes(1)); } @Test public void testToString() { RetrySettings retrySettings = RetrySettings.newBuilder().build(); Set retryableCodes = ImmutableSet.of(StatusCode.Code.DEADLINE_EXCEEDED); - Duration idleTime = Duration.ofSeconds(100); + java.time.Duration idleTime = java.time.Duration.ofSeconds(100); ServerStreamingCallSettings serverCallSettings = ServerStreamingCallSettings.newBuilder() .setRetrySettings(retrySettings) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java index 7400007231..34cabb8994 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java @@ -46,32 +46,31 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class StreamingRetryAlgorithmTest { private static final RetrySettings DEFAULT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(10L)) - .setInitialRpcTimeout(Duration.ofMillis(100L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(10L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100L)) .setMaxAttempts(10) - .setMaxRetryDelay(Duration.ofSeconds(10L)) - .setMaxRpcTimeout(Duration.ofSeconds(30L)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(10L)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(30L)) .setRetryDelayMultiplier(1.4) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeout(Duration.ofMinutes(10L)) + .setTotalTimeout(java.time.Duration.ofMinutes(10L)) .build(); private static final RetrySettings CONTEXT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(20L)) - .setInitialRpcTimeout(Duration.ofMillis(200L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(20L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(200L)) .setMaxAttempts(10) - .setMaxRetryDelay(Duration.ofSeconds(20L)) - .setMaxRpcTimeout(Duration.ofSeconds(60L)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(20L)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(60L)) .setRetryDelayMultiplier(2.4) .setRpcTimeoutMultiplier(2.5) - .setTotalTimeout(Duration.ofMinutes(20L)) + .setTotalTimeout(java.time.Duration.ofMinutes(20L)) .build(); @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index 6838d57252..59267d912e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -39,7 +39,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 UnaryCallSettingsTest { @@ -47,17 +46,18 @@ public class UnaryCallSettingsTest { @Test public void testSetSimpleTimeoutNoRetries() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); assertThat(builder.getRetryableCodes().size()).isEqualTo(0); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); - assertThat(builder.getRetrySettings().getTotalTimeout()).isEqualTo(Duration.ofSeconds(13)); + assertThat(builder.getRetrySettings().getTotalTimeout()) + .isEqualTo(java.time.Duration.ofSeconds(13)); } @Test public void testEquals() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); UnaryCallSettings settings13 = builder.build(); assertEquals(settings13, settings13); @@ -66,7 +66,7 @@ public void testEquals() { assertEquals(settings13.hashCode(), settings13.hashCode()); UnaryCallSettings.Builder builder5 = new UnaryCallSettings.Builder(); - builder5.setSimpleTimeoutNoRetries(Duration.ofSeconds(5)); + builder5.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(5)); UnaryCallSettings settings5 = builder5.build(); assertNotEquals(settings13, settings5); @@ -77,11 +77,11 @@ public void testEquals() { public void testEquals_retrySettings() { RetrySettings initialSettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -114,11 +114,11 @@ public void testEquals_retryableCodes() { public void testRetrySettingsBuilder() { RetrySettings initialSettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(5)) - .setMaxRetryDelay(Duration.ofSeconds(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(5)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(Duration.ofMillis(100)) - .setMaxRpcTimeout(Duration.ofMillis(200)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -127,11 +127,12 @@ public void testRetrySettingsBuilder() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder().setRetrySettings(initialSettings); - builder.retrySettings().setMaxRetryDelay(Duration.ofMinutes(1)); + builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); - assertThat(builder.getRetrySettings().getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1)); + assertThat(builder.getRetrySettings().getMaxRetryDelay()) + .isEqualTo(java.time.Duration.ofMinutes(1)); assertThat(builder.build().getRetrySettings().getMaxRetryDelay()) - .isEqualTo(Duration.ofMinutes(1)); + .isEqualTo(java.time.Duration.ofMinutes(1)); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java index e20218452c..bc6d2436d4 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java @@ -50,16 +50,15 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class WatchdogTest { private static final ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(1); private FakeApiClock clock; - private final Duration checkInterval = Duration.ofMillis(1000); - private Duration waitTime = Duration.ofSeconds(10); - private Duration idleTime = Duration.ofMinutes(5); + private final java.time.Duration checkInterval = java.time.Duration.ofMillis(1000); + private java.time.Duration waitTime = java.time.Duration.ofSeconds(10); + private java.time.Duration idleTime = java.time.Duration.ofMinutes(5); private Watchdog watchdog; private MockServerStreamingCallable callable; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java index 84d40e11cc..bab447d4b9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java @@ -48,15 +48,14 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; @InternalApi("for testing") public class FakeCallContext implements ApiCallContext { private final Credentials credentials; private final FakeChannel channel; - private final Duration timeout; - private final Duration streamWaitTimeout; - private final Duration streamIdleTimeout; + private final java.time.Duration timeout; + private final java.time.Duration streamWaitTimeout; + private final java.time.Duration streamIdleTimeout; private final ImmutableMap> extraHeaders; private final ApiCallContextOptions options; private final ApiTracer tracer; @@ -66,9 +65,9 @@ public class FakeCallContext implements ApiCallContext { private FakeCallContext( Credentials credentials, FakeChannel channel, - Duration timeout, - Duration streamWaitTimeout, - Duration streamIdleTimeout, + java.time.Duration timeout, + java.time.Duration streamWaitTimeout, + java.time.Duration streamIdleTimeout, ImmutableMap> extraHeaders, ApiCallContextOptions options, ApiTracer tracer, @@ -138,17 +137,17 @@ public ApiCallContext merge(ApiCallContext inputCallContext) { newCallCredentials = credentials; } - Duration newTimeout = fakeCallContext.timeout; + java.time.Duration newTimeout = fakeCallContext.timeout; if (newTimeout == null) { newTimeout = timeout; } - Duration newStreamWaitTimeout = fakeCallContext.streamWaitTimeout; + java.time.Duration newStreamWaitTimeout = fakeCallContext.streamWaitTimeout; if (newStreamWaitTimeout == null) { newStreamWaitTimeout = streamWaitTimeout; } - Duration newStreamIdleTimeout = fakeCallContext.streamIdleTimeout; + java.time.Duration newStreamIdleTimeout = fakeCallContext.streamIdleTimeout; if (newStreamIdleTimeout == null) { newStreamIdleTimeout = streamIdleTimeout; } @@ -231,19 +230,31 @@ public FakeChannel getChannel() { } @Override - public Duration getTimeout() { + public java.time.Duration getTimeoutDuration() { return timeout; } + @Override + public ApiCallContext withStreamWaitTimeout( + @Nullable org.threeten.bp.Duration streamWaitTimeout) { + return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); + } + @Nullable @Override - public Duration getStreamWaitTimeout() { + public java.time.Duration getStreamWaitTimeoutDuration() { return streamWaitTimeout; } + @Override + public ApiCallContext withStreamIdleTimeout( + @Nullable org.threeten.bp.Duration streamIdleTimeout) { + return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); + } + @Nullable @Override - public Duration getStreamIdleTimeout() { + public java.time.Duration getStreamIdleTimeoutDuration() { return streamIdleTimeout; } @@ -273,6 +284,11 @@ public FakeCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } + @Override + public FakeCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { + return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + } + public FakeCallContext withChannel(FakeChannel channel) { return new FakeCallContext( this.credentials, @@ -288,7 +304,7 @@ public FakeCallContext withChannel(FakeChannel channel) { } @Override - public FakeCallContext withTimeout(Duration timeout) { + public FakeCallContext withTimeout(java.time.Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; @@ -312,8 +328,14 @@ public FakeCallContext withTimeout(Duration timeout) { this.retryableCodes); } + @Nullable @Override - public ApiCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout) { + public org.threeten.bp.Duration getTimeout() { + return org.threeten.bp.Duration.ofNanos(getTimeoutDuration().toNanos()); + } + + @Override + public ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout) { return new FakeCallContext( this.credentials, this.channel, @@ -327,8 +349,14 @@ public ApiCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout this.retryableCodes); } + @Nullable + @Override + public org.threeten.bp.Duration getStreamWaitTimeout() { + return org.threeten.bp.Duration.ofNanos(getStreamWaitTimeoutDuration().toNanos()); + } + @Override - public ApiCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout) { + public ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout) { Preconditions.checkNotNull(streamIdleTimeout); return new FakeCallContext( this.credentials, @@ -343,6 +371,12 @@ public ApiCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout this.retryableCodes); } + @Nullable + @Override + public org.threeten.bp.Duration getStreamIdleTimeout() { + return org.threeten.bp.Duration.ofNanos(getStreamIdleTimeout().toNanos()); + } + @Override public ApiCallContext withExtraHeaders(Map> extraHeaders) { Preconditions.checkNotNull(extraHeaders); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java index 8cf6f82fa9..6726f216b9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java @@ -60,7 +60,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class OpencensusTracerTest { @@ -85,7 +84,7 @@ public void testUnarySuccessExample() { ApiException error0 = new DeadlineExceededException( "deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true); - tracer.attemptFailed(error0, Duration.ofMillis(5)); + tracer.attemptFailed(error0, java.time.Duration.ofMillis(5)); tracer.attemptStarted(1); tracer.connectionSelected("2"); @@ -136,7 +135,7 @@ public void testLongRunningExample() { // Initial poll of the initial rpc tracer.attemptStarted(0); - tracer.attemptFailed(null, Duration.ofMillis(5)); + tracer.attemptFailed(null, java.time.Duration.ofMillis(5)); // Initial rpc finished tracer.lroStartSucceeded(); @@ -260,7 +259,7 @@ public void testResponseCount() { tracer.attemptStarted(0); tracer.responseReceived(); tracer.responseReceived(); - tracer.attemptFailed(new RuntimeException(), Duration.ofMillis(1)); + tracer.attemptFailed(new RuntimeException(), java.time.Duration.ofMillis(1)); // Next attempt got 1 message, then successfully finished the attempt and the logical operation. tracer.attemptStarted(1); @@ -288,7 +287,7 @@ public void testRequestCount() { tracer.attemptStarted(0); tracer.requestSent(); tracer.requestSent(); - tracer.attemptFailed(new RuntimeException(), Duration.ofMillis(1)); + tracer.attemptFailed(new RuntimeException(), java.time.Duration.ofMillis(1)); // Next attempt sent 1 message, then successfully finished the attempt and the logical // operation. @@ -314,7 +313,7 @@ public void testRequestCount() { @Test public void testAttemptNumber() { tracer.attemptStarted(0); - tracer.attemptFailed(new RuntimeException(), Duration.ofMillis(1)); + tracer.attemptFailed(new RuntimeException(), java.time.Duration.ofMillis(1)); tracer.attemptStarted(1); tracer.attemptSucceeded(); tracer.operationSucceeded(); @@ -339,7 +338,7 @@ public void testStatusCode() { tracer.attemptFailed( new DeadlineExceededException( "deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true), - Duration.ofMillis(1)); + java.time.Duration.ofMillis(1)); tracer.attemptStarted(1); ApiException permanentError = diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java index 834b357e4d..07d1fd2b13 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java @@ -56,7 +56,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class TracedCallableTest { @@ -103,7 +102,7 @@ public void testNonRetriedCallable() throws Exception { // Verify that callables configured to not retry have the appropriate tracer interactions. UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(Duration.ofMillis(5L)) + .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(5L)) .build(); UnaryCallable callable = setupTracedUnaryCallable(callSettings); innerResult.set("No, my refrigerator is not running!"); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index a1069b48a2..c007538275 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -21,7 +21,6 @@ import com.google.api.core.BetaApi; import com.google.api.gax.retrying.RetrySettings; import java.io.Serializable; -import org.threeten.bp.Duration; /** * This class represents an options wrapper around the {@link RetrySettings} class and is an @@ -52,12 +51,22 @@ private RetryOption(OptionType type, Object value) { } /** See {@link RetrySettings#getTotalTimeout()}. */ - public static RetryOption totalTimeout(Duration totalTimeout) { + public static RetryOption totalTimeout(org.threeten.bp.Duration totalTimeout) { + return totalTimeout(java.time.Duration.ofNanos(totalTimeout.toNanos())); + } + + /** See {@link RetrySettings#getTotalTimeout()}. */ + public static RetryOption totalTimeout(java.time.Duration totalTimeout) { return new RetryOption(OptionType.TOTAL_TIMEOUT, totalTimeout); } /** See {@link RetrySettings#getInitialRetryDelay()}. */ - public static RetryOption initialRetryDelay(Duration initialRetryDelay) { + public static RetryOption initialRetryDelay(org.threeten.bp.Duration initialRetryDelay) { + return initialRetryDelay(java.time.Duration.ofNanos(initialRetryDelay.toNanos())); + } + + /** See {@link RetrySettings#getInitialRetryDelay()}. */ + public static RetryOption initialRetryDelay(java.time.Duration initialRetryDelay) { return new RetryOption(OptionType.INITIAL_RETRY_DELAY, initialRetryDelay); } @@ -67,7 +76,12 @@ public static RetryOption retryDelayMultiplier(double retryDelayMultiplier) { } /** See {@link RetrySettings#getMaxRetryDelay()}. */ - public static RetryOption maxRetryDelay(Duration maxRetryDelay) { + public static RetryOption maxRetryDelay(org.threeten.bp.Duration maxRetryDelay) { + return maxRetryDelay(java.time.Duration.ofNanos(maxRetryDelay.toNanos())); + } + + /** See {@link RetrySettings#getMaxRetryDelay()}. */ + public static RetryOption maxRetryDelay(java.time.Duration maxRetryDelay) { return new RetryOption(OptionType.MAX_RETRY_DELAY, maxRetryDelay); } @@ -124,16 +138,16 @@ public static RetrySettings mergeToSettings(RetrySettings settings, RetryOption. for (RetryOption option : options) { switch (option.type) { case TOTAL_TIMEOUT: - builder.setTotalTimeout((Duration) option.value); + builder.setTotalTimeout((java.time.Duration) option.value); break; case INITIAL_RETRY_DELAY: - builder.setInitialRetryDelay((Duration) option.value); + builder.setInitialRetryDelay((java.time.Duration) option.value); break; case RETRY_DELAY_MULTIPLIER: builder.setRetryDelayMultiplier((Double) option.value); break; case MAX_RETRY_DELAY: - builder.setMaxRetryDelay((Duration) option.value); + builder.setMaxRetryDelay((java.time.Duration) option.value); break; case MAX_ATTEMPTS: builder.setMaxAttempts((Integer) option.value); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index 9679c6299c..a6bd70d5f3 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -56,7 +56,6 @@ import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import org.threeten.bp.Duration; /** Utility class to start and stop a local service which is used by unit testing. */ @InternalApi @@ -116,7 +115,7 @@ protected final void startProcess(String blockUntilOutput) * Waits for the local service's subprocess to terminate, and stop any possible thread listening * for its output. */ - protected final int waitForProcess(Duration timeout) + protected final int waitForProcess(java.time.Duration timeout) throws IOException, InterruptedException, TimeoutException { if (activeRunner != null) { int exitCode = activeRunner.waitFor(timeout); @@ -130,7 +129,7 @@ protected final int waitForProcess(Duration timeout) return 0; } - private static int waitForProcess(final Process process, Duration timeout) + private static int waitForProcess(final Process process, java.time.Duration timeout) throws InterruptedException, TimeoutException { if (process == null) { return 0; @@ -181,7 +180,7 @@ public String getProjectId() { public abstract void start() throws IOException, InterruptedException; /** Stops the local emulator. */ - public abstract void stop(Duration timeout) + public abstract void stop(java.time.Duration timeout) throws IOException, InterruptedException, TimeoutException; /** Resets the internal state of the emulator. */ @@ -227,7 +226,7 @@ protected interface EmulatorRunner { void start() throws IOException; /** Wait for the emulator associated to this runner to terminate, returning the exit status. */ - int waitFor(Duration timeout) throws InterruptedException, TimeoutException; + int waitFor(java.time.Duration timeout) throws InterruptedException, TimeoutException; /** Returns the process associated to the emulator, if any. */ Process getProcess(); @@ -265,7 +264,7 @@ public void start() throws IOException { } @Override - public int waitFor(Duration timeout) throws InterruptedException, TimeoutException { + public int waitFor(java.time.Duration timeout) throws InterruptedException, TimeoutException { return waitForProcess(process, timeout); } @@ -375,7 +374,7 @@ public Path call() throws IOException { } @Override - public int waitFor(Duration timeout) throws InterruptedException, TimeoutException { + public int waitFor(java.time.Duration timeout) throws InterruptedException, TimeoutException { return waitForProcess(process, timeout); } diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index ebea89f2fc..aa2cc3e6b8 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -21,26 +21,25 @@ import com.google.api.gax.retrying.RetrySettings; import org.junit.Test; -import org.threeten.bp.Duration; public class RetryOptionTest { private static final RetryOption TOTAL_TIMEOUT = - RetryOption.totalTimeout(Duration.ofMillis(420L)); + RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); private static final RetryOption INITIAL_RETRY_DELAY = - RetryOption.initialRetryDelay(Duration.ofMillis(42L)); + RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); private static final RetryOption RETRY_DELAY_MULTIPLIER = RetryOption.retryDelayMultiplier(1.5); private static final RetryOption MAX_RETRY_DELAY = - RetryOption.maxRetryDelay(Duration.ofMillis(100)); + RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); private static final RetryOption MAX_ATTEMPTS = RetryOption.maxAttempts(100); private static final RetryOption JITTERED = RetryOption.jittered(false); private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofMillis(420L)) - .setInitialRetryDelay(Duration.ofMillis(42L)) + .setTotalTimeout(java.time.Duration.ofMillis(420L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(42L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(100)) + .setMaxRetryDelay(java.time.Duration.ofMillis(100)) .setMaxAttempts(100) .setJittered(false) .build(); @@ -61,10 +60,10 @@ public void testEqualsAndHashCode() { assertNotEquals(MAX_ATTEMPTS, MAX_RETRY_DELAY); assertNotEquals(JITTERED, MAX_ATTEMPTS); - RetryOption totalTimeout = RetryOption.totalTimeout(Duration.ofMillis(420L)); - RetryOption initialRetryDelay = RetryOption.initialRetryDelay(Duration.ofMillis(42L)); + RetryOption totalTimeout = RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); + RetryOption initialRetryDelay = RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); RetryOption retryDelayMultiplier = RetryOption.retryDelayMultiplier(1.5); - RetryOption maxRetryDelay = RetryOption.maxRetryDelay(Duration.ofMillis(100)); + RetryOption maxRetryDelay = RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); RetryOption maxAttempts = RetryOption.maxAttempts(100); RetryOption jittered = RetryOption.jittered(false); @@ -101,17 +100,17 @@ public void testMergeToSettings() { assertEquals(retrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setTotalTimeout(Duration.ofMillis(420L)).build(); + defRetrySettings.toBuilder().setTotalTimeout(java.time.Duration.ofMillis(420L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setMaxRetryDelay(Duration.ofMillis(100)).build(); + defRetrySettings.toBuilder().setMaxRetryDelay(java.time.Duration.ofMillis(100)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setInitialRetryDelay(Duration.ofMillis(42L)).build(); + defRetrySettings.toBuilder().setInitialRetryDelay(java.time.Duration.ofMillis(42L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 6c35c665b5..996efecca1 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.io.Serializable; -import org.threeten.bp.Duration; public class SerializationTest extends BaseSerializationTest { @@ -37,7 +36,7 @@ public class SerializationTest extends BaseSerializationTest { private static final Role SOME_ROLE = Role.viewer(); private static final Policy SOME_IAM_POLICY = Policy.newBuilder().build(); private static final RetryOption CHECKING_PERIOD = - RetryOption.initialRetryDelay(Duration.ofSeconds(42)); + RetryOption.initialRetryDelay(java.time.Duration.ofSeconds(42)); private static final LabelDescriptor LABEL_DESCRIPTOR = new LabelDescriptor("project_id", ValueType.STRING, "The project id"); private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index 2c6d7495be..678a1f53cf 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -33,7 +33,6 @@ import java.util.logging.Logger; import org.easymock.EasyMock; import org.junit.Test; -import org.threeten.bp.Duration; public class BaseEmulatorHelperTest { @@ -71,7 +70,7 @@ public void start() throws IOException, InterruptedException { } @Override - public void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException { + public void stop(java.time.Duration timeout) throws IOException, InterruptedException, TimeoutException { waitForProcess(timeout); } @@ -91,13 +90,13 @@ public void testEmulatorHelper() throws IOException, InterruptedException, Timeo emulatorRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(emulatorRunner.getProcess()).andReturn(process); - emulatorRunner.waitFor(Duration.ofMinutes(1)); + emulatorRunner.waitFor(java.time.Duration.ofMinutes(1)); EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, emulatorRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(emulatorRunner), BLOCK_UNTIL); helper.start(); - helper.stop(Duration.ofMinutes(1)); + helper.stop(java.time.Duration.ofMinutes(1)); EasyMock.verify(); } @@ -157,13 +156,13 @@ public void testEmulatorHelperMultipleRunners() secondRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(secondRunner.getProcess()).andReturn(process); - secondRunner.waitFor(Duration.ofMinutes(1)); + secondRunner.waitFor(java.time.Duration.ofMinutes(1)); EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, secondRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(firstRunner, secondRunner), BLOCK_UNTIL); helper.start(); - helper.stop(Duration.ofMinutes(1)); + helper.stop(java.time.Duration.ofMinutes(1)); EasyMock.verify(); } From 484fd7400d0041cb7d436982e600602a4e827f14 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 12:32:35 -0400 Subject: [PATCH 003/141] chore: use java.time conversion util --- .../google/api/gax/grpc/GrpcCallContext.java | 15 ++++--- .../InstantiatingGrpcChannelProvider.java | 13 ++++--- .../api/gax/httpjson/HttpJsonCallContext.java | 15 ++++--- .../api/gax/batching/BatchingSettings.java | 10 +++-- .../api/gax/batching/ThresholdBatcher.java | 3 +- .../api/gax/retrying/RetrySettings.java | 39 ++++++++++--------- .../gax/retrying/TimedAttemptSettings.java | 15 ++++--- .../com/google/api/gax/rpc/ClientContext.java | 7 +++- .../google/api/gax/rpc/ClientSettings.java | 9 +++-- .../rpc/InstantiatingWatchdogProvider.java | 4 +- .../gax/rpc/ServerStreamingCallSettings.java | 17 ++++---- .../com/google/api/gax/rpc/StubSettings.java | 9 +++-- .../java/com/google/api/gax/rpc/Watchdog.java | 6 ++- .../api/gax/util/TimeConversionUtils.java | 17 ++++++++ .../api/gax/rpc/testing/FakeCallContext.java | 15 ++++--- .../java/com/google/cloud/RetryOption.java | 7 ++-- 16 files changed, 129 insertions(+), 72 deletions(-) create mode 100644 gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 14b44a2c6e..a30f493293 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -56,6 +56,9 @@ import javax.annotation.Nullable; import org.threeten.bp.Duration; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * GrpcCallContext encapsulates context data used to make a grpc call. * @@ -175,7 +178,7 @@ public GrpcCallContext withTransportChannel(TransportChannel inputChannel) { /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @Override public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { - return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + return withTimeout(toJavaTimeDuration(timeout)); } @Override @@ -206,7 +209,7 @@ public GrpcCallContext withTimeout(@Nullable java.time.Duration timeout) { @Nullable @Override public org.threeten.bp.Duration getTimeout() { - return org.threeten.bp.Duration.ofNanos(getTimeoutDuration().toNanos()); + return toThreetenDuration(getTimeoutDuration()); } @Nullable @@ -222,7 +225,7 @@ public java.time.Duration getTimeoutDuration() { @Override public GrpcCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { - return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); + return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); } @Override @@ -255,7 +258,7 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration stream @Override public GrpcCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { - return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); + return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); } @Override @@ -456,7 +459,7 @@ public CallOptions getCallOptions() { @Override @Nullable public org.threeten.bp.Duration getStreamWaitTimeout() { - return org.threeten.bp.Duration.ofNanos(getStreamWaitTimeoutDuration().toNanos()); + return toThreetenDuration(getStreamWaitTimeoutDuration()); } /** @@ -473,7 +476,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { @Override @Nullable public org.threeten.bp.Duration getStreamIdleTimeout() { - return org.threeten.bp.Duration.ofNanos(getStreamIdleTimeoutDuration().toNanos()); + return toThreetenDuration(getStreamIdleTimeoutDuration()); } /** * The stream idle timeout set for this context. diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 659736c5bb..0319eda18c 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -67,6 +67,9 @@ import javax.annotation.Nullable; import javax.net.ssl.KeyManagerFactory; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * InstantiatingGrpcChannelProvider is a TransportChannelProvider which constructs a gRPC * ManagedChannel with a number of configured inputs every time getChannel(...) is called. These @@ -400,7 +403,7 @@ public String getEndpoint() { } public org.threeten.bp.Duration getKeepAliveTime() { - return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeDuration().toNanos()); + return toThreetenDuration(getKeepAliveTimeDuration()); } /** The time without read activity before sending a keepalive ping. */ @@ -409,7 +412,7 @@ public java.time.Duration getKeepAliveTimeDuration() { } public org.threeten.bp.Duration getKeepAliveTimeout() { - return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeoutDuration().toNanos()); + return toThreetenDuration(getKeepAliveTimeoutDuration()); } /** The time without read activity after sending a keepalive ping. */ @@ -595,7 +598,7 @@ public Integer getMaxInboundMetadataSize() { * org.threeten.bp.Duration} */ public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { - return setKeepAliveTime(java.time.Duration.ofNanos(duration.toNanos())); + return setKeepAliveTime(toJavaTimeDuration(duration)); } /** The time without read activity before sending a keepalive ping. */ public Builder setKeepAliveTime(java.time.Duration duration) { @@ -605,7 +608,7 @@ public Builder setKeepAliveTime(java.time.Duration duration) { /** Backport of {@link #getKeepAliveTimeDuration()} */ public org.threeten.bp.Duration getKeepAliveTime() { - return org.threeten.bp.Duration.ofNanos(getKeepAliveTimeDuration().toNanos()); + return toThreetenDuration(getKeepAliveTimeDuration()); } /** The time without read activity before sending a keepalive ping. */ @@ -614,7 +617,7 @@ public java.time.Duration getKeepAliveTimeDuration() { } public Builder setKeepAliveTimeout(org.threeten.bp.Duration duration) { - return setKeepAliveTimeout(java.time.Duration.ofNanos(duration.toNanos())); + return setKeepAliveTimeout(toJavaTimeDuration(duration)); } /** The time without read activity after sending a keepalive ping. */ diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 67899eacfe..6f1c094e09 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -50,6 +50,9 @@ import javax.annotation.Nullable; import org.threeten.bp.Duration; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * HttpJsonCallContext encapsulates context data used to make an http-json call. * @@ -234,7 +237,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @Override public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { - return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + return withTimeout(toJavaTimeDuration(timeout)); } @Override @@ -266,7 +269,7 @@ public HttpJsonCallContext withTimeout(java.time.Duration timeout) { @Nullable @Override public org.threeten.bp.Duration getTimeout() { - return org.threeten.bp.Duration.ofNanos(getTimeoutDuration().toNanos()); + return toThreetenDuration(getTimeoutDuration()); } @Nullable @@ -282,7 +285,7 @@ public java.time.Duration getTimeoutDuration() { @Override public HttpJsonCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { - return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); + return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); } @Override @@ -309,7 +312,7 @@ public HttpJsonCallContext withStreamWaitTimeout(@Nullable java.time.Duration st @Override @Nullable public org.threeten.bp.Duration getStreamWaitTimeout() { - return org.threeten.bp.Duration.ofNanos(getStreamWaitTimeoutDuration().toNanos()); + return toThreetenDuration(getStreamWaitTimeoutDuration()); } /** @@ -330,7 +333,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { @Override public HttpJsonCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { - return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); + return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); } @Override @@ -357,7 +360,7 @@ public HttpJsonCallContext withStreamIdleTimeout(@Nullable java.time.Duration st @Override @Nullable public org.threeten.bp.Duration getStreamIdleTimeout() { - return org.threeten.bp.Duration.ofNanos(getStreamIdleTimeoutDuration().toNanos()); + return toThreetenDuration(getStreamIdleTimeoutDuration()); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index f82311c52b..1ef0144b9e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -30,10 +30,14 @@ package com.google.api.gax.batching; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import com.google.api.gax.util.TimeConversionUtils; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * Represents the batching settings to use for an API method that is capable of batching. * @@ -100,7 +104,7 @@ public abstract class BatchingSettings { /** Get the delay threshold to use for batching. */ @Nullable public final org.threeten.bp.Duration getDelayThreshold() { - return org.threeten.bp.Duration.ofNanos(getDelayThresholdDuration().toNanos()); + return toThreetenDuration(getDelayThresholdDuration()); } /** Get the delay threshold to use for batching. */ @@ -152,7 +156,7 @@ public abstract static class Builder { * org.threeten.bp.Duration} */ public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) { - return setDelayThresholdDuration(java.time.Duration.ofNanos(delayThreshold.toNanos())); + return setDelayThresholdDuration(toJavaTimeDuration(delayThreshold)); } /** @@ -160,7 +164,7 @@ public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) * org.threeten.bp.Duration} This is a convenience public method to keep name conformity */ public final Builder setDelayThreshold(java.time.Duration delayThreshold) { - return setDelayThresholdDuration(java.time.Duration.ofNanos(delayThreshold.toNanos())); + return setDelayThresholdDuration(delayThreshold); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index db966fe9fa..b2d8788851 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.batching; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.api.core.ApiFunction; @@ -124,7 +125,7 @@ public Builder setMaxDelay(java.time.Duration maxDelay) { /** Set the max delay for a batch. This is counted from the first item added to a batch. */ public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { - this.maxDelay = java.time.Duration.ofNanos(maxDelay.toNanos()); + this.maxDelay = toJavaTimeDuration(maxDelay); return this; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index bc810c3c84..08a14b0435 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -34,6 +34,9 @@ import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * Holds the parameters for retry or poll logic with jitter, timeout and exponential * backoff. Actual implementation of the logic is elsewhere. @@ -73,7 +76,7 @@ public abstract class RetrySettings implements Serializable { /** Backport of {@link #getTotalTimeoutDuration()} */ public final org.threeten.bp.Duration getTotalTimeout() { - return org.threeten.bp.Duration.ofNanos(getTotalTimeoutDuration().toNanos()); + return toThreetenDuration(getTotalTimeoutDuration()); } /** @@ -85,7 +88,7 @@ public final org.threeten.bp.Duration getTotalTimeout() { /** Backport of {@link #getInitialRetryDelayDuration()} */ public final org.threeten.bp.Duration getInitialRetryDelay() { - return org.threeten.bp.Duration.ofNanos(getInitialRetryDelayDuration().toNanos()); + return toThreetenDuration(getInitialRetryDelayDuration()); } /** @@ -104,7 +107,7 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { /** Backport of {@link #getMaxRetryDelayDuration()} */ public final org.threeten.bp.Duration getMaxRetryDelay() { - return org.threeten.bp.Duration.ofNanos(getMaxRetryDelayDuration().toNanos()); + return toThreetenDuration(getMaxRetryDelayDuration()); } /** @@ -137,7 +140,7 @@ public final org.threeten.bp.Duration getMaxRetryDelay() { /** Backport of {@link #getInitialRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getInitialRpcTimeout() { - return org.threeten.bp.Duration.ofNanos(getInitialRpcTimeoutDuration().toNanos()); + return toThreetenDuration(getInitialRpcTimeoutDuration()); } /** @@ -156,7 +159,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { /** Backport of {@link #getMaxRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getMaxRpcTimeout() { - return org.threeten.bp.Duration.ofNanos(getMaxRpcTimeoutDuration().toNanos()); + return toThreetenDuration(getMaxRpcTimeoutDuration()); } /** @@ -193,7 +196,7 @@ public abstract static class Builder { * org.threeten.bp.Duration} */ public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { - return setTotalTimeoutDuration(java.time.Duration.ofNanos(totalTimeout.toNanos())); + return setTotalTimeoutDuration(toJavaTimeDuration(totalTimeout)); } /** @@ -201,7 +204,7 @@ public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { * org.threeten.bp.Duration} This is a convenience public method to keep name conformity */ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { - return setTotalTimeoutDuration(java.time.Duration.ofNanos(totalTimeout.toNanos())); + return setTotalTimeoutDuration(totalTimeout); } /** @@ -216,7 +219,7 @@ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { * org.threeten.bp.Duration} */ public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { - return setInitialRetryDelay(java.time.Duration.ofNanos(initialDelay.toNanos())); + return setInitialRetryDelay(toJavaTimeDuration(initialDelay)); } /** @@ -246,7 +249,7 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { * org.threeten.bp.Duration} */ public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { - return setMaxRetryDelayDuration(java.time.Duration.ofNanos(maxDelay.toNanos())); + return setMaxRetryDelayDuration(toJavaTimeDuration(maxDelay)); } /** @@ -290,7 +293,7 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { * org.threeten.bp.Duration} */ public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { - return setInitialRpcTimeoutDuration(java.time.Duration.ofNanos(initialTimeout.toNanos())); + return setInitialRpcTimeoutDuration(toJavaTimeDuration(initialTimeout)); } /** @@ -319,12 +322,12 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { * org.threeten.bp.Duration} */ public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { - return setMaxRpcTimeoutDuration(java.time.Duration.ofNanos(maxTimeout.toNanos())); + return setMaxRpcTimeoutDuration(toJavaTimeDuration(maxTimeout)); } /** * Overload of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} using {@link - * java.time..Duration} This is a convenience public method to keep name conformity + * java.time.Duration} This is a convenience public method to keep name conformity */ public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { return setMaxRpcTimeoutDuration(maxTimeout); @@ -339,7 +342,7 @@ public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { /** Backport of {@link #getTotalTimeoutDuration()} */ public final org.threeten.bp.Duration getTotalTimeout() { - return org.threeten.bp.Duration.ofNanos(getTotalTimeoutDuration().toNanos()); + return toThreetenDuration(getTotalTimeoutDuration()); } /** @@ -351,7 +354,7 @@ public final org.threeten.bp.Duration getTotalTimeout() { /** Backport of {@link #getInitialRetryDelay()} */ public final org.threeten.bp.Duration getInitialRetryDelay() { - return org.threeten.bp.Duration.ofNanos(getInitialRetryDelayDuration().toNanos()); + return toThreetenDuration(getInitialRetryDelayDuration()); } /** @@ -387,7 +390,7 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { /** Backport of {@link #getMaxRetryDelayDuration()} */ public final org.threeten.bp.Duration getMaxRetryDelay() { - return org.threeten.bp.Duration.ofNanos(getMaxRetryDelayDuration().toNanos()); + return toThreetenDuration(getMaxRetryDelayDuration()); } /** @@ -399,7 +402,7 @@ public final org.threeten.bp.Duration getMaxRetryDelay() { /** Backport of {@link #getInitialRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getInitialRpcTimeout() { - return org.threeten.bp.Duration.ofNanos((getInitialRpcTimeoutDuration().toNanos())); + return toThreetenDuration((getInitialRpcTimeoutDuration())); } /** @@ -417,7 +420,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { /** Backport of {@link #getMaxRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getMaxRpcTimeout() { - return org.threeten.bp.Duration.ofNanos((getMaxRpcTimeoutDuration().toNanos())); + return toThreetenDuration((getMaxRpcTimeoutDuration())); } /** @@ -432,7 +435,7 @@ public final org.threeten.bp.Duration getMaxRpcTimeout() { */ @BetaApi public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { - return setLogicalTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + return setLogicalTimeout(toJavaTimeDuration(timeout)); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index b72d284093..d295e7fdca 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -32,6 +32,9 @@ import com.google.api.core.ApiClock; import com.google.auto.value.AutoValue; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ @AutoValue public abstract class TimedAttemptSettings { @@ -41,7 +44,7 @@ public abstract class TimedAttemptSettings { /** Backport of {@link #getRetryDelayDuration()} */ public final org.threeten.bp.Duration getRetryDelay() { - return org.threeten.bp.Duration.ofNanos(getRetryDelayDuration().toNanos()); + return toThreetenDuration(getRetryDelayDuration()); } /** @@ -52,7 +55,7 @@ public final org.threeten.bp.Duration getRetryDelay() { /** Backport of {@link #getRpcTimeoutDuration()} */ public final org.threeten.bp.Duration getRpcTimeout() { - return org.threeten.bp.Duration.ofNanos(getRpcTimeoutDuration().toNanos()); + return toThreetenDuration(getRpcTimeoutDuration()); } /** Returns rpc timeout used for this attempt. */ @@ -60,7 +63,7 @@ public final org.threeten.bp.Duration getRpcTimeout() { /** Backport of {@link #getRandomizedRetryDelayDuration()} */ public final org.threeten.bp.Duration getRandomizedRetryDelay() { - return org.threeten.bp.Duration.ofNanos(getRandomizedRetryDelayDuration().toNanos()); + return toThreetenDuration(getRandomizedRetryDelayDuration()); } /** @@ -104,7 +107,7 @@ public abstract static class Builder { * org.threeten.bp.Duration} */ public final Builder setRetryDelay(org.threeten.bp.Duration value) { - return setRetryDelayDuration(java.time.Duration.ofNanos(value.toNanos())); + return setRetryDelayDuration(toJavaTimeDuration(value)); } /** @@ -126,7 +129,7 @@ public final Builder setRetryDelay(java.time.Duration value) { * org.threeten.bp.Duration} */ public final Builder setRpcTimeout(org.threeten.bp.Duration value) { - return setRpcTimeoutDuration(java.time.Duration.ofNanos(value.toNanos())); + return setRpcTimeoutDuration(toJavaTimeDuration(value)); } /** @@ -145,7 +148,7 @@ public final Builder setRpcTimeout(java.time.Duration value) { * org.threeten.bp.Duration} */ public final Builder setRandomizedRetryDelay(org.threeten.bp.Duration value) { - return setRandomizedRetryDelayDuration(java.time.Duration.ofNanos(value.toNanos())); + return setRandomizedRetryDelayDuration(toJavaTimeDuration(value)); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 338db8c806..2c3ffef39a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -58,6 +58,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * Encapsulates client state, including executor, credentials, and transport channel. * @@ -104,7 +107,7 @@ public abstract class ClientContext { */ @Nonnull public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { - return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); + return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); } @Nonnull @@ -360,7 +363,7 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { - return setStreamWatchdogCheckIntervalDuration(java.time.Duration.ofNanos(duration.toNanos())); + return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(duration)); } public final Builder setStreamWatchdogCheckInterval(java.time.Duration duration) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index c2d75b8d88..077abe8f41 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -39,6 +39,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * A base settings class to configure a client class. * @@ -112,7 +115,7 @@ public final WatchdogProvider getWatchdogProvider() { */ @Nonnull public final org.threeten.bp.Duration getWatchdogCheckInterval() { - return org.threeten.bp.Duration.ofNanos(getWatchdogCheckIntervalDuration().toNanos()); + return toThreetenDuration(getWatchdogCheckIntervalDuration()); } @Nonnull @@ -266,7 +269,7 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { } public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { - return setWatchdogCheckInterval(java.time.Duration.ofNanos(checkInterval.toNanos())); + return setWatchdogCheckInterval(toJavaTimeDuration(checkInterval)); } public B setWatchdogCheckInterval(@Nullable java.time.Duration checkInterval) { @@ -350,7 +353,7 @@ public WatchdogProvider getWatchdogProvider() { @Nullable public org.threeten.bp.Duration getWatchdogCheckInterval() { - return org.threeten.bp.Duration.ofNanos(getWatchdogCheckIntervalDuration().toNanos()); + return toThreetenDuration(getWatchdogCheckIntervalDuration()); } @Nullable diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index 44a726e27e..ee70950f7a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -36,6 +36,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + /** * A watchdog provider which instantiates a new provider on every request. * @@ -87,7 +89,7 @@ public boolean needsCheckInterval() { @Override public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { return withCheckInterval( - java.time.Duration.ofNanos(Preconditions.checkNotNull(checkInterval).toNanos())); + toJavaTimeDuration(Preconditions.checkNotNull(checkInterval))); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index f04eb49bf6..b118bce13b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -40,6 +40,9 @@ import java.util.Set; import javax.annotation.Nonnull; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * A settings class to configure a {@link ServerStreamingCallable}. * @@ -120,7 +123,7 @@ public StreamResumptionStrategy getResumptionStrategy() { /** Backport of {@link #getIdleTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getIdleTimeout() { - return org.threeten.bp.Duration.ofNanos(getIdleTimeoutDuration().toNanos()); + return toThreetenDuration(getIdleTimeoutDuration()); } /** @@ -135,7 +138,7 @@ public java.time.Duration getIdleTimeoutDuration() { /** Backport of {@link #getWaitTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getWaitTimeout() { - return org.threeten.bp.Duration.ofNanos(getWaitTimeoutDuration().toNanos()); + return toThreetenDuration(getWaitTimeoutDuration()); } /** @@ -259,7 +262,7 @@ public RetrySettings getRetrySettings() { */ public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { - return setSimpleTimeoutNoRetries(java.time.Duration.ofNanos(timeout.toNanos())); + return setSimpleTimeoutNoRetries(toJavaTimeDuration(timeout)); } /** Disables retries and sets the overall timeout. */ @@ -300,7 +303,7 @@ public StreamResumptionStrategy getResumptionStrategy() { /** Backport of {@link #getIdleTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getIdleTimeout() { - return org.threeten.bp.Duration.ofNanos(getIdleTimeoutDuration().toNanos()); + return toThreetenDuration(getIdleTimeoutDuration()); } @Nonnull @@ -313,7 +316,7 @@ public java.time.Duration getIdleTimeoutDuration() { */ public Builder setIdleTimeout( @Nonnull org.threeten.bp.Duration idleTimeout) { - return setIdleTimeout(java.time.Duration.ofNanos(idleTimeout.toNanos())); + return setIdleTimeout(toJavaTimeDuration(idleTimeout)); } /** @@ -328,7 +331,7 @@ public Builder setIdleTimeout(@Nonnull java.time.Duration i /** Backport of {@link #getWaitTimeoutDuration()} */ @Nonnull public org.threeten.bp.Duration getWaitTimeout() { - return org.threeten.bp.Duration.ofNanos(getWaitTimeoutDuration().toNanos()); + return toThreetenDuration(getWaitTimeoutDuration()); } @Nonnull @@ -342,7 +345,7 @@ public java.time.Duration getWaitTimeoutDuration() { */ public Builder setWaitTimeout( @Nonnull org.threeten.bp.Duration waitTimeout) { - return setWaitTimeout(java.time.Duration.ofNanos(waitTimeout.toNanos())); + return setWaitTimeout(toJavaTimeDuration(waitTimeout)); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index cda0bd3a19..7d75c24a1f 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -49,6 +49,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * A base settings class to configure a client stub class. * @@ -161,7 +164,7 @@ public final WatchdogProvider getStreamWatchdogProvider() { /** Backport of {@link #getStreamWatchdogCheckIntervalDuration()} */ @Nonnull public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { - return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); + return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); } @Nonnull @@ -448,7 +451,7 @@ public B setQuotaProjectId(String quotaProjectId) { * org.threeten.bp.Duration} */ public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { - return setStreamWatchdogCheckInterval(java.time.Duration.ofNanos(checkInterval.toNanos())); + return setStreamWatchdogCheckInterval(toJavaTimeDuration(checkInterval)); } /** @@ -541,7 +544,7 @@ public String getQuotaProjectId() { } public org.threeten.bp.Duration getStreamWatchdogCheckInterval() { - return org.threeten.bp.Duration.ofNanos(getStreamWatchdogCheckIntervalDuration().toNanos()); + return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); } @Nonnull diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index b186b210c8..a53372dbfa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -47,6 +47,8 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.GuardedBy; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + /** * Prevents the streams from hanging indefinitely. This middleware garbage collects idle streams in * case the user forgot to close a ServerStream or if a connection is reset and GRPC does not get @@ -106,8 +108,8 @@ public ResponseObserver watch( @Nonnull org.threeten.bp.Duration idleTimeout) { return watch( innerObserver, - java.time.Duration.ofNanos(waitTimeout.toNanos()), - java.time.Duration.ofNanos(idleTimeout.toNanos())); + toJavaTimeDuration(waitTimeout), + toJavaTimeDuration(idleTimeout)); } /** Wraps the target observer with timing constraints. */ public ResponseObserver watch( diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java new file mode 100644 index 0000000000..78592c995f --- /dev/null +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java @@ -0,0 +1,17 @@ +package com.google.api.gax.util; + +public class TimeConversionUtils { + public static java.time.Duration toJavaTimeDuration(org.threeten.bp.Duration source) { + if (source == null) { + return null; + } + return toJavaTimeDuration(source); + } + + public static org.threeten.bp.Duration toThreetenDuration(java.time.Duration source) { + if (source == null) { + return null; + } + return toThreetenDuration(source); + } +} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java index bab447d4b9..ad917c4049 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java @@ -49,6 +49,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + @InternalApi("for testing") public class FakeCallContext implements ApiCallContext { private final Credentials credentials; @@ -237,7 +240,7 @@ public java.time.Duration getTimeoutDuration() { @Override public ApiCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { - return withStreamWaitTimeout(java.time.Duration.ofNanos(streamWaitTimeout.toNanos())); + return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); } @Nullable @@ -249,7 +252,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { @Override public ApiCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { - return withStreamIdleTimeout(java.time.Duration.ofNanos(streamIdleTimeout.toNanos())); + return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); } @Nullable @@ -286,7 +289,7 @@ public FakeCallContext withTransportChannel(TransportChannel inputChannel) { @Override public FakeCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { - return withTimeout(java.time.Duration.ofNanos(timeout.toNanos())); + return withTimeout(toJavaTimeDuration(timeout)); } public FakeCallContext withChannel(FakeChannel channel) { @@ -331,7 +334,7 @@ public FakeCallContext withTimeout(java.time.Duration timeout) { @Nullable @Override public org.threeten.bp.Duration getTimeout() { - return org.threeten.bp.Duration.ofNanos(getTimeoutDuration().toNanos()); + return toThreetenDuration(getTimeoutDuration()); } @Override @@ -352,7 +355,7 @@ public ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamW @Nullable @Override public org.threeten.bp.Duration getStreamWaitTimeout() { - return org.threeten.bp.Duration.ofNanos(getStreamWaitTimeoutDuration().toNanos()); + return toThreetenDuration(getStreamWaitTimeoutDuration()); } @Override @@ -374,7 +377,7 @@ public ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamI @Nullable @Override public org.threeten.bp.Duration getStreamIdleTimeout() { - return org.threeten.bp.Duration.ofNanos(getStreamIdleTimeout().toNanos()); + return toThreetenDuration(getStreamIdleTimeoutDuration()); } @Override diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index c007538275..d73616d990 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -16,6 +16,7 @@ package com.google.cloud; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.core.BetaApi; @@ -52,7 +53,7 @@ private RetryOption(OptionType type, Object value) { /** See {@link RetrySettings#getTotalTimeout()}. */ public static RetryOption totalTimeout(org.threeten.bp.Duration totalTimeout) { - return totalTimeout(java.time.Duration.ofNanos(totalTimeout.toNanos())); + return totalTimeout(toJavaTimeDuration(totalTimeout)); } /** See {@link RetrySettings#getTotalTimeout()}. */ @@ -62,7 +63,7 @@ public static RetryOption totalTimeout(java.time.Duration totalTimeout) { /** See {@link RetrySettings#getInitialRetryDelay()}. */ public static RetryOption initialRetryDelay(org.threeten.bp.Duration initialRetryDelay) { - return initialRetryDelay(java.time.Duration.ofNanos(initialRetryDelay.toNanos())); + return initialRetryDelay(toJavaTimeDuration(initialRetryDelay)); } /** See {@link RetrySettings#getInitialRetryDelay()}. */ @@ -77,7 +78,7 @@ public static RetryOption retryDelayMultiplier(double retryDelayMultiplier) { /** See {@link RetrySettings#getMaxRetryDelay()}. */ public static RetryOption maxRetryDelay(org.threeten.bp.Duration maxRetryDelay) { - return maxRetryDelay(java.time.Duration.ofNanos(maxRetryDelay.toNanos())); + return maxRetryDelay(toJavaTimeDuration(maxRetryDelay)); } /** See {@link RetrySettings#getMaxRetryDelay()}. */ From 455b61bdf40fbbd469529ecd9b3ee9247bcc2672 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 12:34:14 -0400 Subject: [PATCH 004/141] chore: fmt --- .../gapic/model/GapicServiceConfigTest.java | 4 ++-- .../protoparser/ServiceConfigParserTest.java | 6 +++--- .../google/api/gax/grpc/GrpcCallContext.java | 6 +++--- .../InstantiatingGrpcChannelProvider.java | 6 +++--- .../api/gax/httpjson/HttpJsonCallContext.java | 6 +++--- .../api/gax/batching/BatchingSettings.java | 7 +++---- .../api/gax/retrying/RetrySettings.java | 6 +++--- .../gax/retrying/TimedAttemptSettings.java | 6 +++--- .../com/google/api/gax/rpc/ClientContext.java | 6 +++--- .../google/api/gax/rpc/ClientSettings.java | 6 +++--- .../rpc/InstantiatingWatchdogProvider.java | 7 +++---- .../gax/rpc/ServerStreamingCallSettings.java | 6 +++--- .../com/google/api/gax/rpc/StubSettings.java | 6 +++--- .../java/com/google/api/gax/rpc/Watchdog.java | 9 +++------ .../api/gax/util/TimeConversionUtils.java | 20 +++++++++---------- .../api/gax/rpc/testing/FakeCallContext.java | 6 +++--- .../cloud/testing/BaseEmulatorHelperTest.java | 3 ++- 17 files changed, 56 insertions(+), 60 deletions(-) diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java index e19c6c71cc..ca4cd84418 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java @@ -97,8 +97,8 @@ public void serviceConfig_basic() { MethodConfig.RetryPolicy retryPolicy = settings.retryPolicy(); assertEquals(3, retryPolicy.getMaxAttempts()); - assertEquals(100,Durations.toMillis(retryPolicy.getInitialBackoff())); - assertEquals(3000,Durations.toMillis(retryPolicy.getMaxBackoff())); + assertEquals(100, Durations.toMillis(retryPolicy.getInitialBackoff())); + assertEquals(3000, Durations.toMillis(retryPolicy.getMaxBackoff())); assertEquals(2.0, retryPolicy.getBackoffMultiplier(), EPSILON); String retryCodeName = serviceConfig.getRetryCodeName(service, method); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java index 956ec8cbe4..8a27f7fd4f 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java @@ -51,8 +51,8 @@ public void parseServiceConfig_basic() { MethodConfig.RetryPolicy retryPolicy = methodConfig.getRetryPolicy(); assertEquals(5, retryPolicy.getMaxAttempts()); - assertEquals(500,Durations.toMillis(retryPolicy.getInitialBackoff())); - assertEquals(30000,Durations.toMillis(retryPolicy.getMaxBackoff())); + assertEquals(500, Durations.toMillis(retryPolicy.getInitialBackoff())); + assertEquals(30000, Durations.toMillis(retryPolicy.getMaxBackoff())); assertEquals(2.0, retryPolicy.getBackoffMultiplier(), EPSILON); assertEquals(1, retryPolicy.getRetryableStatusCodesList().size()); @@ -72,7 +72,7 @@ public void parseServiceConfig_showcase() { MethodConfig methodConfig = config.getMethodConfigList().get(0); assertEquals(2, methodConfig.getNameList().size()); assertTrue(methodConfig.getNameList().get(0).getMethod().isEmpty()); - assertEquals(5000,Durations.toMillis(methodConfig.getTimeout())); + assertEquals(5000, Durations.toMillis(methodConfig.getTimeout())); methodConfig = config.getMethodConfigList().get(1); assertEquals(9, methodConfig.getNameList().size()); diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index a30f493293..eec2727eb4 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.grpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.BetaApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -56,9 +59,6 @@ import javax.annotation.Nullable; import org.threeten.bp.Duration; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * GrpcCallContext encapsulates context data used to make a grpc call. * diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 0319eda18c..9ccfe1add7 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.grpc; +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; @@ -67,9 +70,6 @@ import javax.annotation.Nullable; import javax.net.ssl.KeyManagerFactory; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * InstantiatingGrpcChannelProvider is a TransportChannelProvider which constructs a gRPC * ManagedChannel with a number of configured inputs every time getChannel(...) is called. These diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 6f1c094e09..a812f59ea3 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.httpjson; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.BetaApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -50,9 +53,6 @@ import javax.annotation.Nullable; import org.threeten.bp.Duration; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * HttpJsonCallContext encapsulates context data used to make an http-json call. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 1ef0144b9e..096d010e67 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -29,15 +29,14 @@ */ package com.google.api.gax.batching; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.gax.batching.FlowController.LimitExceededBehavior; -import com.google.api.gax.util.TimeConversionUtils; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * Represents the batching settings to use for an API method that is capable of batching. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 08a14b0435..8dae4af941 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -29,14 +29,14 @@ */ package com.google.api.gax.retrying; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.BetaApi; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * Holds the parameters for retry or poll logic with jitter, timeout and exponential * backoff. Actual implementation of the logic is elsewhere. diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index d295e7fdca..cf7dd64ce4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -29,12 +29,12 @@ */ package com.google.api.gax.retrying; -import com.google.api.core.ApiClock; -import com.google.auto.value.AutoValue; - import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; +import com.google.api.core.ApiClock; +import com.google.auto.value.AutoValue; + /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ @AutoValue public abstract class TimedAttemptSettings { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 2c3ffef39a..445750e0b4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.client.util.Strings; import com.google.api.core.ApiClock; import com.google.api.core.BetaApi; @@ -58,9 +61,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * Encapsulates client state, including executor, credentials, and transport channel. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 077abe8f41..3d57df8a1b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; import com.google.api.gax.core.CredentialsProvider; @@ -39,9 +42,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * A base settings class to configure a client class. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index ee70950f7a..ad8b9655aa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -29,6 +29,8 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.common.base.Preconditions; @@ -36,8 +38,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; - /** * A watchdog provider which instantiates a new provider on every request. * @@ -88,8 +88,7 @@ public boolean needsCheckInterval() { */ @Override public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { - return withCheckInterval( - toJavaTimeDuration(Preconditions.checkNotNull(checkInterval))); + return withCheckInterval(toJavaTimeDuration(Preconditions.checkNotNull(checkInterval))); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index b118bce13b..07460ad447 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.SimpleStreamResumptionStrategy; import com.google.api.gax.retrying.StreamResumptionStrategy; @@ -40,9 +43,6 @@ import java.util.Set; import javax.annotation.Nonnull; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * A settings class to configure a {@link ServerStreamingCallable}. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index 7d75c24a1f..44ca82cc6a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; @@ -49,9 +52,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * A base settings class to configure a client stub class. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index a53372dbfa..80a9d3d193 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -29,6 +29,8 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.ApiClock; import com.google.api.gax.core.BackgroundResource; import com.google.common.base.Preconditions; @@ -47,8 +49,6 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.GuardedBy; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; - /** * Prevents the streams from hanging indefinitely. This middleware garbage collects idle streams in * case the user forgot to close a ServerStream or if a connection is reset and GRPC does not get @@ -106,10 +106,7 @@ public ResponseObserver watch( ResponseObserver innerObserver, @Nonnull org.threeten.bp.Duration waitTimeout, @Nonnull org.threeten.bp.Duration idleTimeout) { - return watch( - innerObserver, - toJavaTimeDuration(waitTimeout), - toJavaTimeDuration(idleTimeout)); + return watch(innerObserver, toJavaTimeDuration(waitTimeout), toJavaTimeDuration(idleTimeout)); } /** Wraps the target observer with timing constraints. */ public ResponseObserver watch( diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java index 78592c995f..c59c4cc7ab 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java @@ -1,17 +1,17 @@ package com.google.api.gax.util; public class TimeConversionUtils { - public static java.time.Duration toJavaTimeDuration(org.threeten.bp.Duration source) { - if (source == null) { - return null; - } - return toJavaTimeDuration(source); + public static java.time.Duration toJavaTimeDuration(org.threeten.bp.Duration source) { + if (source == null) { + return null; } + return toJavaTimeDuration(source); + } - public static org.threeten.bp.Duration toThreetenDuration(java.time.Duration source) { - if (source == null) { - return null; - } - return toThreetenDuration(source); + public static org.threeten.bp.Duration toThreetenDuration(java.time.Duration source) { + if (source == null) { + return null; } + return toThreetenDuration(source); + } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java index ad917c4049..17eddb3a11 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java @@ -29,6 +29,9 @@ */ package com.google.api.gax.rpc.testing; +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.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -49,9 +52,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - @InternalApi("for testing") public class FakeCallContext implements ApiCallContext { private final Credentials credentials; diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index 678a1f53cf..db3f17dc36 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -70,7 +70,8 @@ public void start() throws IOException, InterruptedException { } @Override - public void stop(java.time.Duration timeout) throws IOException, InterruptedException, TimeoutException { + public void stop(java.time.Duration timeout) + throws IOException, InterruptedException, TimeoutException { waitForProcess(timeout); } From c5eee47eb8ab1f96d4c0fff746a462f55282a3ac Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 13:11:19 -0400 Subject: [PATCH 005/141] chore: restore mistake in search/replace --- .../api/gax/util/TimeConversionUtils.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java index c59c4cc7ab..e65c403d3a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java @@ -1,3 +1,33 @@ +/* + * Copyright 2023 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package com.google.api.gax.util; public class TimeConversionUtils { @@ -5,13 +35,13 @@ public static java.time.Duration toJavaTimeDuration(org.threeten.bp.Duration sou if (source == null) { return null; } - return toJavaTimeDuration(source); + return java.time.Duration.ofNanos(source.toNanos()); } public static org.threeten.bp.Duration toThreetenDuration(java.time.Duration source) { if (source == null) { return null; } - return toThreetenDuration(source); + return org.threeten.bp.Duration.ofNanos(source.toNanos()); } } From ef83e0d2742686323a613a0a147525b6af244735 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 15:21:21 -0400 Subject: [PATCH 006/141] chore: ignore java time / threeten differences --- gax-java/gax/clirr-ignored-differences.xml | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gax-java/gax/clirr-ignored-differences.xml b/gax-java/gax/clirr-ignored-differences.xml index 15b4a76c8a..6d6662f0cc 100644 --- a/gax-java/gax/clirr-ignored-differences.xml +++ b/gax-java/gax/clirr-ignored-differences.xml @@ -19,4 +19,39 @@ *setWaitTimeout* com.google.api.gax.rpc.ServerStreamingCallSettings$Builder + + 7014 + com/google/api/gax/*/* + org.threeten.bp.Duration *(*) + + + 7014 + com/google/api/gax/*/* + * *(org.threeten.bp.Duration) + + + 7013 + com/google/api/gax/*/* + java.time.Duration *Duration(*) + + + 7013 + com/google/api/gax/*/* + * set*Duration(*) + + + 7005 + com/google/api/gax/*/* + * *(*java.time.Duration*) + + + 7012 + com/google/api/gax/*/* + * get*Duration() + + + 7012 + com/google/api/gax/*/* + * *(java.time.Duration) + From ee31831c512dd7c2a9c2de7d1383b14846abbe66 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 15:22:30 -0400 Subject: [PATCH 007/141] chore: adapt tests --- .../rpc/ServerStreamingAttemptCallable.java | 5 +-- .../ExponentialRetryAlgorithmTest.java | 33 ++++++++++--------- .../api/gax/retrying/RetrySettingsTest.java | 6 ++-- .../api/gax/rpc/AttemptCallableTest.java | 6 ++-- .../gax/rpc/CheckingAttemptCallableTest.java | 4 +-- .../google/api/gax/rpc/ClientContextTest.java | 2 +- .../gax/rpc/OperationCallableImplTest.java | 2 +- .../rpc/ServerStreamingCallSettingsTest.java | 16 ++++----- .../api/gax/rpc/UnaryCallSettingsTest.java | 6 ++-- 9 files changed, 41 insertions(+), 39 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java index 70bf4eeda0..39bbd7b289 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java @@ -209,9 +209,10 @@ public Void call() { ApiCallContext attemptContext = context; if (!outerRetryingFuture.getAttemptSettings().getRpcTimeout().isZero() - && attemptContext.getTimeout() == null) { + && attemptContext.getTimeoutDuration() == null) { attemptContext = - attemptContext.withTimeout(outerRetryingFuture.getAttemptSettings().getRpcTimeout()); + attemptContext.withTimeout( + outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration()); } attemptContext diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index 63cbdebd71..e37feab030 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -77,10 +77,10 @@ public void testCreateFirstAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); - assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeout()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeoutDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); } @Test @@ -90,10 +90,11 @@ public void testCreateFirstAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); - assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(retrySettingsOverride.getInitialRpcTimeout(), attempt.getRpcTimeout()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals( + retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeoutDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); } @Test @@ -104,13 +105,13 @@ public void testCreateNextAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeoutDuration()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeoutDuration()); } @Test @@ -121,13 +122,13 @@ public void testCreateNextAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeoutDuration()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeoutDuration()); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index 5901e9bfb1..c5bdc93f01 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -40,9 +40,9 @@ public void retrySettingsSetLogicalTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); - Truth.assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getTotalTimeout()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(timeout); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 044484d9dd..0e207782c6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -92,14 +92,14 @@ public void testRpcTimeout() { callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(longerTimeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } @Test @@ -116,6 +116,6 @@ public void testRpcTimeoutIsNotErased() { callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(callerTimeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(callerTimeout); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index f763b891c5..922fd62044 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -92,13 +92,13 @@ public void testRpcTimeout() { callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(longerTimeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 124726b1bc..5ffd46ea10 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -292,7 +292,7 @@ private void runTest( Truth.assertThat(clientContext.getCredentials()).isSameInstanceAs(credentials); Truth.assertThat(clientContext.getClock()).isSameInstanceAs(clock); Truth.assertThat(clientContext.getStreamWatchdog()).isSameInstanceAs(watchdog); - Truth.assertThat(clientContext.getStreamWatchdogCheckInterval()) + Truth.assertThat(clientContext.getStreamWatchdogCheckIntervalDuration()) .isEqualTo(watchdogCheckInterval); Truth.assertThat(clientContext.getHeaders()).isEqualTo(ImmutableMap.of("k1", "v1")); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index f307d0c4b8..6bc6495bd0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -567,7 +567,7 @@ public void testFutureCallContextPropagation() throws Exception { callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); - assertThat(callContextCaptor.getValue().getTimeout()) + assertThat(callContextCaptor.getValue().getTimeoutDuration()) .isEqualTo(java.time.Duration.ofMillis(10)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java index 4d2fd595fd..6856618914 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java @@ -92,9 +92,9 @@ public void idleTimeoutIsNotLost() { ServerStreamingCallSettings.newBuilder(); builder.setIdleTimeout(idleTimeout); - assertThat(builder.getIdleTimeout()).isEqualTo(idleTimeout); - assertThat(builder.build().getIdleTimeout()).isEqualTo(idleTimeout); - assertThat(builder.build().toBuilder().getIdleTimeout()).isEqualTo(idleTimeout); + assertThat(builder.getIdleTimeoutDuration()).isEqualTo(idleTimeout); + assertThat(builder.build().getIdleTimeoutDuration()).isEqualTo(idleTimeout); + assertThat(builder.build().toBuilder().getIdleTimeoutDuration()).isEqualTo(idleTimeout); } @Test @@ -106,9 +106,9 @@ public void waitTimeoutIsNotLost() { builder.setWaitTimeout(waitTimeout); - assertThat(builder.getWaitTimeout()).isEqualTo(waitTimeout); - assertThat(builder.build().getWaitTimeout()).isEqualTo(waitTimeout); - assertThat(builder.build().toBuilder().getWaitTimeout()).isEqualTo(waitTimeout); + assertThat(builder.getWaitTimeoutDuration()).isEqualTo(waitTimeout); + assertThat(builder.build().getWaitTimeoutDuration()).isEqualTo(waitTimeout); + assertThat(builder.build().toBuilder().getWaitTimeoutDuration()).isEqualTo(waitTimeout); } @Test @@ -130,9 +130,9 @@ public void testRetrySettingsBuilder() { builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); - assertThat(builder.getRetrySettings().getMaxRetryDelay()) + assertThat(builder.getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); - assertThat(builder.build().getRetrySettings().getMaxRetryDelay()) + assertThat(builder.build().getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index 59267d912e..ce810e273e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -50,7 +50,7 @@ public void testSetSimpleTimeoutNoRetries() { assertThat(builder.getRetryableCodes().size()).isEqualTo(0); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); - assertThat(builder.getRetrySettings().getTotalTimeout()) + assertThat(builder.getRetrySettings().getTotalTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(13)); } @@ -129,9 +129,9 @@ public void testRetrySettingsBuilder() { builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); - assertThat(builder.getRetrySettings().getMaxRetryDelay()) + assertThat(builder.getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); - assertThat(builder.build().getRetrySettings().getMaxRetryDelay()) + assertThat(builder.build().getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); } From f6b3fd70e7ea410c730ac49e32029ab077f651f1 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 15:22:30 -0400 Subject: [PATCH 008/141] chore: adapt tests --- .../rpc/ServerStreamingAttemptCallable.java | 5 +-- .../ExponentialRetryAlgorithmTest.java | 33 ++++++++++--------- .../api/gax/retrying/RetrySettingsTest.java | 6 ++-- .../api/gax/rpc/AttemptCallableTest.java | 6 ++-- .../com/google/api/gax/rpc/CallableTest.java | 4 +-- .../gax/rpc/CheckingAttemptCallableTest.java | 4 +-- .../google/api/gax/rpc/ClientContextTest.java | 2 +- .../api/gax/rpc/ClientSettingsTest.java | 8 +++-- .../gax/rpc/OperationCallableImplTest.java | 2 +- .../rpc/ServerStreamingCallSettingsTest.java | 16 ++++----- .../api/gax/rpc/UnaryCallSettingsTest.java | 6 ++-- 11 files changed, 48 insertions(+), 44 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java index 70bf4eeda0..39bbd7b289 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java @@ -209,9 +209,10 @@ public Void call() { ApiCallContext attemptContext = context; if (!outerRetryingFuture.getAttemptSettings().getRpcTimeout().isZero() - && attemptContext.getTimeout() == null) { + && attemptContext.getTimeoutDuration() == null) { attemptContext = - attemptContext.withTimeout(outerRetryingFuture.getAttemptSettings().getRpcTimeout()); + attemptContext.withTimeout( + outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration()); } attemptContext diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index 63cbdebd71..e37feab030 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -77,10 +77,10 @@ public void testCreateFirstAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); - assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeout()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeoutDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); } @Test @@ -90,10 +90,11 @@ public void testCreateFirstAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); - assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(retrySettingsOverride.getInitialRpcTimeout(), attempt.getRpcTimeout()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals( + retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeoutDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); } @Test @@ -104,13 +105,13 @@ public void testCreateNextAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeoutDuration()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeoutDuration()); } @Test @@ -121,13 +122,13 @@ public void testCreateNextAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeoutDuration()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelay()); - assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeoutDuration()); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index 5901e9bfb1..c5bdc93f01 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -40,9 +40,9 @@ public void retrySettingsSetLogicalTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); - Truth.assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getTotalTimeout()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(timeout); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 044484d9dd..0e207782c6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -92,14 +92,14 @@ public void testRpcTimeout() { callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(longerTimeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } @Test @@ -116,6 +116,6 @@ public void testRpcTimeoutIsNotErased() { callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(callerTimeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(callerTimeout); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 5b1d61220e..931cca682b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -123,7 +123,7 @@ public void testNonRetriedServerStreamingCallable() throws Exception { callable.call("Is your refrigerator running?", callContext); verify(callContext, atLeastOnce()).getRetrySettings(); - verify(callContext).getTimeout(); + verify(callContext).getTimeoutDuration(); verify(callContext).withTimeout(timeout); } @@ -141,7 +141,7 @@ public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exce callable.call("Is your refrigerator running?", callContextWithRetrySettings); verify(callContextWithRetrySettings, atLeastOnce()).getRetrySettings(); - verify(callContextWithRetrySettings).getTimeout(); + verify(callContextWithRetrySettings).getTimeoutDuration(); verify(callContextWithRetrySettings).withTimeout(timeout); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index f763b891c5..922fd62044 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -92,13 +92,13 @@ public void testRpcTimeout() { callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(timeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(timeout); // Make sure that subsequent attempts can extend the time out java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); callable.call(); - assertThat(capturedCallContext.getValue().getTimeout()).isEqualTo(longerTimeout); + assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 124726b1bc..5ffd46ea10 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -292,7 +292,7 @@ private void runTest( Truth.assertThat(clientContext.getCredentials()).isSameInstanceAs(credentials); Truth.assertThat(clientContext.getClock()).isSameInstanceAs(clock); Truth.assertThat(clientContext.getStreamWatchdog()).isSameInstanceAs(watchdog); - Truth.assertThat(clientContext.getStreamWatchdogCheckInterval()) + Truth.assertThat(clientContext.getStreamWatchdogCheckIntervalDuration()) .isEqualTo(watchdogCheckInterval); Truth.assertThat(clientContext.getHeaders()).isEqualTo(ImmutableMap.of("k1", "v1")); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java index 1b287ef05b..905cf58217 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java @@ -186,7 +186,8 @@ public void testBuilder() throws Exception { Truth.assertThat(builder.getHeaderProvider()).isSameInstanceAs(headerProvider); Truth.assertThat(builder.getInternalHeaderProvider()).isSameInstanceAs(internalHeaderProvider); Truth.assertThat(builder.getWatchdogProvider()).isSameInstanceAs(watchdogProvider); - Truth.assertThat(builder.getWatchdogCheckInterval()).isSameInstanceAs(watchdogCheckInterval); + Truth.assertThat(builder.getWatchdogCheckIntervalDuration()) + .isSameInstanceAs(watchdogCheckInterval); Truth.assertThat(builder.getQuotaProjectId()).isEqualTo(quotaProjectId); String builderString = builder.toString(); @@ -243,7 +244,7 @@ public void testBuilderFromClientContext() throws Exception { .containsEntry("spiffykey", "spiffyvalue"); Truth.assertThat(builder.getWatchdogProvider()).isInstanceOf(FixedWatchdogProvider.class); Truth.assertThat(builder.getWatchdogProvider().getWatchdog()).isSameInstanceAs(watchdog); - Truth.assertThat(builder.getWatchdogCheckInterval()).isEqualTo(watchdogCheckInterval); + Truth.assertThat(builder.getWatchdogCheckIntervalDuration()).isEqualTo(watchdogCheckInterval); Truth.assertThat(builder.getQuotaProjectId()).isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); } @@ -283,7 +284,8 @@ public void testBuilderFromSettings() throws Exception { Truth.assertThat(newBuilder.getInternalHeaderProvider()) .isSameInstanceAs(internalHeaderProvider); Truth.assertThat(newBuilder.getWatchdogProvider()).isSameInstanceAs(watchdogProvider); - Truth.assertThat(newBuilder.getWatchdogCheckInterval()).isEqualTo(watchdogCheckInterval); + Truth.assertThat(newBuilder.getWatchdogCheckIntervalDuration()) + .isEqualTo(watchdogCheckInterval); Truth.assertThat(newBuilder.getQuotaProjectId()).isEqualTo(quotaProjectId); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index f307d0c4b8..6bc6495bd0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -567,7 +567,7 @@ public void testFutureCallContextPropagation() throws Exception { callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); - assertThat(callContextCaptor.getValue().getTimeout()) + assertThat(callContextCaptor.getValue().getTimeoutDuration()) .isEqualTo(java.time.Duration.ofMillis(10)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java index 4d2fd595fd..6856618914 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java @@ -92,9 +92,9 @@ public void idleTimeoutIsNotLost() { ServerStreamingCallSettings.newBuilder(); builder.setIdleTimeout(idleTimeout); - assertThat(builder.getIdleTimeout()).isEqualTo(idleTimeout); - assertThat(builder.build().getIdleTimeout()).isEqualTo(idleTimeout); - assertThat(builder.build().toBuilder().getIdleTimeout()).isEqualTo(idleTimeout); + assertThat(builder.getIdleTimeoutDuration()).isEqualTo(idleTimeout); + assertThat(builder.build().getIdleTimeoutDuration()).isEqualTo(idleTimeout); + assertThat(builder.build().toBuilder().getIdleTimeoutDuration()).isEqualTo(idleTimeout); } @Test @@ -106,9 +106,9 @@ public void waitTimeoutIsNotLost() { builder.setWaitTimeout(waitTimeout); - assertThat(builder.getWaitTimeout()).isEqualTo(waitTimeout); - assertThat(builder.build().getWaitTimeout()).isEqualTo(waitTimeout); - assertThat(builder.build().toBuilder().getWaitTimeout()).isEqualTo(waitTimeout); + assertThat(builder.getWaitTimeoutDuration()).isEqualTo(waitTimeout); + assertThat(builder.build().getWaitTimeoutDuration()).isEqualTo(waitTimeout); + assertThat(builder.build().toBuilder().getWaitTimeoutDuration()).isEqualTo(waitTimeout); } @Test @@ -130,9 +130,9 @@ public void testRetrySettingsBuilder() { builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); - assertThat(builder.getRetrySettings().getMaxRetryDelay()) + assertThat(builder.getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); - assertThat(builder.build().getRetrySettings().getMaxRetryDelay()) + assertThat(builder.build().getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index 59267d912e..ce810e273e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -50,7 +50,7 @@ public void testSetSimpleTimeoutNoRetries() { assertThat(builder.getRetryableCodes().size()).isEqualTo(0); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); - assertThat(builder.getRetrySettings().getTotalTimeout()) + assertThat(builder.getRetrySettings().getTotalTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(13)); } @@ -129,9 +129,9 @@ public void testRetrySettingsBuilder() { builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); - assertThat(builder.getRetrySettings().getMaxRetryDelay()) + assertThat(builder.getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); - assertThat(builder.build().getRetrySettings().getMaxRetryDelay()) + assertThat(builder.build().getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); } From 521c8fb25547b560bb4adb084cdb00dba8111716 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 16:02:01 -0400 Subject: [PATCH 009/141] chore: fix expected output using Duration in tests --- .../common/RetrySettingsComposerTest.java | 26 +++++++++---------- .../SampleBodyJavaFormatterTest.java | 4 +-- .../SettingsSampleComposerTest.java | 4 +-- .../api/gax/core/RecordingScheduler.java | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java index ecce73d810..ca11ef7004 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java @@ -121,18 +121,18 @@ public void paramDefinitionsBlock_basic() { "settings =" + " RetrySettings.newBuilder().setInitialRetryDelay(" + "Duration.ofMillis(100L)).setRetryDelayMultiplier(2.0)" - + ".setMaxRetryDelayjava.time.Duration.ofMillis(3000L))" - + ".setInitialRpcTimeoutjava.time.Duration.ofMillis(10000L))" + + ".setMaxRetryDelay(java.time.Duration.ofMillis(3000L))" + + ".setInitialRpcTimeout(java.time.Duration.ofMillis(10000L))" + ".setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeoutjava.time.Duration.ofMillis(10000L))" - + ".setTotalTimeoutjava.time.Duration.ofMillis(10000L)).build();\n", + + ".setMaxRpcTimeout(java.time.Duration.ofMillis(10000L))" + + ".setTotalTimeout(java.time.Duration.ofMillis(10000L)).build();\n", "definitions.put(\"retry_policy_1_params\", settings);\n", "settings =" + " RetrySettings.newBuilder()" - + ".setInitialRpcTimeoutjava.time.Duration.ofMillis(5000L))" + + ".setInitialRpcTimeout(java.time.Duration.ofMillis(5000L))" + ".setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeoutjava.time.Duration.ofMillis(5000L))" - + ".setTotalTimeoutjava.time.Duration.ofMillis(5000L)).build();\n", + + ".setMaxRpcTimeout(java.time.Duration.ofMillis(5000L))" + + ".setTotalTimeout(java.time.Duration.ofMillis(5000L)).build();\n", "definitions.put(\"no_retry_0_params\", settings);\n", "RETRY_PARAM_DEFINITIONS = definitions.build();\n", "}\n"); @@ -341,10 +341,10 @@ public void lroBuilderExpr() { + "WaitResponse.class))" + ".setMetadataTransformer(ProtoOperationTransformers.MetadataTransformer.create(" + "WaitMetadata.class)).setPollingAlgorithm(OperationTimedPollAlgorithm.create(" - + "RetrySettings.newBuilder().setInitialRetryDelayjava.time.Duration.ofMillis(5000L))" - + ".setRetryDelayMultiplier(1.5).setMaxRetryDelayjava.time.Duration.ofMillis(45000L))" - + ".setInitialRpcTimeoutjava.time.Duration.ZERO).setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeoutjava.time.Duration.ZERO).setTotalTimeoutjava.time.Duration.ofMillis(300000L))" + + "RetrySettings.newBuilder().setInitialRetryDelay(java.time.Duration.ofMillis(5000L))" + + ".setRetryDelayMultiplier(1.5).setMaxRetryDelay(java.time.Duration.ofMillis(45000L))" + + ".setInitialRpcTimeout(java.time.Duration.ZERO).setRpcTimeoutMultiplier(1.0)" + + ".setMaxRpcTimeout(java.time.Duration.ZERO).setTotalTimeout(java.time.Duration.ofMillis(300000L))" + ".build()))"); assertEquals(expected, writerVisitor.write()); } @@ -394,7 +394,7 @@ public void batchingSettings_minimalFlowControlSettings() { + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(100L)" + ".setRequestByteThreshold(1048576L)" - + ".setDelayThresholdjava.time.Duration.ofMillis(10L))" + + ".setDelayThreshold(java.time.Duration.ofMillis(10L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore)" @@ -451,7 +451,7 @@ public void batchingSettings_fullFlowControlSettings() { + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(1000L)" + ".setRequestByteThreshold(1048576L)" - + ".setDelayThresholdjava.time.Duration.ofMillis(50L))" + + ".setDelayThreshold(java.time.Duration.ofMillis(50L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setMaxOutstandingElementCount(100000L)" diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java index 8c256930fa..5e8376d894 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java @@ -49,7 +49,7 @@ public void validFormatSampleCode_longChainMethod() { String sampleCode = "echoSettingsBuilder.echoSettings().setRetrySettings(" + "echoSettingsBuilder.echoSettings().getRetrySettings().toBuilder()" - + ".setTotalTimeoutjava.time.Duration.ofSeconds(30)).build());"; + + ".setTotalTimeout(java.time.Duration.ofSeconds(30)).build());"; String result = SampleBodyJavaFormatter.format(sampleCode); String expected = LineFormatter.lines( @@ -60,7 +60,7 @@ public void validFormatSampleCode_longChainMethod() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeoutjava.time.Duration.ofSeconds(30))\n", + " .setTotalTimeout(java.time.Duration.ofSeconds(30))\n", " .build());"); assertEquals(expected, result); } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java index 35bbd07cd5..5fd3db1daa 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java @@ -61,7 +61,7 @@ public void composeSettingsSample_serviceSettingsClass() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeoutjava.time.Duration.ofSeconds(30))\n", + " .setTotalTimeout(java.time.Duration.ofSeconds(30))\n", " .build());\n", "EchoSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); @@ -89,7 +89,7 @@ public void composeSettingsSample_serviceStubClass() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeoutjava.time.Duration.ofSeconds(30))\n", + " .setTotalTimeout(java.time.Duration.ofSeconds(30))\n", " .build());\n", "EchoStubSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java b/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java index cb29dda299..d495cf0d63 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/core/RecordingScheduler.java @@ -87,7 +87,7 @@ public List answer(InvocationOnMock invocation) throws Throwable { } }); - // Listjava.time.Duration> getSleepDurations() + // List getSleepDurations() when(mock.getSleepDurations()).thenReturn(sleepDurations); // int getIterationsCount() From 63b882d31cc91b7bb4a2e6b98a8601773abbda7a Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 20 Jul 2023 16:26:10 -0400 Subject: [PATCH 010/141] chore: fix clirr in other projects --- gax-java/gax-grpc/clirr-ignored-differences.xml | 9 +++++++++ gax-java/gax/clirr-ignored-differences.xml | 13 ++++++++++++- .../google-cloud-core/clirr-ignored-differences.xml | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gax-java/gax-grpc/clirr-ignored-differences.xml diff --git a/gax-java/gax-grpc/clirr-ignored-differences.xml b/gax-java/gax-grpc/clirr-ignored-differences.xml new file mode 100644 index 0000000000..5af8ca965a --- /dev/null +++ b/gax-java/gax-grpc/clirr-ignored-differences.xml @@ -0,0 +1,9 @@ + + + + + 7002 + com/google/api/gax/grpc/InstantiatingGrpcChannelProvider$Builder + org.threeten.bp.Duration * + + diff --git a/gax-java/gax/clirr-ignored-differences.xml b/gax-java/gax/clirr-ignored-differences.xml index 6d6662f0cc..4cbcb4f0b9 100644 --- a/gax-java/gax/clirr-ignored-differences.xml +++ b/gax-java/gax/clirr-ignored-differences.xml @@ -42,7 +42,8 @@ 7005 com/google/api/gax/*/* - * *(*java.time.Duration*) + * *(*org.threeten.bp.Duration*) + * 7012 @@ -54,4 +55,14 @@ com/google/api/gax/*/* * *(java.time.Duration) + + 7002 + com/google/api/gax/*/* + *org.threeten.bp.Duration *() + + + 7002 + com/google/api/gax/grpc/InstantiatingGrpcChannelProvider$Builder + * * + diff --git a/java-core/google-cloud-core/clirr-ignored-differences.xml b/java-core/google-cloud-core/clirr-ignored-differences.xml index 0f7f80a7b4..e1bb7bcc78 100644 --- a/java-core/google-cloud-core/clirr-ignored-differences.xml +++ b/java-core/google-cloud-core/clirr-ignored-differences.xml @@ -12,4 +12,10 @@ com/google/cloud/ReadChannel long limit() + + 7005 + com/google/cloud/testing/* + * *(org.threeten.bp.Duration) + * + From 774139aaf1376449b111d5ec86b87edf916f350c Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jul 2023 13:57:04 -0400 Subject: [PATCH 011/141] chore: internal usage of java.time in gax --- .../google/api/gax/grpc/GrpcClientCalls.java | 4 +- .../api/gax/grpc/GrpcCallContextTest.java | 40 ++++----- .../InstantiatingGrpcChannelProviderTest.java | 4 +- .../api/gax/httpjson/HttpJsonClientCalls.java | 4 +- .../gax/httpjson/HttpJsonCallContextTest.java | 20 ++--- .../api/gax/batching/BatchingSettings.java | 9 +-- .../api/gax/retrying/RetrySettings.java | 81 +++++++++---------- .../gax/retrying/TimedAttemptSettings.java | 25 +++--- .../google/api/gax/rpc/ApiCallContext.java | 6 +- .../google/api/gax/rpc/AttemptCallable.java | 2 +- .../com/google/api/gax/rpc/Callables.java | 4 +- .../com/google/api/gax/rpc/ClientContext.java | 13 ++- .../google/api/gax/rpc/ClientSettings.java | 9 +-- .../gax/rpc/ServerStreamingCallSettings.java | 2 +- .../com/google/api/gax/rpc/CallableTest.java | 4 +- 15 files changed, 111 insertions(+), 116 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java index bc72f6f1f1..ad8e05a5b2 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java @@ -74,9 +74,9 @@ public static ClientCall newCall( Preconditions.checkNotNull(callOptions); // Try to convert the timeout into a deadline and use it if it occurs before the actual deadline - if (grpcContext.getTimeout() != null) { + if (grpcContext.getTimeoutDuration() != null) { Deadline newDeadline = - Deadline.after(grpcContext.getTimeout().toMillis(), TimeUnit.MILLISECONDS); + Deadline.after(grpcContext.getTimeoutDuration().toMillis(), TimeUnit.MILLISECONDS); Deadline oldDeadline = callOptions.getDeadline(); if (oldDeadline == null || newDeadline.isBefore(oldDeadline)) { diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index ec0018b85a..711e101bd7 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -129,7 +129,7 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { org.threeten.bp.Duration timeout = null; - assertNull(GrpcCallContext.createDefault().withTimeout(timeout).getTimeout()); + assertNull(GrpcCallContext.createDefault().withTimeout(timeout).getTimeoutDuration()); } @Test @@ -137,13 +137,13 @@ public void testWithNegativeTimeout() { assertNull( GrpcCallContext.createDefault() .withTimeout(java.time.Duration.ofSeconds(-1L)) - .getTimeout()); + .getTimeoutDuration()); } @Test public void testWithZeroTimeout() { assertNull( - GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(0L)).getTimeout()); + GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(0L)).getTimeoutDuration()); } @Test @@ -152,12 +152,12 @@ public void testWithShorterTimeout() { GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); // Sanity check - Truth.assertThat(ctxWithLongTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(10)); + Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(10)); // Shorten the timeout and make sure it changed GrpcCallContext ctxWithShorterTimeout = ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); - Truth.assertThat(ctxWithShorterTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); } @Test @@ -166,12 +166,12 @@ public void testWithLongerTimeout() { GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); // Sanity check - Truth.assertThat(ctxWithShortTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); // Try to extend the timeout and verify that it was ignored GrpcCallContext ctxWithUnchangedTimeout = ctxWithShortTimeout.withTimeout(java.time.Duration.ofSeconds(10)); - Truth.assertThat(ctxWithUnchangedTimeout.getTimeout()) + Truth.assertThat(ctxWithUnchangedTimeout.getTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(5)); } @@ -181,12 +181,12 @@ public void testMergeWithNullTimeout() { GrpcCallContext baseContext = GrpcCallContext.createDefault().withTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); - Truth.assertThat(baseContext.merge(defaultOverlay).getTimeout()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(defaultOverlay).getTimeoutDuration()).isEqualTo(timeout); org.threeten.bp.Duration callContextTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withTimeout(callContextTimeout); - Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeout()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()).isEqualTo(timeout); } @Test @@ -195,14 +195,14 @@ public void testMergeWithTimeout() { GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withTimeout(timeout); - Truth.assertThat(ctx1.merge(ctx2).getTimeout()).isEqualTo(timeout); + Truth.assertThat(ctx1.merge(ctx2).getTimeoutDuration()).isEqualTo(timeout); } @Test public void testWithStreamingWaitTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(15); GrpcCallContext context = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); - Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(timeout); + Truth.assertThat(context.getStreamWaitTimeoutDuration()).isEqualTo(timeout); } @Test @@ -211,12 +211,12 @@ public void testMergeWithNullStreamingWaitTimeout() { GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); - Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeout()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeoutDuration()).isEqualTo(timeout); org.threeten.bp.Duration streamWaitTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withStreamWaitTimeout(streamWaitTimeout); - Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamWaitTimeout()) + Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamWaitTimeoutDuration()) .isEqualTo(timeout); } @@ -224,7 +224,7 @@ public void testMergeWithNullStreamingWaitTimeout() { public void testWithZeroStreamingWaitTimeout() { java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( - GrpcCallContext.createDefault().withStreamWaitTimeout(timeout).getStreamWaitTimeout()) + GrpcCallContext.createDefault().withStreamWaitTimeout(timeout).getStreamWaitTimeoutDuration()) .isEqualTo(timeout); } @@ -234,14 +234,14 @@ public void testMergeWithStreamingWaitTimeout() { GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); - Truth.assertThat(ctx1.merge(ctx2).getStreamWaitTimeout()).isEqualTo(timeout); + Truth.assertThat(ctx1.merge(ctx2).getStreamWaitTimeoutDuration()).isEqualTo(timeout); } @Test public void testWithStreamingIdleTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(15); GrpcCallContext context = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); - Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(timeout); + Truth.assertThat(context.getStreamIdleTimeoutDuration()).isEqualTo(timeout); } @Test @@ -250,12 +250,12 @@ public void testMergeWithNullStreamingIdleTimeout() { GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); - Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeout()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeoutDuration()).isEqualTo(timeout); org.threeten.bp.Duration idleTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withStreamIdleTimeout(idleTimeout); - Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamIdleTimeout()) + Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamIdleTimeoutDuration()) .isEqualTo(timeout); } @@ -263,7 +263,7 @@ public void testMergeWithNullStreamingIdleTimeout() { public void testWithZeroStreamingIdleTimeout() { java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( - GrpcCallContext.createDefault().withStreamIdleTimeout(timeout).getStreamIdleTimeout()) + GrpcCallContext.createDefault().withStreamIdleTimeout(timeout).getStreamIdleTimeoutDuration()) .isEqualTo(timeout); } @@ -273,7 +273,7 @@ public void testMergeWithStreamingIdleTimeout() { GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); - Truth.assertThat(ctx1.merge(ctx2).getStreamIdleTimeout()).isEqualTo(timeout); + Truth.assertThat(ctx1.merge(ctx2).getStreamIdleTimeoutDuration()).isEqualTo(timeout); } @Test diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index fcab281538..3b2ac56733 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -101,8 +101,8 @@ public void testKeepAlive() { .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); - assertEquals(provider.getKeepAliveTime(), keepaliveTime); - assertEquals(provider.getKeepAliveTimeout(), keepaliveTimeout); + assertEquals(provider.getKeepAliveTimeDuration(), keepaliveTime); + assertEquals(provider.getKeepAliveTimeoutDuration(), keepaliveTimeout); assertEquals(provider.getKeepAliveWithoutCalls(), keepaliveWithoutCalls); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index 8fb26065f0..507b593a57 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -51,7 +51,7 @@ public static HttpJsonClientCall newC // Use the context's timeout instead of calculating a future deadline with the System clock. // The timeout value is calculated from TimedAttemptSettings which accounts for the // TotalTimeout value set in the RetrySettings. - if (httpJsonContext.getTimeout() != null) { + if (httpJsonContext.getTimeoutDuration() != null) { HttpJsonCallOptions callOptions = httpJsonContext.getCallOptions(); // HttpJsonChannel expects the HttpJsonCallOptions and we store the timeout duration // inside the HttpJsonCallOptions @@ -65,7 +65,7 @@ public static HttpJsonClientCall newC callOptions = callOptions .toBuilder() - .setTimeout(java.time.Duration.ofMillis(httpJsonContext.getTimeout().toMillis())) + .setTimeout(java.time.Duration.ofMillis(httpJsonContext.getTimeoutDuration().toMillis())) .build(); } httpJsonContext = httpJsonContext.withCallOptions(callOptions); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index a06d439040..3f488fa783 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -117,7 +117,7 @@ public void testMergeWrongType() { @Test public void testWithTimeout() { org.threeten.bp.Duration timeout = null; - assertNull(HttpJsonCallContext.createDefault().withTimeout(timeout).getTimeout()); + assertNull(HttpJsonCallContext.createDefault().withTimeout(timeout).getTimeoutDuration()); } @Test @@ -125,7 +125,7 @@ public void testWithNegativeTimeout() { assertNull( HttpJsonCallContext.createDefault() .withTimeout(java.time.Duration.ofSeconds(-1L)) - .getTimeout()); + .getTimeoutDuration()); } @Test @@ -133,7 +133,7 @@ public void testWithZeroTimeout() { assertNull( HttpJsonCallContext.createDefault() .withTimeout(java.time.Duration.ofSeconds(0L)) - .getTimeout()); + .getTimeoutDuration()); } @Test @@ -142,12 +142,12 @@ public void testWithShorterTimeout() { HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); // Sanity check - Truth.assertThat(ctxWithLongTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(10)); + Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(10)); // Shorten the timeout and make sure it changed HttpJsonCallContext ctxWithShorterTimeout = ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); - Truth.assertThat(ctxWithShorterTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); } @Test @@ -156,12 +156,12 @@ public void testWithLongerTimeout() { HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); // Sanity check - Truth.assertThat(ctxWithShortTimeout.getTimeout()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); // Try to extend the timeout and verify that it was ignored HttpJsonCallContext ctxWithUnchangedTimeout = ctxWithShortTimeout.withTimeout(java.time.Duration.ofSeconds(10)); - Truth.assertThat(ctxWithUnchangedTimeout.getTimeout()) + Truth.assertThat(ctxWithUnchangedTimeout.getTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(5)); } @@ -171,12 +171,12 @@ public void testMergeWithNullTimeout() { HttpJsonCallContext baseContext = HttpJsonCallContext.createDefault().withTimeout(timeout); HttpJsonCallContext defaultOverlay = HttpJsonCallContext.createDefault(); - Truth.assertThat(baseContext.merge(defaultOverlay).getTimeout()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(defaultOverlay).getTimeoutDuration()).isEqualTo(timeout); org.threeten.bp.Duration callContextTimeout = null; HttpJsonCallContext explicitNullOverlay = HttpJsonCallContext.createDefault().withTimeout(callContextTimeout); - Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeout()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()).isEqualTo(timeout); } @Test @@ -185,7 +185,7 @@ public void testMergeWithTimeout() { HttpJsonCallContext ctx1 = HttpJsonCallContext.createDefault(); HttpJsonCallContext ctx2 = HttpJsonCallContext.createDefault().withTimeout(timeout); - Truth.assertThat(ctx1.merge(ctx2).getTimeout()).isEqualTo(timeout); + Truth.assertThat(ctx1.merge(ctx2).getTimeoutDuration()).isEqualTo(timeout); } @Test diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 096d010e67..652577e808 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -30,7 +30,6 @@ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.auto.value.AutoValue; @@ -102,13 +101,13 @@ public abstract class BatchingSettings { /** Get the delay threshold to use for batching. */ @Nullable - public final org.threeten.bp.Duration getDelayThreshold() { - return toThreetenDuration(getDelayThresholdDuration()); - } + public abstract org.threeten.bp.Duration getDelayThreshold(); /** Get the delay threshold to use for batching. */ @Nullable - public abstract java.time.Duration getDelayThresholdDuration(); + public final java.time.Duration getDelayThresholdDuration() { + return toJavaTimeDuration(getDelayThreshold()); + } /** Returns the Boolean object to indicate if the batching is enabled. Default to true */ public abstract Boolean getIsEnabled(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 8dae4af941..9aaaa4da5d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -30,7 +30,6 @@ package com.google.api.gax.retrying; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.BetaApi; import com.google.auto.value.AutoValue; @@ -75,28 +74,28 @@ public abstract class RetrySettings implements Serializable { private static final long serialVersionUID = 8258475264439710899L; /** Backport of {@link #getTotalTimeoutDuration()} */ - public final org.threeten.bp.Duration getTotalTimeout() { - return toThreetenDuration(getTotalTimeoutDuration()); - } + public abstract org.threeten.bp.Duration getTotalTimeout(); /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call * until it gives up completely. The higher the total timeout, the more retries can be attempted. * The default value is {@code Duration.ZERO}. */ - public abstract java.time.Duration getTotalTimeoutDuration(); + public final java.time.Duration getTotalTimeoutDuration() { + return toJavaTimeDuration(getTotalTimeout()); + } /** Backport of {@link #getInitialRetryDelayDuration()} */ - public final org.threeten.bp.Duration getInitialRetryDelay() { - return toThreetenDuration(getInitialRetryDelayDuration()); - } + public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getInitialRetryDelayDuration(); + public final java.time.Duration getInitialRetryDelayDuration() { + return toJavaTimeDuration(getInitialRetryDelay()); + } /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -106,16 +105,16 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { public abstract double getRetryDelayMultiplier(); /** Backport of {@link #getMaxRetryDelayDuration()} */ - public final org.threeten.bp.Duration getMaxRetryDelay() { - return toThreetenDuration(getMaxRetryDelayDuration()); - } + public abstract org.threeten.bp.Duration getMaxRetryDelay(); /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getMaxRetryDelayDuration(); + public final java.time.Duration getMaxRetryDelayDuration() { + return toJavaTimeDuration(getMaxRetryDelay()); + } /** * MaxAttempts defines the maximum number of attempts to perform. The default value is {@code 0}. @@ -139,16 +138,16 @@ public final org.threeten.bp.Duration getMaxRetryDelay() { public abstract boolean isJittered(); /** Backport of {@link #getInitialRpcTimeoutDuration()} */ - public final org.threeten.bp.Duration getInitialRpcTimeout() { - return toThreetenDuration(getInitialRpcTimeoutDuration()); - } + public abstract org.threeten.bp.Duration getInitialRpcTimeout(); /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getInitialRpcTimeoutDuration(); + public final java.time.Duration getInitialRpcTimeoutDuration() { + return toJavaTimeDuration(getInitialRpcTimeout()); + } /** * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is @@ -158,16 +157,16 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { public abstract double getRpcTimeoutMultiplier(); /** Backport of {@link #getMaxRpcTimeoutDuration()} */ - public final org.threeten.bp.Duration getMaxRpcTimeout() { - return toThreetenDuration(getMaxRpcTimeoutDuration()); - } + public abstract org.threeten.bp.Duration getMaxRpcTimeout(); /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier * can't increase the RPC timeout higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getMaxRpcTimeoutDuration(); + public final java.time.Duration getMaxRpcTimeoutDuration() { + return toJavaTimeDuration(getMaxRpcTimeout()); + } public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() @@ -341,28 +340,28 @@ public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { abstract Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout); /** Backport of {@link #getTotalTimeoutDuration()} */ - public final org.threeten.bp.Duration getTotalTimeout() { - return toThreetenDuration(getTotalTimeoutDuration()); - } + public abstract org.threeten.bp.Duration getTotalTimeout(); /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call * until it gives up completely. The higher the total timeout, the more retries can be * attempted. The default value is {@code Duration.ZERO}. */ - public abstract java.time.Duration getTotalTimeoutDuration(); + public final java.time.Duration getTotalTimeoutDuration() { + return toJavaTimeDuration(getTotalTimeout()); + } /** Backport of {@link #getInitialRetryDelay()} */ - public final org.threeten.bp.Duration getInitialRetryDelay() { - return toThreetenDuration(getInitialRetryDelayDuration()); - } + public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getInitialRetryDelayDuration(); + public final java.time.Duration getInitialRetryDelayDuration() { + return toJavaTimeDuration(getInitialRetryDelay()); + } /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -389,28 +388,28 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { public abstract boolean isJittered(); /** Backport of {@link #getMaxRetryDelayDuration()} */ - public final org.threeten.bp.Duration getMaxRetryDelay() { - return toThreetenDuration(getMaxRetryDelayDuration()); - } + public abstract org.threeten.bp.Duration getMaxRetryDelay(); /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getMaxRetryDelayDuration(); + public final java.time.Duration getMaxRetryDelayDuration() { + return toJavaTimeDuration(getMaxRetryDelay()); + } /** Backport of {@link #getInitialRpcTimeoutDuration()} */ - public final org.threeten.bp.Duration getInitialRpcTimeout() { - return toThreetenDuration((getInitialRpcTimeoutDuration())); - } + public abstract org.threeten.bp.Duration getInitialRpcTimeout(); /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract java.time.Duration getInitialRpcTimeoutDuration(); + public final java.time.Duration getInitialRpcTimeoutDuration() { + return toJavaTimeDuration(getInitialRpcTimeout()); + } /** * See the class documentation of {@link RetrySettings} for a description of what this value @@ -419,15 +418,15 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { public abstract double getRpcTimeoutMultiplier(); /** Backport of {@link #getMaxRpcTimeoutDuration()} */ - public final org.threeten.bp.Duration getMaxRpcTimeout() { - return toThreetenDuration((getMaxRpcTimeoutDuration())); - } + public abstract org.threeten.bp.Duration getMaxRpcTimeout(); /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier * can't increase the RPC timeout higher than this amount. */ - public abstract java.time.Duration getMaxRpcTimeoutDuration(); + public final java.time.Duration getMaxRpcTimeoutDuration() { + return toJavaTimeDuration(getMaxRpcTimeout()); + } /** * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index cf7dd64ce4..d974bdde1a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -30,7 +30,6 @@ package com.google.api.gax.retrying; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.ApiClock; import com.google.auto.value.AutoValue; @@ -43,34 +42,34 @@ public abstract class TimedAttemptSettings { public abstract RetrySettings getGlobalSettings(); /** Backport of {@link #getRetryDelayDuration()} */ - public final org.threeten.bp.Duration getRetryDelay() { - return toThreetenDuration(getRetryDelayDuration()); - } + public abstract org.threeten.bp.Duration getRetryDelay(); /** * Returns the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public abstract java.time.Duration getRetryDelayDuration(); + public final java.time.Duration getRetryDelayDuration() { + return toJavaTimeDuration(getRetryDelay()); + } /** Backport of {@link #getRpcTimeoutDuration()} */ - public final org.threeten.bp.Duration getRpcTimeout() { - return toThreetenDuration(getRpcTimeoutDuration()); - } + public abstract org.threeten.bp.Duration getRpcTimeout(); /** Returns rpc timeout used for this attempt. */ - public abstract java.time.Duration getRpcTimeoutDuration(); + public final java.time.Duration getRpcTimeoutDuration() { + return toJavaTimeDuration(getRpcTimeout()); + } /** Backport of {@link #getRandomizedRetryDelayDuration()} */ - public final org.threeten.bp.Duration getRandomizedRetryDelay() { - return toThreetenDuration(getRandomizedRetryDelayDuration()); - } + public abstract org.threeten.bp.Duration getRandomizedRetryDelay(); /** * Returns randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public abstract java.time.Duration getRandomizedRetryDelayDuration(); + public final java.time.Duration getRandomizedRetryDelayDuration() { + return toJavaTimeDuration(getRandomizedRetryDelay()); + } /** * The attempt count. It is a zero-based value (first attempt will have this value set to 0). For diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index ac2e60a075..0351419071 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -109,7 +109,7 @@ public interface ApiCallContext extends RetryingContext { * value will use the default in the callable. * *

Please note that this timeout is best effort and the maximum resolution is configured in - * {@link StubSettings#getStreamWatchdogCheckInterval()}. + * {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. */ ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout); @@ -138,7 +138,7 @@ public interface ApiCallContext extends RetryingContext { * amount of timeout that can pass between a message being received by {@link * ResponseObserver#onResponse(Object)} and demand being signaled via {@link * StreamController#request(int)}. Please note that this timeout is best effort and the maximum - * resolution configured in {@link StubSettings#getStreamWatchdogCheckInterval()}. This is useful + * resolution configured in {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. This is useful * to clean up streams that were partially read but never closed. When the timeout has been * reached, the stream will be closed with a nonretryable {@link WatchdogTimeoutException} and a * status of {@link StatusCode.Code#ABORTED}. @@ -147,7 +147,7 @@ public interface ApiCallContext extends RetryingContext { * value will use the default in the callable. * *

Please note that this timeout is best effort and the maximum resolution is configured in - * {@link StubSettings#getStreamWatchdogCheckInterval()}. + * {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. */ ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java index 10a68117c0..d34aaddb05 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java @@ -70,7 +70,7 @@ public ResponseT call() { try { // Set the RPC timeout if the caller did not provide their own. java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); - if (!rpcTimeout.isZero() && callContext.getTimeout() == null) { + if (!rpcTimeout.isZero() && callContext.getTimeoutDuration() == null) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 3cab37fee2..8099544fa9 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -115,8 +115,8 @@ public static ServerStreamingCallable callable.withDefaultCallContext( clientContext .getDefaultCallContext() - .withStreamIdleTimeout(callSettings.getIdleTimeout()) - .withStreamWaitTimeout(callSettings.getWaitTimeout())); + .withStreamIdleTimeout(callSettings.getIdleTimeoutDuration()) + .withStreamWaitTimeout(callSettings.getWaitTimeoutDuration())); return callable; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 445750e0b4..24a7c6fadd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -30,7 +30,6 @@ package com.google.api.gax.rpc; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.client.util.Strings; import com.google.api.core.ApiClock; @@ -106,12 +105,12 @@ public abstract class ClientContext { * @return */ @Nonnull - public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { - return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); - } + public abstract org.threeten.bp.Duration getStreamWatchdogCheckInterval(); @Nonnull - public abstract java.time.Duration getStreamWatchdogCheckIntervalDuration(); + public final java.time.Duration getStreamWatchdogCheckIntervalDuration() { + return toJavaTimeDuration(getStreamWatchdogCheckInterval()); + } @Nullable public abstract String getEndpoint(); @@ -259,7 +258,7 @@ public static ClientContext create(StubSettings settings) throws IOException { if (watchdogProvider != null) { if (watchdogProvider.needsCheckInterval()) { watchdogProvider = - watchdogProvider.withCheckInterval(settings.getStreamWatchdogCheckInterval()); + watchdogProvider.withCheckInterval(settings.getStreamWatchdogCheckIntervalDuration()); } if (watchdogProvider.needsClock()) { watchdogProvider = watchdogProvider.withClock(clock); @@ -294,7 +293,7 @@ public static ClientContext create(StubSettings settings) throws IOException { .setEndpoint(settings.getEndpoint()) .setQuotaProjectId(settings.getQuotaProjectId()) .setStreamWatchdog(watchdog) - .setStreamWatchdogCheckInterval(settings.getStreamWatchdogCheckInterval()) + .setStreamWatchdogCheckInterval(settings.getStreamWatchdogCheckIntervalDuration()) .setTracerFactory(settings.getTracerFactory()) .build(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 3d57df8a1b..88c2799539 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -30,7 +30,6 @@ package com.google.api.gax.rpc; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; @@ -115,12 +114,12 @@ public final WatchdogProvider getWatchdogProvider() { */ @Nonnull public final org.threeten.bp.Duration getWatchdogCheckInterval() { - return toThreetenDuration(getWatchdogCheckIntervalDuration()); + return stubSettings.getStreamWatchdogCheckInterval(); } @Nonnull public final java.time.Duration getWatchdogCheckIntervalDuration() { - return stubSettings.getStreamWatchdogCheckIntervalDuration(); + return toJavaTimeDuration(getWatchdogCheckInterval()); } /** Gets the GDCH API audience that was previously set in this Builder */ @@ -353,12 +352,12 @@ public WatchdogProvider getWatchdogProvider() { @Nullable public org.threeten.bp.Duration getWatchdogCheckInterval() { - return toThreetenDuration(getWatchdogCheckIntervalDuration()); + return stubSettings.getStreamWatchdogCheckInterval(); } @Nullable public java.time.Duration getWatchdogCheckIntervalDuration() { - return stubSettings.getStreamWatchdogCheckIntervalDuration(); + return toJavaTimeDuration(getWatchdogCheckInterval()); } /** Gets the GDCH API audience that was previously set in this Builder */ diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 07460ad447..1d460b8d5d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -69,7 +69,7 @@ *

  • RPC timeouts apply to the time interval between caller demanding more responses via {@link * StreamController#request(int)} and the {@link ResponseObserver} receiving the message. *
  • RPC timeouts are best effort and are checked once every {@link - * StubSettings#getStreamWatchdogCheckInterval()}. + * StubSettings#getStreamWatchdogCheckIntervalDuration()}. *
  • Attempt counts are reset as soon as a response is received. This means that max attempts is * the maximum number of failures in a row. *
  • totalTimeout still applies to the entire stream. diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 931cca682b..c15d13f22f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -86,7 +86,7 @@ public void testNonRetriedCallable() throws Exception { callable.futureCall("Is your refrigerator running?", callContext); verify(callContext, atLeastOnce()).getRetrySettings(); - verify(callContext).getTimeout(); + verify(callContext).getTimeoutDuration(); verify(callContext).withTimeout(timeout); } @@ -108,7 +108,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { callable.futureCall("Is your refrigerator running?", callContextWithRetrySettings); verify(callContextWithRetrySettings, atLeastOnce()).getRetrySettings(); - verify(callContextWithRetrySettings).getTimeout(); + verify(callContextWithRetrySettings).getTimeoutDuration(); verify(callContextWithRetrySettings).withTimeout(timeout); } From 0be22ab0373c2c70f841ee8e40ed14bf359a2cf5 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jul 2023 17:30:46 -0400 Subject: [PATCH 012/141] chore: adapt builder of `retrying` --- .../stub/OperationsStubSettings.java | 10 +- .../api/gax/grpc/GrpcCallableFactoryTest.java | 4 +- .../grpc/GrpcDirectStreamControllerTest.java | 10 +- .../api/gax/grpc/GrpcLongRunningTest.java | 10 +- .../com/google/api/gax/grpc/SettingsTest.java | 18 +-- .../com/google/api/gax/grpc/TimeoutTest.java | 20 +-- .../stub/OperationsStubSettings.java | 10 +- .../google/api/gax/httpjson/RetryingTest.java | 14 +-- .../api/gax/batching/BatchingSettings.java | 20 ++- .../api/gax/batching/ThresholdBatcher.java | 3 +- .../retrying/ExponentialRetryAlgorithm.java | 32 ++--- .../api/gax/retrying/RetrySettings.java | 116 ++++++------------ .../gax/retrying/TimedAttemptSettings.java | 55 +++------ .../google/api/gax/rpc/AttemptCallable.java | 2 +- .../com/google/api/gax/rpc/Callables.java | 2 +- .../api/gax/rpc/CheckingAttemptCallable.java | 2 +- .../rpc/ServerStreamingAttemptCallable.java | 2 +- .../gax/rpc/ServerStreamingCallSettings.java | 30 ++--- .../google/api/gax/rpc/UnaryCallSettings.java | 2 +- .../batching/BatchingCallSettingsTest.java | 4 +- .../AbstractRetryingExecutorTest.java | 6 +- .../ExponentialRetryAlgorithmTest.java | 62 +++++----- .../api/gax/retrying/FailingCallable.java | 20 +-- .../api/gax/retrying/RetrySettingsTest.java | 12 +- .../ScheduledRetryingExecutorTest.java | 24 ++-- .../api/gax/rpc/AttemptCallableTest.java | 6 +- .../com/google/api/gax/rpc/BatchingTest.java | 8 +- .../com/google/api/gax/rpc/CallableTest.java | 18 +-- .../google/api/gax/rpc/CancellationTest.java | 20 +-- .../gax/rpc/CheckingAttemptCallableTest.java | 6 +- .../gax/rpc/OperationCallableImplTest.java | 46 +++---- .../com/google/api/gax/rpc/RetryingTest.java | 28 ++--- .../ServerStreamingAttemptCallableTest.java | 18 +-- .../gax/rpc/StreamingRetryAlgorithmTest.java | 20 +-- .../api/gax/rpc/UnaryCallSettingsTest.java | 6 +- .../api/gax/tracing/TracedCallableTest.java | 2 +- .../java/com/google/cloud/RetryOption.java | 6 +- .../com/google/cloud/RetryOptionTest.java | 24 ++-- 38 files changed, 314 insertions(+), 384 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java index 853242eedd..f5d40becd2 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java @@ -242,13 +242,13 @@ public static class Builder extends StubSettings.BuildernewBuilder() .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofSeconds(1)) + .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); @@ -122,7 +122,7 @@ public void createServerStreamingCallableRetryableExceptions() { .setRetryableCodes(Code.INVALID_ARGUMENT) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofSeconds(1)) + .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java index 082b2a15ef..ad2bc95169 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java @@ -100,11 +100,11 @@ public boolean canResume() { .setRetryableCodes(StatusCode.Code.DEADLINE_EXCEEDED) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofMinutes(1)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(1)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(1)) - .setInitialRetryDelay(java.time.Duration.ofMillis(1)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1)) + .setTotalTimeout(org.threeten.bp.Duration.ofMinutes(1)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(1)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(1)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1)) .build()) .build(); // Store a list of resources to manually close at the end of the test diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java index 07d8af8272..8be1b6e51b 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java @@ -74,15 +74,15 @@ public class GrpcLongRunningTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(1L)) .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(1L)) - .setTotalTimeout(java.time.Duration.ofMillis(5L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(1L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(5L)) .build(); private ManagedChannel channel; diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index 514838de88..d07fdcfeb5 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -111,13 +111,13 @@ private static class FakeStubSettings extends StubSettings { RetrySettings settings = null; settings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(100L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100L)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(java.time.Duration.ofMillis(1000L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1000L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2000L)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(java.time.Duration.ofMillis(30000L)) - .setTotalTimeout(java.time.Duration.ofMillis(45000L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(30000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(45000L)) .build(); definitions.put("default", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -223,7 +223,7 @@ private static Builder createDefault() { BatchingSettings.newBuilder() .setElementCountThreshold(800L) .setRequestByteThreshold(8388608L) - .setDelayThreshold(java.time.Duration.ofMillis(100)) + .setDelayThreshold(org.threeten.bp.Duration.ofMillis(100)) .build()); builder .fakeMethodBatching() @@ -336,7 +336,7 @@ public void unaryCallSettingsBuilderBuildDoesNotFailUnsetProperties() { @Test public void callSettingsBuildFromTimeoutNoRetries() { - java.time.Duration timeout = java.time.Duration.ofMillis(60000); + org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(60000); UnaryCallSettings.Builder builderA = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -350,9 +350,9 @@ public void callSettingsBuildFromTimeoutNoRetries() { .setRetrySettings( RetrySettings.newBuilder() .setTotalTimeout(timeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) .setInitialRpcTimeout(timeout) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(timeout) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java index 01245cf9a1..9ab74005de 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java @@ -73,12 +73,12 @@ public class TimeoutTest { private static final ImmutableSet emptyRetryCodes = ImmutableSet.of(); private static final ImmutableSet retryUnknownCode = ImmutableSet.of(StatusCode.Code.UNKNOWN); - private static final java.time.Duration totalTimeout = - java.time.Duration.ofDays(DEADLINE_IN_DAYS); - private static final java.time.Duration maxRpcTimeout = - java.time.Duration.ofMinutes(DEADLINE_IN_MINUTES); - private static final java.time.Duration initialRpcTimeout = - java.time.Duration.ofSeconds(DEADLINE_IN_SECONDS); + private static final org.threeten.bp.Duration totalTimeout = + org.threeten.bp.Duration.ofDays(DEADLINE_IN_DAYS); + private static final org.threeten.bp.Duration maxRpcTimeout = + org.threeten.bp.Duration.ofMinutes(DEADLINE_IN_MINUTES); + private static final org.threeten.bp.Duration initialRpcTimeout = + org.threeten.bp.Duration.ofSeconds(DEADLINE_IN_SECONDS); private static final GrpcCallContext defaultCallContext = GrpcCallContext.createDefault(); @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); @@ -91,9 +91,9 @@ public void testNonRetryUnarySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) @@ -117,9 +117,9 @@ public void testNonRetryUnarySettingsContextWithRetry() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java index b47755b714..323ef13e64 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java @@ -292,13 +292,13 @@ public static class Builder extends StubSettings.Builder callSettings = createSettings(retryable, retrySettings); UnaryCallable callable = diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 652577e808..c3f7ed121f 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -30,10 +30,12 @@ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; + import javax.annotation.Nullable; /** @@ -149,21 +151,11 @@ public abstract static class Builder { */ public abstract Builder setRequestByteThreshold(Long requestByteThreshold); - /** - * Overload of {@link #setDelayThresholdDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) { - return setDelayThresholdDuration(toJavaTimeDuration(delayThreshold)); - } /** - * Overload of {@link #setDelayThresholdDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} This is a convenience public method to keep name conformity + * Backport of {@link #setDelayThreshold(java.time.Duration)} */ - public final Builder setDelayThreshold(java.time.Duration delayThreshold) { - return setDelayThresholdDuration(delayThreshold); - } + public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); /** * Set the delay threshold to use for batching. After this amount of time has elapsed (counting @@ -171,7 +163,9 @@ public final Builder setDelayThreshold(java.time.Duration delayThreshold) { * value should not be set too high, usually on the order of milliseconds. Otherwise, calls * might appear to never complete. */ - public abstract Builder setDelayThresholdDuration(java.time.Duration delayThreshold); + public final Builder setDelayThreshold(java.time.Duration delayThreshold) { + return setDelayThreshold(toThreetenDuration(delayThreshold)); + } /** * Set if the batch should be enabled. If set to false, the batch logic will be disabled and the diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index b2d8788851..3e4d6cc2a8 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -125,8 +125,7 @@ public Builder setMaxDelay(java.time.Duration maxDelay) { /** Set the max delay for a batch. This is counted from the first item added to a batch. */ public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { - this.maxDelay = toJavaTimeDuration(maxDelay); - return this; + return setMaxDelay(toJavaTimeDuration(maxDelay)); } /** Set the thresholds for the ThresholdBatcher. */ diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index 8d54579e8e..23ee616bba 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -33,6 +33,8 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; +import org.threeten.bp.Duration; + import java.util.concurrent.ThreadLocalRandom; /** @@ -68,9 +70,9 @@ public ExponentialRetryAlgorithm(RetrySettings globalSettings, ApiClock clock) { public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) - .setRetryDelay(java.time.Duration.ZERO) + .setRetryDelay(Duration.ZERO) .setRpcTimeout(globalSettings.getInitialRpcTimeout()) - .setRandomizedRetryDelay(java.time.Duration.ZERO) + .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -98,8 +100,8 @@ public TimedAttemptSettings createFirstAttempt(RetryingContext context) { // retrySettings, but a new call will not (unless overridden again). .setGlobalSettings(retrySettings) .setRpcTimeout(retrySettings.getInitialRpcTimeout()) - .setRetryDelay(java.time.Duration.ZERO) - .setRandomizedRetryDelay(java.time.Duration.ZERO) + .setRetryDelay(Duration.ZERO) + .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -129,7 +131,7 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti (long) (settings.getRetryDelayMultiplier() * previousSettings.getRetryDelay().toMillis()); newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis()); } - java.time.Duration randomDelay = java.time.Duration.ofMillis(nextRandomLong(newRetryDelay)); + org.threeten.bp.Duration randomDelay = org.threeten.bp.Duration.ofMillis(nextRandomLong(newRetryDelay)); // The rpc timeout is determined as follows: // attempt #0 - use the initialRpcTimeout; @@ -143,11 +145,11 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti // If set, calculate time remaining in the totalTimeout since the start, taking into account the // next attempt's delay, in order to truncate the RPC timeout should it exceed the totalTimeout. if (!settings.getTotalTimeout().isZero()) { - java.time.Duration timeElapsed = - java.time.Duration.ofNanos(clock.nanoTime()) - .minus(java.time.Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); - java.time.Duration timeLeft = - settings.getTotalTimeoutDuration().minus(timeElapsed).minus(randomDelay); + org.threeten.bp.Duration timeElapsed = + org.threeten.bp.Duration.ofNanos(clock.nanoTime()) + .minus(org.threeten.bp.Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); + org.threeten.bp.Duration timeLeft = + settings.getTotalTimeout().minus(timeElapsed).minus(randomDelay); // If timeLeft at this point is < 0, the shouldRetry logic will prevent // the attempt from being made as it would exceed the totalTimeout. A negative RPC timeout @@ -158,8 +160,8 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti return TimedAttemptSettings.newBuilder() .setGlobalSettings(previousSettings.getGlobalSettings()) - .setRetryDelay(java.time.Duration.ofMillis(newRetryDelay)) - .setRpcTimeout(java.time.Duration.ofMillis(newRpcTimeout)) + .setRetryDelay(Duration.ofMillis(newRetryDelay)) + .setRpcTimeout(Duration.ofMillis(newRpcTimeout)) .setRandomizedRetryDelay(randomDelay) .setAttemptCount(previousSettings.getAttemptCount() + 1) .setOverallAttemptCount(previousSettings.getOverallAttemptCount() + 1) @@ -198,7 +200,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { RetrySettings globalSettings = nextAttemptSettings.getGlobalSettings(); int maxAttempts = globalSettings.getMaxAttempts(); - java.time.Duration totalTimeout = globalSettings.getTotalTimeoutDuration(); + org.threeten.bp.Duration totalTimeout = globalSettings.getTotalTimeout(); // If total timeout and maxAttempts is not set then do not attempt retry. if (totalTimeout.isZero() && maxAttempts == 0) { @@ -210,8 +212,8 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { - nextAttemptSettings.getFirstAttemptStartTimeNanos() + nextAttemptSettings.getRandomizedRetryDelay().toNanos(); - java.time.Duration timeLeft = - totalTimeout.minus(java.time.Duration.ofNanos(totalTimeSpentNanos)); + org.threeten.bp.Duration timeLeft = + totalTimeout.minus(org.threeten.bp.Duration.ofNanos(totalTimeSpentNanos)); // Convert time spent to milliseconds to standardize the units being used for // retries. Otherwise, we would be using nanoseconds to determine if retries // should be attempted and milliseconds for retry delays and rpc timeouts diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 9aaaa4da5d..50030b6735 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -30,10 +30,12 @@ package com.google.api.gax.retrying; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.BetaApi; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; + import java.io.Serializable; /** @@ -170,15 +172,15 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() - .setTotalTimeout(java.time.Duration.ZERO) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeout(org.threeten.bp.Duration.ZERO) + .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) .setMaxAttempts(0) .setJittered(true) - .setInitialRpcTimeout(java.time.Duration.ZERO) + .setInitialRpcTimeout(org.threeten.bp.Duration.ZERO) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(java.time.Duration.ZERO); + .setMaxRpcTimeout(org.threeten.bp.Duration.ZERO); } public abstract Builder toBuilder(); @@ -191,50 +193,32 @@ public static Builder newBuilder() { public abstract static class Builder { /** - * Overload of {@link #setTotalTimeout(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * Backport of {@link #setTotalTimeout(java.time.Duration)} */ - public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { - return setTotalTimeoutDuration(toJavaTimeDuration(totalTimeout)); - } - - /** - * Overload of {@link #setTotalTimeout(java.time.Duration)} using {@link - * org.threeten.bp.Duration} This is a convenience public method to keep name conformity - */ - public final Builder setTotalTimeout(java.time.Duration totalTimeout) { - return setTotalTimeoutDuration(totalTimeout); - } + public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call * until it gives up completely. The higher the total timeout, the more retries can be * attempted. The default value is {@code Duration.ZERO}. */ - public abstract Builder setTotalTimeoutDuration(java.time.Duration totalTimeout); - - /** - * Overload of {@link #setInitialRetryDelay(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { - return setInitialRetryDelay(toJavaTimeDuration(initialDelay)); + public final Builder setTotalTimeout(java.time.Duration totalTimeout) { + return setTotalTimeout(toThreetenDuration(totalTimeout)); } /** - * Overload of {@link #setInitialRetryDelay(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * Backport of {@link #setInitialRetryDelay(java.time.Duration)} */ - public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { - return setInitialRetryDelayDuration(initialDelay); - } + public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); /** * InitialRetryDelay controls the delay before the first retry. Subsequent retries will use this * value adjusted according to the RetryDelayMultiplier. The default value is {@code * Duration.ZERO}. */ - public abstract Builder setInitialRetryDelayDuration(java.time.Duration initialDelay); + public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { + return setInitialRetryDelay(toThreetenDuration(initialDelay)); + } /** * RetryDelayMultiplier controls the change in retry delay. The retry delay of the previous call @@ -244,27 +228,18 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { public abstract Builder setRetryDelayMultiplier(double multiplier); /** - * Overload of {@link #setMaxRetryDelayDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { - return setMaxRetryDelayDuration(toJavaTimeDuration(maxDelay)); - } - - /** - * Overload of {@link #setMaxRetryDelayDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * Backport of {@link #setMaxRetryDelay(java.time.Duration)} */ - public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { - return setMaxRetryDelayDuration(maxDelay); - } + public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier * can't increase the retry delay higher than this amount. The default value is {@code * Duration.ZERO}. */ - abstract Builder setMaxRetryDelayDuration(java.time.Duration maxDelay); + public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { + return setMaxRetryDelay(toThreetenDuration(maxDelay)); + } /** * MaxAttempts defines the maximum number of attempts to perform. The default value is {@code @@ -288,27 +263,18 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { public abstract Builder setJittered(boolean jittered); /** - * Overload of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * Backport of {@link #setInitialRpcTimeout(java.time.Duration)} */ - public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { - return setInitialRpcTimeoutDuration(toJavaTimeDuration(initialTimeout)); - } - - /** - * Overload of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { - return setInitialRpcTimeoutDuration(initialTimeout); - } + public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this * value adjusted according to the RpcTimeoutMultiplier. The default value is {@code * Duration.ZERO}. */ - abstract Builder setInitialRpcTimeoutDuration(java.time.Duration initialTimeout); + public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { + return setInitialRpcTimeout(toThreetenDuration(initialTimeout)); + } /** * See the class documentation of {@link RetrySettings} for a description of what this value @@ -317,27 +283,19 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { public abstract Builder setRpcTimeoutMultiplier(double multiplier); /** - * Overload of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { - return setMaxRpcTimeoutDuration(toJavaTimeDuration(maxTimeout)); - } - - /** - * Overload of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} using {@link - * java.time.Duration} This is a convenience public method to keep name conformity + * Backport of {@link #setMaxRpcTimeout(java.time.Duration)} */ - public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { - return setMaxRpcTimeoutDuration(maxTimeout); - } + public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier * can't increase the RPC timeout higher than this amount. The default value is {@code * Duration.ZERO}. */ - abstract Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout); + public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { + return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); + } + /** Backport of {@link #getTotalTimeoutDuration()} */ public abstract org.threeten.bp.Duration getTotalTimeout(); @@ -434,7 +392,10 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { */ @BetaApi public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { - return setLogicalTimeout(toJavaTimeDuration(timeout)); + return setRpcTimeoutMultiplier(1) + .setInitialRpcTimeout(timeout) + .setMaxRpcTimeout(timeout) + .setTotalTimeout(timeout); } /** @@ -448,10 +409,7 @@ public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { */ @BetaApi public Builder setLogicalTimeout(java.time.Duration timeout) { - return setRpcTimeoutMultiplier(1) - .setInitialRpcTimeout(timeout) - .setMaxRpcTimeout(timeout) - .setTotalTimeout(timeout); + return setLogicalTimeout(toThreetenDuration(timeout)); } abstract RetrySettings autoBuild(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index d974bdde1a..e89234db6a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -30,6 +30,7 @@ package com.google.api.gax.retrying; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.ApiClock; import com.google.auto.value.AutoValue; @@ -102,67 +103,43 @@ public abstract static class Builder { public abstract Builder setGlobalSettings(RetrySettings value); /** - * Overload of {@link #setRetryDelayDuration(java.time.Duration)} using {@link + * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - public final Builder setRetryDelay(org.threeten.bp.Duration value) { - return setRetryDelayDuration(toJavaTimeDuration(value)); - } - - /** - * Overload of {@link #setRetryDelayDuration(java.time.Duration)} using {@link - * java.time.Duration} This is a convenience public method to keep name conformity - */ - public final Builder setRetryDelay(java.time.Duration value) { - return setRetryDelayDuration(value); - } + public abstract Builder setRetryDelay(org.threeten.bp.Duration value); /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public abstract Builder setRetryDelayDuration(java.time.Duration value); - - /** - * Overload of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setRpcTimeout(org.threeten.bp.Duration value) { - return setRpcTimeoutDuration(toJavaTimeDuration(value)); + public final Builder setRetryDelay(java.time.Duration value) { + return setRetryDelay(toThreetenDuration(value)); } /** - * Overload of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link - * java.time.Duration} This is a convenience public method to keep name conformity + * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ - public final Builder setRpcTimeout(java.time.Duration value) { - return setRpcTimeoutDuration(value); - } + public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); /** Sets rpc timeout used for this attempt. */ - public abstract Builder setRpcTimeoutDuration(java.time.Duration value); - - /** - * Overload of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - public final Builder setRandomizedRetryDelay(org.threeten.bp.Duration value) { - return setRandomizedRetryDelayDuration(toJavaTimeDuration(value)); + public final Builder setRpcTimeout(java.time.Duration value){ + return setRpcTimeout(toThreetenDuration(value)); } /** - * Overload of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link - * java.time.Duration} This is a convenience public method to keep name conformity + * Backport of {@link #setRandomizedRetryDelay(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ - public final Builder setRandomizedRetryDelay(java.time.Duration value) { - return setRandomizedRetryDelayDuration(value); - } + public abstract Builder setRandomizedRetryDelay(org.threeten.bp.Duration value); /** * Sets randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public abstract Builder setRandomizedRetryDelayDuration(java.time.Duration value); + public final Builder setRandomizedRetryDelay(java.time.Duration value) { + return setRandomizedRetryDelay(toThreetenDuration(value)); + } /** * Set the attempt count. It is a zero-based value (first attempt will have this value set to diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java index d34aaddb05..df4b117dfa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java @@ -69,7 +69,7 @@ public ResponseT call() { try { // Set the RPC timeout if the caller did not provide their own. - java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); + org.threeten.bp.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); if (!rpcTimeout.isZero() && callContext.getTimeoutDuration() == null) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 8099544fa9..2b088b1843 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -63,7 +63,7 @@ public static UnaryCallable retrying( settings = settings .toBuilder() - .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeoutDuration()) + .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeout()) .build(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java index 53c20b911b..7ef4b76613 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java @@ -65,7 +65,7 @@ public ResponseT call() { ApiCallContext callContext = originalCallContext; try { - java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); + org.threeten.bp.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); if (!rpcTimeout.isZero()) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java index 39bbd7b289..c3edf37d73 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java @@ -212,7 +212,7 @@ public Void call() { && attemptContext.getTimeoutDuration() == null) { attemptContext = attemptContext.withTimeout( - outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration()); + outerRetryingFuture.getAttemptSettings().getRpcTimeout()); } attemptContext diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 1d460b8d5d..6ae8a6db01 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -262,26 +262,26 @@ public RetrySettings getRetrySettings() { */ public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { - return setSimpleTimeoutNoRetries(toJavaTimeDuration(timeout)); + setRetryableCodes(); + setRetrySettings( + RetrySettings.newBuilder() + .setTotalTimeout(timeout) + .setInitialRetryDelay(java.time.Duration.ZERO) + .setRetryDelayMultiplier(1) + .setMaxRetryDelay(java.time.Duration.ZERO) + .setInitialRpcTimeout(timeout) + .setRpcTimeoutMultiplier(1) + .setMaxRpcTimeout(timeout) + .setMaxAttempts(1) + .build()); + + return this; } /** Disables retries and sets the overall timeout. */ public Builder setSimpleTimeoutNoRetries( @Nonnull java.time.Duration timeout) { - setRetryableCodes(); - setRetrySettings( - RetrySettings.newBuilder() - .setTotalTimeout(timeout) - .setInitialRetryDelay(java.time.Duration.ZERO) - .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ZERO) - .setInitialRpcTimeout(timeout) - .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(timeout) - .setMaxAttempts(1) - .build()); - - return this; + return setSimpleTimeoutNoRetries(toThreetenDuration(timeout)); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 8866103d89..09ce44e2ae 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -195,7 +195,7 @@ public UnaryCallSettings.Builder setRetrySettings( /** Disables retries and sets the RPC timeout. */ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( - java.time.Duration timeout) { + org.threeten.bp.Duration timeout) { setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java index 51e8a1a8be..81609d2c1f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java @@ -49,7 +49,7 @@ public class BatchingCallSettingsTest { BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(20L) - .setDelayThreshold(java.time.Duration.ofMillis(5)) + .setDelayThreshold(org.threeten.bp.Duration.ofMillis(5)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100L) @@ -90,7 +90,7 @@ public void testBuilderFromSettings() { BatchingCallSettings.Builder> builder = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC_V2); RetrySettings retrySettings = - RetrySettings.newBuilder().setTotalTimeout(java.time.Duration.ofMinutes(1)).build(); + RetrySettings.newBuilder().setTotalTimeout(org.threeten.bp.Duration.ofMinutes(1)).build(); builder .setBatchingSettings(BATCHING_SETTINGS) .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java index 9f354afb24..905cb6ae2b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java @@ -232,9 +232,9 @@ public void testCancelOuterFutureBeforeStart() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setTotalTimeout(java.time.Duration.ofMillis(10_000L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_000L)) .build(); RetryingExecutorWithContext executor = getExecutor(getAlgorithm(retrySettings, 0, null)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index e37feab030..ce7d22125a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -46,26 +46,26 @@ public class ExponentialRetryAlgorithmTest { private final RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(8L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(1L)) .setRpcTimeoutMultiplier(2.0) - .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) - .setTotalTimeout(java.time.Duration.ofMillis(200L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(8L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(200L)) .build(); private final ExponentialRetryAlgorithm algorithm = new ExponentialRetryAlgorithm(retrySettings, clock); private final RetrySettings retrySettingsOverride = RetrySettings.newBuilder() .setMaxAttempts(3) - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) .setRetryDelayMultiplier(3.0) - .setMaxRetryDelay(java.time.Duration.ofMillis(18L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(18L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(3.0) - .setMaxRpcTimeout(java.time.Duration.ofMillis(18L)) - .setTotalTimeout(java.time.Duration.ofMillis(300L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(18L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(300L)) .build(); private final RetryingContext retryingContext = FakeCallContext.createDefault().withRetrySettings(retrySettingsOverride); @@ -77,10 +77,10 @@ public void testCreateFirstAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); - assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); - assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeoutDuration()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRandomizedRetryDelay()); + assertEquals(org.threeten.bp.Duration.ofMillis(1L), attempt.getRpcTimeout()); + assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); } @Test @@ -90,11 +90,11 @@ public void testCreateFirstAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); - assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRandomizedRetryDelay()); assertEquals( - retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeoutDuration()); - assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeout()); + assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); } @Test @@ -105,13 +105,13 @@ public void testCreateNextAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelayDuration()); - assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeoutDuration()); + assertEquals(org.threeten.bp.Duration.ofMillis(1L), secondAttempt.getRetryDelay()); + assertEquals(org.threeten.bp.Duration.ofMillis(2L), secondAttempt.getRpcTimeout()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelayDuration()); - assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeoutDuration()); + assertEquals(org.threeten.bp.Duration.ofMillis(2L), thirdAttempt.getRetryDelay()); + assertEquals(org.threeten.bp.Duration.ofMillis(4L), thirdAttempt.getRpcTimeout()); } @Test @@ -122,13 +122,13 @@ public void testCreateNextAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelayDuration()); - assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeoutDuration()); + assertEquals(org.threeten.bp.Duration.ofMillis(2L), secondAttempt.getRetryDelay()); + assertEquals(org.threeten.bp.Duration.ofMillis(6L), secondAttempt.getRpcTimeout()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelayDuration()); - assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeoutDuration()); + assertEquals(org.threeten.bp.Duration.ofMillis(6L), thirdAttempt.getRetryDelay()); + assertEquals(org.threeten.bp.Duration.ofMillis(18L), thirdAttempt.getRpcTimeout()); } @Test @@ -136,19 +136,19 @@ public void testTruncateToTotalTimeout() { RetrySettings timeoutSettings = retrySettings .toBuilder() - .setInitialRpcTimeout(java.time.Duration.ofSeconds(4L)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(4L)) - .setTotalTimeout(java.time.Duration.ofSeconds(4L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofSeconds(4L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(4L)) + .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(4L)) .build(); ExponentialRetryAlgorithm timeoutAlg = new ExponentialRetryAlgorithm(timeoutSettings, clock); TimedAttemptSettings firstAttempt = timeoutAlg.createFirstAttempt(); TimedAttemptSettings secondAttempt = timeoutAlg.createNextAttempt(firstAttempt); assertThat(secondAttempt.getRpcTimeout()).isAtLeast(firstAttempt.getRpcTimeout()); - assertThat(secondAttempt.getRpcTimeoutDuration()).isAtMost(java.time.Duration.ofSeconds(4L)); + assertThat(secondAttempt.getRpcTimeout()).isAtMost(org.threeten.bp.Duration.ofSeconds(4L)); TimedAttemptSettings thirdAttempt = timeoutAlg.createNextAttempt(secondAttempt); - assertThat(thirdAttempt.getRpcTimeoutDuration()).isAtMost(java.time.Duration.ofSeconds(4L)); + assertThat(thirdAttempt.getRpcTimeout()).isAtMost(org.threeten.bp.Duration.ofSeconds(4L)); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java index de5804c6cc..1a4cc8f66b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java @@ -39,24 +39,24 @@ class FailingCallable implements Callable { static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(8L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(8L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(8L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(8L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) - .setTotalTimeout(java.time.Duration.ofMillis(400L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(8L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(400L)) .build(); static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(java.time.Duration.ofNanos(1L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofNanos(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofNanos(1L)) - .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofNanos(1L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) - .setTotalTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) + .setTotalTimeout(org.threeten.bp.Duration.ofNanos(1L)) .build(); private AtomicInteger attemptsCount = new AtomicInteger(0); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index c5bdc93f01..f8758c694d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -36,7 +36,7 @@ public class RetrySettingsTest { @Test public void retrySettingsSetLogicalTimeout() { - java.time.Duration timeout = java.time.Duration.ofMillis(60000); + org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(60000); RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); @@ -49,13 +49,13 @@ public void retrySettingsSetLogicalTimeout() { public void retrySettingsMerge() { RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(45000)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2000)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(45000)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2000)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(java.time.Duration.ofMillis(30000)) - .setInitialRetryDelay(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(30000)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(java.time.Duration.ofMillis(1000)); + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1000)); RetrySettings.Builder mergedBuilder = RetrySettings.newBuilder(); mergedBuilder.merge(builder); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java index e86f794f22..2e87f1d15c 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java @@ -92,7 +92,7 @@ public void testSuccessWithFailuresPeekAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -143,7 +143,7 @@ public void testSuccessWithFailuresGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -197,7 +197,7 @@ public void testCancelGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -255,9 +255,9 @@ public void testCancelOuterFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); @@ -283,9 +283,9 @@ public void testCancelIsTraced() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); @@ -313,9 +313,9 @@ public void testCancelProxiedFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 0e207782c6..0bf0b32d81 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -65,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(java.time.Duration.ofSeconds(1)) - .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) - .setRpcTimeout(java.time.Duration.ZERO) + .setRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) + .setRandomizedRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) + .setRpcTimeout(org.threeten.bp.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java index 30c992b8c0..a489293ae3 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java @@ -81,7 +81,7 @@ public void teardown() { public void batching() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -101,7 +101,7 @@ public void batching() throws Exception { public void batchingWithFlowControl() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) .setElementCountThreshold(4L) .setRequestByteThreshold(null) .setFlowControlSettings( @@ -179,7 +179,7 @@ public void batchingDisabled() throws Exception { public void batchingWithBlockingCallThreshold() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -208,7 +208,7 @@ public ApiFuture> futureCall(LabeledIntList request, ApiCallContex public void batchingException() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index c15d13f22f..1a3726c5f7 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -58,9 +58,9 @@ public class CallableTest { private RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(java.time.Duration.ofMillis(5L)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(5L)) - .setTotalTimeout(java.time.Duration.ofMillis(10L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(5L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(5L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10L)) .build(); @Spy private ApiCallContext callContext = FakeCallContext.createDefault(); @@ -76,7 +76,7 @@ public class CallableTest { public void testNonRetriedCallable() throws Exception { innerResult = SettableApiFuture.create(); when(innerCallable.futureCall(anyString(), any(ApiCallContext.class))).thenReturn(innerResult); - java.time.Duration timeout = java.time.Duration.ofMillis(5L); + org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(5L); UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(timeout).build(); @@ -97,13 +97,13 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(10L)) .build(); UnaryCallable callable = Callables.retrying(innerCallable, callSettings, clientContext); innerResult.set("No, my refrigerator is not running!"); - java.time.Duration timeout = retrySettings.getInitialRpcTimeoutDuration(); + org.threeten.bp.Duration timeout = retrySettings.getInitialRpcTimeout(); callable.futureCall("Is your refrigerator running?", callContextWithRetrySettings); @@ -114,7 +114,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { @Test public void testNonRetriedServerStreamingCallable() throws Exception { - java.time.Duration timeout = java.time.Duration.ofMillis(5L); + org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(5L); ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder().setSimpleTimeoutNoRetries(timeout).build(); ServerStreamingCallable callable = @@ -131,12 +131,12 @@ public void testNonRetriedServerStreamingCallable() throws Exception { public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exception { ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder() - .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(10L)) .build(); ServerStreamingCallable callable = Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); - java.time.Duration timeout = retrySettings.getInitialRpcTimeoutDuration(); + org.threeten.bp.Duration timeout = retrySettings.getInitialRpcTimeout(); callable.call("Is your refrigerator running?", callContextWithRetrySettings); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java index 7914ab876d..ae0a9673c7 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java @@ -62,24 +62,24 @@ public class CancellationTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) - .setTotalTimeout(java.time.Duration.ofMillis(20L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(20L)) .build(); private static final RetrySettings SLOW_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(3000L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(3000L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(3000L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(3000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(3000L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(3000L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(3000L)) - .setTotalTimeout(java.time.Duration.ofMillis(3000L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(3000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(3000L)) .build(); private FakeApiClock fakeClock; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index 922fd62044..9d5c3087e8 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -65,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(java.time.Duration.ofSeconds(1)) - .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) - .setRpcTimeout(java.time.Duration.ZERO) + .setRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) + .setRandomizedRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) + .setRpcTimeout(org.threeten.bp.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 6bc6495bd0..218b58a5c9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -79,31 +79,31 @@ public class OperationCallableImplTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) - .setTotalTimeout(java.time.Duration.ofMillis(10L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAST_RECHECKING_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) .setInitialRpcTimeout( - java.time.Duration + org.threeten.bp.Duration .ZERO) // supposed to be ignored, but are not actually, so we set to zero .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier( 1) // supposed to be ignored, but are not actually, so we set to one .setMaxRpcTimeout( - java.time.Duration + org.threeten.bp.Duration .ZERO) // supposed to be ignored, but are not actually, so we set to zero - .setTotalTimeout(java.time.Duration.ofMillis(5L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(5L)) .build(); private FakeChannel initialChannel; @@ -485,10 +485,10 @@ public void testFutureCallPollRPCTimeout() throws Exception { // for LRO polling. They are not actually ignored in code, so they changing them // here has an actual affect. This test verifies that they work as such, but in // practice generated clients set the RPC timeouts to 0 to be ignored. - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(1)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(100)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(2) - .setTotalTimeout(java.time.Duration.ofSeconds(5L)) + .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(5L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -522,17 +522,17 @@ public void testFutureCallPollRPCTimeout() throws Exception { callable.futureCall(2, FakeCallContext.createDefault()).get(10, TimeUnit.SECONDS); - List actualTimeouts = Lists.newArrayList(); + List actualTimeouts = Lists.newArrayList(); for (ApiCallContext callContext : callContextCaptor.getAllValues()) { - actualTimeouts.add(callContext.getTimeoutDuration()); + actualTimeouts.add(callContext.getTimeout()); } - List expectedTimeouts = + List expectedTimeouts = Lists.newArrayList( - java.time.Duration.ofMillis(100), - java.time.Duration.ofMillis(200), - java.time.Duration.ofMillis(400)); + org.threeten.bp.Duration.ofMillis(100), + org.threeten.bp.Duration.ofMillis(200), + org.threeten.bp.Duration.ofMillis(400)); assertThat(actualTimeouts).isEqualTo(expectedTimeouts); } @@ -563,12 +563,12 @@ public void testFutureCallContextPropagation() throws Exception { initialCallable, callSettings, initialContext, longRunningClient); ApiCallContext callContext = - FakeCallContext.createDefault().withTimeout(java.time.Duration.ofMillis(10)); + FakeCallContext.createDefault().withTimeout(org.threeten.bp.Duration.ofMillis(10)); callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); assertThat(callContextCaptor.getValue().getTimeoutDuration()) - .isEqualTo(java.time.Duration.ofMillis(10)); + .isEqualTo(org.threeten.bp.Duration.ofMillis(10)); } @Test @@ -593,7 +593,7 @@ public void testFutureCallPollDoneOnMany() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(iterationsCount)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(iterationsCount)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -703,7 +703,7 @@ public void testFutureCallPollCancelOnLongTimeoutExceeded() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java index da6639cb54..f07558f2ed 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java @@ -68,24 +68,24 @@ public class RetryingTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) - .setTotalTimeout(java.time.Duration.ofMillis(10L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(java.time.Duration.ofNanos(0L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofNanos(0L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(0L)) - .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(0L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) - .setTotalTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) + .setTotalTimeout(org.threeten.bp.Duration.ofNanos(1L)) .build(); @Before @@ -151,8 +151,8 @@ public void retryTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) .build(); assertRetrying(retrySettings); @@ -169,8 +169,8 @@ public void retryUsingContextTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) .build(); try { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index 70128775f7..f4ff8f8c1a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -60,8 +60,8 @@ public class ServerStreamingAttemptCallableTest { private AccumulatingObserver observer; private FakeRetryingFuture fakeRetryingFuture; private StreamResumptionStrategy resumptionStrategy; - private static java.time.Duration totalTimeout = java.time.Duration.ofHours(1); - private static final java.time.Duration attemptTimeout = java.time.Duration.ofMinutes(1); + private static org.threeten.bp.Duration totalTimeout = org.threeten.bp.Duration.ofHours(1); + private static final org.threeten.bp.Duration attemptTimeout = org.threeten.bp.Duration.ofMinutes(1); private FakeCallContext mockedCallContext; @Before @@ -91,8 +91,8 @@ private ServerStreamingAttemptCallable createCallable(ApiCallCon public void testUserProvidedContextTimeout() { // Mock up the ApiCallContext as if the user provided a timeout and streamWaitTimeout. Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer(); - Mockito.doReturn(java.time.Duration.ofHours(5)).when(mockedCallContext).getTimeoutDuration(); - Mockito.doReturn(java.time.Duration.ofHours(5)) + Mockito.doReturn(org.threeten.bp.Duration.ofHours(5)).when(mockedCallContext).getTimeout(); + Mockito.doReturn(org.threeten.bp.Duration.ofHours(5)) .when(mockedCallContext) .getStreamWaitTimeoutDuration(); @@ -103,7 +103,7 @@ public void testUserProvidedContextTimeout() { Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeoutDuration(); Mockito.verify(mockedCallContext, Mockito.never()).withTimeout(totalTimeout); Mockito.verify(mockedCallContext, Mockito.never()) - .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); + .withStreamWaitTimeout(Mockito.any(org.threeten.bp.Duration.class)); // Should notify outer observer Truth.assertThat(observer.controller).isNotNull(); @@ -132,7 +132,7 @@ public void testNoUserProvidedContextTimeout() { Mockito.doReturn(mockedCallContext).when(mockedCallContext).withTimeout(attemptTimeout); Mockito.doReturn(mockedCallContext) .when(mockedCallContext) - .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); + .withStreamWaitTimeout(Mockito.any(org.threeten.bp.Duration.class)); ServerStreamingAttemptCallable callable = createCallable(mockedCallContext); callable.start(); @@ -478,9 +478,9 @@ private static class FakeRetryingFuture extends AbstractApiFuture .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) - .setRandomizedRetryDelay(java.time.Duration.ofMillis(1)) - .setRetryDelay(java.time.Duration.ofMillis(1)) - .setRpcTimeout(java.time.Duration.ofMinutes(1)) + .setRandomizedRetryDelay(org.threeten.bp.Duration.ofMillis(1)) + .setRetryDelay(org.threeten.bp.Duration.ofMillis(1)) + .setRpcTimeout(org.threeten.bp.Duration.ofMinutes(1)) .build(); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java index 34cabb8994..7dc5acbdaa 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java @@ -51,26 +51,26 @@ public class StreamingRetryAlgorithmTest { private static final RetrySettings DEFAULT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(10L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(10L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(100L)) .setMaxAttempts(10) - .setMaxRetryDelay(java.time.Duration.ofSeconds(10L)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(30L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofSeconds(10L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(30L)) .setRetryDelayMultiplier(1.4) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeout(java.time.Duration.ofMinutes(10L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMinutes(10L)) .build(); private static final RetrySettings CONTEXT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(20L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(200L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(20L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(200L)) .setMaxAttempts(10) - .setMaxRetryDelay(java.time.Duration.ofSeconds(20L)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(60L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofSeconds(20L)) + .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(60L)) .setRetryDelayMultiplier(2.4) .setRpcTimeoutMultiplier(2.5) - .setTotalTimeout(java.time.Duration.ofMinutes(20L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMinutes(20L)) .build(); @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index ce810e273e..e39248b4e6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -46,7 +46,7 @@ public class UnaryCallSettingsTest { @Test public void testSetSimpleTimeoutNoRetries() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofSeconds(13)); assertThat(builder.getRetryableCodes().size()).isEqualTo(0); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); @@ -57,7 +57,7 @@ public void testSetSimpleTimeoutNoRetries() { @Test public void testEquals() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofSeconds(13)); UnaryCallSettings settings13 = builder.build(); assertEquals(settings13, settings13); @@ -66,7 +66,7 @@ public void testEquals() { assertEquals(settings13.hashCode(), settings13.hashCode()); UnaryCallSettings.Builder builder5 = new UnaryCallSettings.Builder(); - builder5.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(5)); + builder5.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofSeconds(5)); UnaryCallSettings settings5 = builder5.build(); assertNotEquals(settings13, settings5); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java index 07d1fd2b13..516ba958f9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java @@ -102,7 +102,7 @@ public void testNonRetriedCallable() throws Exception { // Verify that callables configured to not retry have the appropriate tracer interactions. UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(5L)) + .setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(5L)) .build(); UnaryCallable callable = setupTracedUnaryCallable(callSettings); innerResult.set("No, my refrigerator is not running!"); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index d73616d990..0787b3fcf5 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -139,16 +139,16 @@ public static RetrySettings mergeToSettings(RetrySettings settings, RetryOption. for (RetryOption option : options) { switch (option.type) { case TOTAL_TIMEOUT: - builder.setTotalTimeout((java.time.Duration) option.value); + builder.setTotalTimeout((org.threeten.bp.Duration) option.value); break; case INITIAL_RETRY_DELAY: - builder.setInitialRetryDelay((java.time.Duration) option.value); + builder.setInitialRetryDelay((org.threeten.bp.Duration) option.value); break; case RETRY_DELAY_MULTIPLIER: builder.setRetryDelayMultiplier((Double) option.value); break; case MAX_RETRY_DELAY: - builder.setMaxRetryDelay((java.time.Duration) option.value); + builder.setMaxRetryDelay((org.threeten.bp.Duration) option.value); break; case MAX_ATTEMPTS: builder.setMaxAttempts((Integer) option.value); diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index aa2cc3e6b8..afdc5043b4 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -25,21 +25,21 @@ public class RetryOptionTest { private static final RetryOption TOTAL_TIMEOUT = - RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); + RetryOption.totalTimeout(org.threeten.bp.Duration.ofMillis(420L)); private static final RetryOption INITIAL_RETRY_DELAY = - RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); + RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)); private static final RetryOption RETRY_DELAY_MULTIPLIER = RetryOption.retryDelayMultiplier(1.5); private static final RetryOption MAX_RETRY_DELAY = - RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); + RetryOption.maxRetryDelay(org.threeten.bp.Duration.ofMillis(100)); private static final RetryOption MAX_ATTEMPTS = RetryOption.maxAttempts(100); private static final RetryOption JITTERED = RetryOption.jittered(false); private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(420L)) - .setInitialRetryDelay(java.time.Duration.ofMillis(42L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(420L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(java.time.Duration.ofMillis(100)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(100)) .setMaxAttempts(100) .setJittered(false) .build(); @@ -60,10 +60,10 @@ public void testEqualsAndHashCode() { assertNotEquals(MAX_ATTEMPTS, MAX_RETRY_DELAY); assertNotEquals(JITTERED, MAX_ATTEMPTS); - RetryOption totalTimeout = RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); - RetryOption initialRetryDelay = RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); + RetryOption totalTimeout = RetryOption.totalTimeout(org.threeten.bp.Duration.ofMillis(420L)); + RetryOption initialRetryDelay = RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)); RetryOption retryDelayMultiplier = RetryOption.retryDelayMultiplier(1.5); - RetryOption maxRetryDelay = RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); + RetryOption maxRetryDelay = RetryOption.maxRetryDelay(org.threeten.bp.Duration.ofMillis(100)); RetryOption maxAttempts = RetryOption.maxAttempts(100); RetryOption jittered = RetryOption.jittered(false); @@ -100,17 +100,17 @@ public void testMergeToSettings() { assertEquals(retrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setTotalTimeout(java.time.Duration.ofMillis(420L)).build(); + defRetrySettings.toBuilder().setTotalTimeout(org.threeten.bp.Duration.ofMillis(420L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setMaxRetryDelay(java.time.Duration.ofMillis(100)).build(); + defRetrySettings.toBuilder().setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(100)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setInitialRetryDelay(java.time.Duration.ofMillis(42L)).build(); + defRetrySettings.toBuilder().setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); From 03a9f65487cb9836df894564e4fcb6d5bc1c4dd6 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jul 2023 21:26:51 -0400 Subject: [PATCH 013/141] chore: adapt builders in `gax` --- .../java/com/google/api/gax/rpc/ClientContext.java | 9 +++------ .../com/google/api/gax/rpc/ClientSettings.java | 7 ++++--- .../com/google/api/gax/rpc/UnaryCallSettings.java | 14 +++++++++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 24a7c6fadd..473e39442d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -30,6 +30,7 @@ package com.google.api.gax.rpc; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.client.util.Strings; import com.google.api.core.ApiClock; @@ -361,16 +362,12 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); - public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { - return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(duration)); - } + public abstract Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration); public final Builder setStreamWatchdogCheckInterval(java.time.Duration duration) { - return setStreamWatchdogCheckIntervalDuration(duration); + return setStreamWatchdogCheckInterval(toThreetenDuration(duration)); } - public abstract Builder setStreamWatchdogCheckIntervalDuration(java.time.Duration duration); - /** * Set the {@link ApiTracerFactory} that will be used to generate traces for operations. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 88c2799539..a49c7eae83 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -119,7 +119,7 @@ public final org.threeten.bp.Duration getWatchdogCheckInterval() { @Nonnull public final java.time.Duration getWatchdogCheckIntervalDuration() { - return toJavaTimeDuration(getWatchdogCheckInterval()); + return stubSettings.getStreamWatchdogCheckIntervalDuration(); } /** Gets the GDCH API audience that was previously set in this Builder */ @@ -268,7 +268,8 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { } public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { - return setWatchdogCheckInterval(toJavaTimeDuration(checkInterval)); + stubSettings.setStreamWatchdogCheckInterval(checkInterval); + return self(); } public B setWatchdogCheckInterval(@Nullable java.time.Duration checkInterval) { @@ -357,7 +358,7 @@ public org.threeten.bp.Duration getWatchdogCheckInterval() { @Nullable public java.time.Duration getWatchdogCheckIntervalDuration() { - return toJavaTimeDuration(getWatchdogCheckInterval()); + return stubSettings.getStreamWatchdogCheckIntervalDuration(); } /** Gets the GDCH API audience that was previously set in this Builder */ diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 09ce44e2ae..1055bdc015 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -34,8 +34,12 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; +import org.threeten.bp.Duration; + import java.util.Set; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + /** * A base settings class to configure a UnaryCallable. An instance of UnaryCallSettings is not * sufficient on its own to construct a UnaryCallable; a concrete derived type is necessary. @@ -193,7 +197,9 @@ public UnaryCallSettings.Builder setRetrySettings( return this; } - /** Disables retries and sets the RPC timeout. */ + /** + * Backport of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} + */ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { setRetryableCodes(); @@ -211,6 +217,12 @@ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( return this; } + /** Disables retries and sets the RPC timeout. */ + public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( + java.time.Duration timeout) { + return setSimpleTimeoutNoRetries(toThreetenDuration(timeout)); + } + /** * See the class documentation of {@link UnaryCallSettings} for a description of what retryable * codes do. From 523d100b4e03534d97e3aa06eaa5933b49897d76 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jul 2023 21:38:08 -0400 Subject: [PATCH 014/141] chore: adapt builders in `gax-grpc` --- .../com/google/api/gax/grpc/GrpcCallContextTest.java | 4 ++-- .../grpc/InstantiatingGrpcChannelProviderTest.java | 2 +- .../java/com/google/api/gax/rpc/AttemptCallable.java | 2 +- .../google/api/gax/rpc/CheckingAttemptCallable.java | 2 +- .../api/gax/rpc/ServerStreamingAttemptCallable.java | 2 +- .../api/gax/rpc/OperationCallableImplTest.java | 12 ++++++------ .../gax/rpc/ServerStreamingAttemptCallableTest.java | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 711e101bd7..8068075e9b 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -213,7 +213,7 @@ public void testMergeWithNullStreamingWaitTimeout() { GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeoutDuration()).isEqualTo(timeout); - org.threeten.bp.Duration streamWaitTimeout = null; + java.time.Duration streamWaitTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withStreamWaitTimeout(streamWaitTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamWaitTimeoutDuration()) @@ -252,7 +252,7 @@ public void testMergeWithNullStreamingIdleTimeout() { GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeoutDuration()).isEqualTo(timeout); - org.threeten.bp.Duration idleTimeout = null; + java.time.Duration idleTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withStreamIdleTimeout(idleTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamIdleTimeoutDuration()) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 3b2ac56733..3c097acced 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -179,7 +179,7 @@ public void testToBuilder() { assertThat(builder.getEndpoint()).isEqualTo("fake.endpoint:443"); assertThat(builder.getMaxInboundMessageSize()).isEqualTo(12345678); assertThat(builder.getMaxInboundMetadataSize()).isEqualTo(4096); - assertThat(builder.getKeepAliveTime()).isEqualTo(keepaliveTime); + assertThat(builder.getKeepAliveTimeDuration()).isEqualTo(keepaliveTime); assertThat(builder.getKeepAliveTimeoutDuration()).isEqualTo(keepaliveTimeout); assertThat(builder.getChannelConfigurator()).isEqualTo(channelConfigurator); assertThat(builder.getPoolSize()).isEqualTo(5); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java index df4b117dfa..d34aaddb05 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java @@ -69,7 +69,7 @@ public ResponseT call() { try { // Set the RPC timeout if the caller did not provide their own. - org.threeten.bp.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); + java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero() && callContext.getTimeoutDuration() == null) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java index 7ef4b76613..53c20b911b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java @@ -65,7 +65,7 @@ public ResponseT call() { ApiCallContext callContext = originalCallContext; try { - org.threeten.bp.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); + java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero()) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java index c3edf37d73..39bbd7b289 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java @@ -212,7 +212,7 @@ public Void call() { && attemptContext.getTimeoutDuration() == null) { attemptContext = attemptContext.withTimeout( - outerRetryingFuture.getAttemptSettings().getRpcTimeout()); + outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration()); } attemptContext diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 218b58a5c9..47645ac2dc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -522,17 +522,17 @@ public void testFutureCallPollRPCTimeout() throws Exception { callable.futureCall(2, FakeCallContext.createDefault()).get(10, TimeUnit.SECONDS); - List actualTimeouts = Lists.newArrayList(); + List actualTimeouts = Lists.newArrayList(); for (ApiCallContext callContext : callContextCaptor.getAllValues()) { - actualTimeouts.add(callContext.getTimeout()); + actualTimeouts.add(callContext.getTimeoutDuration()); } - List expectedTimeouts = + List expectedTimeouts = Lists.newArrayList( - org.threeten.bp.Duration.ofMillis(100), - org.threeten.bp.Duration.ofMillis(200), - org.threeten.bp.Duration.ofMillis(400)); + java.time.Duration.ofMillis(100), + java.time.Duration.ofMillis(200), + java.time.Duration.ofMillis(400)); assertThat(actualTimeouts).isEqualTo(expectedTimeouts); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index f4ff8f8c1a..c0cba5ad6d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -91,8 +91,8 @@ private ServerStreamingAttemptCallable createCallable(ApiCallCon public void testUserProvidedContextTimeout() { // Mock up the ApiCallContext as if the user provided a timeout and streamWaitTimeout. Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer(); - Mockito.doReturn(org.threeten.bp.Duration.ofHours(5)).when(mockedCallContext).getTimeout(); - Mockito.doReturn(org.threeten.bp.Duration.ofHours(5)) + Mockito.doReturn(java.time.Duration.ofHours(5)).when(mockedCallContext).getTimeoutDuration(); + Mockito.doReturn(java.time.Duration.ofHours(5)) .when(mockedCallContext) .getStreamWaitTimeoutDuration(); @@ -103,7 +103,7 @@ public void testUserProvidedContextTimeout() { Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeoutDuration(); Mockito.verify(mockedCallContext, Mockito.never()).withTimeout(totalTimeout); Mockito.verify(mockedCallContext, Mockito.never()) - .withStreamWaitTimeout(Mockito.any(org.threeten.bp.Duration.class)); + .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); // Should notify outer observer Truth.assertThat(observer.controller).isNotNull(); @@ -132,7 +132,7 @@ public void testNoUserProvidedContextTimeout() { Mockito.doReturn(mockedCallContext).when(mockedCallContext).withTimeout(attemptTimeout); Mockito.doReturn(mockedCallContext) .when(mockedCallContext) - .withStreamWaitTimeout(Mockito.any(org.threeten.bp.Duration.class)); + .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); ServerStreamingAttemptCallable callable = createCallable(mockedCallContext); callable.start(); From 43f3077b84dbbc279ffba240bb9dabe7e8d2353d Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jul 2023 21:45:46 -0400 Subject: [PATCH 015/141] chore: adapt builders in `gax-httpjson` --- .../java/com/google/api/gax/grpc/GrpcCallContextTest.java | 4 ++-- .../google/api/gax/httpjson/HttpJsonCallContextTest.java | 4 ++-- .../test/java/com/google/api/gax/rpc/CallableTest.java | 8 ++++---- .../com/google/api/gax/rpc/OperationCallableImplTest.java | 2 +- .../api/gax/rpc/ServerStreamingAttemptCallableTest.java | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 8068075e9b..c2ea883eb1 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -128,7 +128,7 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { - org.threeten.bp.Duration timeout = null; + java.time.Duration timeout = null; assertNull(GrpcCallContext.createDefault().withTimeout(timeout).getTimeoutDuration()); } @@ -183,7 +183,7 @@ public void testMergeWithNullTimeout() { GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeoutDuration()).isEqualTo(timeout); - org.threeten.bp.Duration callContextTimeout = null; + java.time.Duration callContextTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withTimeout(callContextTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()).isEqualTo(timeout); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 3f488fa783..8e01a6fde7 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -116,7 +116,7 @@ public void testMergeWrongType() { @Test public void testWithTimeout() { - org.threeten.bp.Duration timeout = null; + java.time.Duration timeout = null; assertNull(HttpJsonCallContext.createDefault().withTimeout(timeout).getTimeoutDuration()); } @@ -173,7 +173,7 @@ public void testMergeWithNullTimeout() { HttpJsonCallContext defaultOverlay = HttpJsonCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeoutDuration()).isEqualTo(timeout); - org.threeten.bp.Duration callContextTimeout = null; + java.time.Duration callContextTimeout = null; HttpJsonCallContext explicitNullOverlay = HttpJsonCallContext.createDefault().withTimeout(callContextTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()).isEqualTo(timeout); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 1a3726c5f7..23cb0d7fdd 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -76,7 +76,7 @@ public class CallableTest { public void testNonRetriedCallable() throws Exception { innerResult = SettableApiFuture.create(); when(innerCallable.futureCall(anyString(), any(ApiCallContext.class))).thenReturn(innerResult); - org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(5L); + java.time.Duration timeout = java.time.Duration.ofMillis(5L); UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(timeout).build(); @@ -103,7 +103,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { Callables.retrying(innerCallable, callSettings, clientContext); innerResult.set("No, my refrigerator is not running!"); - org.threeten.bp.Duration timeout = retrySettings.getInitialRpcTimeout(); + java.time.Duration timeout = retrySettings.getInitialRpcTimeoutDuration(); callable.futureCall("Is your refrigerator running?", callContextWithRetrySettings); @@ -114,7 +114,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { @Test public void testNonRetriedServerStreamingCallable() throws Exception { - org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(5L); + java.time.Duration timeout = java.time.Duration.ofMillis(5L); ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder().setSimpleTimeoutNoRetries(timeout).build(); ServerStreamingCallable callable = @@ -136,7 +136,7 @@ public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exce ServerStreamingCallable callable = Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); - org.threeten.bp.Duration timeout = retrySettings.getInitialRpcTimeout(); + java.time.Duration timeout = retrySettings.getInitialRpcTimeoutDuration(); callable.call("Is your refrigerator running?", callContextWithRetrySettings); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 47645ac2dc..b2f028dd8d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -563,7 +563,7 @@ public void testFutureCallContextPropagation() throws Exception { initialCallable, callSettings, initialContext, longRunningClient); ApiCallContext callContext = - FakeCallContext.createDefault().withTimeout(org.threeten.bp.Duration.ofMillis(10)); + FakeCallContext.createDefault().withTimeout(java.time.Duration.ofMillis(10)); callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index c0cba5ad6d..ea1c7da9d3 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -60,8 +60,8 @@ public class ServerStreamingAttemptCallableTest { private AccumulatingObserver observer; private FakeRetryingFuture fakeRetryingFuture; private StreamResumptionStrategy resumptionStrategy; - private static org.threeten.bp.Duration totalTimeout = org.threeten.bp.Duration.ofHours(1); - private static final org.threeten.bp.Duration attemptTimeout = org.threeten.bp.Duration.ofMinutes(1); + private static java.time.Duration totalTimeout = java.time.Duration.ofHours(1); + private static final java.time.Duration attemptTimeout = java.time.Duration.ofMinutes(1); private FakeCallContext mockedCallContext; @Before From d4d1428901f4d9b5dbd29d2bfb8b4d94e4a4d857 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Thu, 27 Jul 2023 11:50:00 -0400 Subject: [PATCH 016/141] feat: Introduce @ObsoleteApi --- .../java/com/google/api/core/ObsoleteApi.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java new file mode 100644 index 0000000000..90db67ee71 --- /dev/null +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -0,0 +1,63 @@ +/* + * Copyright 2023, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.core; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates a public API is obsolete, and will be deprecated in the next major version. + * + *

    Usage guidelines: + * + *

      + *
    1. This annotation is used only on APIs with non-private visibility. Private interfaces should not + * use it. + *
    2. This annotation should only be added if either an alternative API is provided or we plan to stop supporting the API in next major version + *
    + */ +@BetaApi +@Retention(RetentionPolicy.RUNTIME) +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE +}) +@Documented +public @interface ObsoleteApi { + /** Context information such as links to a discussion thread, tracking issue, etc. */ + String value() default ""; +} From e26105815cad30fc17a8955fde4e14c8156cf28d Mon Sep 17 00:00:00 2001 From: Blake Li Date: Thu, 27 Jul 2023 11:51:55 -0400 Subject: [PATCH 017/141] chore: format --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index 90db67ee71..f11d4f3878 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -41,9 +41,10 @@ *

    Usage guidelines: * *

      - *
    1. This annotation is used only on APIs with non-private visibility. Private interfaces should not - * use it. - *
    2. This annotation should only be added if either an alternative API is provided or we plan to stop supporting the API in next major version + *
    3. This annotation is used only on APIs with non-private visibility. Private interfaces should + * not use it. + *
    4. This annotation should only be added if either an alternative API is provided or we plan to + * stop supporting the API in next major version *
    */ @BetaApi From 490b214a49a21f48f4f5e7ed64f146e04a422c1b Mon Sep 17 00:00:00 2001 From: Blake Li Date: Thu, 27 Jul 2023 17:10:17 -0400 Subject: [PATCH 018/141] Update api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java Co-authored-by: Mike Eltsufin --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index f11d4f3878..09c665eeca 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -44,7 +44,7 @@ *
  • This annotation is used only on APIs with non-private visibility. Private interfaces should * not use it. *
  • This annotation should only be added if either an alternative API is provided or we plan to - * stop supporting the API in next major version + * stop supporting the API in the next major version. * */ @BetaApi From a1a013638bf73fae51191b7307f8e85e6c30c124 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Thu, 27 Jul 2023 17:10:32 -0400 Subject: [PATCH 019/141] Update api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java Co-authored-by: Mike Eltsufin --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index 09c665eeca..e9fb94037a 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -43,7 +43,7 @@ *
      *
    1. This annotation is used only on APIs with non-private visibility. Private interfaces should * not use it. - *
    2. This annotation should only be added if either an alternative API is provided or we plan to + *
    3. This annotation should only be added if either an alternative API is provided and/or we plan to * stop supporting the API in the next major version. *
    */ From 8fda8988a0a5ae26cba7b6742b559e1629a02a66 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Thu, 27 Jul 2023 17:25:20 -0400 Subject: [PATCH 020/141] chore: format --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index e9fb94037a..f18d8acc4e 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -43,8 +43,8 @@ *
      *
    1. This annotation is used only on APIs with non-private visibility. Private interfaces should * not use it. - *
    2. This annotation should only be added if either an alternative API is provided and/or we plan to - * stop supporting the API in the next major version. + *
    3. This annotation should only be added if either an alternative API is provided and/or we + * plan to stop supporting the API in the next major version. *
    */ @BetaApi From 7879446d6cc00ef0eb2de2d41d076ed5dbd12ea5 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Thu, 27 Jul 2023 17:59:10 -0400 Subject: [PATCH 021/141] chore: Rename value to description. --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index f18d8acc4e..8cc3066ca1 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -41,10 +41,10 @@ *

    Usage guidelines: * *

      - *
    1. This annotation is used only on APIs with non-private visibility. Private interfaces should - * not use it. + *
    2. This annotation must be used only on APIs with non-private visibility. *
    3. This annotation should only be added if either an alternative API is provided and/or we * plan to stop supporting the API in the next major version. + *
    4. This annotation must be added with a description. *
    */ @BetaApi @@ -60,5 +60,5 @@ @Documented public @interface ObsoleteApi { /** Context information such as links to a discussion thread, tracking issue, etc. */ - String value() default ""; + String description(); } From 5e2c20eefe8bfc11a88cde54fbef4266727a91d0 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Fri, 28 Jul 2023 16:46:27 -0400 Subject: [PATCH 022/141] doc: Add a blurb in README.md --- gax-java/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gax-java/README.md b/gax-java/README.md index 4a524e435b..f42a1f947e 100644 --- a/gax-java/README.md +++ b/gax-java/README.md @@ -109,6 +109,8 @@ additional qualifications: with this annotation, but methods can be added, thus breaking any code implementing the interface. See the javadocs for more details on other consequences of this annotation. +1. Components marked with `@ObsoleteApi` are stable for usage in the current major version, + but will be marked with `@Deprecated` in the next major version release. ### Submodule notes From 3945a98b94e6fc0d1cda13df27df2d4e54aa60d3 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Fri, 28 Jul 2023 23:43:23 -0400 Subject: [PATCH 023/141] doc: Update wording. --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index 8cc3066ca1..c3c3a894a1 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -36,14 +36,14 @@ import java.lang.annotation.Target; /** - * Indicates a public API is obsolete, and will be deprecated in the next major version. + * Indicates a public API is obsolete, and will be deprecated in a future major version. * *

    Usage guidelines: * *

      *
    1. This annotation must be used only on APIs with non-private visibility. *
    2. This annotation should only be added if either an alternative API is provided and/or we - * plan to stop supporting the API in the next major version. + * plan to stop supporting the API in a future major version. *
    3. This annotation must be added with a description. *
    */ From 5e9c638205774267600a72e2f34137a26fb43ac1 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Mon, 31 Jul 2023 11:15:23 -0400 Subject: [PATCH 024/141] doc: Update wording. --- gax-java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/README.md b/gax-java/README.md index f42a1f947e..d6df5d7646 100644 --- a/gax-java/README.md +++ b/gax-java/README.md @@ -110,7 +110,7 @@ additional qualifications: code implementing the interface. See the javadocs for more details on other consequences of this annotation. 1. Components marked with `@ObsoleteApi` are stable for usage in the current major version, - but will be marked with `@Deprecated` in the next major version release. + but will be marked with `@Deprecated` in a future major version. ### Submodule notes From 0b5d5e630d102a3d883d3594920eefc810b69b09 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Mon, 31 Jul 2023 16:48:15 -0400 Subject: [PATCH 025/141] doc: Update wording. --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index c3c3a894a1..4b3add0e15 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -36,15 +36,16 @@ import java.lang.annotation.Target; /** - * Indicates a public API is obsolete, and will be deprecated in a future major version. + * Indicates a public API is obsolete, and will be deprecated in a future version. * *

    Usage guidelines: * *

      *
    1. This annotation must be used only on APIs with non-private visibility. *
    2. This annotation should only be added if either an alternative API is provided and/or we - * plan to stop supporting the API in a future major version. - *
    3. This annotation must be added with a description. + * plan to stop supporting the API in a future version. + *
    4. This annotation must be used with a description. + *
    5. Alternative APIs must be referenced in Javadoc and/or description if possible. *
    */ @BetaApi From 2e07a48ab206a450a38c356d0c0a0b26b558968e Mon Sep 17 00:00:00 2001 From: Blake Li Date: Mon, 31 Jul 2023 17:29:09 -0400 Subject: [PATCH 026/141] chore: rename description to value. --- .../src/main/java/com/google/api/core/ObsoleteApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java index 4b3add0e15..3598394a72 100644 --- a/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java +++ b/api-common-java/src/main/java/com/google/api/core/ObsoleteApi.java @@ -61,5 +61,5 @@ @Documented public @interface ObsoleteApi { /** Context information such as links to a discussion thread, tracking issue, etc. */ - String description(); + String value(); } From e6c20b7a3ed0d72a2d72d63c9880144e40cfac94 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jul 2023 21:48:55 -0400 Subject: [PATCH 027/141] chore: adapt builders in `google-cloud-core` --- .../google/api/gax/batching/BatcherImplTest.java | 12 ++++++------ .../com/google/api/gax/rpc/BatcherFactoryTest.java | 2 +- .../google/api/gax/rpc/BatchingCallableTest.java | 2 +- .../src/main/java/com/google/cloud/RetryOption.java | 13 +++++++------ .../main/java/com/google/cloud/ServiceOptions.java | 11 +++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index 5f43047126..a8ce70e633 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -92,7 +92,7 @@ public class BatcherImplTest { BatchingSettings.newBuilder() .setElementCountThreshold(1000L) .setRequestByteThreshold(1000L) - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1000)) + .setDelayThreshold(java.time.Duration.ofSeconds(1000)) .build(); @After @@ -371,7 +371,7 @@ public void testWhenThresholdIsDisabled() throws Exception { BatchingSettings.newBuilder() .setElementCountThreshold(null) .setRequestByteThreshold(null) - .setDelayThresholdDuration(null) + .setDelayThreshold((org.threeten.bp.Duration) null) .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(2); @@ -385,7 +385,7 @@ public void testWhenDelayThresholdExceeds() throws Exception { BatchingSettings settings = batchingSettings .toBuilder() - .setDelayThresholdDuration(java.time.Duration.ofMillis(100)) + .setDelayThreshold(java.time.Duration.ofMillis(100)) .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(6); @@ -419,7 +419,7 @@ public ApiFuture> futureCall( BatchingSettings settings = batchingSettings .toBuilder() - .setDelayThresholdDuration(java.time.Duration.ofMillis(50)) + .setDelayThreshold(org.threeten.bp.Duration.ofMillis(50)) .build(); try (final BatcherImpl> batcherTest = @@ -466,7 +466,7 @@ public void testPushCurrentBatchRunnable() throws Exception { BatchingSettings settings = batchingSettings .toBuilder() - .setDelayThresholdDuration(java.time.Duration.ofMillis(DELAY_TIME)) + .setDelayThreshold(org.threeten.bp.Duration.ofMillis(DELAY_TIME)) .build(); BatcherImpl> batcher = createDefaultBatcherImpl(settings, null); @@ -992,7 +992,7 @@ public ApiFuture futureCall(Object o, ApiCallContext apiCallContext) { Object prototype = new Object(); BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) .setElementCountThreshold(100L) .setRequestByteThreshold(100L) .setFlowControlSettings(FlowControlSettings.getDefaultInstance()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java index 3ea1ecf3ca..0fa0091f6a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java @@ -66,7 +66,7 @@ public void tearDown() { public void testGetPushingBatcher() { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java index 8ac84bade4..82c34571d6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java @@ -67,7 +67,7 @@ public void testBatchedCall() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(10)) + .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(10)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index 0787b3fcf5..a1250b4855 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -17,6 +17,7 @@ package com.google.cloud; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.core.BetaApi; @@ -53,22 +54,22 @@ private RetryOption(OptionType type, Object value) { /** See {@link RetrySettings#getTotalTimeout()}. */ public static RetryOption totalTimeout(org.threeten.bp.Duration totalTimeout) { - return totalTimeout(toJavaTimeDuration(totalTimeout)); + return new RetryOption(OptionType.TOTAL_TIMEOUT, totalTimeout); } /** See {@link RetrySettings#getTotalTimeout()}. */ public static RetryOption totalTimeout(java.time.Duration totalTimeout) { - return new RetryOption(OptionType.TOTAL_TIMEOUT, totalTimeout); + return totalTimeout(toThreetenDuration(totalTimeout)); } /** See {@link RetrySettings#getInitialRetryDelay()}. */ public static RetryOption initialRetryDelay(org.threeten.bp.Duration initialRetryDelay) { - return initialRetryDelay(toJavaTimeDuration(initialRetryDelay)); + return new RetryOption(OptionType.INITIAL_RETRY_DELAY, initialRetryDelay); } /** See {@link RetrySettings#getInitialRetryDelay()}. */ public static RetryOption initialRetryDelay(java.time.Duration initialRetryDelay) { - return new RetryOption(OptionType.INITIAL_RETRY_DELAY, initialRetryDelay); + return initialRetryDelay(toThreetenDuration(initialRetryDelay)); } /** See {@link RetrySettings#getRetryDelayMultiplier()}. */ @@ -78,12 +79,12 @@ public static RetryOption retryDelayMultiplier(double retryDelayMultiplier) { /** See {@link RetrySettings#getMaxRetryDelay()}. */ public static RetryOption maxRetryDelay(org.threeten.bp.Duration maxRetryDelay) { - return maxRetryDelay(toJavaTimeDuration(maxRetryDelay)); + return new RetryOption(OptionType.MAX_RETRY_DELAY, maxRetryDelay); } /** See {@link RetrySettings#getMaxRetryDelay()}. */ public static RetryOption maxRetryDelay(java.time.Duration maxRetryDelay) { - return new RetryOption(OptionType.MAX_RETRY_DELAY, maxRetryDelay); + return maxRetryDelay(toThreetenDuration(maxRetryDelay)); } /** See {@link RetrySettings#getMaxAttempts()}. */ diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 231b9040c9..b5ce8c0b50 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -68,7 +68,6 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.threeten.bp.Duration; /** * Abstract class representing service options. @@ -732,13 +731,13 @@ public static RetrySettings getNoRetrySettings() { private static RetrySettings.Builder getDefaultRetrySettingsBuilder() { return RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(Duration.ofMillis(1000L)) - .setMaxRetryDelay(Duration.ofMillis(32_000L)) + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1000L)) + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(32_000L)) .setRetryDelayMultiplier(2.0) - .setTotalTimeout(Duration.ofMillis(50_000L)) - .setInitialRpcTimeout(Duration.ofMillis(50_000L)) + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(50_000L)) + .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(50_000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(50_000L)); + .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(50_000L)); } protected abstract Set getScopes(); From d7b0cf36e4b4da6db974fbceb89725ab20b76849 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 1 Aug 2023 11:30:52 -0400 Subject: [PATCH 028/141] chore: format --- .../api/gax/grpc/GrpcCallContextTest.java | 30 +++++++++++++------ .../api/gax/httpjson/HttpJsonClientCalls.java | 3 +- .../gax/httpjson/HttpJsonCallContextTest.java | 12 +++++--- .../api/gax/batching/BatchingSettings.java | 6 +--- .../retrying/ExponentialRetryAlgorithm.java | 12 ++++---- .../api/gax/retrying/RetrySettings.java | 28 +++++------------ .../gax/retrying/TimedAttemptSettings.java | 8 ++--- .../google/api/gax/rpc/ApiCallContext.java | 4 +-- .../google/api/gax/rpc/ClientSettings.java | 1 - .../gax/rpc/ServerStreamingCallSettings.java | 20 ++++++------- .../google/api/gax/rpc/UnaryCallSettings.java | 12 +++----- .../api/gax/batching/BatcherImplTest.java | 5 +--- .../ExponentialRetryAlgorithmTest.java | 3 +- .../java/com/google/cloud/RetryOption.java | 1 - .../com/google/cloud/RetryOptionTest.java | 18 ++++++++--- 15 files changed, 82 insertions(+), 81 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index c2ea883eb1..013f0bf860 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -143,7 +143,9 @@ public void testWithNegativeTimeout() { @Test public void testWithZeroTimeout() { assertNull( - GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(0L)).getTimeoutDuration()); + GrpcCallContext.createDefault() + .withTimeout(java.time.Duration.ofSeconds(0L)) + .getTimeoutDuration()); } @Test @@ -152,12 +154,14 @@ public void testWithShorterTimeout() { GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); // Sanity check - Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(10)); + Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()) + .isEqualTo(java.time.Duration.ofSeconds(10)); // Shorten the timeout and make sure it changed GrpcCallContext ctxWithShorterTimeout = ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); - Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()) + .isEqualTo(java.time.Duration.ofSeconds(5)); } @Test @@ -166,7 +170,8 @@ public void testWithLongerTimeout() { GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); // Sanity check - Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()) + .isEqualTo(java.time.Duration.ofSeconds(5)); // Try to extend the timeout and verify that it was ignored GrpcCallContext ctxWithUnchangedTimeout = @@ -186,7 +191,8 @@ public void testMergeWithNullTimeout() { java.time.Duration callContextTimeout = null; GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withTimeout(callContextTimeout); - Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()) + .isEqualTo(timeout); } @Test @@ -211,7 +217,8 @@ public void testMergeWithNullStreamingWaitTimeout() { GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); - Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeoutDuration()) + .isEqualTo(timeout); java.time.Duration streamWaitTimeout = null; GrpcCallContext explicitNullOverlay = @@ -224,7 +231,9 @@ public void testMergeWithNullStreamingWaitTimeout() { public void testWithZeroStreamingWaitTimeout() { java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( - GrpcCallContext.createDefault().withStreamWaitTimeout(timeout).getStreamWaitTimeoutDuration()) + GrpcCallContext.createDefault() + .withStreamWaitTimeout(timeout) + .getStreamWaitTimeoutDuration()) .isEqualTo(timeout); } @@ -250,7 +259,8 @@ public void testMergeWithNullStreamingIdleTimeout() { GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); - Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeoutDuration()) + .isEqualTo(timeout); java.time.Duration idleTimeout = null; GrpcCallContext explicitNullOverlay = @@ -263,7 +273,9 @@ public void testMergeWithNullStreamingIdleTimeout() { public void testWithZeroStreamingIdleTimeout() { java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( - GrpcCallContext.createDefault().withStreamIdleTimeout(timeout).getStreamIdleTimeoutDuration()) + GrpcCallContext.createDefault() + .withStreamIdleTimeout(timeout) + .getStreamIdleTimeoutDuration()) .isEqualTo(timeout); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index 507b593a57..34af69112f 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -65,7 +65,8 @@ public static HttpJsonClientCall newC callOptions = callOptions .toBuilder() - .setTimeout(java.time.Duration.ofMillis(httpJsonContext.getTimeoutDuration().toMillis())) + .setTimeout( + java.time.Duration.ofMillis(httpJsonContext.getTimeoutDuration().toMillis())) .build(); } httpJsonContext = httpJsonContext.withCallOptions(callOptions); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 8e01a6fde7..02e7019b7e 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -142,12 +142,14 @@ public void testWithShorterTimeout() { HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); // Sanity check - Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(10)); + Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()) + .isEqualTo(java.time.Duration.ofSeconds(10)); // Shorten the timeout and make sure it changed HttpJsonCallContext ctxWithShorterTimeout = ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); - Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()) + .isEqualTo(java.time.Duration.ofSeconds(5)); } @Test @@ -156,7 +158,8 @@ public void testWithLongerTimeout() { HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); // Sanity check - Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()).isEqualTo(java.time.Duration.ofSeconds(5)); + Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()) + .isEqualTo(java.time.Duration.ofSeconds(5)); // Try to extend the timeout and verify that it was ignored HttpJsonCallContext ctxWithUnchangedTimeout = @@ -176,7 +179,8 @@ public void testMergeWithNullTimeout() { java.time.Duration callContextTimeout = null; HttpJsonCallContext explicitNullOverlay = HttpJsonCallContext.createDefault().withTimeout(callContextTimeout); - Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()) + .isEqualTo(timeout); } @Test diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index c3f7ed121f..0c27f8689a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -35,7 +35,6 @@ import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; - import javax.annotation.Nullable; /** @@ -151,10 +150,7 @@ public abstract static class Builder { */ public abstract Builder setRequestByteThreshold(Long requestByteThreshold); - - /** - * Backport of {@link #setDelayThreshold(java.time.Duration)} - */ + /** Backport of {@link #setDelayThreshold(java.time.Duration)} */ public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index 23ee616bba..c2126f31db 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -33,9 +33,8 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; -import org.threeten.bp.Duration; - import java.util.concurrent.ThreadLocalRandom; +import org.threeten.bp.Duration; /** * The timed retry algorithm which uses jittered exponential backoff factor for calculating the next @@ -131,7 +130,8 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti (long) (settings.getRetryDelayMultiplier() * previousSettings.getRetryDelay().toMillis()); newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis()); } - org.threeten.bp.Duration randomDelay = org.threeten.bp.Duration.ofMillis(nextRandomLong(newRetryDelay)); + org.threeten.bp.Duration randomDelay = + org.threeten.bp.Duration.ofMillis(nextRandomLong(newRetryDelay)); // The rpc timeout is determined as follows: // attempt #0 - use the initialRpcTimeout; @@ -146,8 +146,10 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti // next attempt's delay, in order to truncate the RPC timeout should it exceed the totalTimeout. if (!settings.getTotalTimeout().isZero()) { org.threeten.bp.Duration timeElapsed = - org.threeten.bp.Duration.ofNanos(clock.nanoTime()) - .minus(org.threeten.bp.Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); + org.threeten.bp.Duration.ofNanos(clock.nanoTime()) + .minus( + org.threeten.bp.Duration.ofNanos( + previousSettings.getFirstAttemptStartTimeNanos())); org.threeten.bp.Duration timeLeft = settings.getTotalTimeout().minus(timeElapsed).minus(randomDelay); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 50030b6735..cea0d6c259 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -35,7 +35,6 @@ import com.google.api.core.BetaApi; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; - import java.io.Serializable; /** @@ -192,9 +191,7 @@ public static Builder newBuilder() { @AutoValue.Builder public abstract static class Builder { - /** - * Backport of {@link #setTotalTimeout(java.time.Duration)} - */ + /** Backport of {@link #setTotalTimeout(java.time.Duration)} */ public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); /** @@ -206,9 +203,7 @@ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { return setTotalTimeout(toThreetenDuration(totalTimeout)); } - /** - * Backport of {@link #setInitialRetryDelay(java.time.Duration)} - */ + /** Backport of {@link #setInitialRetryDelay(java.time.Duration)} */ public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); /** @@ -227,9 +222,7 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { */ public abstract Builder setRetryDelayMultiplier(double multiplier); - /** - * Backport of {@link #setMaxRetryDelay(java.time.Duration)} - */ + /** Backport of {@link #setMaxRetryDelay(java.time.Duration)} */ public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); /** @@ -262,9 +255,7 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { @VisibleForTesting public abstract Builder setJittered(boolean jittered); - /** - * Backport of {@link #setInitialRpcTimeout(java.time.Duration)} - */ + /** Backport of {@link #setInitialRpcTimeout(java.time.Duration)} */ public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); /** @@ -282,9 +273,7 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { */ public abstract Builder setRpcTimeoutMultiplier(double multiplier); - /** - * Backport of {@link #setMaxRpcTimeout(java.time.Duration)} - */ + /** Backport of {@link #setMaxRpcTimeout(java.time.Duration)} */ public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); /** @@ -296,7 +285,6 @@ public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); } - /** Backport of {@link #getTotalTimeoutDuration()} */ public abstract org.threeten.bp.Duration getTotalTimeout(); @@ -393,9 +381,9 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { @BetaApi public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { return setRpcTimeoutMultiplier(1) - .setInitialRpcTimeout(timeout) - .setMaxRpcTimeout(timeout) - .setTotalTimeout(timeout); + .setInitialRpcTimeout(timeout) + .setMaxRpcTimeout(timeout) + .setTotalTimeout(timeout); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index e89234db6a..b79b9ce3ff 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -103,8 +103,7 @@ public abstract static class Builder { public abstract Builder setGlobalSettings(RetrySettings value); /** - * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} */ public abstract Builder setRetryDelay(org.threeten.bp.Duration value); @@ -117,13 +116,12 @@ public final Builder setRetryDelay(java.time.Duration value) { } /** - * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); /** Sets rpc timeout used for this attempt. */ - public final Builder setRpcTimeout(java.time.Duration value){ + public final Builder setRpcTimeout(java.time.Duration value) { return setRpcTimeout(toThreetenDuration(value)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 0351419071..6b0831a739 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -138,8 +138,8 @@ public interface ApiCallContext extends RetryingContext { * amount of timeout that can pass between a message being received by {@link * ResponseObserver#onResponse(Object)} and demand being signaled via {@link * StreamController#request(int)}. Please note that this timeout is best effort and the maximum - * resolution configured in {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. This is useful - * to clean up streams that were partially read but never closed. When the timeout has been + * resolution configured in {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. This is + * useful to clean up streams that were partially read but never closed. When the timeout has been * reached, the stream will be closed with a nonretryable {@link WatchdogTimeoutException} and a * status of {@link StatusCode.Code#ABORTED}. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index a49c7eae83..f02e8992de 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.rpc; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 6ae8a6db01..b5678ce26a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -264,16 +264,16 @@ public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { setRetryableCodes(); setRetrySettings( - RetrySettings.newBuilder() - .setTotalTimeout(timeout) - .setInitialRetryDelay(java.time.Duration.ZERO) - .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ZERO) - .setInitialRpcTimeout(timeout) - .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(timeout) - .setMaxAttempts(1) - .build()); + RetrySettings.newBuilder() + .setTotalTimeout(timeout) + .setInitialRetryDelay(java.time.Duration.ZERO) + .setRetryDelayMultiplier(1) + .setMaxRetryDelay(java.time.Duration.ZERO) + .setInitialRpcTimeout(timeout) + .setRpcTimeoutMultiplier(1) + .setMaxRpcTimeout(timeout) + .setMaxAttempts(1) + .build()); return this; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 1055bdc015..e81b501649 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -29,17 +29,15 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.InternalExtensionOnly; import com.google.api.gax.retrying.RetrySettings; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import org.threeten.bp.Duration; - import java.util.Set; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - /** * A base settings class to configure a UnaryCallable. An instance of UnaryCallSettings is not * sufficient on its own to construct a UnaryCallable; a concrete derived type is necessary. @@ -197,9 +195,7 @@ public UnaryCallSettings.Builder setRetrySettings( return this; } - /** - * Backport of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} - */ + /** Backport of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} */ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { setRetryableCodes(); @@ -219,7 +215,7 @@ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( /** Disables retries and sets the RPC timeout. */ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( - java.time.Duration timeout) { + java.time.Duration timeout) { return setSimpleTimeoutNoRetries(toThreetenDuration(timeout)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index a8ce70e633..917f4d4584 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -383,10 +383,7 @@ public void testWhenThresholdIsDisabled() throws Exception { @Test public void testWhenDelayThresholdExceeds() throws Exception { BatchingSettings settings = - batchingSettings - .toBuilder() - .setDelayThreshold(java.time.Duration.ofMillis(100)) - .build(); + batchingSettings.toBuilder().setDelayThreshold(java.time.Duration.ofMillis(100)).build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(6); assertThat(result.isDone()).isFalse(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index ce7d22125a..0e8be8e41a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -92,8 +92,7 @@ public void testCreateFirstAttemptOverride() { assertEquals(0, attempt.getOverallAttemptCount()); assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals( - retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeout()); + assertEquals(retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeout()); assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); } diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index a1250b4855..a0074554fc 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -16,7 +16,6 @@ package com.google.cloud; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index afdc5043b4..f2f968a524 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -61,7 +61,8 @@ public void testEqualsAndHashCode() { assertNotEquals(JITTERED, MAX_ATTEMPTS); RetryOption totalTimeout = RetryOption.totalTimeout(org.threeten.bp.Duration.ofMillis(420L)); - RetryOption initialRetryDelay = RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)); + RetryOption initialRetryDelay = + RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)); RetryOption retryDelayMultiplier = RetryOption.retryDelayMultiplier(1.5); RetryOption maxRetryDelay = RetryOption.maxRetryDelay(org.threeten.bp.Duration.ofMillis(100)); RetryOption maxAttempts = RetryOption.maxAttempts(100); @@ -100,17 +101,26 @@ public void testMergeToSettings() { assertEquals(retrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setTotalTimeout(org.threeten.bp.Duration.ofMillis(420L)).build(); + defRetrySettings + .toBuilder() + .setTotalTimeout(org.threeten.bp.Duration.ofMillis(420L)) + .build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(100)).build(); + defRetrySettings + .toBuilder() + .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(100)) + .build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)).build(); + defRetrySettings + .toBuilder() + .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)) + .build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); From 5cf12896ffc3c1dfa6da600b82b700fba394801a Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 1 Aug 2023 11:44:35 -0400 Subject: [PATCH 029/141] chore: fix tests in gax/gax --- .../main/java/com/google/api/gax/rpc/ClientSettings.java | 1 - .../api/gax/retrying/ExponentialRetryAlgorithmTest.java | 2 +- .../java/com/google/api/gax/retrying/RetrySettingsTest.java | 6 +++--- .../com/google/api/gax/rpc/OperationCallableImplTest.java | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index f02e8992de..6351961851 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.rpc; - import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; import com.google.api.gax.core.CredentialsProvider; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index 0e8be8e41a..3ed9617191 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -92,7 +92,7 @@ public void testCreateFirstAttemptOverride() { assertEquals(0, attempt.getOverallAttemptCount()); assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeout()); + assertEquals(retrySettingsOverride.getInitialRpcTimeout(), attempt.getRpcTimeout()); assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index f8758c694d..2c11f9eb87 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -40,9 +40,9 @@ public void retrySettingsSetLogicalTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); - Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getTotalTimeout()).isEqualTo(timeout); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index b2f028dd8d..1bbf8808ce 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -568,7 +568,7 @@ public void testFutureCallContextPropagation() throws Exception { callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); assertThat(callContextCaptor.getValue().getTimeoutDuration()) - .isEqualTo(org.threeten.bp.Duration.ofMillis(10)); + .isEqualTo(java.time.Duration.ofMillis(10)); } @Test From 8e221c17cb77f00ff90c20d7dc75cf7d961422ba Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 1 Aug 2023 12:26:59 -0400 Subject: [PATCH 030/141] chore: add @ObsoleteApi annotation --- .../google/api/gax/grpc/GrpcCallContext.java | 12 +++++++++--- .../grpc/InstantiatingGrpcChannelProvider.java | 6 ++++++ .../api/gax/httpjson/HttpJsonCallContext.java | 12 +++++++++--- .../api/gax/batching/BatchingSettings.java | 3 +++ .../api/gax/batching/ThresholdBatcher.java | 2 ++ .../gax/retrying/ExponentialRetryAlgorithm.java | 13 ++++++------- .../google/api/gax/retrying/RetrySettings.java | 17 +++++++++++++++++ .../api/gax/retrying/TimedAttemptSettings.java | 7 +++++++ .../com/google/api/gax/rpc/ApiCallContext.java | 13 +++++++++---- .../com/google/api/gax/rpc/ClientContext.java | 3 +++ .../com/google/api/gax/rpc/ClientSettings.java | 4 ++++ .../api/gax/rpc/FixedWatchdogProvider.java | 2 ++ .../gax/rpc/InstantiatingWatchdogProvider.java | 2 ++ .../gax/rpc/ServerStreamingCallSettings.java | 8 ++++++++ .../com/google/api/gax/rpc/StubSettings.java | 4 ++++ .../google/api/gax/rpc/UnaryCallSettings.java | 2 ++ .../java/com/google/api/gax/rpc/Watchdog.java | 2 ++ .../google/api/gax/rpc/WatchdogProvider.java | 2 ++ .../main/java/com/google/cloud/RetryOption.java | 4 ++++ 19 files changed, 101 insertions(+), 17 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index eec2727eb4..a5ec6f97e1 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -33,6 +33,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.BetaApi; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.StatusCode; @@ -57,7 +58,6 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * GrpcCallContext encapsulates context data used to make a grpc call. @@ -177,6 +177,7 @@ public GrpcCallContext withTransportChannel(TransportChannel inputChannel) { /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @Override + @ObsoleteApi("Use withTimeout(java.time.Duration) instead") public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { return withTimeout(toJavaTimeDuration(timeout)); } @@ -208,6 +209,7 @@ public GrpcCallContext withTimeout(@Nullable java.time.Duration timeout) { @Nullable @Override + @ObsoleteApi("Use getTimeoutDuration() instead") public org.threeten.bp.Duration getTimeout() { return toThreetenDuration(getTimeoutDuration()); } @@ -223,6 +225,7 @@ public java.time.Duration getTimeoutDuration() { * org.threeten.bp.Duration} */ @Override + @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") public GrpcCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); @@ -256,6 +259,7 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration stream * @return */ @Override + @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") public GrpcCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); @@ -458,6 +462,7 @@ public CallOptions getCallOptions() { /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Override @Nullable + @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") public org.threeten.bp.Duration getStreamWaitTimeout() { return toThreetenDuration(getStreamWaitTimeoutDuration()); } @@ -465,7 +470,7 @@ public org.threeten.bp.Duration getStreamWaitTimeout() { /** * The stream wait timeout set for this context. * - * @see ApiCallContext#withStreamWaitTimeout(Duration) + * @see ApiCallContext#withStreamWaitTimeout(java.time.Duration) */ @Override @Nullable @@ -475,13 +480,14 @@ public java.time.Duration getStreamWaitTimeoutDuration() { @Override @Nullable + @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") public org.threeten.bp.Duration getStreamIdleTimeout() { return toThreetenDuration(getStreamIdleTimeoutDuration()); } /** * The stream idle timeout set for this context. * - * @see ApiCallContext#withStreamIdleTimeout(Duration) + * @see ApiCallContext#withStreamIdleTimeout(java.time.Duration) */ @Override @Nullable diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 9ccfe1add7..3f10e4d0bd 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -36,6 +36,7 @@ import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.api.core.InternalExtensionOnly; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.ExecutorProvider; import com.google.api.gax.rpc.FixedHeaderProvider; import com.google.api.gax.rpc.HeaderProvider; @@ -402,6 +403,7 @@ public String getEndpoint() { return endpoint; } + @ObsoleteApi("Use getKeepAliveTimeDuration() instead") public org.threeten.bp.Duration getKeepAliveTime() { return toThreetenDuration(getKeepAliveTimeDuration()); } @@ -411,6 +413,7 @@ public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } + @ObsoleteApi("Use getKeepAliveTimeoutDuration() instead") public org.threeten.bp.Duration getKeepAliveTimeout() { return toThreetenDuration(getKeepAliveTimeoutDuration()); } @@ -597,6 +600,7 @@ public Integer getMaxInboundMetadataSize() { * Overload of {@link #setKeepAliveTime(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use setKeepAliveTime(java.time.Duration) instead") public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { return setKeepAliveTime(toJavaTimeDuration(duration)); } @@ -607,6 +611,7 @@ public Builder setKeepAliveTime(java.time.Duration duration) { } /** Backport of {@link #getKeepAliveTimeDuration()} */ + @ObsoleteApi("Use getKeepAliveTimeDuration() instead") public org.threeten.bp.Duration getKeepAliveTime() { return toThreetenDuration(getKeepAliveTimeDuration()); } @@ -616,6 +621,7 @@ public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } + @ObsoleteApi("Use setKeepAliveTimeout(java.time.Duration) instead") public Builder setKeepAliveTimeout(org.threeten.bp.Duration duration) { return setKeepAliveTimeout(toJavaTimeDuration(duration)); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index a812f59ea3..ba7a962bec 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -33,6 +33,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.BetaApi; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.StatusCode; @@ -51,7 +52,6 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * HttpJsonCallContext encapsulates context data used to make an http-json call. @@ -236,6 +236,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @Override + @ObsoleteApi("Use withTimeout(java.time.Duration) instead") public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { return withTimeout(toJavaTimeDuration(timeout)); } @@ -268,6 +269,7 @@ public HttpJsonCallContext withTimeout(java.time.Duration timeout) { /** Backport of {@link #getTimeoutDuration()} */ @Nullable @Override + @ObsoleteApi("Use getTimeoutDuration instead") public org.threeten.bp.Duration getTimeout() { return toThreetenDuration(getTimeoutDuration()); } @@ -283,6 +285,7 @@ public java.time.Duration getTimeoutDuration() { * org.threeten.bp.Duration} */ @Override + @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") public HttpJsonCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); @@ -311,6 +314,7 @@ public HttpJsonCallContext withStreamWaitTimeout(@Nullable java.time.Duration st /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Override @Nullable + @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") public org.threeten.bp.Duration getStreamWaitTimeout() { return toThreetenDuration(getStreamWaitTimeoutDuration()); } @@ -318,7 +322,7 @@ public org.threeten.bp.Duration getStreamWaitTimeout() { /** * The stream wait timeout set for this context. * - * @see ApiCallContext#withStreamWaitTimeout(Duration) + * @see ApiCallContext#withStreamWaitTimeout(java.time.Duration) */ @Override @Nullable @@ -331,6 +335,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { * org.threeten.bp.Duration} */ @Override + @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") public HttpJsonCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); @@ -359,6 +364,7 @@ public HttpJsonCallContext withStreamIdleTimeout(@Nullable java.time.Duration st /** Backport of {@link #getStreamIdleTimeoutDuration()} */ @Override @Nullable + @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") public org.threeten.bp.Duration getStreamIdleTimeout() { return toThreetenDuration(getStreamIdleTimeoutDuration()); } @@ -366,7 +372,7 @@ public org.threeten.bp.Duration getStreamIdleTimeout() { /** * The stream idle timeout set for this context. * - * @see ApiCallContext#withStreamIdleTimeout(Duration) + * @see ApiCallContext#withStreamIdleTimeout(java.time.Duration) */ @Override @Nullable diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 0c27f8689a..1aa7d73d70 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -32,6 +32,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; @@ -102,6 +103,7 @@ public abstract class BatchingSettings { /** Get the delay threshold to use for batching. */ @Nullable + @ObsoleteApi("Use getDelayThresholdDuration() instead") public abstract org.threeten.bp.Duration getDelayThreshold(); /** Get the delay threshold to use for batching. */ @@ -151,6 +153,7 @@ public abstract static class Builder { public abstract Builder setRequestByteThreshold(Long requestByteThreshold); /** Backport of {@link #setDelayThreshold(java.time.Duration)} */ + @ObsoleteApi("Use setDelayThreshold(java.time.Duration) instead") public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 3e4d6cc2a8..fa75036c82 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -36,6 +36,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutureCallback; import com.google.api.core.ApiFutures; +import com.google.api.core.ObsoleteApi; import com.google.api.core.SettableApiFuture; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.common.annotations.VisibleForTesting; @@ -124,6 +125,7 @@ public Builder setMaxDelay(java.time.Duration maxDelay) { } /** Set the max delay for a batch. This is counted from the first item added to a batch. */ + @ObsoleteApi("Use setMaxDelay(java.time.Duration) instead") public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { return setMaxDelay(toJavaTimeDuration(maxDelay)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index c2126f31db..6d53c026e3 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -34,7 +34,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import java.util.concurrent.ThreadLocalRandom; -import org.threeten.bp.Duration; /** * The timed retry algorithm which uses jittered exponential backoff factor for calculating the next @@ -69,9 +68,9 @@ public ExponentialRetryAlgorithm(RetrySettings globalSettings, ApiClock clock) { public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) - .setRetryDelay(Duration.ZERO) + .setRetryDelay(org.threeten.bp.Duration.ZERO) .setRpcTimeout(globalSettings.getInitialRpcTimeout()) - .setRandomizedRetryDelay(Duration.ZERO) + .setRandomizedRetryDelay(org.threeten.bp.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -99,8 +98,8 @@ public TimedAttemptSettings createFirstAttempt(RetryingContext context) { // retrySettings, but a new call will not (unless overridden again). .setGlobalSettings(retrySettings) .setRpcTimeout(retrySettings.getInitialRpcTimeout()) - .setRetryDelay(Duration.ZERO) - .setRandomizedRetryDelay(Duration.ZERO) + .setRetryDelay(org.threeten.bp.Duration.ZERO) + .setRandomizedRetryDelay(org.threeten.bp.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -162,8 +161,8 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti return TimedAttemptSettings.newBuilder() .setGlobalSettings(previousSettings.getGlobalSettings()) - .setRetryDelay(Duration.ofMillis(newRetryDelay)) - .setRpcTimeout(Duration.ofMillis(newRpcTimeout)) + .setRetryDelay(org.threeten.bp.Duration.ofMillis(newRetryDelay)) + .setRpcTimeout(org.threeten.bp.Duration.ofMillis(newRpcTimeout)) .setRandomizedRetryDelay(randomDelay) .setAttemptCount(previousSettings.getAttemptCount() + 1) .setOverallAttemptCount(previousSettings.getOverallAttemptCount() + 1) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index cea0d6c259..183add3f55 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -33,6 +33,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.BetaApi; +import com.google.api.core.ObsoleteApi; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; @@ -75,6 +76,7 @@ public abstract class RetrySettings implements Serializable { private static final long serialVersionUID = 8258475264439710899L; /** Backport of {@link #getTotalTimeoutDuration()} */ + @ObsoleteApi("Use getTotalTimeoutDuration() instead") public abstract org.threeten.bp.Duration getTotalTimeout(); /** @@ -87,6 +89,7 @@ public final java.time.Duration getTotalTimeoutDuration() { } /** Backport of {@link #getInitialRetryDelayDuration()} */ + @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** @@ -106,6 +109,7 @@ public final java.time.Duration getInitialRetryDelayDuration() { public abstract double getRetryDelayMultiplier(); /** Backport of {@link #getMaxRetryDelayDuration()} */ + @ObsoleteApi("Use getMaxRetryDelayDuration()") public abstract org.threeten.bp.Duration getMaxRetryDelay(); /** @@ -139,6 +143,7 @@ public final java.time.Duration getMaxRetryDelayDuration() { public abstract boolean isJittered(); /** Backport of {@link #getInitialRpcTimeoutDuration()} */ + @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") public abstract org.threeten.bp.Duration getInitialRpcTimeout(); /** @@ -158,6 +163,7 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { public abstract double getRpcTimeoutMultiplier(); /** Backport of {@link #getMaxRpcTimeoutDuration()} */ + @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") public abstract org.threeten.bp.Duration getMaxRpcTimeout(); /** @@ -192,6 +198,7 @@ public static Builder newBuilder() { public abstract static class Builder { /** Backport of {@link #setTotalTimeout(java.time.Duration)} */ + @ObsoleteApi("Use setTotalTimeout(java.time.Duration) instead") public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); /** @@ -204,6 +211,7 @@ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { } /** Backport of {@link #setInitialRetryDelay(java.time.Duration)} */ + @ObsoleteApi("Use setInitialRetryDelay(java.time.Duration) instead") public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); /** @@ -223,6 +231,7 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { public abstract Builder setRetryDelayMultiplier(double multiplier); /** Backport of {@link #setMaxRetryDelay(java.time.Duration)} */ + @ObsoleteApi("Use setMaxRetryDelay(java.time.Duration) instead") public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); /** @@ -256,6 +265,7 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { public abstract Builder setJittered(boolean jittered); /** Backport of {@link #setInitialRpcTimeout(java.time.Duration)} */ + @ObsoleteApi("Use setInitialRpcTimeout(java.time.Duration) instead") public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); /** @@ -274,6 +284,7 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { public abstract Builder setRpcTimeoutMultiplier(double multiplier); /** Backport of {@link #setMaxRpcTimeout(java.time.Duration)} */ + @ObsoleteApi("Use setMaxRpcTimeout(java.time.Duration) instead") public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); /** @@ -286,6 +297,7 @@ public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { } /** Backport of {@link #getTotalTimeoutDuration()} */ + @ObsoleteApi("Use getTotalTimeoutDuration() instead") public abstract org.threeten.bp.Duration getTotalTimeout(); /** @@ -298,6 +310,7 @@ public final java.time.Duration getTotalTimeoutDuration() { } /** Backport of {@link #getInitialRetryDelay()} */ + @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** @@ -334,6 +347,7 @@ public final java.time.Duration getInitialRetryDelayDuration() { public abstract boolean isJittered(); /** Backport of {@link #getMaxRetryDelayDuration()} */ + @ObsoleteApi("Use getMaxRetryDelayDuration() instead") public abstract org.threeten.bp.Duration getMaxRetryDelay(); /** @@ -346,6 +360,7 @@ public final java.time.Duration getMaxRetryDelayDuration() { } /** Backport of {@link #getInitialRpcTimeoutDuration()} */ + @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") public abstract org.threeten.bp.Duration getInitialRpcTimeout(); /** @@ -364,6 +379,7 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { public abstract double getRpcTimeoutMultiplier(); /** Backport of {@link #getMaxRpcTimeoutDuration()} */ + @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") public abstract org.threeten.bp.Duration getMaxRpcTimeout(); /** @@ -379,6 +395,7 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { * org.threeten.bp.Duration} */ @BetaApi + @ObsoleteApi("Use setLogicalTimeout(java.time.Duration) instead") public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { return setRpcTimeoutMultiplier(1) .setInitialRpcTimeout(timeout) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index b79b9ce3ff..ef79a46b20 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -33,6 +33,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.ApiClock; +import com.google.api.core.ObsoleteApi; import com.google.auto.value.AutoValue; /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ @@ -43,6 +44,7 @@ public abstract class TimedAttemptSettings { public abstract RetrySettings getGlobalSettings(); /** Backport of {@link #getRetryDelayDuration()} */ + @ObsoleteApi("Use getRetryDelayDuration() instead") public abstract org.threeten.bp.Duration getRetryDelay(); /** @@ -54,6 +56,7 @@ public final java.time.Duration getRetryDelayDuration() { } /** Backport of {@link #getRpcTimeoutDuration()} */ + @ObsoleteApi("Use getRpcTimeoutDuration() instead") public abstract org.threeten.bp.Duration getRpcTimeout(); /** Returns rpc timeout used for this attempt. */ @@ -62,6 +65,7 @@ public final java.time.Duration getRpcTimeoutDuration() { } /** Backport of {@link #getRandomizedRetryDelayDuration()} */ + @ObsoleteApi("Use getRandomizedRetryDelayDuration() instead") public abstract org.threeten.bp.Duration getRandomizedRetryDelay(); /** @@ -105,6 +109,7 @@ public abstract static class Builder { /** * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} */ + @ObsoleteApi("Use setRetryDelay(java.time.Duration) instead") public abstract Builder setRetryDelay(org.threeten.bp.Duration value); /** @@ -118,6 +123,7 @@ public final Builder setRetryDelay(java.time.Duration value) { /** * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ + @ObsoleteApi("Use setRpcTimeout(java.time.Duration) instead") public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); /** Sets rpc timeout used for this attempt. */ @@ -129,6 +135,7 @@ public final Builder setRpcTimeout(java.time.Duration value) { * Backport of {@link #setRandomizedRetryDelay(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use setRandomizedRetryDelay(java.time.Duration) instead") public abstract Builder setRandomizedRetryDelay(org.threeten.bp.Duration value); /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 6b0831a739..2a068474a5 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -31,6 +31,7 @@ import com.google.api.core.BetaApi; import com.google.api.core.InternalExtensionOnly; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.RetryingContext; import com.google.api.gax.rpc.StatusCode.Code; @@ -42,7 +43,6 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Context for an API call. @@ -64,6 +64,7 @@ public interface ApiCallContext extends RetryingContext { ApiCallContext withTransportChannel(TransportChannel channel); /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ + @ObsoleteApi("Use withTimeout(java.time.Duration) instead") ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); /** @@ -82,6 +83,7 @@ public interface ApiCallContext extends RetryingContext { /** Backport of {@link #getTimeoutDuration()} */ @Nullable + @ObsoleteApi("Use getTimeoutDuration() instead") org.threeten.bp.Duration getTimeout(); /** Returns the configured per-RPC timeout. */ @@ -92,6 +94,7 @@ public interface ApiCallContext extends RetryingContext { * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link * org.threeten.bp.Duration } */ + @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") ApiCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout); /** @@ -115,6 +118,7 @@ public interface ApiCallContext extends RetryingContext { /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Nullable + @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") org.threeten.bp.Duration getStreamWaitTimeout(); /** @@ -129,6 +133,7 @@ public interface ApiCallContext extends RetryingContext { * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") ApiCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout); /** @@ -153,16 +158,16 @@ public interface ApiCallContext extends RetryingContext { /** Backport of {@link #getStreamIdleTimeoutDuration()} */ @Nullable + @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") org.threeten.bp.Duration getStreamIdleTimeout(); /** * The stream idle timeout set for this context. * - * @see #withStreamIdleTimeout(Duration) + * @see #withStreamIdleTimeout(java.time.Duration) */ @Nullable java.time.Duration getStreamIdleTimeoutDuration(); - /** * The {@link ApiTracer} that was previously set for this context. * @@ -217,7 +222,7 @@ public interface ApiCallContext extends RetryingContext { * } * * Setting a logical call timeout for the context can be done similarly with {@link - * RetrySettings.Builder#setLogicalTimeout(Duration timeout)}. + * RetrySettings.Builder#setLogicalTimeout(java.time.Duration timeout)}. * *

    Example usage: * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 473e39442d..af448facbf 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -36,6 +36,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.BetaApi; import com.google.api.core.NanoClock; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.ExecutorAsBackgroundResource; import com.google.api.gax.core.ExecutorProvider; @@ -106,6 +107,7 @@ public abstract class ClientContext { * @return */ @Nonnull + @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public abstract org.threeten.bp.Duration getStreamWatchdogCheckInterval(); @Nonnull @@ -362,6 +364,7 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); + @ObsoleteApi("Use setStreamWatchdogCheckInterval(java.time.Duration) instead") public abstract Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration); public final Builder setStreamWatchdogCheckInterval(java.time.Duration duration) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 6351961851..e8b4fa8e5c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -31,6 +31,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.ExecutorProvider; import com.google.common.base.MoreObjects; @@ -111,6 +112,7 @@ public final WatchdogProvider getWatchdogProvider() { * @return */ @Nonnull + @ObsoleteApi("Use getWatchdogCheckIntervalDuration() instead") public final org.threeten.bp.Duration getWatchdogCheckInterval() { return stubSettings.getStreamWatchdogCheckInterval(); } @@ -265,6 +267,7 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { return self(); } + @ObsoleteApi("Use setWatchdogCheckInterval(java.time.Duration) instead") public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { stubSettings.setStreamWatchdogCheckInterval(checkInterval); return self(); @@ -350,6 +353,7 @@ public WatchdogProvider getWatchdogProvider() { } @Nullable + @ObsoleteApi("Use getWatchdogCheckIntervalDuration() instead") public org.threeten.bp.Duration getWatchdogCheckInterval() { return stubSettings.getStreamWatchdogCheckInterval(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java index 9d8054ab1d..3c3e3a27b5 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java @@ -31,6 +31,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -70,6 +71,7 @@ public boolean needsCheckInterval() { } @Override + @ObsoleteApi("Use withCheckInterval(java.time.Duration) instead") public WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval) { throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index ad8b9655aa..d4acdba4f4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -33,6 +33,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.common.base.Preconditions; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; @@ -87,6 +88,7 @@ public boolean needsCheckInterval() { * @return */ @Override + @ObsoleteApi("Use withCheckInterval(java.time.Duration) instead") public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { return withCheckInterval(toJavaTimeDuration(Preconditions.checkNotNull(checkInterval))); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index b5678ce26a..9e78cb0051 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -32,6 +32,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.SimpleStreamResumptionStrategy; import com.google.api.gax.retrying.StreamResumptionStrategy; @@ -122,6 +123,7 @@ public StreamResumptionStrategy getResumptionStrategy() { /** Backport of {@link #getIdleTimeoutDuration()} */ @Nonnull + @ObsoleteApi("Use getIdleTimeoutDuration() instead") public org.threeten.bp.Duration getIdleTimeout() { return toThreetenDuration(getIdleTimeoutDuration()); } @@ -137,6 +139,7 @@ public java.time.Duration getIdleTimeoutDuration() { /** Backport of {@link #getWaitTimeoutDuration()} */ @Nonnull + @ObsoleteApi("Use getWaitTimeoutDuration() instead") public org.threeten.bp.Duration getWaitTimeout() { return toThreetenDuration(getWaitTimeoutDuration()); } @@ -260,6 +263,7 @@ public RetrySettings getRetrySettings() { * Overload of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use setSimpleTimeoutNoRetries(java.time.Duration) instead") public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { setRetryableCodes(); @@ -302,6 +306,7 @@ public StreamResumptionStrategy getResumptionStrategy() { /** Backport of {@link #getIdleTimeoutDuration()} */ @Nonnull + @ObsoleteApi("Use getIdleTimeoutDuration() instead") public org.threeten.bp.Duration getIdleTimeout() { return toThreetenDuration(getIdleTimeoutDuration()); } @@ -314,6 +319,7 @@ public java.time.Duration getIdleTimeoutDuration() { /** * Overlad of {@link #setIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ + @ObsoleteApi("Use setIdleTimeout(java.time.Duration) instead") public Builder setIdleTimeout( @Nonnull org.threeten.bp.Duration idleTimeout) { return setIdleTimeout(toJavaTimeDuration(idleTimeout)); @@ -330,6 +336,7 @@ public Builder setIdleTimeout(@Nonnull java.time.Duration i /** Backport of {@link #getWaitTimeoutDuration()} */ @Nonnull + @ObsoleteApi("Use getWaitTimeoutDuration() instead") public org.threeten.bp.Duration getWaitTimeout() { return toThreetenDuration(getWaitTimeoutDuration()); } @@ -343,6 +350,7 @@ public java.time.Duration getWaitTimeoutDuration() { * Overload of {@link #setWaitTimeout(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use setWaitTimeout(java.time.Duration) instead") public Builder setWaitTimeout( @Nonnull org.threeten.bp.Duration waitTimeout) { return setWaitTimeout(toJavaTimeDuration(waitTimeout)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index 44ca82cc6a..ec723a83ee 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -36,6 +36,7 @@ import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; import com.google.api.core.NanoClock; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.ExecutorProvider; import com.google.api.gax.core.FixedCredentialsProvider; @@ -163,6 +164,7 @@ public final WatchdogProvider getStreamWatchdogProvider() { /** Backport of {@link #getStreamWatchdogCheckIntervalDuration()} */ @Nonnull + @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); } @@ -450,6 +452,7 @@ public B setQuotaProjectId(String quotaProjectId) { * Overload of {@link #setStreamWatchdogCheckInterval(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use setStreamWatchdogCheckInterval(java.time.Duration) instead") public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { return setStreamWatchdogCheckInterval(toJavaTimeDuration(checkInterval)); } @@ -543,6 +546,7 @@ public String getQuotaProjectId() { return quotaProjectId; } + @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public org.threeten.bp.Duration getStreamWatchdogCheckInterval() { return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index e81b501649..9d4b74e852 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -32,6 +32,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.InternalExtensionOnly; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; @@ -196,6 +197,7 @@ public UnaryCallSettings.Builder setRetrySettings( } /** Backport of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} */ + @ObsoleteApi("Use setSimpleTimeoutNoRetries(java.time.Duration) instead") public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { setRetryableCodes(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 80a9d3d193..5943c5aa14 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -32,6 +32,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.ApiClock; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.BackgroundResource; import com.google.common.base.Preconditions; import java.time.Duration; @@ -102,6 +103,7 @@ private void start() { * Overload of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using * {@link org.threeten.bp.Duration} */ + @ObsoleteApi("Use watch(ResponseObserver, java.time.Duration, java.time.Duration) instead") public ResponseObserver watch( ResponseObserver innerObserver, @Nonnull org.threeten.bp.Duration waitTimeout, diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index 89dc58abef..a54ee53114 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -30,6 +30,7 @@ package com.google.api.gax.rpc; import com.google.api.core.ApiClock; +import com.google.api.core.ObsoleteApi; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; @@ -44,6 +45,7 @@ public interface WatchdogProvider { * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ + @ObsoleteApi("Use withCheckInterval(java.time.Duration) instead") WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); WatchdogProvider withCheckInterval(java.time.Duration checkInterval); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index a0074554fc..51e87be750 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.core.BetaApi; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import java.io.Serializable; @@ -52,6 +53,7 @@ private RetryOption(OptionType type, Object value) { } /** See {@link RetrySettings#getTotalTimeout()}. */ + @ObsoleteApi("Use totalTimeout(java.time.Duration) instead") public static RetryOption totalTimeout(org.threeten.bp.Duration totalTimeout) { return new RetryOption(OptionType.TOTAL_TIMEOUT, totalTimeout); } @@ -62,6 +64,7 @@ public static RetryOption totalTimeout(java.time.Duration totalTimeout) { } /** See {@link RetrySettings#getInitialRetryDelay()}. */ + @ObsoleteApi("Use initialRetryDelay(java.time.Duration) instead") public static RetryOption initialRetryDelay(org.threeten.bp.Duration initialRetryDelay) { return new RetryOption(OptionType.INITIAL_RETRY_DELAY, initialRetryDelay); } @@ -77,6 +80,7 @@ public static RetryOption retryDelayMultiplier(double retryDelayMultiplier) { } /** See {@link RetrySettings#getMaxRetryDelay()}. */ + @ObsoleteApi("Use maxRetryDelay(java.time.Duration) instead") public static RetryOption maxRetryDelay(org.threeten.bp.Duration maxRetryDelay) { return new RetryOption(OptionType.MAX_RETRY_DELAY, maxRetryDelay); } From 667f2da15d0800d87d0866e36627ac23955c0b01 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 1 Aug 2023 13:06:50 -0400 Subject: [PATCH 031/141] chore: revert changes in gapic-generator-java --- .../common/RetrySettingsComposerTest.java | 26 +++++++++---------- .../SampleBodyJavaFormatterTest.java | 4 +-- ...ServiceClientHeaderSampleComposerTest.java | 6 ++--- .../SettingsSampleComposerTest.java | 4 +-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java index ca11ef7004..0d567f409d 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposerTest.java @@ -121,18 +121,18 @@ public void paramDefinitionsBlock_basic() { "settings =" + " RetrySettings.newBuilder().setInitialRetryDelay(" + "Duration.ofMillis(100L)).setRetryDelayMultiplier(2.0)" - + ".setMaxRetryDelay(java.time.Duration.ofMillis(3000L))" - + ".setInitialRpcTimeout(java.time.Duration.ofMillis(10000L))" + + ".setMaxRetryDelay(Duration.ofMillis(3000L))" + + ".setInitialRpcTimeout(Duration.ofMillis(10000L))" + ".setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeout(java.time.Duration.ofMillis(10000L))" - + ".setTotalTimeout(java.time.Duration.ofMillis(10000L)).build();\n", + + ".setMaxRpcTimeout(Duration.ofMillis(10000L))" + + ".setTotalTimeout(Duration.ofMillis(10000L)).build();\n", "definitions.put(\"retry_policy_1_params\", settings);\n", "settings =" + " RetrySettings.newBuilder()" - + ".setInitialRpcTimeout(java.time.Duration.ofMillis(5000L))" + + ".setInitialRpcTimeout(Duration.ofMillis(5000L))" + ".setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeout(java.time.Duration.ofMillis(5000L))" - + ".setTotalTimeout(java.time.Duration.ofMillis(5000L)).build();\n", + + ".setMaxRpcTimeout(Duration.ofMillis(5000L))" + + ".setTotalTimeout(Duration.ofMillis(5000L)).build();\n", "definitions.put(\"no_retry_0_params\", settings);\n", "RETRY_PARAM_DEFINITIONS = definitions.build();\n", "}\n"); @@ -341,10 +341,10 @@ public void lroBuilderExpr() { + "WaitResponse.class))" + ".setMetadataTransformer(ProtoOperationTransformers.MetadataTransformer.create(" + "WaitMetadata.class)).setPollingAlgorithm(OperationTimedPollAlgorithm.create(" - + "RetrySettings.newBuilder().setInitialRetryDelay(java.time.Duration.ofMillis(5000L))" - + ".setRetryDelayMultiplier(1.5).setMaxRetryDelay(java.time.Duration.ofMillis(45000L))" - + ".setInitialRpcTimeout(java.time.Duration.ZERO).setRpcTimeoutMultiplier(1.0)" - + ".setMaxRpcTimeout(java.time.Duration.ZERO).setTotalTimeout(java.time.Duration.ofMillis(300000L))" + + "RetrySettings.newBuilder().setInitialRetryDelay(Duration.ofMillis(5000L))" + + ".setRetryDelayMultiplier(1.5).setMaxRetryDelay(Duration.ofMillis(45000L))" + + ".setInitialRpcTimeout(Duration.ZERO).setRpcTimeoutMultiplier(1.0)" + + ".setMaxRpcTimeout(Duration.ZERO).setTotalTimeout(Duration.ofMillis(300000L))" + ".build()))"); assertEquals(expected, writerVisitor.write()); } @@ -394,7 +394,7 @@ public void batchingSettings_minimalFlowControlSettings() { + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(100L)" + ".setRequestByteThreshold(1048576L)" - + ".setDelayThreshold(java.time.Duration.ofMillis(10L))" + + ".setDelayThreshold(Duration.ofMillis(10L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore)" @@ -451,7 +451,7 @@ public void batchingSettings_fullFlowControlSettings() { + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(1000L)" + ".setRequestByteThreshold(1048576L)" - + ".setDelayThreshold(java.time.Duration.ofMillis(50L))" + + ".setDelayThreshold(Duration.ofMillis(50L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setMaxOutstandingElementCount(100000L)" diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java index 5e8376d894..af58e7a30c 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SampleBodyJavaFormatterTest.java @@ -49,7 +49,7 @@ public void validFormatSampleCode_longChainMethod() { String sampleCode = "echoSettingsBuilder.echoSettings().setRetrySettings(" + "echoSettingsBuilder.echoSettings().getRetrySettings().toBuilder()" - + ".setTotalTimeout(java.time.Duration.ofSeconds(30)).build());"; + + ".setTotalTimeout(Duration.ofSeconds(30)).build());"; String result = SampleBodyJavaFormatter.format(sampleCode); String expected = LineFormatter.lines( @@ -60,7 +60,7 @@ public void validFormatSampleCode_longChainMethod() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeout(java.time.Duration.ofSeconds(30))\n", + " .setTotalTimeout(Duration.ofSeconds(30))\n", " .build());"); assertEquals(expected, result); } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java index 92294cd2f0..bf33f30e26 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/ServiceClientHeaderSampleComposerTest.java @@ -163,7 +163,7 @@ public void composeClassHeaderSample_firstMethodIsNotUnaryRpc() { String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", - " java.time.Duration ttl =java.time.Duration.newBuilder().build();\n", + " Duration ttl = Duration.newBuilder().build();\n", " WaitResponse response = echoClient.waitAsync(ttl).get();\n", "}"); Assert.assertEquals(results, expected); @@ -806,7 +806,7 @@ public void valid_composeShowcaseMethodSample_lroRpcWithReturnResponseType() { String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", - " java.time.Duration ttl =java.time.Duration.newBuilder().build();\n", + " Duration ttl = Duration.newBuilder().build();\n", " WaitResponse response = echoClient.waitAsync(ttl).get();\n", "}"); Assert.assertEquals(results, expected); @@ -888,7 +888,7 @@ public void valid_composeShowcaseMethodSample_lroRpcWithReturnVoid() { String expected = LineFormatter.lines( "try (EchoClient echoClient = EchoClient.create()) {\n", - " java.time.Duration ttl =java.time.Duration.newBuilder().build();\n", + " Duration ttl = Duration.newBuilder().build();\n", " echoClient.waitAsync(ttl).get();\n", "}"); Assert.assertEquals(results, expected); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java index 5fd3db1daa..00f319b0ce 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/samplecode/SettingsSampleComposerTest.java @@ -61,7 +61,7 @@ public void composeSettingsSample_serviceSettingsClass() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeout(java.time.Duration.ofSeconds(30))\n", + " .setTotalTimeout(Duration.ofSeconds(30))\n", " .build());\n", "EchoSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); @@ -89,7 +89,7 @@ public void composeSettingsSample_serviceStubClass() { " .echoSettings()\n", " .getRetrySettings()\n", " .toBuilder()\n", - " .setTotalTimeout(java.time.Duration.ofSeconds(30))\n", + " .setTotalTimeout(Duration.ofSeconds(30))\n", " .build());\n", "EchoStubSettings echoSettings = echoSettingsBuilder.build();"); assertEquals(results.get(), expected); From 6113cea26e76f509913b2100ad7d958995e67101 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 1 Aug 2023 14:02:03 -0400 Subject: [PATCH 032/141] chore: changes in `Instant` --- .../api/gax/httpjson/HttpJsonCallContext.java | 16 ++++++---- .../api/gax/httpjson/HttpJsonCallOptions.java | 32 +++++++++---------- .../api/gax/util/TimeConversionUtils.java | 14 ++++++++ 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index ba7a962bec..86b7b3761c 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -30,7 +30,9 @@ package com.google.api.gax.httpjson; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.BetaApi; import com.google.api.core.ObsoleteApi; @@ -439,14 +441,15 @@ public HttpJsonCallOptions getCallOptions() { /** Backport of {@link #getDeadlineInstant()} */ @Deprecated @Nullable + @ObsoleteApi("Use getDeadlineInstant() instead") public org.threeten.bp.Instant getDeadline() { - return org.threeten.bp.Instant.ofEpochMilli(getDeadlineInstant().toEpochMilli()); + return getCallOptions() != null ? getCallOptions().getDeadline() : null; } @Deprecated @Nullable public java.time.Instant getDeadlineInstant() { - return getCallOptions() != null ? getCallOptions().getDeadlineInstant() : null; + return toJavaTimeInstant(getDeadline()); } @Deprecated @@ -525,15 +528,16 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { /** Overload of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} */ @Deprecated + @ObsoleteApi("Use withDeadline(java.time.Instant) instead") public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { - return withDeadline(java.time.Instant.ofEpochMilli(newDeadline.toEpochMilli())); + HttpJsonCallOptions.Builder builder = + callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); + return withCallOptions(builder.setDeadline(newDeadline).build()); } @Deprecated public HttpJsonCallContext withDeadline(java.time.Instant newDeadline) { - HttpJsonCallOptions.Builder builder = - callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); - return withCallOptions(builder.setDeadline(newDeadline).build()); + return withDeadline(toThreetenInstant(newDeadline)); } @Nonnull diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index b40adf1829..973e6bdcc5 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -29,12 +29,17 @@ */ package com.google.api.gax.httpjson; +import com.google.api.core.ObsoleteApi; import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; + import java.time.Duration; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + /** Options for an http-json call, including deadline and credentials. */ @AutoValue public abstract class HttpJsonCallOptions { @@ -44,12 +49,13 @@ public abstract class HttpJsonCallOptions { public abstract Duration getTimeout(); @Nullable - public final org.threeten.bp.Instant getDeadline() { - return org.threeten.bp.Instant.ofEpochMilli(getDeadlineInstant().toEpochMilli()); - } + @ObsoleteApi("Use getDeadlineInstant() instead") + public abstract org.threeten.bp.Instant getDeadline(); @Nullable - public abstract java.time.Instant getDeadlineInstant(); + public final java.time.Instant getDeadlineInstant() { + return toJavaTimeInstant(getDeadline()); + } @Nullable public abstract Credentials getCredentials(); @@ -70,7 +76,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { Builder builder = this.toBuilder(); - java.time.Instant newDeadline = inputOptions.getDeadlineInstant(); + org.threeten.bp.Instant newDeadline = inputOptions.getDeadline(); if (newDeadline != null) { builder.setDeadline(newDeadline); } @@ -100,23 +106,15 @@ public abstract static class Builder { public abstract Builder setTimeout(java.time.Duration value); /** - * Overload of {@link #setDeadlineInstant(java.time.Instant)} using {@link - * org.threeten.bp.Instant} + * Backport of {@link #setDeadline(java.time.Instant)} */ - public final Builder setDeadline(org.threeten.bp.Instant value) { - return setDeadlineInstant(java.time.Instant.ofEpochMilli(value.toEpochMilli())); - } + @ObsoleteApi("Use setDeadline(java.time.Instant) instead") + public abstract Builder setDeadline(org.threeten.bp.Instant value); - /** - * Overload of {@link #setDeadlineInstant(java.time.Instant)} using {@link - * org.threeten.bp.Instant} This is a convenience public method to keep name conformity - */ public final Builder setDeadline(java.time.Instant value) { - return setDeadlineInstant(value); + return setDeadline(toThreetenInstant(value)); } - public abstract Builder setDeadlineInstant(java.time.Instant value); - public abstract Builder setCredentials(Credentials value); public abstract Builder setTypeRegistry(TypeRegistry value); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java index e65c403d3a..d19fa39fc2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java @@ -44,4 +44,18 @@ public static org.threeten.bp.Duration toThreetenDuration(java.time.Duration sou } return org.threeten.bp.Duration.ofNanos(source.toNanos()); } + + public static java.time.Instant toJavaTimeInstant(org.threeten.bp.Instant source) { + if (source == null) { + return null; + } + return java.time.Instant.ofEpochMilli(source.toEpochMilli()); + } + + public static org.threeten.bp.Instant toThreetenInstant(java.time.Instant source) { + if (source == null) { + return null; + } + return org.threeten.bp.Instant.ofEpochMilli(source.toEpochMilli()); + } } From 999261838ef8cccce3a592019d2247efc0677af4 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 2 Aug 2023 21:01:30 -0400 Subject: [PATCH 033/141] chore: use java.time methods on builders --- .../common/RetrySettingsComposer.java | 2 +- .../stub/OperationsStubSettings.java | 10 +-- .../api/gax/grpc/GrpcCallableFactoryTest.java | 4 +- .../grpc/GrpcDirectStreamControllerTest.java | 10 +-- .../api/gax/grpc/GrpcLongRunningTest.java | 10 +-- .../com/google/api/gax/grpc/SettingsTest.java | 18 ++--- .../com/google/api/gax/grpc/TimeoutTest.java | 20 +++--- .../api/gax/httpjson/HttpJsonCallContext.java | 2 +- .../api/gax/httpjson/HttpJsonCallOptions.java | 11 ++-- .../stub/OperationsStubSettings.java | 10 +-- .../google/api/gax/httpjson/RetryingTest.java | 14 ++-- .../google/api/gax/batching/BatcherImpl.java | 4 +- .../api/gax/batching/BatchingSettings.java | 6 +- .../api/gax/retrying/BasicRetryingFuture.java | 2 +- .../retrying/ExponentialRetryAlgorithm.java | 55 ++++++++-------- .../api/gax/retrying/RetrySettings.java | 52 +++++++-------- .../retrying/ScheduledRetryingExecutor.java | 2 +- .../google/api/gax/rpc/BatcherFactory.java | 2 +- .../com/google/api/gax/rpc/Callables.java | 7 +- .../google/api/gax/rpc/ClientSettings.java | 2 +- .../rpc/ServerStreamingAttemptCallable.java | 2 +- .../gax/rpc/ServerStreamingCallSettings.java | 12 ++-- .../google/api/gax/rpc/UnaryCallSettings.java | 14 ++-- .../api/gax/batching/BatcherImplTest.java | 11 ++-- .../batching/BatchingCallSettingsTest.java | 4 +- .../AbstractRetryingExecutorTest.java | 6 +- .../ExponentialRetryAlgorithmTest.java | 66 ++++++++++--------- .../api/gax/retrying/FailingCallable.java | 20 +++--- .../api/gax/retrying/RetrySettingsTest.java | 33 ++++++---- .../ScheduledRetryingExecutorTest.java | 24 +++---- .../api/gax/rpc/AttemptCallableTest.java | 6 +- .../api/gax/rpc/BatcherFactoryTest.java | 2 +- .../api/gax/rpc/BatchingCallableTest.java | 2 +- .../com/google/api/gax/rpc/BatchingTest.java | 8 +-- .../com/google/api/gax/rpc/CallableTest.java | 10 +-- .../google/api/gax/rpc/CancellationTest.java | 20 +++--- .../gax/rpc/CheckingAttemptCallableTest.java | 6 +- .../gax/rpc/OperationCallableImplTest.java | 30 ++++----- .../com/google/api/gax/rpc/RetryingTest.java | 28 ++++---- .../ServerStreamingAttemptCallableTest.java | 6 +- .../gax/rpc/StreamingRetryAlgorithmTest.java | 28 ++++---- .../api/gax/rpc/UnaryCallSettingsTest.java | 6 +- .../api/gax/tracing/TracedCallableTest.java | 2 +- .../com/google/cloud/RetryOptionTest.java | 34 ++++------ 44 files changed, 309 insertions(+), 314 deletions(-) diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java index e5e4ad4195..0cf564079b 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java @@ -714,7 +714,7 @@ private static TypeStore createStaticTypes() { List> concreteClazzes = Arrays.asList( BatchingSettings.class, - org.threeten.bp.Duration.class, + Duration.class, FlowControlSettings.class, FlowController.LimitExceededBehavior.class, ImmutableMap.class, diff --git a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java index f5d40becd2..853242eedd 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java @@ -242,13 +242,13 @@ public static class Builder extends StubSettings.BuildernewBuilder() .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(1)) + .setTotalTimeout(java.time.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); @@ -122,7 +122,7 @@ public void createServerStreamingCallableRetryableExceptions() { .setRetryableCodes(Code.INVALID_ARGUMENT) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(1)) + .setTotalTimeout(java.time.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java index ad2bc95169..082b2a15ef 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java @@ -100,11 +100,11 @@ public boolean canResume() { .setRetryableCodes(StatusCode.Code.DEADLINE_EXCEEDED) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMinutes(1)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(1)) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(1)) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1)) + .setTotalTimeout(java.time.Duration.ofMinutes(1)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(1)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(1)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1)) .build()) .build(); // Store a list of resources to manually close at the end of the test diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java index 8be1b6e51b..07d8af8272 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java @@ -74,15 +74,15 @@ public class GrpcLongRunningTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(1L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(5L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(1L)) + .setTotalTimeout(java.time.Duration.ofMillis(5L)) .build(); private ManagedChannel channel; diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index d07fdcfeb5..514838de88 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -111,13 +111,13 @@ private static class FakeStubSettings extends StubSettings { RetrySettings settings = null; settings = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(100L)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1000L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1000L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2000L)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(30000L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(45000L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(30000L)) + .setTotalTimeout(java.time.Duration.ofMillis(45000L)) .build(); definitions.put("default", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -223,7 +223,7 @@ private static Builder createDefault() { BatchingSettings.newBuilder() .setElementCountThreshold(800L) .setRequestByteThreshold(8388608L) - .setDelayThreshold(org.threeten.bp.Duration.ofMillis(100)) + .setDelayThreshold(java.time.Duration.ofMillis(100)) .build()); builder .fakeMethodBatching() @@ -336,7 +336,7 @@ public void unaryCallSettingsBuilderBuildDoesNotFailUnsetProperties() { @Test public void callSettingsBuildFromTimeoutNoRetries() { - org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(60000); + java.time.Duration timeout = java.time.Duration.ofMillis(60000); UnaryCallSettings.Builder builderA = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -350,9 +350,9 @@ public void callSettingsBuildFromTimeoutNoRetries() { .setRetrySettings( RetrySettings.newBuilder() .setTotalTimeout(timeout) - .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setInitialRpcTimeout(timeout) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(timeout) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java index 9ab74005de..01245cf9a1 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java @@ -73,12 +73,12 @@ public class TimeoutTest { private static final ImmutableSet emptyRetryCodes = ImmutableSet.of(); private static final ImmutableSet retryUnknownCode = ImmutableSet.of(StatusCode.Code.UNKNOWN); - private static final org.threeten.bp.Duration totalTimeout = - org.threeten.bp.Duration.ofDays(DEADLINE_IN_DAYS); - private static final org.threeten.bp.Duration maxRpcTimeout = - org.threeten.bp.Duration.ofMinutes(DEADLINE_IN_MINUTES); - private static final org.threeten.bp.Duration initialRpcTimeout = - org.threeten.bp.Duration.ofSeconds(DEADLINE_IN_SECONDS); + private static final java.time.Duration totalTimeout = + java.time.Duration.ofDays(DEADLINE_IN_DAYS); + private static final java.time.Duration maxRpcTimeout = + java.time.Duration.ofMinutes(DEADLINE_IN_MINUTES); + private static final java.time.Duration initialRpcTimeout = + java.time.Duration.ofSeconds(DEADLINE_IN_SECONDS); private static final GrpcCallContext defaultCallContext = GrpcCallContext.createDefault(); @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); @@ -91,9 +91,9 @@ public void testNonRetryUnarySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) @@ -117,9 +117,9 @@ public void testNonRetryUnarySettingsContextWithRetry() { RetrySettings retrySettings = RetrySettings.newBuilder() .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setInitialRpcTimeout(initialRpcTimeout) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 86b7b3761c..923bda6c50 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -531,7 +531,7 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { @ObsoleteApi("Use withDeadline(java.time.Instant) instead") public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { HttpJsonCallOptions.Builder builder = - callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); + callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); return withCallOptions(builder.setDeadline(newDeadline).build()); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index 973e6bdcc5..d54988bdc9 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -29,17 +29,16 @@ */ package com.google.api.gax.httpjson; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.ObsoleteApi; import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; - import java.time.Duration; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; - /** Options for an http-json call, including deadline and credentials. */ @AutoValue public abstract class HttpJsonCallOptions { @@ -105,9 +104,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { public abstract static class Builder { public abstract Builder setTimeout(java.time.Duration value); - /** - * Backport of {@link #setDeadline(java.time.Instant)} - */ + /** Backport of {@link #setDeadline(java.time.Instant)} */ @ObsoleteApi("Use setDeadline(java.time.Instant) instead") public abstract Builder setDeadline(org.threeten.bp.Instant value); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java index 323ef13e64..b47755b714 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java @@ -292,13 +292,13 @@ public static class Builder extends StubSettings.Builder callSettings = createSettings(retryable, retrySettings); UnaryCallable callable = diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java index 415e43610a..8cb437a5e2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java @@ -198,8 +198,8 @@ public BatcherImpl( } this.flowController = flowController; currentOpenBatch = new Batch<>(prototype, batchingDescriptor, batcherStats); - if (batchingSettings.getDelayThreshold() != null) { - long delay = batchingSettings.getDelayThreshold().toMillis(); + if (batchingSettings.getDelayThresholdDuration() != null) { + long delay = batchingSettings.getDelayThresholdDuration().toMillis(); PushCurrentBatchRunnable runnable = new PushCurrentBatchRunnable<>(this); scheduledFuture = diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 1aa7d73d70..216c521aff 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -124,7 +124,7 @@ public static Builder newBuilder() { .setIsEnabled(true) .setElementCountThreshold(1L) .setRequestByteThreshold(1L) - .setDelayThreshold(org.threeten.bp.Duration.ofMillis(1)) + .setDelayThreshold(java.time.Duration.ofMillis(1)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) @@ -187,8 +187,8 @@ public BatchingSettings build() { settings.getRequestByteThreshold() == null || settings.getRequestByteThreshold() > 0, "requestByteThreshold must be either unset or positive"); Preconditions.checkArgument( - settings.getDelayThreshold() == null - || settings.getDelayThreshold().compareTo(org.threeten.bp.Duration.ZERO) > 0, + settings.getDelayThresholdDuration() == null + || settings.getDelayThresholdDuration().compareTo(java.time.Duration.ZERO) > 0, "delayThreshold must be either unset or positive"); return settings; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java index a07242a436..cb47a845cb 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java @@ -183,7 +183,7 @@ void handleAttempt(Throwable throwable, ResponseT response) { ? callable.getClass().getEnclosingMethod().getName() : ""), "attemptCount: " + attemptSettings.getAttemptCount(), - "delay: " + attemptSettings.getRetryDelay(), + "delay: " + attemptSettings.getRetryDelayDuration(), "retriableException: " + throwable }); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index 6d53c026e3..c922264e14 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -68,9 +68,9 @@ public ExponentialRetryAlgorithm(RetrySettings globalSettings, ApiClock clock) { public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) - .setRetryDelay(org.threeten.bp.Duration.ZERO) - .setRpcTimeout(globalSettings.getInitialRpcTimeout()) - .setRandomizedRetryDelay(org.threeten.bp.Duration.ZERO) + .setRetryDelay(java.time.Duration.ZERO) + .setRpcTimeout(globalSettings.getInitialRpcTimeoutDuration()) + .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -97,9 +97,9 @@ public TimedAttemptSettings createFirstAttempt(RetryingContext context) { // Attempts created using the TimedAttemptSettings built here will use these // retrySettings, but a new call will not (unless overridden again). .setGlobalSettings(retrySettings) - .setRpcTimeout(retrySettings.getInitialRpcTimeout()) - .setRetryDelay(org.threeten.bp.Duration.ZERO) - .setRandomizedRetryDelay(org.threeten.bp.Duration.ZERO) + .setRpcTimeout(retrySettings.getInitialRpcTimeoutDuration()) + .setRetryDelay(java.time.Duration.ZERO) + .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -123,34 +123,35 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti // attempt #1 - use initialRetryDelay; // attempt #2+ - use the calculated value (i.e. the following if statement is true only // if we are about to calculate the value for the upcoming 2nd+ attempt). - long newRetryDelay = settings.getInitialRetryDelay().toMillis(); + long newRetryDelay = settings.getInitialRetryDelayDuration().toMillis(); if (previousSettings.getAttemptCount() > 0) { newRetryDelay = - (long) (settings.getRetryDelayMultiplier() * previousSettings.getRetryDelay().toMillis()); - newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis()); + (long) + (settings.getRetryDelayMultiplier() + * previousSettings.getRetryDelayDuration().toMillis()); + newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelayDuration().toMillis()); } - org.threeten.bp.Duration randomDelay = - org.threeten.bp.Duration.ofMillis(nextRandomLong(newRetryDelay)); + java.time.Duration randomDelay = java.time.Duration.ofMillis(nextRandomLong(newRetryDelay)); // The rpc timeout is determined as follows: // attempt #0 - use the initialRpcTimeout; // attempt #1+ - use the calculated value, or the time remaining in totalTimeout if the // calculated value would exceed the totalTimeout. long newRpcTimeout = - (long) (settings.getRpcTimeoutMultiplier() * previousSettings.getRpcTimeout().toMillis()); - newRpcTimeout = Math.min(newRpcTimeout, settings.getMaxRpcTimeout().toMillis()); + (long) + (settings.getRpcTimeoutMultiplier() + * previousSettings.getRpcTimeoutDuration().toMillis()); + newRpcTimeout = Math.min(newRpcTimeout, settings.getMaxRpcTimeoutDuration().toMillis()); // The totalTimeout could be zero if a callable is only using maxAttempts to limit retries. // If set, calculate time remaining in the totalTimeout since the start, taking into account the // next attempt's delay, in order to truncate the RPC timeout should it exceed the totalTimeout. - if (!settings.getTotalTimeout().isZero()) { - org.threeten.bp.Duration timeElapsed = - org.threeten.bp.Duration.ofNanos(clock.nanoTime()) - .minus( - org.threeten.bp.Duration.ofNanos( - previousSettings.getFirstAttemptStartTimeNanos())); - org.threeten.bp.Duration timeLeft = - settings.getTotalTimeout().minus(timeElapsed).minus(randomDelay); + if (!settings.getTotalTimeoutDuration().isZero()) { + java.time.Duration timeElapsed = + java.time.Duration.ofNanos(clock.nanoTime()) + .minus(java.time.Duration.ofNanos(previousSettings.getFirstAttemptStartTimeNanos())); + java.time.Duration timeLeft = + settings.getTotalTimeoutDuration().minus(timeElapsed).minus(randomDelay); // If timeLeft at this point is < 0, the shouldRetry logic will prevent // the attempt from being made as it would exceed the totalTimeout. A negative RPC timeout @@ -161,8 +162,8 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti return TimedAttemptSettings.newBuilder() .setGlobalSettings(previousSettings.getGlobalSettings()) - .setRetryDelay(org.threeten.bp.Duration.ofMillis(newRetryDelay)) - .setRpcTimeout(org.threeten.bp.Duration.ofMillis(newRpcTimeout)) + .setRetryDelay(java.time.Duration.ofMillis(newRetryDelay)) + .setRpcTimeout(java.time.Duration.ofMillis(newRpcTimeout)) .setRandomizedRetryDelay(randomDelay) .setAttemptCount(previousSettings.getAttemptCount() + 1) .setOverallAttemptCount(previousSettings.getOverallAttemptCount() + 1) @@ -201,7 +202,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { RetrySettings globalSettings = nextAttemptSettings.getGlobalSettings(); int maxAttempts = globalSettings.getMaxAttempts(); - org.threeten.bp.Duration totalTimeout = globalSettings.getTotalTimeout(); + java.time.Duration totalTimeout = globalSettings.getTotalTimeoutDuration(); // If total timeout and maxAttempts is not set then do not attempt retry. if (totalTimeout.isZero() && maxAttempts == 0) { @@ -211,10 +212,10 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { long totalTimeSpentNanos = clock.nanoTime() - nextAttemptSettings.getFirstAttemptStartTimeNanos() - + nextAttemptSettings.getRandomizedRetryDelay().toNanos(); + + nextAttemptSettings.getRandomizedRetryDelayDuration().toNanos(); - org.threeten.bp.Duration timeLeft = - totalTimeout.minus(org.threeten.bp.Duration.ofNanos(totalTimeSpentNanos)); + java.time.Duration timeLeft = + totalTimeout.minus(java.time.Duration.ofNanos(totalTimeSpentNanos)); // Convert time spent to milliseconds to standardize the units being used for // retries. Otherwise, we would be using nanoseconds to determine if retries // should be attempted and milliseconds for retry delays and rpc timeouts diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 183add3f55..81b295a8fd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -177,15 +177,15 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() - .setTotalTimeout(org.threeten.bp.Duration.ZERO) - .setInitialRetryDelay(org.threeten.bp.Duration.ZERO) + .setTotalTimeout(java.time.Duration.ZERO) + .setInitialRetryDelay(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(org.threeten.bp.Duration.ZERO) + .setMaxRetryDelay(java.time.Duration.ZERO) .setMaxAttempts(0) .setJittered(true) - .setInitialRpcTimeout(org.threeten.bp.Duration.ZERO) + .setInitialRpcTimeout(java.time.Duration.ZERO) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(org.threeten.bp.Duration.ZERO); + .setMaxRpcTimeout(java.time.Duration.ZERO); } public abstract Builder toBuilder(); @@ -309,7 +309,7 @@ public final java.time.Duration getTotalTimeoutDuration() { return toJavaTimeDuration(getTotalTimeout()); } - /** Backport of {@link #getInitialRetryDelay()} */ + /** Backport of {@link #getInitialRetryDelayDuration()} */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public abstract org.threeten.bp.Duration getInitialRetryDelay(); @@ -397,10 +397,7 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { @BetaApi @ObsoleteApi("Use setLogicalTimeout(java.time.Duration) instead") public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { - return setRpcTimeoutMultiplier(1) - .setInitialRpcTimeout(timeout) - .setMaxRpcTimeout(timeout) - .setTotalTimeout(timeout); + return setLogicalTimeout(toJavaTimeDuration(timeout)); } /** @@ -414,32 +411,35 @@ public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { */ @BetaApi public Builder setLogicalTimeout(java.time.Duration timeout) { - return setLogicalTimeout(toThreetenDuration(timeout)); + return setRpcTimeoutMultiplier(1) + .setInitialRpcTimeout(timeout) + .setMaxRpcTimeout(timeout) + .setTotalTimeout(timeout); } abstract RetrySettings autoBuild(); public RetrySettings build() { RetrySettings params = autoBuild(); - if (params.getTotalTimeout().toMillis() < 0) { + if (params.getTotalTimeoutDuration().toMillis() < 0) { throw new IllegalStateException("total timeout must not be negative"); } - if (params.getInitialRetryDelay().toMillis() < 0) { + if (params.getInitialRetryDelayDuration().toMillis() < 0) { throw new IllegalStateException("initial retry delay must not be negative"); } if (params.getRetryDelayMultiplier() < 1.0) { throw new IllegalStateException("retry delay multiplier must be at least 1"); } - if (params.getMaxRetryDelay().compareTo(params.getInitialRetryDelay()) < 0) { + if (params.getMaxRetryDelayDuration().compareTo(params.getInitialRetryDelayDuration()) < 0) { throw new IllegalStateException("max retry delay must not be shorter than initial delay"); } if (params.getMaxAttempts() < 0) { throw new IllegalStateException("max attempts must be non-negative"); } - if (params.getInitialRpcTimeout().toMillis() < 0) { + if (params.getInitialRpcTimeoutDuration().toMillis() < 0) { throw new IllegalStateException("initial rpc timeout must not be negative"); } - if (params.getMaxRpcTimeout().compareTo(params.getInitialRpcTimeout()) < 0) { + if (params.getMaxRpcTimeoutDuration().compareTo(params.getInitialRpcTimeoutDuration()) < 0) { throw new IllegalStateException("max rpc timeout must not be shorter than initial timeout"); } if (params.getRpcTimeoutMultiplier() < 1.0) { @@ -449,28 +449,28 @@ public RetrySettings build() { } public RetrySettings.Builder merge(RetrySettings.Builder newSettings) { - if (newSettings.getTotalTimeout() != null) { - setTotalTimeout(newSettings.getTotalTimeout()); + if (newSettings.getTotalTimeoutDuration() != null) { + setTotalTimeout(newSettings.getTotalTimeoutDuration()); } - if (newSettings.getInitialRetryDelay() != null) { - setInitialRetryDelay(newSettings.getInitialRetryDelay()); + if (newSettings.getInitialRetryDelayDuration() != null) { + setInitialRetryDelay(newSettings.getInitialRetryDelayDuration()); } if (newSettings.getRetryDelayMultiplier() >= 1) { setRetryDelayMultiplier(newSettings.getRetryDelayMultiplier()); } - if (newSettings.getMaxRetryDelay() != null) { - setMaxRetryDelay(newSettings.getMaxRetryDelay()); + if (newSettings.getMaxRetryDelayDuration() != null) { + setMaxRetryDelay(newSettings.getMaxRetryDelayDuration()); } setMaxAttempts(newSettings.getMaxAttempts()); setJittered(newSettings.isJittered()); - if (newSettings.getInitialRpcTimeout() != null) { - setInitialRpcTimeout(newSettings.getInitialRpcTimeout()); + if (newSettings.getInitialRpcTimeoutDuration() != null) { + setInitialRpcTimeout(newSettings.getInitialRpcTimeoutDuration()); } if (newSettings.getRpcTimeoutMultiplier() >= 1) { setRpcTimeoutMultiplier(newSettings.getRpcTimeoutMultiplier()); } - if (newSettings.getMaxRpcTimeout() != null) { - setMaxRpcTimeout(newSettings.getMaxRpcTimeout()); + if (newSettings.getMaxRpcTimeoutDuration() != null) { + setMaxRpcTimeout(newSettings.getMaxRpcTimeoutDuration()); } return this; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ScheduledRetryingExecutor.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ScheduledRetryingExecutor.java index b6ee0a0c19..c796ebd090 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ScheduledRetryingExecutor.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ScheduledRetryingExecutor.java @@ -115,7 +115,7 @@ public ApiFuture submit(RetryingFuture retryingFuture) { ListenableFuture attemptFuture = scheduler.schedule( retryingFuture.getCallable(), - retryingFuture.getAttemptSettings().getRandomizedRetryDelay().toMillis(), + retryingFuture.getAttemptSettings().getRandomizedRetryDelayDuration().toMillis(), TimeUnit.MILLISECONDS); return new ListenableFutureToApiFuture<>(attemptFuture); } catch (RejectedExecutionException e) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java index 8ac8093998..a703afd078 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java @@ -113,7 +113,7 @@ private ThresholdBatcher> createBatcher(PartitionKey return ThresholdBatcher.>newBuilder() .setThresholds(getThresholds(batchingSettings)) .setExecutor(executor) - .setMaxDelay(batchingSettings.getDelayThreshold()) + .setMaxDelay(batchingSettings.getDelayThresholdDuration()) .setReceiver(processor) .setFlowController(batchingFlowController) .setBatchMerger(new BatchMergerImpl()) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 2b088b1843..5fd6a53fc0 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -63,7 +63,7 @@ public static UnaryCallable retrying( settings = settings .toBuilder() - .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeout()) + .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } @@ -88,7 +88,7 @@ public static ServerStreamingCallable settings = settings .toBuilder() - .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeout()) + .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } @@ -231,6 +231,7 @@ private static boolean areRetriesDisabled( Collection retryableCodes, RetrySettings retrySettings) { return retrySettings.getMaxAttempts() == 1 || retryableCodes.isEmpty() - || (retrySettings.getMaxAttempts() == 0 && retrySettings.getTotalTimeout().isZero()); + || (retrySettings.getMaxAttempts() == 0 + && retrySettings.getTotalTimeoutDuration().isZero()); } } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index e8b4fa8e5c..3e0dffc4c0 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -390,7 +390,7 @@ public String toString() { .add("endpoint", getEndpoint()) .add("quotaProjectId", getQuotaProjectId()) .add("watchdogProvider", getWatchdogProvider()) - .add("watchdogCheckInterval", getWatchdogCheckInterval()) + .add("watchdogCheckInterval", getWatchdogCheckIntervalDuration()) .add("gdchApiAudience", getGdchApiAudience()) .toString(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java index 39bbd7b289..34117f94e9 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java @@ -208,7 +208,7 @@ public Void call() { ApiCallContext attemptContext = context; - if (!outerRetryingFuture.getAttemptSettings().getRpcTimeout().isZero() + if (!outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration().isZero() && attemptContext.getTimeoutDuration() == null) { attemptContext = attemptContext.withTimeout( diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 9e78cb0051..90101cd00e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -266,6 +266,12 @@ public RetrySettings getRetrySettings() { @ObsoleteApi("Use setSimpleTimeoutNoRetries(java.time.Duration) instead") public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { + return setSimpleTimeoutNoRetries(toJavaTimeDuration(timeout)); + } + + /** Disables retries and sets the overall timeout. */ + public Builder setSimpleTimeoutNoRetries( + @Nonnull java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() @@ -282,12 +288,6 @@ public Builder setSimpleTimeoutNoRetries( return this; } - /** Disables retries and sets the overall timeout. */ - public Builder setSimpleTimeoutNoRetries( - @Nonnull java.time.Duration timeout) { - return setSimpleTimeoutNoRetries(toThreetenDuration(timeout)); - } - /** * See the class documentation of {@link ServerStreamingCallSettings} for a description of what * StreamResumptionStrategy does. diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 9d4b74e852..31ae80e185 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -29,7 +29,7 @@ */ package com.google.api.gax.rpc; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.InternalExtensionOnly; import com.google.api.core.ObsoleteApi; @@ -200,6 +200,12 @@ public UnaryCallSettings.Builder setRetrySettings( @ObsoleteApi("Use setSimpleTimeoutNoRetries(java.time.Duration) instead") public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { + return setSimpleTimeoutNoRetries(toJavaTimeDuration(timeout)); + } + + /** Disables retries and sets the RPC timeout. */ + public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( + java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() @@ -215,12 +221,6 @@ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( return this; } - /** Disables retries and sets the RPC timeout. */ - public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( - java.time.Duration timeout) { - return setSimpleTimeoutNoRetries(toThreetenDuration(timeout)); - } - /** * See the class documentation of {@link UnaryCallSettings} for a description of what retryable * codes do. diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index 917f4d4584..bc8466f3bb 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -371,7 +371,7 @@ public void testWhenThresholdIsDisabled() throws Exception { BatchingSettings.newBuilder() .setElementCountThreshold(null) .setRequestByteThreshold(null) - .setDelayThreshold((org.threeten.bp.Duration) null) + .setDelayThreshold((java.time.Duration) null) .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(2); @@ -414,10 +414,7 @@ public ApiFuture> futureCall( } }; BatchingSettings settings = - batchingSettings - .toBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofMillis(50)) - .build(); + batchingSettings.toBuilder().setDelayThreshold(java.time.Duration.ofMillis(50)).build(); try (final BatcherImpl> batcherTest = new BatcherImpl<>(SQUARER_BATCHING_DESC_V2, callable, labeledIntList, settings, EXECUTOR)) { @@ -463,7 +460,7 @@ public void testPushCurrentBatchRunnable() throws Exception { BatchingSettings settings = batchingSettings .toBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofMillis(DELAY_TIME)) + .setDelayThreshold(java.time.Duration.ofMillis(DELAY_TIME)) .build(); BatcherImpl> batcher = createDefaultBatcherImpl(settings, null); @@ -989,7 +986,7 @@ public ApiFuture futureCall(Object o, ApiCallContext apiCallContext) { Object prototype = new Object(); BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(100L) .setRequestByteThreshold(100L) .setFlowControlSettings(FlowControlSettings.getDefaultInstance()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java index 81609d2c1f..51e8a1a8be 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java @@ -49,7 +49,7 @@ public class BatchingCallSettingsTest { BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(20L) - .setDelayThreshold(org.threeten.bp.Duration.ofMillis(5)) + .setDelayThreshold(java.time.Duration.ofMillis(5)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100L) @@ -90,7 +90,7 @@ public void testBuilderFromSettings() { BatchingCallSettings.Builder> builder = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC_V2); RetrySettings retrySettings = - RetrySettings.newBuilder().setTotalTimeout(org.threeten.bp.Duration.ofMinutes(1)).build(); + RetrySettings.newBuilder().setTotalTimeout(java.time.Duration.ofMinutes(1)).build(); builder .setBatchingSettings(BATCHING_SETTINGS) .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java index 905cb6ae2b..9f354afb24 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java @@ -232,9 +232,9 @@ public void testCancelOuterFutureBeforeStart() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_000L)) .build(); RetryingExecutorWithContext executor = getExecutor(getAlgorithm(retrySettings, 0, null)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index 3ed9617191..d74a6edd50 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -46,26 +46,26 @@ public class ExponentialRetryAlgorithmTest { private final RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(8L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) .setRpcTimeoutMultiplier(2.0) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(8L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(200L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) + .setTotalTimeout(java.time.Duration.ofMillis(200L)) .build(); private final ExponentialRetryAlgorithm algorithm = new ExponentialRetryAlgorithm(retrySettings, clock); private final RetrySettings retrySettingsOverride = RetrySettings.newBuilder() .setMaxAttempts(3) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(3.0) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(18L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(18L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(3.0) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(18L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(300L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(18L)) + .setTotalTimeout(java.time.Duration.ofMillis(300L)) .build(); private final RetryingContext retryingContext = FakeCallContext.createDefault().withRetrySettings(retrySettingsOverride); @@ -77,10 +77,10 @@ public void testCreateFirstAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); - assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(org.threeten.bp.Duration.ofMillis(1L), attempt.getRpcTimeout()); - assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(1L), attempt.getRpcTimeoutDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); } @Test @@ -90,10 +90,11 @@ public void testCreateFirstAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(0, attempt.getAttemptCount()); assertEquals(0, attempt.getOverallAttemptCount()); - assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); - assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRandomizedRetryDelay()); - assertEquals(retrySettingsOverride.getInitialRpcTimeout(), attempt.getRpcTimeout()); - assertEquals(org.threeten.bp.Duration.ZERO, attempt.getRetryDelay()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRandomizedRetryDelayDuration()); + assertEquals( + retrySettingsOverride.getInitialRpcTimeoutDuration(), attempt.getRpcTimeoutDuration()); + assertEquals(java.time.Duration.ZERO, attempt.getRetryDelayDuration()); } @Test @@ -104,13 +105,13 @@ public void testCreateNextAttempt() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(org.threeten.bp.Duration.ofMillis(1L), secondAttempt.getRetryDelay()); - assertEquals(org.threeten.bp.Duration.ofMillis(2L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(1L), secondAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRpcTimeoutDuration()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(org.threeten.bp.Duration.ofMillis(2L), thirdAttempt.getRetryDelay()); - assertEquals(org.threeten.bp.Duration.ofMillis(4L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), thirdAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(4L), thirdAttempt.getRpcTimeoutDuration()); } @Test @@ -121,13 +122,13 @@ public void testCreateNextAttemptOverride() { // Checking only the most core values, to not make this test too implementation specific. assertEquals(1, secondAttempt.getAttemptCount()); assertEquals(1, secondAttempt.getOverallAttemptCount()); - assertEquals(org.threeten.bp.Duration.ofMillis(2L), secondAttempt.getRetryDelay()); - assertEquals(org.threeten.bp.Duration.ofMillis(6L), secondAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(2L), secondAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(6L), secondAttempt.getRpcTimeoutDuration()); TimedAttemptSettings thirdAttempt = algorithm.createNextAttempt(secondAttempt); assertEquals(2, thirdAttempt.getAttemptCount()); - assertEquals(org.threeten.bp.Duration.ofMillis(6L), thirdAttempt.getRetryDelay()); - assertEquals(org.threeten.bp.Duration.ofMillis(18L), thirdAttempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(6L), thirdAttempt.getRetryDelayDuration()); + assertEquals(java.time.Duration.ofMillis(18L), thirdAttempt.getRpcTimeoutDuration()); } @Test @@ -135,19 +136,20 @@ public void testTruncateToTotalTimeout() { RetrySettings timeoutSettings = retrySettings .toBuilder() - .setInitialRpcTimeout(org.threeten.bp.Duration.ofSeconds(4L)) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(4L)) - .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(4L)) + .setInitialRpcTimeout(java.time.Duration.ofSeconds(4L)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(4L)) + .setTotalTimeout(java.time.Duration.ofSeconds(4L)) .build(); ExponentialRetryAlgorithm timeoutAlg = new ExponentialRetryAlgorithm(timeoutSettings, clock); TimedAttemptSettings firstAttempt = timeoutAlg.createFirstAttempt(); TimedAttemptSettings secondAttempt = timeoutAlg.createNextAttempt(firstAttempt); - assertThat(secondAttempt.getRpcTimeout()).isAtLeast(firstAttempt.getRpcTimeout()); - assertThat(secondAttempt.getRpcTimeout()).isAtMost(org.threeten.bp.Duration.ofSeconds(4L)); + assertThat(secondAttempt.getRpcTimeoutDuration()) + .isAtLeast(firstAttempt.getRpcTimeoutDuration()); + assertThat(secondAttempt.getRpcTimeoutDuration()).isAtMost(java.time.Duration.ofSeconds(4L)); TimedAttemptSettings thirdAttempt = timeoutAlg.createNextAttempt(secondAttempt); - assertThat(thirdAttempt.getRpcTimeout()).isAtMost(org.threeten.bp.Duration.ofSeconds(4L)); + assertThat(thirdAttempt.getRpcTimeoutDuration()).isAtMost(java.time.Duration.ofSeconds(4L)); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java index 1a4cc8f66b..de5804c6cc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java @@ -39,24 +39,24 @@ class FailingCallable implements Callable { static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(8L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(8L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(8L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(8L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(8L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(8L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(400L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) + .setTotalTimeout(java.time.Duration.ofMillis(400L)) .build(); static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(org.threeten.bp.Duration.ofNanos(1L)) + .setInitialRetryDelay(java.time.Duration.ofNanos(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofNanos(1L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) + .setMaxRetryDelay(java.time.Duration.ofNanos(1L)) + .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) - .setTotalTimeout(org.threeten.bp.Duration.ofNanos(1L)) + .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) + .setTotalTimeout(java.time.Duration.ofNanos(1L)) .build(); private AtomicInteger attemptsCount = new AtomicInteger(0); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index 2c11f9eb87..1a437842c6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -36,42 +36,47 @@ public class RetrySettingsTest { @Test public void retrySettingsSetLogicalTimeout() { - org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(60000); + java.time.Duration timeout = java.time.Duration.ofMillis(60000); RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); - Truth.assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getTotalTimeout()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(timeout); } @Test public void retrySettingsMerge() { RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(45000)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2000)) + .setTotalTimeout(java.time.Duration.ofMillis(45000)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2000)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(30000)) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(30000)) + .setInitialRetryDelay(java.time.Duration.ofMillis(100)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1000)); + .setMaxRetryDelay(java.time.Duration.ofMillis(1000)); RetrySettings.Builder mergedBuilder = RetrySettings.newBuilder(); mergedBuilder.merge(builder); RetrySettings settingsA = builder.build(); RetrySettings settingsB = mergedBuilder.build(); - Truth.assertThat(settingsA.getTotalTimeout()).isEqualTo(settingsB.getTotalTimeout()); - Truth.assertThat(settingsA.getInitialRetryDelay()).isEqualTo(settingsB.getInitialRetryDelay()); + Truth.assertThat(settingsA.getTotalTimeoutDuration()) + .isEqualTo(settingsB.getTotalTimeoutDuration()); + Truth.assertThat(settingsA.getInitialRetryDelayDuration()) + .isEqualTo(settingsB.getInitialRetryDelayDuration()); Truth.assertThat(settingsA.getRpcTimeoutMultiplier()) .isWithin(0) .of(settingsB.getRpcTimeoutMultiplier()); - Truth.assertThat(settingsA.getMaxRpcTimeout()).isEqualTo(settingsB.getMaxRpcTimeout()); - Truth.assertThat(settingsA.getInitialRetryDelay()).isEqualTo(settingsB.getInitialRetryDelay()); + Truth.assertThat(settingsA.getMaxRpcTimeoutDuration()) + .isEqualTo(settingsB.getMaxRpcTimeoutDuration()); + Truth.assertThat(settingsA.getInitialRetryDelayDuration()) + .isEqualTo(settingsB.getInitialRetryDelayDuration()); Truth.assertThat(settingsA.getRetryDelayMultiplier()) .isWithin(0) .of(settingsB.getRetryDelayMultiplier()); - Truth.assertThat(settingsA.getMaxRetryDelay()).isEqualTo(settingsB.getMaxRetryDelay()); + Truth.assertThat(settingsA.getMaxRetryDelayDuration()) + .isEqualTo(settingsB.getMaxRetryDelayDuration()); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java index 2e87f1d15c..e86f794f22 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java @@ -92,7 +92,7 @@ public void testSuccessWithFailuresPeekAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -143,7 +143,7 @@ public void testSuccessWithFailuresGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -197,7 +197,7 @@ public void testCancelGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -255,9 +255,9 @@ public void testCancelOuterFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); @@ -283,9 +283,9 @@ public void testCancelIsTraced() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); @@ -313,9 +313,9 @@ public void testCancelProxiedFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1_000L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10_0000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 0bf0b32d81..0e207782c6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -65,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) - .setRandomizedRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) - .setRpcTimeout(org.threeten.bp.Duration.ZERO) + .setRetryDelay(java.time.Duration.ofSeconds(1)) + .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) + .setRpcTimeout(java.time.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java index 0fa0091f6a..ca5e771876 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java @@ -66,7 +66,7 @@ public void tearDown() { public void testGetPushingBatcher() { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java index 82c34571d6..c10a36c845 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java @@ -67,7 +67,7 @@ public void testBatchedCall() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(10)) + .setDelayThreshold(java.time.Duration.ofSeconds(10)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java index a489293ae3..a1cd2b77a5 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java @@ -81,7 +81,7 @@ public void teardown() { public void batching() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -101,7 +101,7 @@ public void batching() throws Exception { public void batchingWithFlowControl() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(4L) .setRequestByteThreshold(null) .setFlowControlSettings( @@ -179,7 +179,7 @@ public void batchingDisabled() throws Exception { public void batchingWithBlockingCallThreshold() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -208,7 +208,7 @@ public ApiFuture> futureCall(LabeledIntList request, ApiCallContex public void batchingException() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(org.threeten.bp.Duration.ofSeconds(1)) + .setDelayThreshold(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 23cb0d7fdd..c15d13f22f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -58,9 +58,9 @@ public class CallableTest { private RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(5L)) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(5L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(5L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(5L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); @Spy private ApiCallContext callContext = FakeCallContext.createDefault(); @@ -97,7 +97,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) .build(); UnaryCallable callable = Callables.retrying(innerCallable, callSettings, clientContext); @@ -131,7 +131,7 @@ public void testNonRetriedServerStreamingCallable() throws Exception { public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exception { ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder() - .setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) .build(); ServerStreamingCallable callable = Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java index ae0a9673c7..7914ab876d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java @@ -62,24 +62,24 @@ public class CancellationTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(20L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(20L)) .build(); private static final RetrySettings SLOW_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(3000L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(3000L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(3000L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(3000L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(3000L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(3000L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(3000L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(3000L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(3000L)) + .setTotalTimeout(java.time.Duration.ofMillis(3000L)) .build(); private FakeApiClock fakeClock; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index 9d5c3087e8..922fd62044 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -65,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) - .setRandomizedRetryDelay(org.threeten.bp.Duration.ofSeconds(1)) - .setRpcTimeout(org.threeten.bp.Duration.ZERO) + .setRetryDelay(java.time.Duration.ofSeconds(1)) + .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) + .setRpcTimeout(java.time.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 1bbf8808ce..6bc6495bd0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -79,31 +79,31 @@ public class OperationCallableImplTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAST_RECHECKING_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) .setInitialRpcTimeout( - org.threeten.bp.Duration + java.time.Duration .ZERO) // supposed to be ignored, but are not actually, so we set to zero .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier( 1) // supposed to be ignored, but are not actually, so we set to one .setMaxRpcTimeout( - org.threeten.bp.Duration + java.time.Duration .ZERO) // supposed to be ignored, but are not actually, so we set to zero - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(5L)) + .setTotalTimeout(java.time.Duration.ofMillis(5L)) .build(); private FakeChannel initialChannel; @@ -485,10 +485,10 @@ public void testFutureCallPollRPCTimeout() throws Exception { // for LRO polling. They are not actually ignored in code, so they changing them // here has an actual affect. This test verifies that they work as such, but in // practice generated clients set the RPC timeouts to 0 to be ignored. - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(100)) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(1)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(2) - .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(5L)) + .setTotalTimeout(java.time.Duration.ofSeconds(5L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -593,7 +593,7 @@ public void testFutureCallPollDoneOnMany() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(iterationsCount)) + .setTotalTimeout(java.time.Duration.ofMillis(iterationsCount)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -703,7 +703,7 @@ public void testFutureCallPollCancelOnLongTimeoutExceeded() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(1000L)) + .setTotalTimeout(java.time.Duration.ofMillis(1000L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java index f07558f2ed..da6639cb54 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java @@ -68,24 +68,24 @@ public class RetryingTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(2L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(2L)) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(10L)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) + .setTotalTimeout(java.time.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(org.threeten.bp.Duration.ofNanos(0L)) + .setInitialRetryDelay(java.time.Duration.ofNanos(0L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(0L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) + .setMaxRetryDelay(java.time.Duration.ofMillis(0L)) + .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofNanos(1L)) - .setTotalTimeout(org.threeten.bp.Duration.ofNanos(1L)) + .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) + .setTotalTimeout(java.time.Duration.ofNanos(1L)) .build(); @Before @@ -151,8 +151,8 @@ public void retryTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); assertRetrying(retrySettings); @@ -169,8 +169,8 @@ public void retryUsingContextTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); try { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index ea1c7da9d3..70128775f7 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -478,9 +478,9 @@ private static class FakeRetryingFuture extends AbstractApiFuture .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) - .setRandomizedRetryDelay(org.threeten.bp.Duration.ofMillis(1)) - .setRetryDelay(org.threeten.bp.Duration.ofMillis(1)) - .setRpcTimeout(org.threeten.bp.Duration.ofMinutes(1)) + .setRandomizedRetryDelay(java.time.Duration.ofMillis(1)) + .setRetryDelay(java.time.Duration.ofMillis(1)) + .setRpcTimeout(java.time.Duration.ofMinutes(1)) .build(); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java index 7dc5acbdaa..6e4c582cc2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java @@ -51,26 +51,26 @@ public class StreamingRetryAlgorithmTest { private static final RetrySettings DEFAULT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(10L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(100L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(10L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(100L)) .setMaxAttempts(10) - .setMaxRetryDelay(org.threeten.bp.Duration.ofSeconds(10L)) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(30L)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(10L)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(30L)) .setRetryDelayMultiplier(1.4) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeout(org.threeten.bp.Duration.ofMinutes(10L)) + .setTotalTimeout(java.time.Duration.ofMinutes(10L)) .build(); private static final RetrySettings CONTEXT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(20L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(200L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(20L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(200L)) .setMaxAttempts(10) - .setMaxRetryDelay(org.threeten.bp.Duration.ofSeconds(20L)) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(60L)) + .setMaxRetryDelay(java.time.Duration.ofSeconds(20L)) + .setMaxRpcTimeout(java.time.Duration.ofSeconds(60L)) .setRetryDelayMultiplier(2.4) .setRpcTimeoutMultiplier(2.5) - .setTotalTimeout(org.threeten.bp.Duration.ofMinutes(20L)) + .setTotalTimeout(java.time.Duration.ofMinutes(20L)) .build(); @Test @@ -85,7 +85,8 @@ public void testFirstAttemptUsesDefaultSettings() { TimedAttemptSettings attempt = algorithm.createFirstAttempt(context); assertThat(attempt.getGlobalSettings()).isSameInstanceAs(DEFAULT_RETRY_SETTINGS); - assertThat(attempt.getRpcTimeout()).isEqualTo(DEFAULT_RETRY_SETTINGS.getInitialRpcTimeout()); + assertThat(attempt.getRpcTimeoutDuration()) + .isEqualTo(DEFAULT_RETRY_SETTINGS.getInitialRpcTimeoutDuration()); } @Test @@ -101,7 +102,8 @@ public void testFirstAttemptUsesContextSettings() { TimedAttemptSettings attempt = algorithm.createFirstAttempt(context); assertThat(attempt.getGlobalSettings()).isSameInstanceAs(CONTEXT_RETRY_SETTINGS); - assertThat(attempt.getRpcTimeout()).isEqualTo(CONTEXT_RETRY_SETTINGS.getInitialRpcTimeout()); + assertThat(attempt.getRpcTimeoutDuration()) + .isEqualTo(CONTEXT_RETRY_SETTINGS.getInitialRpcTimeoutDuration()); } @Test @@ -174,7 +176,7 @@ public void testNextAttemptResetsTimedSettings() { assertThat(third.getFirstAttemptStartTimeNanos()) .isEqualTo(first.getFirstAttemptStartTimeNanos()); // The timeout values are reset to the second call. - assertThat(third.getRpcTimeout()).isEqualTo(second.getRpcTimeout()); + assertThat(third.getRpcTimeoutDuration()).isEqualTo(second.getRpcTimeoutDuration()); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index e39248b4e6..ce810e273e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -46,7 +46,7 @@ public class UnaryCallSettingsTest { @Test public void testSetSimpleTimeoutNoRetries() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); assertThat(builder.getRetryableCodes().size()).isEqualTo(0); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); @@ -57,7 +57,7 @@ public void testSetSimpleTimeoutNoRetries() { @Test public void testEquals() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); UnaryCallSettings settings13 = builder.build(); assertEquals(settings13, settings13); @@ -66,7 +66,7 @@ public void testEquals() { assertEquals(settings13.hashCode(), settings13.hashCode()); UnaryCallSettings.Builder builder5 = new UnaryCallSettings.Builder(); - builder5.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofSeconds(5)); + builder5.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(5)); UnaryCallSettings settings5 = builder5.build(); assertNotEquals(settings13, settings5); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java index 516ba958f9..07d1fd2b13 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java @@ -102,7 +102,7 @@ public void testNonRetriedCallable() throws Exception { // Verify that callables configured to not retry have the appropriate tracer interactions. UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(5L)) + .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(5L)) .build(); UnaryCallable callable = setupTracedUnaryCallable(callSettings); innerResult.set("No, my refrigerator is not running!"); diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index f2f968a524..aa2cc3e6b8 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -25,21 +25,21 @@ public class RetryOptionTest { private static final RetryOption TOTAL_TIMEOUT = - RetryOption.totalTimeout(org.threeten.bp.Duration.ofMillis(420L)); + RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); private static final RetryOption INITIAL_RETRY_DELAY = - RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)); + RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); private static final RetryOption RETRY_DELAY_MULTIPLIER = RetryOption.retryDelayMultiplier(1.5); private static final RetryOption MAX_RETRY_DELAY = - RetryOption.maxRetryDelay(org.threeten.bp.Duration.ofMillis(100)); + RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); private static final RetryOption MAX_ATTEMPTS = RetryOption.maxAttempts(100); private static final RetryOption JITTERED = RetryOption.jittered(false); private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(420L)) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)) + .setTotalTimeout(java.time.Duration.ofMillis(420L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(42L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(100)) + .setMaxRetryDelay(java.time.Duration.ofMillis(100)) .setMaxAttempts(100) .setJittered(false) .build(); @@ -60,11 +60,10 @@ public void testEqualsAndHashCode() { assertNotEquals(MAX_ATTEMPTS, MAX_RETRY_DELAY); assertNotEquals(JITTERED, MAX_ATTEMPTS); - RetryOption totalTimeout = RetryOption.totalTimeout(org.threeten.bp.Duration.ofMillis(420L)); - RetryOption initialRetryDelay = - RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)); + RetryOption totalTimeout = RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); + RetryOption initialRetryDelay = RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); RetryOption retryDelayMultiplier = RetryOption.retryDelayMultiplier(1.5); - RetryOption maxRetryDelay = RetryOption.maxRetryDelay(org.threeten.bp.Duration.ofMillis(100)); + RetryOption maxRetryDelay = RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); RetryOption maxAttempts = RetryOption.maxAttempts(100); RetryOption jittered = RetryOption.jittered(false); @@ -101,26 +100,17 @@ public void testMergeToSettings() { assertEquals(retrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings - .toBuilder() - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(420L)) - .build(); + defRetrySettings.toBuilder().setTotalTimeout(java.time.Duration.ofMillis(420L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings - .toBuilder() - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(100)) - .build(); + defRetrySettings.toBuilder().setMaxRetryDelay(java.time.Duration.ofMillis(100)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings - .toBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(42L)) - .build(); + defRetrySettings.toBuilder().setInitialRetryDelay(java.time.Duration.ofMillis(42L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); From e8a871bb6b0548f88a9cc7589fc8713b0e514fe4 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 2 Aug 2023 21:05:08 -0400 Subject: [PATCH 034/141] chore: restore `RetrySettingsComposer` --- .../generator/gapic/composer/common/RetrySettingsComposer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java index 0cf564079b..e5e4ad4195 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/RetrySettingsComposer.java @@ -714,7 +714,7 @@ private static TypeStore createStaticTypes() { List> concreteClazzes = Arrays.asList( BatchingSettings.class, - Duration.class, + org.threeten.bp.Duration.class, FlowControlSettings.class, FlowController.LimitExceededBehavior.class, ImmutableMap.class, From e20f9740156394e0fa9bca4f005263cb798962cc Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Fri, 25 Aug 2023 19:12:10 +0000 Subject: [PATCH 035/141] chore: use local repository for api-common --- WORKSPACE | 20 ++++++++++++++------ gax-java/WORKSPACE | 14 +++++++++++--- gax-java/dependencies.properties | 2 +- gax-java/gax-grpc/BUILD.bazel | 2 +- gax-java/gax-httpjson/BUILD.bazel | 2 +- gax-java/gax/BUILD.bazel | 4 ++-- rules_java_gapic/java_gapic.bzl | 4 ++-- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 6a8dbc6e38..199334aa75 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -33,15 +33,13 @@ http_archive( ) # protobuf -RULES_JVM_EXTERNAL_TAG = "4.5" - -RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6" - +RULES_JVM_EXTERNAL_TAG = "5.3" +RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac" http_archive( name = "rules_jvm_external", - sha256 = RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, + sha256 = RULES_JVM_EXTERNAL_SHA, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG) ) load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") @@ -129,3 +127,13 @@ http_archive( load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() + +maven_install( + artifacts = [ + 'com.google.api:api-common:2.15.1-SNAPSHOT' + ], + repositories = [ + 'file:///usr/local/google/home/diegomarquezp/.m2/repository', + ] +) + diff --git a/gax-java/WORKSPACE b/gax-java/WORKSPACE index 9c65d85e87..02c6024688 100644 --- a/gax-java/WORKSPACE +++ b/gax-java/WORKSPACE @@ -19,15 +19,23 @@ load("@com_google_protobuf//:protobuf_deps.bzl", # PROTOBUF_MAVEN_ARTIFACTS variable so that the Bazel users can resolve their # dependencies through maven_install. # https://github.com/protocolbuffers/protobuf/issues/9132 -RULES_JVM_EXTERNAL_TAG = "4.2" -RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca" +RULES_JVM_EXTERNAL_TAG = "5.3" +RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac" http_archive( name = "rules_jvm_external", strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, sha256 = RULES_JVM_EXTERNAL_SHA, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG) ) +load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") + +rules_jvm_external_deps() + +load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup") + +rules_jvm_external_setup() + load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( diff --git a/gax-java/dependencies.properties b/gax-java/dependencies.properties index b8592ffe19..2e942be817 100644 --- a/gax-java/dependencies.properties +++ b/gax-java/dependencies.properties @@ -69,7 +69,7 @@ maven.com_google_errorprone_error_prone_annotations=com.google.errorprone:error_ maven.com_google_j2objc_j2objc_annotations=com.google.j2objc:j2objc-annotations:2.8 maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.10.2 maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.10.2 -maven.com_google_api_api_common=com.google.api:api-common:2.7.0 +#maven.com_google_api_api_common=com.google.api:api-common:2.15.1-SNAPSHOT maven.org_threeten_threetenbp=org.threeten:threetenbp:1.6.8 maven.com_google_api_grpc_grpc_google_iam_v1=com.google.api.grpc:grpc-google-iam-v1:1.10.0 maven.com_google_api_grpc_proto_google_iam_v1=com.google.api.grpc:proto-google-iam-v1:1.10.0 diff --git a/gax-java/gax-grpc/BUILD.bazel b/gax-java/gax-grpc/BUILD.bazel index f1dfe02fc6..a51bb801f9 100644 --- a/gax-java/gax-grpc/BUILD.bazel +++ b/gax-java/gax-grpc/BUILD.bazel @@ -20,7 +20,7 @@ _COMPILE_DEPS = [ "@com_google_auth_google_auth_library_oauth2_http//jar", "@com_google_auth_google_auth_library_credentials//jar", "@com_google_api_grpc_proto_google_common_protos//jar", - "@com_google_api_api_common//jar", + "@maven//:com_google_api_api_common", "@com_google_auto_value_auto_value//jar", "@com_google_auto_value_auto_value_annotations//jar", "@com_google_http_client_google_http_client//jar", diff --git a/gax-java/gax-httpjson/BUILD.bazel b/gax-java/gax-httpjson/BUILD.bazel index 0ddf20181d..707e6c31d4 100644 --- a/gax-java/gax-httpjson/BUILD.bazel +++ b/gax-java/gax-httpjson/BUILD.bazel @@ -15,7 +15,7 @@ _COMPILE_DEPS = [ "@com_google_http_client_google_http_client//jar", "@com_google_auth_google_auth_library_oauth2_http//jar", "@com_google_auth_google_auth_library_credentials//jar", - "@com_google_api_api_common//jar", + "@maven//:com_google_api_api_common", "@com_google_auto_value_auto_value//jar", "@com_google_auto_value_auto_value_annotations//jar", "@javax_annotation_javax_annotation_api//jar", diff --git a/gax-java/gax/BUILD.bazel b/gax-java/gax/BUILD.bazel index 0152f2503f..381c758c17 100644 --- a/gax-java/gax/BUILD.bazel +++ b/gax-java/gax/BUILD.bazel @@ -8,7 +8,6 @@ _JAVA_COPTS = [ ] _COMPILE_DEPS = [ - "@com_google_api_api_common//jar", "@com_google_api_grpc_proto_google_common_protos//jar", "@com_google_protobuf_java//jar", "@com_google_auth_google_auth_library_credentials//jar", @@ -26,7 +25,8 @@ _COMPILE_DEPS = [ "@com_google_code_gson_gson//jar", "@com_google_guava_failureaccess//jar", "@javax_annotation_javax_annotation_api//jar", - "@org_graalvm_sdk//jar" + "@org_graalvm_sdk//jar", + "@maven//:com_google_api_api_common", ] _TEST_COMPILE_DEPS = [ diff --git a/rules_java_gapic/java_gapic.bzl b/rules_java_gapic/java_gapic.bzl index a5bf043cca..971db67a84 100644 --- a/rules_java_gapic/java_gapic.bzl +++ b/rules_java_gapic/java_gapic.bzl @@ -279,7 +279,7 @@ def java_gapic_library( name = resource_name_name, srcs = ["%s-resource-name.srcjar" % srcjar_name], deps = [ - "@com_google_api_api_common//jar", + "@maven//:com_google_api_api_common", "@com_google_guava_guava//jar", "@javax_annotation_javax_annotation_api//jar", ], @@ -291,7 +291,7 @@ def java_gapic_library( "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_googleapis//google/longrunning:longrunning_java_proto", "@com_google_protobuf//:protobuf_java", - "@com_google_api_api_common//jar", + "@maven//:com_google_api_api_common", "@com_google_api_gax_java//gax:gax", "@com_google_guava_guava//jar", "@com_google_code_findbugs_jsr305//jar", From f05f2efe2a33ff88b0c77fafda5d3b7db5b00220 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Mon, 28 Aug 2023 21:29:55 +0000 Subject: [PATCH 036/141] chore: use local repository --- WORKSPACE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index 199334aa75..0739071597 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -133,7 +133,7 @@ maven_install( 'com.google.api:api-common:2.15.1-SNAPSHOT' ], repositories = [ - 'file:///usr/local/google/home/diegomarquezp/.m2/repository', + 'm2Local', ] ) From 4703dcdab8abdca12829e990b13f7f9e64682595 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 25 Oct 2023 17:19:08 +0000 Subject: [PATCH 037/141] format source --- .../gax/src/main/java/com/google/api/gax/rpc/Watchdog.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index c11a2e0f59..2ab274aa9c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -219,7 +219,9 @@ class WatchdogStream extends StateCheckingResponseObserver private volatile Throwable error; WatchdogStream( - ResponseObserver responseObserver, java.time.Duration waitTimeout, java.time.Duration idleTimeout) { + ResponseObserver responseObserver, + java.time.Duration waitTimeout, + java.time.Duration idleTimeout) { this.waitTimeout = waitTimeout; this.idleTimeout = idleTimeout; this.outerResponseObserver = responseObserver; From 4635dd517e2cd343d7a924b5df2e51c88c068a5a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 25 Oct 2023 17:49:01 +0000 Subject: [PATCH 038/141] add test for retry settings propagation --- .../it/ITRetrySettingsPropagationTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java new file mode 100644 index 0000000000..1264c16267 --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java @@ -0,0 +1,53 @@ +package com.google.showcase.v1beta1.it; + +import static org.junit.Assert.assertEquals; + +import com.google.api.gax.retrying.RetrySettings; +import org.junit.Test; + +/** + * Tests to confirm that usage of retry settings can be done regardless of whether threeten or + * java.time is being used + */ +public class ITRetrySettingsPropagationTest { + @Test + public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { + java.time.Duration javaTimeCommonValue = java.time.Duration.ofMillis(123l); + org.threeten.bp.Duration threetenConvertedValue = + org.threeten.bp.Duration.ofMillis(javaTimeCommonValue.toMillis()); + RetrySettings javaTimeRetrySettings = RetrySettings.newBuilder() + .setInitialRetryDelay(javaTimeCommonValue) + .setMaxRetryDelay(javaTimeCommonValue) + .setInitialRpcTimeout(javaTimeCommonValue) + .setMaxRpcTimeout(javaTimeCommonValue) + .setTotalTimeout(javaTimeCommonValue) + .build(); + + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRetryDelay()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRetryDelay()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRpcTimeout()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRpcTimeout()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getTotalTimeout()); + } + + @Test + public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { + java.time.Duration threetenCommonValue = java.time.Duration.ofMillis(123l); + org.threeten.bp.Duration javaTimeConvertedValue = + org.threeten.bp.Duration.ofMillis(threetenCommonValue.toMillis()); + RetrySettings threetenRetrySettings = RetrySettings.newBuilder() + .setInitialRetryDelay(threetenCommonValue) + .setMaxRetryDelay(threetenCommonValue) + .setInitialRpcTimeout(threetenCommonValue) + .setMaxRpcTimeout(threetenCommonValue) + .setTotalTimeout(threetenCommonValue) + .build(); + + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRetryDelay()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRetryDelay()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRpcTimeout()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRpcTimeout()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getTotalTimeout()); + } + +} From 7774eb040162810d75263b2835c46175f81959ae Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 25 Oct 2023 18:00:33 +0000 Subject: [PATCH 039/141] restore bazel configurations --- WORKSPACE | 20 ++++++-------------- gax-java/WORKSPACE | 14 +++----------- gax-java/dependencies.properties | 2 +- gax-java/gax-grpc/BUILD.bazel | 2 +- gax-java/gax-httpjson/BUILD.bazel | 2 +- gax-java/gax/BUILD.bazel | 4 ++-- rules_java_gapic/java_gapic.bzl | 4 ++-- 7 files changed, 16 insertions(+), 32 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 47286781da..e9c11d10cd 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -33,13 +33,15 @@ http_archive( ) # protobuf -RULES_JVM_EXTERNAL_TAG = "5.3" -RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac" +RULES_JVM_EXTERNAL_TAG = "4.5" + +RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6" + http_archive( name = "rules_jvm_external", - strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, sha256 = RULES_JVM_EXTERNAL_SHA, - url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG) + strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, ) load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") @@ -127,13 +129,3 @@ http_archive( load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() - -maven_install( - artifacts = [ - 'com.google.api:api-common:2.15.1-SNAPSHOT' - ], - repositories = [ - 'm2Local', - ] -) - diff --git a/gax-java/WORKSPACE b/gax-java/WORKSPACE index 02c6024688..9c65d85e87 100644 --- a/gax-java/WORKSPACE +++ b/gax-java/WORKSPACE @@ -19,23 +19,15 @@ load("@com_google_protobuf//:protobuf_deps.bzl", # PROTOBUF_MAVEN_ARTIFACTS variable so that the Bazel users can resolve their # dependencies through maven_install. # https://github.com/protocolbuffers/protobuf/issues/9132 -RULES_JVM_EXTERNAL_TAG = "5.3" -RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac" +RULES_JVM_EXTERNAL_TAG = "4.2" +RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca" http_archive( name = "rules_jvm_external", strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, sha256 = RULES_JVM_EXTERNAL_SHA, - url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG) + url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, ) -load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") - -rules_jvm_external_deps() - -load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup") - -rules_jvm_external_setup() - load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( diff --git a/gax-java/dependencies.properties b/gax-java/dependencies.properties index e44597429e..f6a76d8d51 100644 --- a/gax-java/dependencies.properties +++ b/gax-java/dependencies.properties @@ -66,7 +66,7 @@ maven.com_google_errorprone_error_prone_annotations=com.google.errorprone:error_ maven.com_google_j2objc_j2objc_annotations=com.google.j2objc:j2objc-annotations:2.8 maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.10.4 maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.10.4 -maven.com_google_api_api_common=com.google.api:api-common:2.19.0 +maven.com_google_api_api_common=com.google.api:api-common:2.18.0 maven.org_threeten_threetenbp=org.threeten:threetenbp:1.6.8 maven.com_google_api_grpc_grpc_google_iam_v1=com.google.api.grpc:grpc-google-iam-v1:1.21.0 maven.com_google_api_grpc_proto_google_iam_v1=com.google.api.grpc:proto-google-iam-v1:1.21.0 diff --git a/gax-java/gax-grpc/BUILD.bazel b/gax-java/gax-grpc/BUILD.bazel index a51bb801f9..f1dfe02fc6 100644 --- a/gax-java/gax-grpc/BUILD.bazel +++ b/gax-java/gax-grpc/BUILD.bazel @@ -20,7 +20,7 @@ _COMPILE_DEPS = [ "@com_google_auth_google_auth_library_oauth2_http//jar", "@com_google_auth_google_auth_library_credentials//jar", "@com_google_api_grpc_proto_google_common_protos//jar", - "@maven//:com_google_api_api_common", + "@com_google_api_api_common//jar", "@com_google_auto_value_auto_value//jar", "@com_google_auto_value_auto_value_annotations//jar", "@com_google_http_client_google_http_client//jar", diff --git a/gax-java/gax-httpjson/BUILD.bazel b/gax-java/gax-httpjson/BUILD.bazel index 58105813b9..15c81e73d4 100644 --- a/gax-java/gax-httpjson/BUILD.bazel +++ b/gax-java/gax-httpjson/BUILD.bazel @@ -16,7 +16,7 @@ _COMPILE_DEPS = [ "@com_google_http_client_google_http_client//jar", "@com_google_auth_google_auth_library_oauth2_http//jar", "@com_google_auth_google_auth_library_credentials//jar", - "@maven//:com_google_api_api_common", + "@com_google_api_api_common//jar", "@com_google_auto_value_auto_value//jar", "@com_google_auto_value_auto_value_annotations//jar", "@javax_annotation_javax_annotation_api//jar", diff --git a/gax-java/gax/BUILD.bazel b/gax-java/gax/BUILD.bazel index 4fe1410659..85c41f8b58 100644 --- a/gax-java/gax/BUILD.bazel +++ b/gax-java/gax/BUILD.bazel @@ -8,6 +8,7 @@ _JAVA_COPTS = [ ] _COMPILE_DEPS = [ + "@com_google_api_api_common//jar", "@com_google_api_grpc_proto_google_common_protos//jar", "@com_google_protobuf_java//jar", "@com_google_auth_google_auth_library_credentials//jar", @@ -26,8 +27,7 @@ _COMPILE_DEPS = [ "@com_google_code_gson_gson//jar", "@com_google_guava_failureaccess//jar", "@javax_annotation_javax_annotation_api//jar", - "@org_graalvm_sdk//jar", - "@maven//:com_google_api_api_common", + "@org_graalvm_sdk//jar" ] _TEST_COMPILE_DEPS = [ diff --git a/rules_java_gapic/java_gapic.bzl b/rules_java_gapic/java_gapic.bzl index 9380db5ed1..f484c474d3 100644 --- a/rules_java_gapic/java_gapic.bzl +++ b/rules_java_gapic/java_gapic.bzl @@ -279,7 +279,7 @@ def java_gapic_library( name = resource_name_name, srcs = ["%s-resource-name.srcjar" % srcjar_name], deps = [ - "@maven//:com_google_api_api_common", + "@com_google_api_api_common//jar", "@com_google_guava_guava//jar", "@javax_annotation_javax_annotation_api//jar", ], @@ -291,7 +291,7 @@ def java_gapic_library( "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_googleapis//google/longrunning:longrunning_java_proto", "@com_google_protobuf//:protobuf_java", - "@maven//:com_google_api_api_common", + "@com_google_api_api_common//jar", "@com_google_api_gax_java//gax:gax", "@com_google_guava_guava//jar", "@com_google_code_findbugs_jsr305//jar", From 63261fa59c893a60c272b2405c32cdd0a32d3c4c Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 25 Oct 2023 18:42:04 +0000 Subject: [PATCH 040/141] rename time objects test --- ...gsPropagationTest.java => ITTimeObjectsPropagationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/{ITRetrySettingsPropagationTest.java => ITTimeObjectsPropagationTest.java} (98%) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java similarity index 98% rename from showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java rename to showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java index 1264c16267..050f167044 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetrySettingsPropagationTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java @@ -9,7 +9,7 @@ * Tests to confirm that usage of retry settings can be done regardless of whether threeten or * java.time is being used */ -public class ITRetrySettingsPropagationTest { +public class ITTimeObjectsPropagationTest { @Test public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { java.time.Duration javaTimeCommonValue = java.time.Duration.ofMillis(123l); From ba456a115f6fde8cf35889fdb3d289f23056b8b1 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 25 Oct 2023 21:15:15 +0000 Subject: [PATCH 041/141] add generic test for time modifier methods --- .../api/gax/batching/ThresholdBatcher.java | 5 ++ .../gax/batching/ThresholdBatcherTest.java | 24 +++++++ .../api/gax/util/TimeConversionTestUtils.java | 67 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index fa75036c82..1951f1d7c1 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -101,6 +101,11 @@ private ThresholdBatcher(Builder builder) { resetThresholds(); } + @VisibleForTesting + public java.time.Duration getMaxDelay() { + return this.maxDelay; + } + /** Builder for a ThresholdBatcher. */ public static class Builder { private Collection> thresholds; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 901aab9bf9..c5d6583644 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -34,6 +34,8 @@ import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import com.google.api.gax.util.TimeConversionTestUtils; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -356,4 +358,26 @@ public void testBatchingFailedRPC() throws Exception { assertThat(trackedFlowController.getBytesReserved()) .isEqualTo(trackedFlowController.getBytesReleased()); } + + @Test + public void testTimeObjectsEquivalence() throws NoSuchMethodException { + AccumulatingBatchReceiver receiver = + new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); + Method build = ThresholdBatcher.Builder.class.getMethod("build"); + Method getMaxDelay = ThresholdBatcher.class.getMethod("getMaxDelay"); + + TimeConversionTestUtils.testDurationGetterAndSetter( + java.time.Duration.ofNanos(123l), + createSimpleBatcherBuidler(receiver), + ThresholdBatcher.Builder.class.getMethod("setMaxDelay", java.time.Duration.class), + build, + getMaxDelay); + + TimeConversionTestUtils.testDurationGetterAndSetter( + org.threeten.bp.Duration.ofNanos(123l), + createSimpleBatcherBuidler(receiver), + ThresholdBatcher.Builder.class.getMethod("setMaxDelay", org.threeten.bp.Duration.class), + build, + getMaxDelay); + } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java new file mode 100644 index 0000000000..ca46bc98d7 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -0,0 +1,67 @@ +package com.google.api.gax.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import org.junit.Assert; + +public class TimeConversionTestUtils { + + public static void testDurationGetterAndSetter( + org.threeten.bp.Duration inputValue, + Object target, + Method setter, + Method buildFunction, + Method getter) { + testBuilderDurationSetter(inputValue, target, setter, buildFunction, getter); + } + + public static void testDurationGetterAndSetter( + org.threeten.bp.Duration inputValue, Object target, Method setter, Method getter) { + testBuilderDurationSetter(inputValue, target, setter, null, getter); + } + + public static void testDurationGetterAndSetter( + java.time.Duration inputValue, + Object target, + Method setter, + Method buildFunction, + Method getter) { + testBuilderDurationSetter(inputValue, target, setter, buildFunction, getter); + } + + public static void testDurationGetterAndSetter( + java.time.Duration inputValue, Object target, Method setter, Method getter) { + testBuilderDurationSetter(inputValue, target, setter, null, getter); + } + + private static void testBuilderDurationSetter( + Object inputValue, Object target, Method setter, Method buildFunction, Method getter) { + try { + Object targetSet = setter.invoke(target, inputValue); + Object obtainedValue; + if (buildFunction != null) { + Object builtTarget = buildFunction.invoke(targetSet); + obtainedValue = getter.invoke(builtTarget); + } else { + obtainedValue = getter.invoke(targetSet); + } + long obtainedNanos = getNanosFromAnyDuration(obtainedValue); + long providedNanos = getNanosFromAnyDuration(inputValue); + Assert.assertEquals(providedNanos, obtainedNanos); + } catch (IllegalAccessException e) { + Assert.fail(e.getMessage()); + } catch (InvocationTargetException e) { + Assert.fail(e.getMessage()); + } + } + + private static long getNanosFromAnyDuration(Object value) { + if (value instanceof java.time.Duration) { + return ((java.time.Duration) value).toMillis(); + } else if (value instanceof org.threeten.bp.Duration) { + return ((org.threeten.bp.Duration) value).toMillis(); + } else { + throw new IllegalArgumentException("Unexpected value type: " + value.getClass().getName()); + } + } +} From 692022273832f52852193c5aafdebf8423d9b9ec Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 3 May 2024 21:50:30 +0000 Subject: [PATCH 042/141] post-merge fixes --- .../com/google/api/gax/grpc/TimeoutTest.java | 2 +- .../httpjson/HttpJsonDirectCallableTest.java | 6 ++-- ...JsonDirectServerStreamingCallableTest.java | 6 ++-- .../retrying/ExponentialRetryAlgorithm.java | 8 ++--- .../google/api/gax/tracing/MetricsTracer.java | 3 +- .../ExponentialRetryAlgorithmTest.java | 24 ++++++++------- .../api/gax/tracing/MetricsTracerTest.java | 3 +- .../api/gax/util/TimeConversionTestUtils.java | 29 +++++++++++++++++++ 8 files changed, 55 insertions(+), 26 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java index 106c4b998c..d4c60d5c31 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java @@ -83,7 +83,7 @@ public class TimeoutTest { java.time.Duration.ofMinutes(DEADLINE_IN_MINUTES); private static final java.time.Duration initialRpcTimeout = java.time.Duration.ofSeconds(DEADLINE_IN_SECONDS); - private static final GrpcCallContext defaultCallContext = GrpcCallContext.createDefault(); + private static GrpcCallContext defaultCallContext; @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); @Mock private Marshaller stringMarshaller; diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java index 28a7c0de8b..770c588198 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java @@ -128,7 +128,7 @@ public static void initialize() throws IOException { defaultCallContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(Duration.ofSeconds(30)) + .withTimeout(java.time.Duration.ofSeconds(30)) .withEndpointContext(endpointContext); } @@ -334,8 +334,8 @@ public void testDeadlineExceededResponse() throws InterruptedException { HttpJsonDirectCallable callable = new HttpJsonDirectCallable<>(FAKE_METHOD_DESCRIPTOR); - HttpJsonCallContext callContext = defaultCallContext - .withTimeout(java.time.Duration.ofSeconds(3)); + HttpJsonCallContext callContext = + defaultCallContext.withTimeout(java.time.Duration.ofSeconds(3)); Field response = createTestMessage(10); MOCK_SERVICE.addResponse(response, java.time.Duration.ofSeconds(5)); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java index 124e0a58c4..8109e6fe4e 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java @@ -90,10 +90,10 @@ public class HttpJsonDirectServerStreamingCallableTest { @Before public void initialize() throws IOException { - initialize(Duration.ofSeconds(30)); + initialize(java.time.Duration.ofSeconds(30)); } - public void initialize(Duration timeout) throws IOException { + public void initialize(java.time.Duration timeout) throws IOException { this.methodServerStreamingRecognize = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.cloud.v1.Fake/ServerStreamingRecognize") @@ -334,7 +334,7 @@ public void testBlockingServerStreaming() { @Test public void testDeadlineExceededServerStreaming() throws InterruptedException, IOException { // set a low timeout to trigger deadline-exceeded sooner - initialize(Duration.ofSeconds(1)); + initialize(java.time.Duration.ofSeconds(1)); mockService.addResponse( new Money[] {DEFAULT_RESPONSE, DEFAULTER_RESPONSE}, java.time.Duration.ofSeconds(30)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index 3f21d9fc5b..865af00bff 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -69,7 +69,7 @@ public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) .setRetryDelay(java.time.Duration.ZERO) - .setRpcTimeout(getInitialTimeout(globalSettings)) + .setRpcTimeout(getInitialTimeoutDuration(globalSettings)) .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) @@ -272,13 +272,13 @@ protected long nextRandomLong(long bound) { * Returns the timeout of the first attempt. The initial timeout will be min(initialRpcTimeout, * totalTimeout) if totalTimeout is set. */ - private Duration getInitialTimeout(RetrySettings retrySettings) { + private java.time.Duration getInitialTimeoutDuration(RetrySettings retrySettings) { // If the totalTimeout is zero (not set), then retries are capped by the max attempt // number. The first attempt will use the initialRpcTimeout value for RPC timeout. long totalTimeout = retrySettings.getTotalTimeout().toMillis(); return totalTimeout == 0 - ? retrySettings.getInitialRpcTimeout() - : Duration.ofMillis( + ? retrySettings.getInitialRpcTimeoutDuration() + : java.time.Duration.ofMillis( Math.min(retrySettings.getInitialRpcTimeout().toMillis(), totalTimeout)); } } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java index 7938bde82b..91e7d2f03c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java @@ -42,7 +42,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * This class computes generic metrics that can be observed in the lifecycle of an RPC operation. @@ -171,7 +170,7 @@ public void attemptCancelled() { * key. */ @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailed(Throwable error, java.time.Duration delay) { attributes.put(STATUS_ATTRIBUTE, extractStatus(error)); metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.MILLISECONDS), attributes); metricsRecorder.recordAttemptCount(1, attributes); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index 658b54fff6..967936b65a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -104,35 +104,37 @@ public void testCreateFirstAttemptHasCorrectTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(Duration.ofMillis(1L)) + .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(Duration.ofMillis(8L)) - .setInitialRpcTimeout(Duration.ofMillis(rpcTimeout)) + .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(rpcTimeout)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(rpcTimeout)) - .setTotalTimeout(Duration.ofMillis(totalTimeout)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(rpcTimeout)) + .setTotalTimeout(java.time.Duration.ofMillis(totalTimeout)) .build(); ExponentialRetryAlgorithm algorithm = new ExponentialRetryAlgorithm(retrySettings, clock); TimedAttemptSettings attempt = algorithm.createFirstAttempt(); - assertEquals(Duration.ofMillis(totalTimeout), attempt.getRpcTimeout()); + assertEquals(java.time.Duration.ofMillis(totalTimeout), attempt.getRpcTimeoutDuration()); long overrideRpcTimeout = 100; long overrideTotalTimeout = 20; RetrySettings retrySettingsOverride = retrySettings .toBuilder() - .setInitialRpcTimeout(Duration.ofMillis(overrideRpcTimeout)) - .setMaxRpcTimeout(Duration.ofMillis(overrideRpcTimeout)) - .setTotalTimeout(Duration.ofMillis(overrideTotalTimeout)) + .setInitialRpcTimeout(java.time.Duration.ofMillis(overrideRpcTimeout)) + .setMaxRpcTimeout(java.time.Duration.ofMillis(overrideRpcTimeout)) + .setTotalTimeout(java.time.Duration.ofMillis(overrideTotalTimeout)) .build(); RetryingContext retryingContext = FakeCallContext.createDefault().withRetrySettings(retrySettingsOverride); attempt = algorithm.createFirstAttempt(retryingContext); - assertEquals(Duration.ofMillis(overrideTotalTimeout), attempt.getRpcTimeout()); + assertEquals( + java.time.Duration.ofMillis(overrideTotalTimeout), attempt.getRpcTimeoutDuration()); - RetrySettings noTotalTimeout = retrySettings.toBuilder().setTotalTimeout(Duration.ZERO).build(); + RetrySettings noTotalTimeout = + retrySettings.toBuilder().setTotalTimeout(java.time.Duration.ZERO).build(); algorithm = new ExponentialRetryAlgorithm(noTotalTimeout, clock); attempt = algorithm.createFirstAttempt(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java index 817c53656c..707735b0de 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java @@ -52,7 +52,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class MetricsTracerTest { @@ -146,7 +145,7 @@ public void testAttemptFailed_recordsAttributes() { ApiException error0 = new NotFoundException( "invalid argument", null, new FakeStatusCode(Code.INVALID_ARGUMENT), false); - metricsTracer.attemptFailed(error0, Duration.ofMillis(2)); + metricsTracer.attemptFailed(error0, java.time.Duration.ofMillis(2)); Map attributes = getAttributes(Code.INVALID_ARGUMENT); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index ca46bc98d7..ae5b3b8f70 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -1,3 +1,32 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.google.api.gax.util; import java.lang.reflect.InvocationTargetException; From 0c8ac5d0417882a53010774ec9aeb5899114a2bc Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sat, 4 May 2024 21:49:35 +0000 Subject: [PATCH 043/141] add tests for GrpcCallContext --- .../api/gax/grpc/GrpcCallContextTest.java | 55 ++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 2aad6cc781..c9a2296c18 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -129,8 +129,31 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { - java.time.Duration timeout = null; - assertNull(GrpcCallContext.createDefault().withTimeout(timeout).getTimeoutDuration()); + java.time.Duration javaTimeTimeout = null; + org.threeten.bp.Duration threetenTimeout = null; + assertNull(GrpcCallContext.createDefault().withTimeout(javaTimeTimeout).getTimeoutDuration()); + assertNull(GrpcCallContext.createDefault().withTimeout(threetenTimeout).getTimeoutDuration()); + final int millis = 123; + javaTimeTimeout = java.time.Duration.ofMillis(millis); + assertEquals( + millis, + GrpcCallContext.createDefault().withTimeout(javaTimeTimeout).getTimeout().toMillis()); + assertEquals( + millis, + GrpcCallContext.createDefault() + .withTimeout(javaTimeTimeout) + .getTimeoutDuration() + .toMillis()); + threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + assertEquals( + millis, + GrpcCallContext.createDefault().withTimeout(threetenTimeout).getTimeout().toMillis()); + assertEquals( + millis, + GrpcCallContext.createDefault() + .withTimeout(threetenTimeout) + .getTimeoutDuration() + .toMillis()); } @Test @@ -207,9 +230,18 @@ public void testMergeWithTimeout() { @Test public void testWithStreamingWaitTimeout() { - java.time.Duration timeout = java.time.Duration.ofSeconds(15); - GrpcCallContext context = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); - Truth.assertThat(context.getStreamWaitTimeoutDuration()).isEqualTo(timeout); + final int seconds = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofSeconds(seconds); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofSeconds(seconds); + + GrpcCallContext context = + GrpcCallContext.createDefault().withStreamWaitTimeout(javaTimeTimeout); + Truth.assertThat(context.getStreamWaitTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(threetenTimeout); + + context = GrpcCallContext.createDefault().withStreamWaitTimeout(threetenTimeout); + Truth.assertThat(context.getStreamWaitTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(threetenTimeout); } @Test @@ -249,9 +281,16 @@ public void testMergeWithStreamingWaitTimeout() { @Test public void testWithStreamingIdleTimeout() { - java.time.Duration timeout = java.time.Duration.ofSeconds(15); - GrpcCallContext context = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); - Truth.assertThat(context.getStreamIdleTimeoutDuration()).isEqualTo(timeout); + final int seconds = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofSeconds(seconds); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofSeconds(seconds); + GrpcCallContext context = + GrpcCallContext.createDefault().withStreamIdleTimeout(javaTimeTimeout); + Truth.assertThat(context.getStreamIdleTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(threetenTimeout); + context = GrpcCallContext.createDefault().withStreamIdleTimeout(threetenTimeout); + Truth.assertThat(context.getStreamIdleTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(threetenTimeout); } @Test From 0c8cfb76f3daa969b344222427c90a7a9bc85f68 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sat, 4 May 2024 22:01:52 +0000 Subject: [PATCH 044/141] add tests for InstantiatingGrpcChannelProvider --- .../InstantiatingGrpcChannelProviderTest.java | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 836494a4fe..375f8d211f 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -93,20 +93,33 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { - java.time.Duration keepaliveTime = java.time.Duration.ofSeconds(1); - java.time.Duration keepaliveTimeout = java.time.Duration.ofSeconds(2); - boolean keepaliveWithoutCalls = true; + java.time.Duration javaTimeKeepAliveTime = java.time.Duration.ofSeconds(1); + java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofSeconds(2); + org.threeten.bp.Duration threetenKeepAliveTime = org.threeten.bp.Duration.ofSeconds(1); + org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofSeconds(2); - InstantiatingGrpcChannelProvider provider = + boolean keepaliveWithoutCalls = true; + List providers = ImmutableList.of( InstantiatingGrpcChannelProvider.newBuilder() - .setKeepAliveTime(keepaliveTime) - .setKeepAliveTimeout(keepaliveTimeout) + .setKeepAliveTime(javaTimeKeepAliveTime) + .setKeepAliveTimeout(javaTimeKeepAliveTimeout) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build(); + .build(), + InstantiatingGrpcChannelProvider.newBuilder() + .setKeepAliveTime(threetenKeepAliveTime) + .setKeepAliveTimeout(threetenKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build() + ); + + for (InstantiatingGrpcChannelProvider provider : providers) { + assertEquals(provider.getKeepAliveWithoutCalls(), keepaliveWithoutCalls); + assertEquals(provider.getKeepAliveTimeDuration(), javaTimeKeepAliveTime); + assertEquals(provider.getKeepAliveTimeoutDuration(), javaTimeKeepAliveTimeout); + assertEquals(provider.getKeepAliveTime(), threetenKeepAliveTime); + assertEquals(provider.getKeepAliveTimeout(), threetenKeepAliveTimeout); + } - assertEquals(provider.getKeepAliveTimeDuration(), keepaliveTime); - assertEquals(provider.getKeepAliveTimeoutDuration(), keepaliveTimeout); - assertEquals(provider.getKeepAliveWithoutCalls(), keepaliveWithoutCalls); } @Test @@ -618,6 +631,7 @@ public void testLogDirectPathMisconfigNotOnGCE() throws Exception { } private static class FakeLogHandler extends Handler { + List records = new ArrayList<>(); @Override @@ -626,10 +640,12 @@ public void publish(LogRecord record) { } @Override - public void flush() {} + public void flush() { + } @Override - public void close() throws SecurityException {} + public void close() throws SecurityException { + } List getAllMessages() { return records.stream().map(LogRecord::getMessage).collect(Collectors.toList()); From f9750cecbdfc79fedb14a0f0fdf2339f1aa11806 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 5 May 2024 00:17:42 +0000 Subject: [PATCH 045/141] add HttpJsonCallContext tests --- .../InstantiatingGrpcChannelProviderTest.java | 31 ++++--- .../gax/httpjson/HttpJsonCallContextTest.java | 56 ++++++++++++- .../gax/batching/ThresholdBatcherTest.java | 27 +++--- .../api/gax/util/TimeConversionTestUtils.java | 84 +++++++------------ 4 files changed, 108 insertions(+), 90 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 375f8d211f..fbeab828c5 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -99,18 +99,18 @@ public void testKeepAlive() { org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofSeconds(2); boolean keepaliveWithoutCalls = true; - List providers = ImmutableList.of( - InstantiatingGrpcChannelProvider.newBuilder() - .setKeepAliveTime(javaTimeKeepAliveTime) - .setKeepAliveTimeout(javaTimeKeepAliveTimeout) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build(), - InstantiatingGrpcChannelProvider.newBuilder() - .setKeepAliveTime(threetenKeepAliveTime) - .setKeepAliveTimeout(threetenKeepAliveTimeout) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build() - ); + List providers = + ImmutableList.of( + InstantiatingGrpcChannelProvider.newBuilder() + .setKeepAliveTime(javaTimeKeepAliveTime) + .setKeepAliveTimeout(javaTimeKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build(), + InstantiatingGrpcChannelProvider.newBuilder() + .setKeepAliveTime(threetenKeepAliveTime) + .setKeepAliveTimeout(threetenKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build()); for (InstantiatingGrpcChannelProvider provider : providers) { assertEquals(provider.getKeepAliveWithoutCalls(), keepaliveWithoutCalls); @@ -119,7 +119,6 @@ public void testKeepAlive() { assertEquals(provider.getKeepAliveTime(), threetenKeepAliveTime); assertEquals(provider.getKeepAliveTimeout(), threetenKeepAliveTimeout); } - } @Test @@ -640,12 +639,10 @@ public void publish(LogRecord record) { } @Override - public void flush() { - } + public void flush() {} @Override - public void close() throws SecurityException { - } + public void close() throws SecurityException {} List getAllMessages() { return records.stream().map(LogRecord::getMessage).collect(Collectors.toList()); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 02e7019b7e..6201041497 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.httpjson; +import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -115,9 +116,58 @@ public void testMergeWrongType() { } @Test - public void testWithTimeout() { - java.time.Duration timeout = null; - assertNull(HttpJsonCallContext.createDefault().withTimeout(timeout).getTimeoutDuration()); + public void testStreamIdleTimeout() { + final long millis = 3; + final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); + testTimeObjectGetterAndSetter( + millis, + () -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), + () -> defaultContext.withStreamIdleTimeout(threetenTimeout), + c -> c.getStreamIdleTimeoutDuration(), + c -> c.getStreamIdleTimeout()); + } + + @Test + public void testStreamWaitTimeout() { + final long millis = 3; + final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); + testTimeObjectGetterAndSetter( + millis, + () -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), + () -> defaultContext.withStreamWaitTimeout(threetenTimeout), + c -> c.getStreamWaitTimeoutDuration(), + c -> c.getStreamWaitTimeout()); + } + + @Test + public void testTimeout() { + final long millis = 3; + final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); + testTimeObjectGetterAndSetter( + millis, + () -> defaultContext.withTimeout(javaTimeTimeout), + () -> defaultContext.withTimeout(threetenTimeout), + c -> c.getTimeoutDuration(), + c -> c.getTimeout()); + } + + @Test + public void testNullTimeout() { + final java.time.Duration javaTimeTimeout = null; + final org.threeten.bp.Duration threetenTimeout = null; + final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); + testTimeObjectGetterAndSetter( + null, + () -> defaultContext.withTimeout(javaTimeTimeout), + () -> defaultContext.withTimeout(javaTimeTimeout), + c -> c.getTimeoutDuration(), + c -> c.getTimeout()); } @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index c5d6583644..73e4f13fc3 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -34,7 +34,6 @@ import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; -import com.google.api.gax.util.TimeConversionTestUtils; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -366,18 +365,18 @@ public void testTimeObjectsEquivalence() throws NoSuchMethodException { Method build = ThresholdBatcher.Builder.class.getMethod("build"); Method getMaxDelay = ThresholdBatcher.class.getMethod("getMaxDelay"); - TimeConversionTestUtils.testDurationGetterAndSetter( - java.time.Duration.ofNanos(123l), - createSimpleBatcherBuidler(receiver), - ThresholdBatcher.Builder.class.getMethod("setMaxDelay", java.time.Duration.class), - build, - getMaxDelay); - - TimeConversionTestUtils.testDurationGetterAndSetter( - org.threeten.bp.Duration.ofNanos(123l), - createSimpleBatcherBuidler(receiver), - ThresholdBatcher.Builder.class.getMethod("setMaxDelay", org.threeten.bp.Duration.class), - build, - getMaxDelay); + // TimeConversionTestUtils.testDurationGetterAndSetter( + // java.time.Duration.ofNanos(123l), + // createSimpleBatcherBuidler(receiver), + // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", java.time.Duration.class), + // build, + // getMaxDelay); + // + // TimeConversionTestUtils.testDurationGetterAndSetter( + // org.threeten.bp.Duration.ofNanos(123l), + // createSimpleBatcherBuidler(receiver), + // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", org.threeten.bp.Duration.class), + // build, + // getMaxDelay); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index ae5b3b8f70..947e834eea 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -29,68 +29,40 @@ */ package com.google.api.gax.util; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -public class TimeConversionTestUtils { - - public static void testDurationGetterAndSetter( - org.threeten.bp.Duration inputValue, - Object target, - Method setter, - Method buildFunction, - Method getter) { - testBuilderDurationSetter(inputValue, target, setter, buildFunction, getter); - } - - public static void testDurationGetterAndSetter( - org.threeten.bp.Duration inputValue, Object target, Method setter, Method getter) { - testBuilderDurationSetter(inputValue, target, setter, null, getter); - } +import java.util.function.Function; +import java.util.function.Supplier; - public static void testDurationGetterAndSetter( - java.time.Duration inputValue, - Object target, - Method setter, - Method buildFunction, - Method getter) { - testBuilderDurationSetter(inputValue, target, setter, buildFunction, getter); - } - - public static void testDurationGetterAndSetter( - java.time.Duration inputValue, Object target, Method setter, Method getter) { - testBuilderDurationSetter(inputValue, target, setter, null, getter); - } +public class TimeConversionTestUtils { - private static void testBuilderDurationSetter( - Object inputValue, Object target, Method setter, Method buildFunction, Method getter) { - try { - Object targetSet = setter.invoke(target, inputValue); - Object obtainedValue; - if (buildFunction != null) { - Object builtTarget = buildFunction.invoke(targetSet); - obtainedValue = getter.invoke(builtTarget); - } else { - obtainedValue = getter.invoke(targetSet); - } - long obtainedNanos = getNanosFromAnyDuration(obtainedValue); - long providedNanos = getNanosFromAnyDuration(inputValue); - Assert.assertEquals(providedNanos, obtainedNanos); - } catch (IllegalAccessException e) { - Assert.fail(e.getMessage()); - } catch (InvocationTargetException e) { - Assert.fail(e.getMessage()); - } + public static void testTimeObjectGetterAndSetter( + Long testValue, + Supplier javaTimeTargetSupplier, + Supplier threetenTargetSupplier, + Function javaTimeGetter, + Function threetenGetter) { + testTimeObjectGetterAndSetter( + testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter); + testTimeObjectGetterAndSetter( + testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter); } - private static long getNanosFromAnyDuration(Object value) { - if (value instanceof java.time.Duration) { - return ((java.time.Duration) value).toMillis(); - } else if (value instanceof org.threeten.bp.Duration) { - return ((org.threeten.bp.Duration) value).toMillis(); + private static void testTimeObjectGetterAndSetter( + Long testValue, + Supplier targetSupplier, + Function javaTimeGetter, + Function threetenGetter) { + Target target = targetSupplier.get(); + java.time.Duration javaTimeValue = javaTimeGetter.apply(target); + org.threeten.bp.Duration threetenValue = threetenGetter.apply(target); + if (testValue == null) { + assertNull(javaTimeValue); + assertNull(threetenValue); } else { - throw new IllegalArgumentException("Unexpected value type: " + value.getClass().getName()); + assertEquals(testValue.longValue(), javaTimeValue.toMillis()); + assertEquals(testValue.longValue(), threetenValue.toMillis()); } } } From 351f829d1b6d67b931d455f4635c758d1354ca8d Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 5 May 2024 00:26:21 +0000 Subject: [PATCH 046/141] modify tests for GrpcCallContext --- .../api/gax/grpc/GrpcCallContextTest.java | 69 ++++++------------- 1 file changed, 22 insertions(+), 47 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index c9a2296c18..8422291baf 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -32,6 +32,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -129,31 +130,13 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { - java.time.Duration javaTimeTimeout = null; - org.threeten.bp.Duration threetenTimeout = null; - assertNull(GrpcCallContext.createDefault().withTimeout(javaTimeTimeout).getTimeoutDuration()); - assertNull(GrpcCallContext.createDefault().withTimeout(threetenTimeout).getTimeoutDuration()); - final int millis = 123; - javaTimeTimeout = java.time.Duration.ofMillis(millis); - assertEquals( - millis, - GrpcCallContext.createDefault().withTimeout(javaTimeTimeout).getTimeout().toMillis()); - assertEquals( - millis, - GrpcCallContext.createDefault() - .withTimeout(javaTimeTimeout) - .getTimeoutDuration() - .toMillis()); - threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); - assertEquals( - millis, - GrpcCallContext.createDefault().withTimeout(threetenTimeout).getTimeout().toMillis()); - assertEquals( - millis, - GrpcCallContext.createDefault() - .withTimeout(threetenTimeout) - .getTimeoutDuration() - .toMillis()); + final long millis = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + GrpcCallContext context = GrpcCallContext.createDefault(); + testTimeObjectGetterAndSetter(millis, () -> context.withTimeout(javaTimeTimeout), + () -> context.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), + c -> c.getTimeout()); } @Test @@ -230,18 +213,13 @@ public void testMergeWithTimeout() { @Test public void testWithStreamingWaitTimeout() { - final int seconds = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofSeconds(seconds); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofSeconds(seconds); - - GrpcCallContext context = - GrpcCallContext.createDefault().withStreamWaitTimeout(javaTimeTimeout); - Truth.assertThat(context.getStreamWaitTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(threetenTimeout); - - context = GrpcCallContext.createDefault().withStreamWaitTimeout(threetenTimeout); - Truth.assertThat(context.getStreamWaitTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(threetenTimeout); + final long millis = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + GrpcCallContext context = GrpcCallContext.createDefault(); + testTimeObjectGetterAndSetter(millis, () -> context.withStreamWaitTimeout(javaTimeTimeout), + () -> context.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), + c -> c.getStreamWaitTimeout()); } @Test @@ -281,16 +259,13 @@ public void testMergeWithStreamingWaitTimeout() { @Test public void testWithStreamingIdleTimeout() { - final int seconds = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofSeconds(seconds); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofSeconds(seconds); - GrpcCallContext context = - GrpcCallContext.createDefault().withStreamIdleTimeout(javaTimeTimeout); - Truth.assertThat(context.getStreamIdleTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(threetenTimeout); - context = GrpcCallContext.createDefault().withStreamIdleTimeout(threetenTimeout); - Truth.assertThat(context.getStreamIdleTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(threetenTimeout); + final long millis = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); + GrpcCallContext context = GrpcCallContext.createDefault(); + testTimeObjectGetterAndSetter(millis, () -> context.withStreamIdleTimeout(javaTimeTimeout), + () -> context.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), + c -> c.getStreamIdleTimeout()); } @Test From 1be5153370f3aca9cbf0397519e7ffb07c96f020 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 5 May 2024 01:09:50 +0000 Subject: [PATCH 047/141] modify InstantiatingGrpcChannelProvider test --- .../InstantiatingGrpcChannelProviderTest.java | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index fbeab828c5..5623f18bc0 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.grpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; @@ -41,6 +42,7 @@ import com.google.api.gax.rpc.mtls.MtlsProvider; import com.google.auth.oauth2.CloudShellCredentials; import com.google.auth.oauth2.ComputeEngineCredentials; +import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.grpc.ManagedChannel; @@ -93,32 +95,33 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { - java.time.Duration javaTimeKeepAliveTime = java.time.Duration.ofSeconds(1); - java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofSeconds(2); - org.threeten.bp.Duration threetenKeepAliveTime = org.threeten.bp.Duration.ofSeconds(1); - org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofSeconds(2); - + final long millis = 15; + java.time.Duration javaTimeKeepAliveTime = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenKeepAliveTime = org.threeten.bp.Duration.ofMillis(millis); + java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofMillis(millis); boolean keepaliveWithoutCalls = true; - List providers = - ImmutableList.of( - InstantiatingGrpcChannelProvider.newBuilder() - .setKeepAliveTime(javaTimeKeepAliveTime) - .setKeepAliveTimeout(javaTimeKeepAliveTimeout) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build(), - InstantiatingGrpcChannelProvider.newBuilder() - .setKeepAliveTime(threetenKeepAliveTime) - .setKeepAliveTimeout(threetenKeepAliveTimeout) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build()); - - for (InstantiatingGrpcChannelProvider provider : providers) { - assertEquals(provider.getKeepAliveWithoutCalls(), keepaliveWithoutCalls); - assertEquals(provider.getKeepAliveTimeDuration(), javaTimeKeepAliveTime); - assertEquals(provider.getKeepAliveTimeoutDuration(), javaTimeKeepAliveTimeout); - assertEquals(provider.getKeepAliveTime(), threetenKeepAliveTime); - assertEquals(provider.getKeepAliveTimeout(), threetenKeepAliveTimeout); - } + InstantiatingGrpcChannelProvider.Builder builder = InstantiatingGrpcChannelProvider.newBuilder(); + Supplier javaTimeProviderSupplier = () -> builder + .setKeepAliveTime(javaTimeKeepAliveTime) + .setKeepAliveTimeout(javaTimeKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build(); + Supplier threetenProviderSupplier = () -> builder + .setKeepAliveTime(threetenKeepAliveTime) + .setKeepAliveTimeout(threetenKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build(); + testTimeObjectGetterAndSetter(millis, javaTimeProviderSupplier, + threetenProviderSupplier, + c -> c.getKeepAliveTimeDuration(), + c -> c.getKeepAliveTime()); + testTimeObjectGetterAndSetter(millis, javaTimeProviderSupplier, + threetenProviderSupplier, + c -> c.getKeepAliveTimeoutDuration(), + c -> c.getKeepAliveTimeout()); + assertEquals(true, javaTimeProviderSupplier.get().getKeepAliveWithoutCalls()); + assertEquals(true, threetenProviderSupplier.get().getKeepAliveWithoutCalls()); } @Test @@ -639,10 +642,12 @@ public void publish(LogRecord record) { } @Override - public void flush() {} + public void flush() { + } @Override - public void close() throws SecurityException {} + public void close() throws SecurityException { + } List getAllMessages() { return records.stream().map(LogRecord::getMessage).collect(Collectors.toList()); From f84b5215e0f94ae9fa8326e2be4ee83ee9ab8072 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 5 May 2024 21:35:20 +0000 Subject: [PATCH 048/141] add tests for HttpJsonCallOptions --- .../gax/httpjson/HttpJsonCallOptionsTest.java | 52 +++++++++++++++++++ .../api/gax/util/TimeConversionTestUtils.java | 40 ++++++++++---- 2 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java new file mode 100644 index 0000000000..3659c57be3 --- /dev/null +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.gax.httpjson; + +import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; +import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; + +import org.junit.Test; + +public class HttpJsonCallOptionsTest { + + @Test + public void testDeadline() { + final long millis = 3; + final java.time.Instant javaTimeDeadline = java.time.Instant.ofEpochMilli(millis); + final org.threeten.bp.Instant threetenDeadline = org.threeten.bp.Instant.ofEpochMilli(millis); + final HttpJsonCallOptions.Builder defaultOptionsBuilder = HttpJsonCallOptions.newBuilder(); + testInstantMethod( + millis, + () -> defaultOptionsBuilder.setDeadline(javaTimeDeadline), + () -> defaultOptionsBuilder.setDeadline(threetenDeadline), + c -> c.build().getDeadlineInstant(), + c -> c.build().getDeadline()); + } +} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index 947e834eea..c81151ca7d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -37,32 +37,54 @@ public class TimeConversionTestUtils { + public static void testInstantMethod( + Long testValue, + Supplier javaTimeTargetSupplier, + Supplier threetenTargetSupplier, + Function javaTimeGetter, + Function threetenGetter) { + Function javaTimeTester = value -> value.toEpochMilli(); + Function threetenTester = value -> value.toEpochMilli(); + testTimeObjectGetterAndSetter( + testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + threetenTester); + testTimeObjectGetterAndSetter( + testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + threetenTester); + } + public static void testTimeObjectGetterAndSetter( Long testValue, Supplier javaTimeTargetSupplier, Supplier threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { + Function javaTimeTester = value -> value.toMillis(); + Function threetenTester = value -> value.toMillis(); testTimeObjectGetterAndSetter( - testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter); + testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + threetenTester); testTimeObjectGetterAndSetter( - testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter); + testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + threetenTester); } - private static void testTimeObjectGetterAndSetter( + private static void testTimeObjectGetterAndSetter( Long testValue, Supplier targetSupplier, - Function javaTimeGetter, - Function threetenGetter) { + Function javaTimeGetter, + Function threetenGetter, + Function javaTimeTester, + Function threetenTester) { Target target = targetSupplier.get(); - java.time.Duration javaTimeValue = javaTimeGetter.apply(target); - org.threeten.bp.Duration threetenValue = threetenGetter.apply(target); + JavaTime javaTimeValue = javaTimeGetter.apply(target); + Threeten threetenValue = threetenGetter.apply(target); if (testValue == null) { assertNull(javaTimeValue); assertNull(threetenValue); } else { - assertEquals(testValue.longValue(), javaTimeValue.toMillis()); - assertEquals(testValue.longValue(), threetenValue.toMillis()); + assertEquals(testValue.longValue(), javaTimeTester.apply(javaTimeValue).longValue()); + assertEquals(testValue.longValue(), threetenTester.apply(threetenValue).longValue()); } } } From 31ab5e07ca57b7d1df9a88cb71b644407a8b621a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 5 May 2024 21:37:39 +0000 Subject: [PATCH 049/141] rename to testDurationMethod() --- .../com/google/api/gax/grpc/GrpcCallContextTest.java | 8 ++++---- .../grpc/InstantiatingGrpcChannelProviderTest.java | 6 +++--- .../api/gax/httpjson/HttpJsonCallContextTest.java | 10 +++++----- .../api/gax/httpjson/HttpJsonCallOptionsTest.java | 1 - .../google/api/gax/util/TimeConversionTestUtils.java | 12 ++++++------ 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 8422291baf..5ac42e8164 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -134,7 +134,7 @@ public void testWithTimeout() { java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); - testTimeObjectGetterAndSetter(millis, () -> context.withTimeout(javaTimeTimeout), + testDurationMethod(millis, () -> context.withTimeout(javaTimeTimeout), () -> context.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @@ -217,7 +217,7 @@ public void testWithStreamingWaitTimeout() { java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); - testTimeObjectGetterAndSetter(millis, () -> context.withStreamWaitTimeout(javaTimeTimeout), + testDurationMethod(millis, () -> context.withStreamWaitTimeout(javaTimeTimeout), () -> context.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -263,7 +263,7 @@ public void testWithStreamingIdleTimeout() { java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); - testTimeObjectGetterAndSetter(millis, () -> context.withStreamIdleTimeout(javaTimeTimeout), + testDurationMethod(millis, () -> context.withStreamIdleTimeout(javaTimeTimeout), () -> context.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 5623f18bc0..350123ded8 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -29,7 +29,7 @@ */ package com.google.api.gax.grpc; -import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; @@ -112,11 +112,11 @@ public void testKeepAlive() { .setKeepAliveTimeout(threetenKeepAliveTimeout) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); - testTimeObjectGetterAndSetter(millis, javaTimeProviderSupplier, + testDurationMethod(millis, javaTimeProviderSupplier, threetenProviderSupplier, c -> c.getKeepAliveTimeDuration(), c -> c.getKeepAliveTime()); - testTimeObjectGetterAndSetter(millis, javaTimeProviderSupplier, + testDurationMethod(millis, javaTimeProviderSupplier, threetenProviderSupplier, c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 6201041497..689a9d5bf2 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -29,7 +29,7 @@ */ package com.google.api.gax.httpjson; -import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -121,7 +121,7 @@ public void testStreamIdleTimeout() { final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); - testTimeObjectGetterAndSetter( + testDurationMethod( millis, () -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), () -> defaultContext.withStreamIdleTimeout(threetenTimeout), @@ -135,7 +135,7 @@ public void testStreamWaitTimeout() { final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); - testTimeObjectGetterAndSetter( + testDurationMethod( millis, () -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), () -> defaultContext.withStreamWaitTimeout(threetenTimeout), @@ -149,7 +149,7 @@ public void testTimeout() { final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); - testTimeObjectGetterAndSetter( + testDurationMethod( millis, () -> defaultContext.withTimeout(javaTimeTimeout), () -> defaultContext.withTimeout(threetenTimeout), @@ -162,7 +162,7 @@ public void testNullTimeout() { final java.time.Duration javaTimeTimeout = null; final org.threeten.bp.Duration threetenTimeout = null; final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); - testTimeObjectGetterAndSetter( + testDurationMethod( null, () -> defaultContext.withTimeout(javaTimeTimeout), () -> defaultContext.withTimeout(javaTimeTimeout), diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java index 3659c57be3..fd56ec43bf 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -30,7 +30,6 @@ package com.google.api.gax.httpjson; import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; -import static com.google.api.gax.util.TimeConversionTestUtils.testTimeObjectGetterAndSetter; import org.junit.Test; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index c81151ca7d..abbe0d841c 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -45,15 +45,15 @@ public static void testInstantMethod( Function threetenGetter) { Function javaTimeTester = value -> value.toEpochMilli(); Function threetenTester = value -> value.toEpochMilli(); - testTimeObjectGetterAndSetter( + testTimeObjectMethod( testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, threetenTester); - testTimeObjectGetterAndSetter( + testTimeObjectMethod( testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, threetenTester); } - public static void testTimeObjectGetterAndSetter( + public static void testDurationMethod( Long testValue, Supplier javaTimeTargetSupplier, Supplier threetenTargetSupplier, @@ -61,15 +61,15 @@ public static void testTimeObjectGetterAndSetter( Function threetenGetter) { Function javaTimeTester = value -> value.toMillis(); Function threetenTester = value -> value.toMillis(); - testTimeObjectGetterAndSetter( + testTimeObjectMethod( testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, threetenTester); - testTimeObjectGetterAndSetter( + testTimeObjectMethod( testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, threetenTester); } - private static void testTimeObjectGetterAndSetter( + private static void testTimeObjectMethod( Long testValue, Supplier targetSupplier, Function javaTimeGetter, From 8fc424d981bcf7f7cdb80cc30ed73ef49abfaa9e Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 5 May 2024 21:38:14 +0000 Subject: [PATCH 050/141] reformat --- .../api/gax/grpc/GrpcCallContextTest.java | 23 +++++++---- .../InstantiatingGrpcChannelProviderTest.java | 41 +++++++++++-------- .../api/gax/util/TimeConversionTestUtils.java | 24 +++++++++-- 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 5ac42e8164..5e6f419f78 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -29,10 +29,10 @@ */ package com.google.api.gax.grpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; @@ -134,8 +134,11 @@ public void testWithTimeout() { java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); - testDurationMethod(millis, () -> context.withTimeout(javaTimeTimeout), - () -> context.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), + testDurationMethod( + millis, + () -> context.withTimeout(javaTimeTimeout), + () -> context.withTimeout(threetenTimeout), + c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @@ -217,8 +220,11 @@ public void testWithStreamingWaitTimeout() { java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); - testDurationMethod(millis, () -> context.withStreamWaitTimeout(javaTimeTimeout), - () -> context.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), + testDurationMethod( + millis, + () -> context.withStreamWaitTimeout(javaTimeTimeout), + () -> context.withStreamWaitTimeout(threetenTimeout), + c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -263,8 +269,11 @@ public void testWithStreamingIdleTimeout() { java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); - testDurationMethod(millis, () -> context.withStreamIdleTimeout(javaTimeTimeout), - () -> context.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), + testDurationMethod( + millis, + () -> context.withStreamIdleTimeout(javaTimeTimeout), + () -> context.withStreamIdleTimeout(threetenTimeout), + c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 350123ded8..011b5172e0 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -101,22 +101,31 @@ public void testKeepAlive() { java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofMillis(millis); boolean keepaliveWithoutCalls = true; - InstantiatingGrpcChannelProvider.Builder builder = InstantiatingGrpcChannelProvider.newBuilder(); - Supplier javaTimeProviderSupplier = () -> builder - .setKeepAliveTime(javaTimeKeepAliveTime) - .setKeepAliveTimeout(javaTimeKeepAliveTimeout) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build(); - Supplier threetenProviderSupplier = () -> builder - .setKeepAliveTime(threetenKeepAliveTime) - .setKeepAliveTimeout(threetenKeepAliveTimeout) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) - .build(); - testDurationMethod(millis, javaTimeProviderSupplier, + InstantiatingGrpcChannelProvider.Builder builder = + InstantiatingGrpcChannelProvider.newBuilder(); + Supplier javaTimeProviderSupplier = + () -> + builder + .setKeepAliveTime(javaTimeKeepAliveTime) + .setKeepAliveTimeout(javaTimeKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build(); + Supplier threetenProviderSupplier = + () -> + builder + .setKeepAliveTime(threetenKeepAliveTime) + .setKeepAliveTimeout(threetenKeepAliveTimeout) + .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .build(); + testDurationMethod( + millis, + javaTimeProviderSupplier, threetenProviderSupplier, c -> c.getKeepAliveTimeDuration(), c -> c.getKeepAliveTime()); - testDurationMethod(millis, javaTimeProviderSupplier, + testDurationMethod( + millis, + javaTimeProviderSupplier, threetenProviderSupplier, c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); @@ -642,12 +651,10 @@ public void publish(LogRecord record) { } @Override - public void flush() { - } + public void flush() {} @Override - public void close() throws SecurityException { - } + public void close() throws SecurityException {} List getAllMessages() { return records.stream().map(LogRecord::getMessage).collect(Collectors.toList()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index abbe0d841c..77f76aad88 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -46,10 +46,18 @@ public static void testInstantMethod( Function javaTimeTester = value -> value.toEpochMilli(); Function threetenTester = value -> value.toEpochMilli(); testTimeObjectMethod( - testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + testValue, + javaTimeTargetSupplier, + javaTimeGetter, + threetenGetter, + javaTimeTester, threetenTester); testTimeObjectMethod( - testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + testValue, + threetenTargetSupplier, + javaTimeGetter, + threetenGetter, + javaTimeTester, threetenTester); } @@ -62,10 +70,18 @@ public static void testDurationMethod( Function javaTimeTester = value -> value.toMillis(); Function threetenTester = value -> value.toMillis(); testTimeObjectMethod( - testValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + testValue, + javaTimeTargetSupplier, + javaTimeGetter, + threetenGetter, + javaTimeTester, threetenTester); testTimeObjectMethod( - testValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, javaTimeTester, + testValue, + threetenTargetSupplier, + javaTimeGetter, + threetenGetter, + javaTimeTester, threetenTester); } From c3bc83f2a571d43e7dc0d80bbe70358ec4b91c7c Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 05:23:12 +0000 Subject: [PATCH 051/141] add annotation based test for autovalue classes --- gax-java/gax/pom.xml | 5 + .../api/gax/batching/BatchingSettings.java | 6 + .../api/gax/util/ThreetenFieldUpgrade.java | 25 ++ ...aluesWithDeprecatedThreetenFieldsTest.java | 249 ++++++++++++++++++ gax-java/pom.xml | 5 + 5 files changed, 290 insertions(+) create mode 100644 gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 07fb0d7006..22e14d5780 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -62,6 +62,11 @@ opentelemetry-api true + + org.reflections + reflections + test + diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 216c521aff..76a356f2dc 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -34,6 +34,8 @@ import com.google.api.core.ObsoleteApi; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import com.google.api.gax.util.ThreetenFieldUpgrade; +import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import javax.annotation.Nullable; @@ -104,10 +106,12 @@ public abstract class BatchingSettings { /** Get the delay threshold to use for batching. */ @Nullable @ObsoleteApi("Use getDelayThresholdDuration() instead") + @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getDelayThreshold(); /** Get the delay threshold to use for batching. */ @Nullable + @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getDelayThresholdDuration() { return toJavaTimeDuration(getDelayThreshold()); } @@ -154,6 +158,7 @@ public abstract static class Builder { /** Backport of {@link #setDelayThreshold(java.time.Duration)} */ @ObsoleteApi("Use setDelayThreshold(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.THREETEN_SETTER) public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); /** @@ -162,6 +167,7 @@ public abstract static class Builder { * value should not be set too high, usually on the order of milliseconds. Otherwise, calls * might appear to never complete. */ + @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.JAVA_TIME_SETTER) public final Builder setDelayThreshold(java.time.Duration delayThreshold) { return setDelayThreshold(toThreetenDuration(delayThreshold)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java new file mode 100644 index 0000000000..60ae29997d --- /dev/null +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java @@ -0,0 +1,25 @@ +package com.google.api.gax.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to mark autovalue class method that refer to a deprecated threeten field Used in + * testing + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ThreetenFieldUpgrade { + enum FieldRole { + JAVA_TIME_GETTER, + THREETEN_GETTER, + JAVA_TIME_SETTER, + THREETEN_SETTER + } + + FieldRole role(); + + String key(); +} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java new file mode 100644 index 0000000000..886c945d2c --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java @@ -0,0 +1,249 @@ +package com.google.api.gax; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import com.google.api.gax.util.ThreetenFieldUpgrade; +import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.logging.Logger; +import javax.annotation.Generated; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.reflections.Reflections; + +@RunWith(JUnit4.class) +public class AutoValuesWithDeprecatedThreetenFieldsTest { + + private static final Logger logger = + Logger.getLogger(AutoValuesWithDeprecatedThreetenFieldsTest.class.getSimpleName()); + + @Test + public void testAutoValueClassesWithThreetenMethods() + throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { + List> targetClasses = getAutoValueClassesWithThreetenMethods(); + for (Class c : targetClasses) { + testAutoValueClassWithThreetenMethods(c); + } + } + + private void testAutoValueClassWithThreetenMethods(Class autoValueClass) + throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { + logger.info(String.format("Testing threeten methods for class %s", autoValueClass.getName())); + + // We first group the methods by key. Each key should contain four methods corresponding to a + // type declared in the ThreetenFieldUpgrade.FieldRole enum. + Map> methodGroups = new HashMap<>(); + + // The FieldRole.JAVA_TIME_GETTER and FieldRole.THREETEN_GETTER methods are found in the main + // abstract class. This loop searchs for them. + for (Method m : autoValueClass.getDeclaredMethods()) { + addToMethodGroupIfHasThreetenFieldUpgrateAnnotation(methodGroups, m); + } + + // The FieldRole.JAVA_TIME_SETTER and FieldRole.THREETEN_SETTER methods are found in the builder + // nested class. + // We first obtain the Builder class + Class builderClass = + Arrays.stream(autoValueClass.getDeclaredClasses()) + .filter(b -> b.getSimpleName().contains("Builder")) + .findFirst() + .orElseThrow( + () -> + new IllegalStateException( + String.format( + "Failed to find Builder class for AutoValue class %s", + autoValueClass.getName()))); + + // Then we loop over the methods to group the methods annotated with ThreetenFieldUpgrade + for (Method m : builderClass.getDeclaredMethods()) { + addToMethodGroupIfHasThreetenFieldUpgrateAnnotation(methodGroups, m); + } + + assertFalse("No method groups could be constructed", methodGroups.isEmpty()); + + // Now, we confirm each method group is complete, sane, and we confirm its behavior by testing + // the getters and setters + for (Entry> methodGroup : methodGroups.entrySet()) { + String groupName = methodGroup.getKey(); + logger.info(String.format("Organizing methods for group '%s'", groupName)); + Map organizedMethods = + organizeMethods(groupName, methodGroup.getValue()); + logger.info(String.format("Confirming structure of method group '%s", groupName)); + confirmGetterAndSetterStructure(organizedMethods); + logger.info(String.format("Confirming behavior of method group '%s", groupName)); + confirmGetterAndSetterBehavior(organizedMethods, autoValueClass, builderClass); + } + } + + private void confirmGetterAndSetterBehavior( + Map organizedMethods, Class autoValueClass, Class builderClass) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); + Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); + Method javaTimeSetter = organizedMethods.get(FieldRole.JAVA_TIME_SETTER); + Method threetenSetter = organizedMethods.get(FieldRole.THREETEN_SETTER); + final long testValue = 123l; + // We use the java.time getter's return type to identify which time class (Duration or Instant) + // we are dealing with. At this point we already ensured consistency of return and parameter + // types + boolean isDuration = javaTimeGetter.getReturnType().equals(java.time.Duration.class); + final Object testJavaTimeObjectValue = + isDuration + ? java.time.Duration.ofMillis(testValue) + : java.time.Instant.ofEpochMilli(testValue); + final Object testThreetenObjectValue = + isDuration + ? org.threeten.bp.Duration.ofMillis(testValue) + : org.threeten.bp.Instant.ofEpochMilli(testValue); + + confirmGetterAndSetterBehaviorUsingSingleSetter( + javaTimeGetter, + threetenGetter, + javaTimeSetter, + autoValueClass, + builderClass, + testJavaTimeObjectValue, + testJavaTimeObjectValue, + testThreetenObjectValue); + confirmGetterAndSetterBehaviorUsingSingleSetter( + javaTimeGetter, + threetenGetter, + threetenSetter, + autoValueClass, + builderClass, + testThreetenObjectValue, + testJavaTimeObjectValue, + testThreetenObjectValue); + } + + private void confirmGetterAndSetterBehaviorUsingSingleSetter( + Method javaTimeGetter, + Method threetenGetter, + Method setter, + Class autoValueClass, + Class builderClass, + Object testSetterValue, + Object testJavaTimeObjectValue, + Object testThreetenObjectValue) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Object builder = autoValueClass.getDeclaredMethod("newBuilder").invoke(autoValueClass); + setter.invoke(builder, testSetterValue); + Object builtObject = builderClass.getMethod("build").invoke(builder); + assertEquals(testJavaTimeObjectValue, javaTimeGetter.invoke(builtObject)); + assertEquals(testThreetenObjectValue, threetenGetter.invoke(builtObject)); + } + + private void confirmGetterAndSetterStructure(Map organizedMethods) { + Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); + Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); + Method javaTimeSetter = organizedMethods.get(FieldRole.JAVA_TIME_SETTER); + Method threetenSetter = organizedMethods.get(FieldRole.THREETEN_SETTER); + // We will inspect the java.time getter to see if we are dealing with Duration or Instant and + // will use this info to confirm consistency among the methods + Class javaTimeGetterReturnType = javaTimeGetter.getReturnType(); + assertTrue( + "The java.time getter should return either java.time.Duration or java.time.Instant", + ImmutableList.of("java.time.Duration", "java.time.Instant") + .contains(javaTimeGetterReturnType.getName())); + + // We will use the following variable to ensure that the rest of the methods are either Duration + // or Instant, depending on what we found about the java.time getter + String commonReturnTypeName = javaTimeGetterReturnType.getSimpleName(); + + assertEquals( + String.format("The threeten getter should return org.threeten.%s", commonReturnTypeName), + String.format("org.threeten.bp.%s", commonReturnTypeName), + threetenGetter.getReturnType().getName()); + assertEquals( + "AutoValue getters should have no parameters", 0, javaTimeGetter.getParameterCount()); + assertEquals( + "AutoValue getters should have no parameters", 0, threetenGetter.getParameterCount()); + assertEquals( + String.format( + "The java.time getter should be named the same as the threeten getter plus the %s suffix", + commonReturnTypeName), + threetenGetter.getName().concat(commonReturnTypeName), + javaTimeGetter.getName()); + + // now we confirm the setter structure + assertEquals( + "Setters should have the same name", javaTimeSetter.getName(), threetenSetter.getName()); + assertEquals("Setters should have a single parameter", 1, javaTimeSetter.getParameterCount()); + assertEquals("Setters should have a single parameter", 1, threetenSetter.getParameterCount()); + assertEquals( + String.format( + "The java.time setter should take a java.time.%s parameter", commonReturnTypeName), + "java.time.".concat(commonReturnTypeName), + javaTimeSetter.getParameterTypes()[0].getName()); + assertEquals( + String.format( + "The threeten setter should take a org.threeten.bp.%s parameter", commonReturnTypeName), + "org.threeten.bp.".concat(commonReturnTypeName), + threetenSetter.getParameterTypes()[0].getName()); + } + + private void addToMethodGroupIfHasThreetenFieldUpgrateAnnotation( + Map> storage, Method m) { + if (!m.isAnnotationPresent(ThreetenFieldUpgrade.class)) { + return; + } + ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); + if (!storage.containsKey(annotation.key())) { + storage.put(annotation.key(), new ArrayList<>()); + } + storage.get(annotation.key()).add(m); + } + + private Map organizeMethods( + String groupName, List methods) { + Map result = new HashMap<>(); + for (Method m : methods) { + ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); + assertFalse( + String.format( + "Method group %s has two or more methods with the %s FieldRole", + groupName, annotation.role()), + result.containsKey(annotation.role())); + result.put(annotation.role(), m); + } + assertEquals( + String.format("Method group %s does not contain all FieldRoles", groupName), + 4, + result.size()); + return result; + } + + private List> getAutoValueClassesWithThreetenMethods() { + Reflections reflections = new Reflections("com.google.api.gax"); + Set> allAutoValues = reflections.getTypesAnnotatedWith(AutoValue.class); + List> result = new ArrayList<>(); + for (Class c : allAutoValues) { + // we don't want generated AutoValue_.* classes + boolean isAutoGenerated = + c.isAnnotationPresent(Generated.class) || c.getSimpleName().startsWith("AutoValue_"); + if (isAutoGenerated) { + continue; + } + List methods = Arrays.asList(c.getDeclaredMethods()); + boolean hasThreetenAnnotatedMethods = + methods.stream().anyMatch(m -> m.isAnnotationPresent(ThreetenFieldUpgrade.class)); + if (hasThreetenAnnotatedMethods) { + result.add(c); + } + } + return result; + } +} diff --git a/gax-java/pom.xml b/gax-java/pom.xml index 5966898fc4..b5178b9bdf 100644 --- a/gax-java/pom.xml +++ b/gax-java/pom.xml @@ -165,6 +165,11 @@ pom import + + org.reflections + reflections + 0.10.2 + From 16fa545ddaaf58c5a1bf238afad2767d40326070 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 05:57:10 +0000 Subject: [PATCH 052/141] add reflection test for httpjson --- gax-java/gax-httpjson/pom.xml | 5 ++ .../api/gax/httpjson/HttpJsonCallOptions.java | 30 +++++++++-- .../gax/httpjson/HttpJsonClientCallImpl.java | 2 +- .../api/gax/httpjson/HttpRequestRunnable.java | 2 +- ...aluesWithDeprecatedThreetenValuesTest.java | 18 +++++++ .../gax/httpjson/HttpJsonCallOptionsTest.java | 51 ------------------- .../httpjson/HttpJsonClientCallImplTest.java | 4 +- 7 files changed, 53 insertions(+), 59 deletions(-) create mode 100644 gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java delete mode 100644 gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java diff --git a/gax-java/gax-httpjson/pom.xml b/gax-java/gax-httpjson/pom.xml index ff8930f609..639764a99b 100644 --- a/gax-java/gax-httpjson/pom.xml +++ b/gax-java/gax-httpjson/pom.xml @@ -87,6 +87,11 @@ test testlib + + org.reflections + reflections + test + diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index d54988bdc9..cfef3cc6d7 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -29,14 +29,17 @@ */ package com.google.api.gax.httpjson; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.ObsoleteApi; +import com.google.api.gax.util.ThreetenFieldUpgrade; +import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; -import java.time.Duration; import javax.annotation.Nullable; /** Options for an http-json call, including deadline and credentials. */ @@ -45,13 +48,23 @@ public abstract class HttpJsonCallOptions { public static final HttpJsonCallOptions DEFAULT = newBuilder().build(); @Nullable - public abstract Duration getTimeout(); + @ObsoleteApi("Use getTimeoutDuration() instead") + @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.THREETEN_GETTER) + public abstract org.threeten.bp.Duration getTimeout(); + + @Nullable + @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.JAVA_TIME_GETTER) + public final java.time.Duration getTimeoutDuration() { + return toJavaTimeDuration(getTimeout()); + } @Nullable @ObsoleteApi("Use getDeadlineInstant() instead") + @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Instant getDeadline(); @Nullable + @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Instant getDeadlineInstant() { return toJavaTimeInstant(getDeadline()); } @@ -81,7 +94,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { } if (inputOptions.getTimeout() != null) { - Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); + java.time.Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); if (newTimeout != null) { builder.setTimeout(newTimeout); } @@ -102,12 +115,21 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { @AutoValue.Builder public abstract static class Builder { - public abstract Builder setTimeout(java.time.Duration value); + @ObsoleteApi("Use setTimeout(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.THREETEN_SETTER) + public abstract Builder setTimeout(org.threeten.bp.Duration value); + + @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.JAVA_TIME_SETTER) + public Builder setTimeout(java.time.Duration value) { + return setTimeout(toThreetenDuration(value)); + } /** Backport of {@link #setDeadline(java.time.Instant)} */ @ObsoleteApi("Use setDeadline(java.time.Instant) instead") + @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.THREETEN_SETTER) public abstract Builder setDeadline(org.threeten.bp.Instant value); + @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.JAVA_TIME_SETTER) public final Builder setDeadline(java.time.Instant value) { return setDeadline(toThreetenInstant(value)); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java index 4ec7572216..ddbb0dd970 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java @@ -178,7 +178,7 @@ public void start(Listener responseListener, HttpJsonMetadata request // Use the timeout duration value instead of calculating the future Instant // Only schedule the deadline if the RPC timeout has been set in the RetrySettings - Duration timeout = callOptions.getTimeout(); + java.time.Duration timeout = callOptions.getTimeoutDuration(); if (timeout != null) { // The future timeout value is guaranteed to not be a negative value as the // RetryAlgorithm will not retry diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index b5597099d2..9b72d6cb6a 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -234,7 +234,7 @@ private HttpRequest buildRequest( httpRequest.getHeaders(), "X-HTTP-Method-Override", originalHttpMethod); } - Duration timeout = httpJsonCallOptions.getTimeout(); + java.time.Duration timeout = httpJsonCallOptions.getTimeoutDuration(); if (timeout != null) { long timeoutMs = timeout.toMillis(); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java new file mode 100644 index 0000000000..8d9056cedc --- /dev/null +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java @@ -0,0 +1,18 @@ +package com.google.api.gax.httpjson; + +import com.google.api.gax.AutoValuesWithDeprecatedThreetenFieldsTest; +import java.lang.reflect.InvocationTargetException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class HttpJsonAutoValuesWithDeprecatedThreetenValuesTest { + + @Test + public void testAutoValueClassesWithThreetenMethods() + throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { + new AutoValuesWithDeprecatedThreetenFieldsTest().testAutoValueClassesWithThreetenMethods(); + } + +} diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java deleted file mode 100644 index fd56ec43bf..0000000000 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.google.api.gax.httpjson; - -import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; - -import org.junit.Test; - -public class HttpJsonCallOptionsTest { - - @Test - public void testDeadline() { - final long millis = 3; - final java.time.Instant javaTimeDeadline = java.time.Instant.ofEpochMilli(millis); - final org.threeten.bp.Instant threetenDeadline = org.threeten.bp.Instant.ofEpochMilli(millis); - final HttpJsonCallOptions.Builder defaultOptionsBuilder = HttpJsonCallOptions.newBuilder(); - testInstantMethod( - millis, - () -> defaultOptionsBuilder.setDeadline(javaTimeDeadline), - () -> defaultOptionsBuilder.setDeadline(threetenDeadline), - c -> c.build().getDeadlineInstant(), - c -> c.build().getDeadline()); - } -} diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java index 0355dd0d4b..d9c8a74694 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java @@ -59,7 +59,7 @@ public class HttpJsonClientCallImplTest { public void responseReceived_noCancellationTask() { ScheduledThreadPoolExecutor deadlineSchedulerExecutor = new ScheduledThreadPoolExecutor(1); // Null timeout means no timeout task created - Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(null); + Mockito.when(httpJsonCallOptions.getTimeoutDuration()).thenReturn(null); HttpJsonClientCallImpl httpJsonClientCall = new HttpJsonClientCallImpl<>( @@ -94,7 +94,7 @@ public void responseReceived_cancellationTaskExists_isCancelledProperly() deadlineSchedulerExecutor.setRemoveOnCancelPolicy(true); // Setting a timeout for this call will enqueue a timeout task - Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(Duration.ofMinutes(10)); + Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(org.threeten.bp.Duration.ofMinutes(10)); String response = "Content"; InputStream inputStream = new ByteArrayInputStream(response.getBytes()); From 4fd48d4e699fb893d350c611d2779f38e9efb44b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 06:38:43 +0000 Subject: [PATCH 053/141] adapt tests of ThresholdBatcher --- .../api/gax/grpc/GrpcCallContextTest.java | 24 +++++-------- .../InstantiatingGrpcChannelProviderTest.java | 34 +++++++++++-------- .../api/gax/httpjson/HttpJsonCallOptions.java | 3 +- .../gax/httpjson/HttpJsonClientCallImpl.java | 1 - .../api/gax/httpjson/HttpRequestRunnable.java | 1 - ...aluesWithDeprecatedThreetenValuesTest.java | 1 - .../gax/httpjson/HttpJsonCallContextTest.java | 24 +++++-------- .../httpjson/HttpJsonClientCallImplTest.java | 4 +-- .../api/gax/batching/ThresholdBatcher.java | 8 +++-- .../gax/batching/ThresholdBatcherTest.java | 27 +++++---------- .../api/gax/util/TimeConversionTestUtils.java | 26 +++++++++----- 11 files changed, 72 insertions(+), 81 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 5e6f419f78..5e22f0b547 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -130,14 +130,11 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { - final long millis = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( - millis, - () -> context.withTimeout(javaTimeTimeout), - () -> context.withTimeout(threetenTimeout), + 123l, + javaTimeTimeout -> context.withTimeout(javaTimeTimeout), + threetenTimeout -> context.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @@ -216,14 +213,11 @@ public void testMergeWithTimeout() { @Test public void testWithStreamingWaitTimeout() { - final long millis = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( - millis, - () -> context.withStreamWaitTimeout(javaTimeTimeout), - () -> context.withStreamWaitTimeout(threetenTimeout), + 123l, + javaTimeTimeout -> context.withStreamWaitTimeout(javaTimeTimeout), + threetenTimeout -> context.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -266,13 +260,11 @@ public void testMergeWithStreamingWaitTimeout() { @Test public void testWithStreamingIdleTimeout() { final long millis = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - () -> context.withStreamIdleTimeout(javaTimeTimeout), - () -> context.withStreamIdleTimeout(threetenTimeout), + javaTimeTimeout -> context.withStreamIdleTimeout(javaTimeTimeout), + threetenTimeout -> context.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 011b5172e0..59aaf8c72b 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -42,7 +42,6 @@ import com.google.api.gax.rpc.mtls.MtlsProvider; import com.google.auth.oauth2.CloudShellCredentials; import com.google.auth.oauth2.ComputeEngineCredentials; -import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.grpc.ManagedChannel; @@ -58,6 +57,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.function.Function; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.stream.Collectors; @@ -96,25 +96,21 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { final long millis = 15; - java.time.Duration javaTimeKeepAliveTime = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenKeepAliveTime = org.threeten.bp.Duration.ofMillis(millis); - java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofMillis(millis); boolean keepaliveWithoutCalls = true; InstantiatingGrpcChannelProvider.Builder builder = InstantiatingGrpcChannelProvider.newBuilder(); - Supplier javaTimeProviderSupplier = - () -> + Function javaTimeProviderSupplier = + javaTimeValue -> builder - .setKeepAliveTime(javaTimeKeepAliveTime) - .setKeepAliveTimeout(javaTimeKeepAliveTimeout) + .setKeepAliveTime(javaTimeValue) + .setKeepAliveTimeout(javaTimeValue) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); - Supplier threetenProviderSupplier = - () -> + Function threetenProviderSupplier = + threetenValue -> builder - .setKeepAliveTime(threetenKeepAliveTime) - .setKeepAliveTimeout(threetenKeepAliveTimeout) + .setKeepAliveTime(threetenValue) + .setKeepAliveTimeout(threetenValue) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); testDurationMethod( @@ -129,8 +125,16 @@ public void testKeepAlive() { threetenProviderSupplier, c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); - assertEquals(true, javaTimeProviderSupplier.get().getKeepAliveWithoutCalls()); - assertEquals(true, threetenProviderSupplier.get().getKeepAliveWithoutCalls()); + assertEquals( + true, + javaTimeProviderSupplier + .apply(java.time.Duration.ofMillis(millis)) + .getKeepAliveWithoutCalls()); + assertEquals( + true, + threetenProviderSupplier + .apply(org.threeten.bp.Duration.ofMillis(millis)) + .getKeepAliveWithoutCalls()); } @Test diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index cfef3cc6d7..43ac4315ab 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -94,7 +94,8 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { } if (inputOptions.getTimeout() != null) { - java.time.Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); + java.time.Duration newTimeout = + java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); if (newTimeout != null) { builder.setTimeout(newTimeout); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java index ddbb0dd970..df9a507519 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java @@ -40,7 +40,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.ArrayDeque; import java.util.Queue; import java.util.concurrent.CancellationException; diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index 9b72d6cb6a..2738844bd0 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -52,7 +52,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.List; import java.util.Map; import java.util.Map.Entry; diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java index 8d9056cedc..1c91860c4c 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java @@ -14,5 +14,4 @@ public void testAutoValueClassesWithThreetenMethods() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { new AutoValuesWithDeprecatedThreetenFieldsTest().testAutoValueClassesWithThreetenMethods(); } - } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 689a9d5bf2..3fa23a849c 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -118,13 +118,11 @@ public void testMergeWrongType() { @Test public void testStreamIdleTimeout() { final long millis = 3; - final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - () -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), - () -> defaultContext.withStreamIdleTimeout(threetenTimeout), + javaTimeTimeout -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), + threetenTimeout -> defaultContext.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } @@ -132,13 +130,11 @@ public void testStreamIdleTimeout() { @Test public void testStreamWaitTimeout() { final long millis = 3; - final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - () -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), - () -> defaultContext.withStreamWaitTimeout(threetenTimeout), + javaTimeTimeout -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), + threetenTimeout -> defaultContext.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -146,26 +142,22 @@ public void testStreamWaitTimeout() { @Test public void testTimeout() { final long millis = 3; - final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - () -> defaultContext.withTimeout(javaTimeTimeout), - () -> defaultContext.withTimeout(threetenTimeout), + javaTimeTimeout -> defaultContext.withTimeout(javaTimeTimeout), + threetenTimeout -> defaultContext.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @Test public void testNullTimeout() { - final java.time.Duration javaTimeTimeout = null; - final org.threeten.bp.Duration threetenTimeout = null; final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( null, - () -> defaultContext.withTimeout(javaTimeTimeout), - () -> defaultContext.withTimeout(javaTimeTimeout), + javaTimeTimeout -> defaultContext.withTimeout(javaTimeTimeout), + threetenTimeout -> defaultContext.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java index d9c8a74694..7ba471ca6b 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java @@ -35,7 +35,6 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Reader; -import java.time.Duration; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -94,7 +93,8 @@ public void responseReceived_cancellationTaskExists_isCancelledProperly() deadlineSchedulerExecutor.setRemoveOnCancelPolicy(true); // Setting a timeout for this call will enqueue a timeout task - Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(org.threeten.bp.Duration.ofMinutes(10)); + Mockito.when(httpJsonCallOptions.getTimeout()) + .thenReturn(org.threeten.bp.Duration.ofMinutes(10)); String response = "Content"; InputStream inputStream = new ByteArrayInputStream(response.getBytes()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 1951f1d7c1..235c80ac9b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -30,6 +30,7 @@ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.api.core.ApiFunction; @@ -101,11 +102,14 @@ private ThresholdBatcher(Builder builder) { resetThresholds(); } - @VisibleForTesting - public java.time.Duration getMaxDelay() { + public java.time.Duration getMaxDelayDuration() { return this.maxDelay; } + public org.threeten.bp.Duration getMaxDelay() { + return toThreetenDuration(this.maxDelay); + } + /** Builder for a ThresholdBatcher. */ public static class Builder { private Collection> thresholds; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 73e4f13fc3..3d8af6833e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -29,12 +29,12 @@ */ package com.google.api.gax.batching; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -359,24 +359,15 @@ public void testBatchingFailedRPC() throws Exception { } @Test - public void testTimeObjectsEquivalence() throws NoSuchMethodException { + public void testMaxDelay() { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); - Method build = ThresholdBatcher.Builder.class.getMethod("build"); - Method getMaxDelay = ThresholdBatcher.class.getMethod("getMaxDelay"); - - // TimeConversionTestUtils.testDurationGetterAndSetter( - // java.time.Duration.ofNanos(123l), - // createSimpleBatcherBuidler(receiver), - // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", java.time.Duration.class), - // build, - // getMaxDelay); - // - // TimeConversionTestUtils.testDurationGetterAndSetter( - // org.threeten.bp.Duration.ofNanos(123l), - // createSimpleBatcherBuidler(receiver), - // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", org.threeten.bp.Duration.class), - // build, - // getMaxDelay); + ThresholdBatcher.Builder builder = createSimpleBatcherBuidler(receiver); + testDurationMethod( + 123l, + jt -> builder.setMaxDelay(jt).build(), + tt -> builder.setMaxDelay(tt).build(), + c -> c.getMaxDelayDuration(), + c -> c.getMaxDelay()); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index 77f76aad88..be14e13a6f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -33,20 +33,22 @@ import static org.junit.Assert.assertNull; import java.util.function.Function; -import java.util.function.Supplier; public class TimeConversionTestUtils { public static void testInstantMethod( Long testValue, - Supplier javaTimeTargetSupplier, - Supplier threetenTargetSupplier, + Function javaTimeTargetSupplier, + Function threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { + java.time.Instant testJavaTimeValue = java.time.Instant.ofEpochMilli(testValue); + org.threeten.bp.Instant testThreetenValue = org.threeten.bp.Instant.ofEpochMilli(testValue); Function javaTimeTester = value -> value.toEpochMilli(); Function threetenTester = value -> value.toEpochMilli(); testTimeObjectMethod( testValue, + testJavaTimeValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, @@ -54,6 +56,7 @@ public static void testInstantMethod( threetenTester); testTimeObjectMethod( testValue, + testThreetenValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, @@ -63,14 +66,19 @@ public static void testInstantMethod( public static void testDurationMethod( Long testValue, - Supplier javaTimeTargetSupplier, - Supplier threetenTargetSupplier, + Function javaTimeTargetSupplier, + Function threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { + java.time.Duration testJavaTimeValue = + testValue == null ? null : java.time.Duration.ofMillis(testValue); + org.threeten.bp.Duration testThreetenValue = + testValue == null ? null : org.threeten.bp.Duration.ofMillis(testValue); Function javaTimeTester = value -> value.toMillis(); Function threetenTester = value -> value.toMillis(); testTimeObjectMethod( testValue, + testJavaTimeValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, @@ -78,6 +86,7 @@ public static void testDurationMethod( threetenTester); testTimeObjectMethod( testValue, + testThreetenValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, @@ -85,14 +94,15 @@ public static void testDurationMethod( threetenTester); } - private static void testTimeObjectMethod( + private static void testTimeObjectMethod( Long testValue, - Supplier targetSupplier, + ForSupplier supplierValue, + Function targetSupplier, Function javaTimeGetter, Function threetenGetter, Function javaTimeTester, Function threetenTester) { - Target target = targetSupplier.get(); + Target target = targetSupplier.apply(supplierValue); JavaTime javaTimeValue = javaTimeGetter.apply(target); Threeten threetenValue = threetenGetter.apply(target); if (testValue == null) { From 5dca441c1d2672fa7d2243460778fc9c98aa40f5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 16:34:20 +0000 Subject: [PATCH 054/141] add test for RetrySettings --- .../api/gax/retrying/RetrySettings.java | 179 ++++-------------- .../api/gax/util/ThreetenFieldUpgrade.java | 4 + ...aluesWithDeprecatedThreetenFieldsTest.java | 51 ++++- .../api/gax/retrying/RetrySettingsTest.java | 23 ++- 4 files changed, 103 insertions(+), 154 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 1298f1217e..03e277061a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -34,6 +34,8 @@ import com.google.api.core.BetaApi; import com.google.api.core.ObsoleteApi; +import com.google.api.gax.util.ThreetenFieldUpgrade; +import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; @@ -83,6 +85,7 @@ public abstract class RetrySettings implements Serializable { /** Backport of {@link #getTotalTimeoutDuration()} */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") + @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getTotalTimeout(); /** @@ -98,12 +101,14 @@ public abstract class RetrySettings implements Serializable { * Duration.ZERO} and LROs have a default total timeout value of {@code Duration.ofMillis(300000)} * (5 minutes). */ + @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getTotalTimeoutDuration() { return toJavaTimeDuration(getTotalTimeout()); } /** Backport of {@link #getInitialRetryDelayDuration()} */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") + @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** @@ -114,6 +119,7 @@ public final java.time.Duration getTotalTimeoutDuration() { * Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ + @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getInitialRetryDelayDuration() { return toJavaTimeDuration(getInitialRetryDelay()); } @@ -130,6 +136,7 @@ public final java.time.Duration getInitialRetryDelayDuration() { /** Backport of {@link #getMaxRetryDelayDuration()} */ @ObsoleteApi("Use getMaxRetryDelayDuration()") + @ThreetenFieldUpgrade(key = "maxRetryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getMaxRetryDelay(); /** @@ -140,6 +147,7 @@ public final java.time.Duration getInitialRetryDelayDuration() { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ + @ThreetenFieldUpgrade(key = "maxRetryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getMaxRetryDelayDuration() { return toJavaTimeDuration(getMaxRetryDelay()); } @@ -175,6 +183,7 @@ public final java.time.Duration getMaxRetryDelayDuration() { /** Backport of {@link #getInitialRpcTimeoutDuration()} */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") + @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getInitialRpcTimeout(); /** @@ -190,6 +199,7 @@ public final java.time.Duration getMaxRetryDelayDuration() { *

    If there are no configurations, Retries have the default initial RPC timeout value of {@code * Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ + @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getInitialRpcTimeoutDuration() { return toJavaTimeDuration(getInitialRpcTimeout()); } @@ -205,6 +215,7 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { /** Backport of {@link #getMaxRpcTimeoutDuration()} */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") + @ThreetenFieldUpgrade(key = "maxRpcTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getMaxRpcTimeout(); /** @@ -214,6 +225,7 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ + @ThreetenFieldUpgrade(key = "maxRpcTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getMaxRpcTimeoutDuration() { return toJavaTimeDuration(getMaxRpcTimeout()); } @@ -242,6 +254,7 @@ public abstract static class Builder { /** Backport of {@link #setTotalTimeout(java.time.Duration)} */ @ObsoleteApi("Use setTotalTimeout(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); /** @@ -257,12 +270,14 @@ public abstract static class Builder { * Duration.ZERO} and LROs have a default total timeout value of {@code * Duration.ofMillis(300000)} (5 minutes). */ + @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.JAVA_TIME_SETTER) public final Builder setTotalTimeout(java.time.Duration totalTimeout) { return setTotalTimeout(toThreetenDuration(totalTimeout)); } /** Backport of {@link #setInitialRetryDelay(java.time.Duration)} */ @ObsoleteApi("Use setInitialRetryDelay(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); /** @@ -273,6 +288,7 @@ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ + @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.JAVA_TIME_SETTER) public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { return setInitialRetryDelay(toThreetenDuration(initialDelay)); } @@ -289,6 +305,7 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { /** Backport of {@link #setMaxRetryDelay(java.time.Duration)} */ @ObsoleteApi("Use setMaxRetryDelay(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "maxRetryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); /** @@ -299,6 +316,10 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ + @ThreetenFieldUpgrade( + key = "maxRetryDelay", + role = FieldRole.JAVA_TIME_SETTER, + defaultTestValue = 5000l) public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { return setMaxRetryDelay(toThreetenDuration(maxDelay)); } @@ -334,6 +355,7 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { /** Backport of {@link #setInitialRpcTimeout(java.time.Duration)} */ @ObsoleteApi("Use setInitialRpcTimeout(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); /** @@ -349,6 +371,7 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { *

    If there are no configurations, Retries have the default initial RPC timeout value of * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ + @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.JAVA_TIME_SETTER) public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { return setInitialRpcTimeout(toThreetenDuration(initialTimeout)); } @@ -364,6 +387,7 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { /** Backport of {@link #setMaxRpcTimeout(java.time.Duration)} */ @ObsoleteApi("Use setMaxRpcTimeout(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "maxRpcTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); /** @@ -373,153 +397,14 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ + @ThreetenFieldUpgrade( + key = "maxRpcTimeout", + role = FieldRole.JAVA_TIME_SETTER, + defaultTestValue = 5000l) public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); } - /** Backport of {@link #getTotalTimeoutDuration()} */ - @ObsoleteApi("Use getTotalTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getTotalTimeout(); - - /** - * TotalTimeout has ultimate control over how long the logic should keep trying the remote call - * until it gives up completely. The higher the total timeout, the more retries and polls can be - * attempted. If this value is {@code Duration.ZERO}, then the logic will instead use the number - * of attempts to determine retries. In the event that both maxAttempts and totalTimeout values - * are both 0, the logic will not retry. If this value is non-{@code Duration.ZERO}, and the - * retry duration has reaches the timeout value, the logic will give up retrying even the number - * of attempts is lower than the maxAttempts value. - * - *

    If there are no configurations, Retries have the default timeout value of {@code - * Duration.ZERO} and LROs have a default total timeout value of {@code - * Duration.ofMillis(300000)} (5 minutes). - */ - public final java.time.Duration getTotalTimeoutDuration() { - return toJavaTimeDuration(getTotalTimeout()); - } - - /** Backport of {@link #getInitialRetryDelayDuration()} */ - @ObsoleteApi("Use getInitialRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getInitialRetryDelay(); - - /** - * InitialRetryDelay controls the delay before the first retry/ poll. Subsequent retries and - * polls will use this value adjusted according to the RetryDelayMultiplier. - * - *

    If there are no configurations, Retries have the default initial retry delay value of - * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code - * Duration.ofMillis(5000)} (5 seconds). - */ - public final java.time.Duration getInitialRetryDelayDuration() { - return toJavaTimeDuration(getInitialRetryDelay()); - } - - /** - * RetryDelayMultiplier controls the change in delay before the next retry or poll. The retry - * delay of the previous call is multiplied by the RetryDelayMultiplier to calculate the retry - * delay for the next call. - * - *

    If there are no configurations, Retries have the default retry delay multiplier value of - * {@code 1.0} and LROs have a default retry delay multiplier of {@code 1.5}. - */ - public abstract double getRetryDelayMultiplier(); - - /** - * MaxAttempts defines the maximum number of retry attempts to perform. If this value is set to - * 0, the logic will instead use the totalTimeout value to determine retries. In the event that - * both the maxAttempts and totalTimeout values are both 0, the logic will not retry. If this - * value is greater than 0, and the number of attempts exceeds this limit, the logic will give - * up retrying even if the total retry time is still lower than totalTimeout. - * - *

    If there are no configurations, Retries and LROs have the default max attempt value of - * {@code 0}. LRO polling does not use this value by default. - * - *

    The first RPC invocation will be considered attempt #0. Subsequent calls (retries) will - * increment the number of attempts and the number of attempts will not exceed this value. - */ - public abstract int getMaxAttempts(); - - /** - * Jitter determines if the delay time should be randomized. In most cases, if jitter is set to - * {@code true} the actual delay time is calculated in the following way: - * - *

    {@code actualDelay = rand_between(0, min(maxRetryDelay, exponentialDelay))}
    - * - * The default value is {@code true}. - */ - public abstract boolean isJittered(); - - /** Backport of {@link #getMaxRetryDelayDuration()} */ - @ObsoleteApi("Use getMaxRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getMaxRetryDelay(); - - /** - * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier - * can't increase the retry delay higher than this amount. - * - *

    If there are no configurations, Retries have the default max retry delay value of {@code - * Duration.ZERO} and LROs have a default max poll retry delay value of {@code - * Duration.ofMillis(45000)} (45 seconds). - */ - public final java.time.Duration getMaxRetryDelayDuration() { - return toJavaTimeDuration(getMaxRetryDelay()); - } - - /** Backport of {@link #getInitialRpcTimeoutDuration()} */ - @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getInitialRpcTimeout(); - - /** - * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this - * value adjusted according to the RpcTimeoutMultiplier. RPC Timeout value of {@code - * Duration.ZERO} allows the RPC to continue indefinitely (until it hits a Connect Timeout or - * the connection has been terminated). - * - *

    {@link #getTotalTimeout()} caps how long the logic should keep trying the RPC until it - * gives up completely. If {@link #getTotalTimeout()} is set, initialRpcTimeout should be <= - * totalTimeout. - * - *

    If there are no configurations, Retries have the default initial RPC timeout value of - * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. - */ - public final java.time.Duration getInitialRpcTimeoutDuration() { - return toJavaTimeDuration(getInitialRpcTimeout()); - } - - /** - * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is - * multiplied by the RpcTimeoutMultiplier to calculate the timeout for the next call. - * - *

    If there are no configurations, Retries have the default RPC Timeout Multiplier value of - * {@code 1.0}. LRO polling does not use the RPC Timeout Multiplier value. - */ - public abstract double getRpcTimeoutMultiplier(); - - /** Backport of {@link #getMaxRpcTimeoutDuration()} */ - @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getMaxRpcTimeout(); - - /** - * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier - * can't increase the RPC timeout higher than this amount. - * - *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code - * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. - */ - public final java.time.Duration getMaxRpcTimeoutDuration() { - return toJavaTimeDuration(getMaxRpcTimeout()); - } - - /** - * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - @BetaApi - @ObsoleteApi("Use setLogicalTimeout(java.time.Duration) instead") - public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { - return setLogicalTimeout(toJavaTimeDuration(timeout)); - } - /** * Configures the timeout settings with the given timeout such that the logical call will take * no longer than the given timeout and each RPC attempt will use only the time remaining in the @@ -531,6 +416,11 @@ public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { */ @BetaApi public Builder setLogicalTimeout(java.time.Duration timeout) { + return setLogicalTimeout(toThreetenDuration(timeout)); + } + + /** Backport of {@link #setLogicalTimeout(java.time.Duration)} */ + public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { return setRpcTimeoutMultiplier(1) .setInitialRpcTimeout(timeout) .setMaxRpcTimeout(timeout) @@ -568,7 +458,8 @@ public RetrySettings build() { return params; } - public RetrySettings.Builder merge(RetrySettings.Builder newSettings) { + public RetrySettings.Builder merge(RetrySettings.Builder newSettingsBuilder) { + RetrySettings newSettings = newSettingsBuilder.build(); if (newSettings.getTotalTimeoutDuration() != null) { setTotalTimeout(newSettings.getTotalTimeoutDuration()); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java index 60ae29997d..7f7ae5599a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java @@ -19,7 +19,11 @@ enum FieldRole { THREETEN_SETTER } + final Long UNSET_DEFAULT_VALUE = Long.MIN_VALUE; + FieldRole role(); String key(); + + long defaultTestValue() default Long.MIN_VALUE; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java index 886c945d2c..86400dd72f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java @@ -8,6 +8,7 @@ import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Sets; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -139,13 +140,49 @@ private void confirmGetterAndSetterBehaviorUsingSingleSetter( Object testJavaTimeObjectValue, Object testThreetenObjectValue) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Object builder = autoValueClass.getDeclaredMethod("newBuilder").invoke(autoValueClass); + + // Some AutoValue classes need default values to be tested with. This section uses a special + // annotation field "defaultTestValue" and ensures the builder is set with such values + for (Entry defaultSetter : + getSettersWithDefaultValue(builderClass, setter).entrySet()) { + Object value = + javaTimeGetter.getReturnType().equals(java.time.Duration.class) + ? java.time.Duration.ofMillis(defaultSetter.getValue()) + : java.time.Instant.ofEpochMilli(defaultSetter.getValue()); + defaultSetter.getKey().invoke(builder, value); + } + + // Now we call the actual setter under test setter.invoke(builder, testSetterValue); Object builtObject = builderClass.getMethod("build").invoke(builder); + + // And we confirm on the created object that the getters behave the same assertEquals(testJavaTimeObjectValue, javaTimeGetter.invoke(builtObject)); assertEquals(testThreetenObjectValue, threetenGetter.invoke(builtObject)); } + private Map getSettersWithDefaultValue(Class builderClass, Method setterUnderTest) { + Map result = new HashMap<>(); + for (Method m : builderClass.getDeclaredMethods()) { + if (!m.isAnnotationPresent(ThreetenFieldUpgrade.class) + || m.getName() == setterUnderTest.getName()) { + continue; + } + ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); + if (annotation.defaultTestValue() == ThreetenFieldUpgrade.UNSET_DEFAULT_VALUE) { + continue; + } + assertEquals( + "defaulTestValue can only be used with JAVA_TIME_SETTER", + FieldRole.JAVA_TIME_SETTER, + annotation.role()); + result.put(m, annotation.defaultTestValue()); + } + return result; + } + private void confirmGetterAndSetterStructure(Map organizedMethods) { Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); @@ -219,10 +256,16 @@ private Map organizeMethods( result.containsKey(annotation.role())); result.put(annotation.role(), m); } - assertEquals( - String.format("Method group %s does not contain all FieldRoles", groupName), - 4, - result.size()); + boolean hasMissingRoles = false; + for (FieldRole expectedRole : Sets.newHashSet(FieldRole.values())) { + if (!result.containsKey(expectedRole)) { + logger.severe( + String.format( + "Method group %s has missing FieldRole '%s'", groupName, expectedRole.name())); + hasMissingRoles = true; + } + } + assertFalse(hasMissingRoles); return result; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index 1a437842c6..a674b2216b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.retrying; +import com.google.common.collect.ImmutableList; import com.google.common.truth.Truth; import org.junit.Test; @@ -36,13 +37,23 @@ public class RetrySettingsTest { @Test public void retrySettingsSetLogicalTimeout() { - java.time.Duration timeout = java.time.Duration.ofMillis(60000); - RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(60000); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(60000); + RetrySettings javaTimeRetrySettings = + RetrySettings.newBuilder().setLogicalTimeout(javaTimeTimeout).build(); + RetrySettings threetenRetrySettings = + RetrySettings.newBuilder().setLogicalTimeout(threetenTimeout).build(); - Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); - Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(timeout); - Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(timeout); + for (RetrySettings retrySettings : + ImmutableList.of(javaTimeRetrySettings, threetenRetrySettings)) { + Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); + Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(threetenTimeout); + Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(threetenTimeout); + Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(javaTimeTimeout); + Truth.assertThat(retrySettings.getTotalTimeout()).isEqualTo(threetenTimeout); + } } @Test From a58f1bf9bb7062e6011b358254b815fee89e16f8 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 20:33:33 +0000 Subject: [PATCH 055/141] use custom annotation for autovalues with default test values --- .../api/gax/retrying/RetrySettings.java | 6 +- .../gax/retrying/TimedAttemptSettings.java | 15 ++++ .../api/gax/util/ThreetenFieldUpgrade.java | 2 - .../ThreetenTestAutoValueOverrideClass.java | 10 +++ ...aluesWithDeprecatedThreetenFieldsTest.java | 72 +++++++++---------- .../retrying/RetrySettingsTestAutoValue.java | 13 ++++ .../TimedAttemptSettingsTestAutoValue.java | 21 ++++++ 7 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 03e277061a..dfd092549a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -318,8 +318,7 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { */ @ThreetenFieldUpgrade( key = "maxRetryDelay", - role = FieldRole.JAVA_TIME_SETTER, - defaultTestValue = 5000l) + role = FieldRole.JAVA_TIME_SETTER) public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { return setMaxRetryDelay(toThreetenDuration(maxDelay)); } @@ -399,8 +398,7 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { */ @ThreetenFieldUpgrade( key = "maxRpcTimeout", - role = FieldRole.JAVA_TIME_SETTER, - defaultTestValue = 5000l) + role = FieldRole.JAVA_TIME_SETTER) public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index ef79a46b20..323e9c360a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -34,7 +34,10 @@ import com.google.api.core.ApiClock; import com.google.api.core.ObsoleteApi; +import com.google.api.gax.util.ThreetenFieldUpgrade; +import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; +import com.google.common.annotations.VisibleForTesting; /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ @AutoValue @@ -45,33 +48,39 @@ public abstract class TimedAttemptSettings { /** Backport of {@link #getRetryDelayDuration()} */ @ObsoleteApi("Use getRetryDelayDuration() instead") + @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getRetryDelay(); /** * Returns the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ + @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getRetryDelayDuration() { return toJavaTimeDuration(getRetryDelay()); } /** Backport of {@link #getRpcTimeoutDuration()} */ @ObsoleteApi("Use getRpcTimeoutDuration() instead") + @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getRpcTimeout(); /** Returns rpc timeout used for this attempt. */ + @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getRpcTimeoutDuration() { return toJavaTimeDuration(getRpcTimeout()); } /** Backport of {@link #getRandomizedRetryDelayDuration()} */ @ObsoleteApi("Use getRandomizedRetryDelayDuration() instead") + @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getRandomizedRetryDelay(); /** * Returns randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ + @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getRandomizedRetryDelayDuration() { return toJavaTimeDuration(getRandomizedRetryDelay()); } @@ -110,12 +119,14 @@ public abstract static class Builder { * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @ObsoleteApi("Use setRetryDelay(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setRetryDelay(org.threeten.bp.Duration value); /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ + @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.JAVA_TIME_SETTER) public final Builder setRetryDelay(java.time.Duration value) { return setRetryDelay(toThreetenDuration(value)); } @@ -124,9 +135,11 @@ public final Builder setRetryDelay(java.time.Duration value) { * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @ObsoleteApi("Use setRpcTimeout(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); /** Sets rpc timeout used for this attempt. */ + @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.JAVA_TIME_SETTER) public final Builder setRpcTimeout(java.time.Duration value) { return setRpcTimeout(toThreetenDuration(value)); } @@ -136,12 +149,14 @@ public final Builder setRpcTimeout(java.time.Duration value) { * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRandomizedRetryDelay(java.time.Duration) instead") + @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setRandomizedRetryDelay(org.threeten.bp.Duration value); /** * Sets randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ + @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.JAVA_TIME_SETTER) public final Builder setRandomizedRetryDelay(java.time.Duration value) { return setRandomizedRetryDelay(toThreetenDuration(value)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java index 7f7ae5599a..58b2fbb74e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java @@ -24,6 +24,4 @@ enum FieldRole { FieldRole role(); String key(); - - long defaultTestValue() default Long.MIN_VALUE; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java new file mode 100644 index 0000000000..8601d57273 --- /dev/null +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java @@ -0,0 +1,10 @@ +package com.google.api.gax.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ThreetenTestAutoValueOverrideClass { } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java index 86400dd72f..459e4a4878 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java @@ -6,6 +6,7 @@ import com.google.api.gax.util.ThreetenFieldUpgrade; import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; +import com.google.api.gax.util.ThreetenTestAutoValueOverrideClass; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -28,8 +29,7 @@ @RunWith(JUnit4.class) public class AutoValuesWithDeprecatedThreetenFieldsTest { - private static final Logger logger = - Logger.getLogger(AutoValuesWithDeprecatedThreetenFieldsTest.class.getSimpleName()); + private static final Logger logger = Logger.getLogger(""); @Test public void testAutoValueClassesWithThreetenMethods() @@ -40,8 +40,16 @@ public void testAutoValueClassesWithThreetenMethods() } } - private void testAutoValueClassWithThreetenMethods(Class autoValueClass) + private void testAutoValueClassWithThreetenMethods(Class initialAutoValueClass) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { + // Here we handle the case where we are processing a class annotated with + // @ThreetenTestAutoValueOverrideClass. In such case, we only extract the custom newBuilder() + // method and process the parent class as usual + Method newBuilderMethod = initialAutoValueClass.getDeclaredMethod("newBuilder"); + final Class autoValueClass = + initialAutoValueClass.isAnnotationPresent(ThreetenTestAutoValueOverrideClass.class) ? + initialAutoValueClass.getSuperclass() : initialAutoValueClass; + logger.info(String.format("Testing threeten methods for class %s", autoValueClass.getName())); // We first group the methods by key. Each key should contain four methods corresponding to a @@ -85,12 +93,14 @@ private void testAutoValueClassWithThreetenMethods(Class autoValueClass) logger.info(String.format("Confirming structure of method group '%s", groupName)); confirmGetterAndSetterStructure(organizedMethods); logger.info(String.format("Confirming behavior of method group '%s", groupName)); - confirmGetterAndSetterBehavior(organizedMethods, autoValueClass, builderClass); + confirmGetterAndSetterBehavior(organizedMethods, autoValueClass, builderClass, + newBuilderMethod); } } private void confirmGetterAndSetterBehavior( - Map organizedMethods, Class autoValueClass, Class builderClass) + Map organizedMethods, Class autoValueClass, Class builderClass, + Method newBuilderMethod) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); @@ -116,6 +126,7 @@ private void confirmGetterAndSetterBehavior( javaTimeSetter, autoValueClass, builderClass, + newBuilderMethod, testJavaTimeObjectValue, testJavaTimeObjectValue, testThreetenObjectValue); @@ -125,6 +136,7 @@ private void confirmGetterAndSetterBehavior( threetenSetter, autoValueClass, builderClass, + newBuilderMethod, testThreetenObjectValue, testJavaTimeObjectValue, testThreetenObjectValue); @@ -136,23 +148,13 @@ private void confirmGetterAndSetterBehaviorUsingSingleSetter( Method setter, Class autoValueClass, Class builderClass, + Method newBuilderMethod, Object testSetterValue, Object testJavaTimeObjectValue, Object testThreetenObjectValue) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Object builder = autoValueClass.getDeclaredMethod("newBuilder").invoke(autoValueClass); - - // Some AutoValue classes need default values to be tested with. This section uses a special - // annotation field "defaultTestValue" and ensures the builder is set with such values - for (Entry defaultSetter : - getSettersWithDefaultValue(builderClass, setter).entrySet()) { - Object value = - javaTimeGetter.getReturnType().equals(java.time.Duration.class) - ? java.time.Duration.ofMillis(defaultSetter.getValue()) - : java.time.Instant.ofEpochMilli(defaultSetter.getValue()); - defaultSetter.getKey().invoke(builder, value); - } + Object builder = newBuilderMethod.invoke(autoValueClass); // Now we call the actual setter under test setter.invoke(builder, testSetterValue); @@ -163,26 +165,6 @@ private void confirmGetterAndSetterBehaviorUsingSingleSetter( assertEquals(testThreetenObjectValue, threetenGetter.invoke(builtObject)); } - private Map getSettersWithDefaultValue(Class builderClass, Method setterUnderTest) { - Map result = new HashMap<>(); - for (Method m : builderClass.getDeclaredMethods()) { - if (!m.isAnnotationPresent(ThreetenFieldUpgrade.class) - || m.getName() == setterUnderTest.getName()) { - continue; - } - ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); - if (annotation.defaultTestValue() == ThreetenFieldUpgrade.UNSET_DEFAULT_VALUE) { - continue; - } - assertEquals( - "defaulTestValue can only be used with JAVA_TIME_SETTER", - FieldRole.JAVA_TIME_SETTER, - annotation.role()); - result.put(m, annotation.defaultTestValue()); - } - return result; - } - private void confirmGetterAndSetterStructure(Map organizedMethods) { Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); @@ -283,7 +265,21 @@ private List> getAutoValueClassesWithThreetenMethods() { List methods = Arrays.asList(c.getDeclaredMethods()); boolean hasThreetenAnnotatedMethods = methods.stream().anyMatch(m -> m.isAnnotationPresent(ThreetenFieldUpgrade.class)); - if (hasThreetenAnnotatedMethods) { + if (!hasThreetenAnnotatedMethods) { + continue; + } + // Some AutoValue classes will have a child class declared in test-scope with, for example, a + // custom newBuilder() method. Such child classes will be annotated with + // @ThreetenTestAutoValueOverrideClass + Set> childrenClasses = reflections.getSubTypesOf(c); + boolean hasChildClassWithCustomBehavior = false; + for (Class child : childrenClasses) { + if (child.isAnnotationPresent(ThreetenTestAutoValueOverrideClass.class)) { + hasChildClassWithCustomBehavior = true; + result.add(child); + } + } + if (!hasChildClassWithCustomBehavior) { result.add(c); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java new file mode 100644 index 0000000000..f5654b408a --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java @@ -0,0 +1,13 @@ +package com.google.api.gax.retrying; + +import com.google.api.gax.util.ThreetenTestAutoValueOverrideClass; + +@ThreetenTestAutoValueOverrideClass +public abstract class RetrySettingsTestAutoValue extends RetrySettings { + + public static RetrySettings.Builder newBuilder() { + return RetrySettings.newBuilder() + .setMaxRpcTimeout(java.time.Duration.ofMillis(999999l)) + .setMaxRetryDelay(java.time.Duration.ofMillis(999999l)); + } +} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java new file mode 100644 index 0000000000..5a282eeff9 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java @@ -0,0 +1,21 @@ +package com.google.api.gax.retrying; + + +import com.google.api.gax.util.ThreetenTestAutoValueOverrideClass; + +@ThreetenTestAutoValueOverrideClass +public abstract class TimedAttemptSettingsTestAutoValue extends TimedAttemptSettings { + + /** + * Custom builder with randon values used to confirm threeten overloaded methods + */ + public static TimedAttemptSettings.Builder newBuilder() { + return TimedAttemptSettings.newBuilder() + .setGlobalSettings(RetrySettings.newBuilder().build()) + .setRetryDelay(java.time.Duration.ofMillis(123l)) + .setRpcTimeout(java.time.Duration.ofMillis(5000l)) + .setAttemptCount(1) + .setFirstAttemptStartTimeNanos(123l) + .setRandomizedRetryDelay(java.time.Duration.ofMillis(5000l)); + } +} From fc2ee3b754d283c661fa67246cb04ec2ec8d5cef Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 23:18:47 +0000 Subject: [PATCH 056/141] Revert "use custom annotation for autovalues with default test values" This reverts commit a58f1bf9bb7062e6011b358254b815fee89e16f8. --- .../api/gax/retrying/RetrySettings.java | 6 +- .../gax/retrying/TimedAttemptSettings.java | 15 ---- .../api/gax/util/ThreetenFieldUpgrade.java | 2 + .../ThreetenTestAutoValueOverrideClass.java | 10 --- ...aluesWithDeprecatedThreetenFieldsTest.java | 72 ++++++++++--------- .../retrying/RetrySettingsTestAutoValue.java | 13 ---- .../TimedAttemptSettingsTestAutoValue.java | 21 ------ 7 files changed, 44 insertions(+), 95 deletions(-) delete mode 100644 gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java delete mode 100644 gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java delete mode 100644 gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index dfd092549a..03e277061a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -318,7 +318,8 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { */ @ThreetenFieldUpgrade( key = "maxRetryDelay", - role = FieldRole.JAVA_TIME_SETTER) + role = FieldRole.JAVA_TIME_SETTER, + defaultTestValue = 5000l) public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { return setMaxRetryDelay(toThreetenDuration(maxDelay)); } @@ -398,7 +399,8 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { */ @ThreetenFieldUpgrade( key = "maxRpcTimeout", - role = FieldRole.JAVA_TIME_SETTER) + role = FieldRole.JAVA_TIME_SETTER, + defaultTestValue = 5000l) public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index 323e9c360a..ef79a46b20 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -34,10 +34,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.ObsoleteApi; -import com.google.api.gax.util.ThreetenFieldUpgrade; -import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; -import com.google.common.annotations.VisibleForTesting; /** Timed attempt execution settings. Defines time-specific properties of a retry attempt. */ @AutoValue @@ -48,39 +45,33 @@ public abstract class TimedAttemptSettings { /** Backport of {@link #getRetryDelayDuration()} */ @ObsoleteApi("Use getRetryDelayDuration() instead") - @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getRetryDelay(); /** * Returns the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getRetryDelayDuration() { return toJavaTimeDuration(getRetryDelay()); } /** Backport of {@link #getRpcTimeoutDuration()} */ @ObsoleteApi("Use getRpcTimeoutDuration() instead") - @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getRpcTimeout(); /** Returns rpc timeout used for this attempt. */ - @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getRpcTimeoutDuration() { return toJavaTimeDuration(getRpcTimeout()); } /** Backport of {@link #getRandomizedRetryDelayDuration()} */ @ObsoleteApi("Use getRandomizedRetryDelayDuration() instead") - @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getRandomizedRetryDelay(); /** * Returns randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getRandomizedRetryDelayDuration() { return toJavaTimeDuration(getRandomizedRetryDelay()); } @@ -119,14 +110,12 @@ public abstract static class Builder { * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @ObsoleteApi("Use setRetryDelay(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setRetryDelay(org.threeten.bp.Duration value); /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - @ThreetenFieldUpgrade(key = "retryDelay", role = FieldRole.JAVA_TIME_SETTER) public final Builder setRetryDelay(java.time.Duration value) { return setRetryDelay(toThreetenDuration(value)); } @@ -135,11 +124,9 @@ public final Builder setRetryDelay(java.time.Duration value) { * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ @ObsoleteApi("Use setRpcTimeout(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); /** Sets rpc timeout used for this attempt. */ - @ThreetenFieldUpgrade(key = "rpcTimeout", role = FieldRole.JAVA_TIME_SETTER) public final Builder setRpcTimeout(java.time.Duration value) { return setRpcTimeout(toThreetenDuration(value)); } @@ -149,14 +136,12 @@ public final Builder setRpcTimeout(java.time.Duration value) { * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRandomizedRetryDelay(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setRandomizedRetryDelay(org.threeten.bp.Duration value); /** * Sets randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - @ThreetenFieldUpgrade(key = "randomizedRetryDelay", role = FieldRole.JAVA_TIME_SETTER) public final Builder setRandomizedRetryDelay(java.time.Duration value) { return setRandomizedRetryDelay(toThreetenDuration(value)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java index 58b2fbb74e..7f7ae5599a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java @@ -24,4 +24,6 @@ enum FieldRole { FieldRole role(); String key(); + + long defaultTestValue() default Long.MIN_VALUE; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java deleted file mode 100644 index 8601d57273..0000000000 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenTestAutoValueOverrideClass.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.google.api.gax.util; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface ThreetenTestAutoValueOverrideClass { } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java index 459e4a4878..86400dd72f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java @@ -6,7 +6,6 @@ import com.google.api.gax.util.ThreetenFieldUpgrade; import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; -import com.google.api.gax.util.ThreetenTestAutoValueOverrideClass; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -29,7 +28,8 @@ @RunWith(JUnit4.class) public class AutoValuesWithDeprecatedThreetenFieldsTest { - private static final Logger logger = Logger.getLogger(""); + private static final Logger logger = + Logger.getLogger(AutoValuesWithDeprecatedThreetenFieldsTest.class.getSimpleName()); @Test public void testAutoValueClassesWithThreetenMethods() @@ -40,16 +40,8 @@ public void testAutoValueClassesWithThreetenMethods() } } - private void testAutoValueClassWithThreetenMethods(Class initialAutoValueClass) + private void testAutoValueClassWithThreetenMethods(Class autoValueClass) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { - // Here we handle the case where we are processing a class annotated with - // @ThreetenTestAutoValueOverrideClass. In such case, we only extract the custom newBuilder() - // method and process the parent class as usual - Method newBuilderMethod = initialAutoValueClass.getDeclaredMethod("newBuilder"); - final Class autoValueClass = - initialAutoValueClass.isAnnotationPresent(ThreetenTestAutoValueOverrideClass.class) ? - initialAutoValueClass.getSuperclass() : initialAutoValueClass; - logger.info(String.format("Testing threeten methods for class %s", autoValueClass.getName())); // We first group the methods by key. Each key should contain four methods corresponding to a @@ -93,14 +85,12 @@ private void testAutoValueClassWithThreetenMethods(Class initialAutoValueClass) logger.info(String.format("Confirming structure of method group '%s", groupName)); confirmGetterAndSetterStructure(organizedMethods); logger.info(String.format("Confirming behavior of method group '%s", groupName)); - confirmGetterAndSetterBehavior(organizedMethods, autoValueClass, builderClass, - newBuilderMethod); + confirmGetterAndSetterBehavior(organizedMethods, autoValueClass, builderClass); } } private void confirmGetterAndSetterBehavior( - Map organizedMethods, Class autoValueClass, Class builderClass, - Method newBuilderMethod) + Map organizedMethods, Class autoValueClass, Class builderClass) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); @@ -126,7 +116,6 @@ private void confirmGetterAndSetterBehavior( javaTimeSetter, autoValueClass, builderClass, - newBuilderMethod, testJavaTimeObjectValue, testJavaTimeObjectValue, testThreetenObjectValue); @@ -136,7 +125,6 @@ private void confirmGetterAndSetterBehavior( threetenSetter, autoValueClass, builderClass, - newBuilderMethod, testThreetenObjectValue, testJavaTimeObjectValue, testThreetenObjectValue); @@ -148,13 +136,23 @@ private void confirmGetterAndSetterBehaviorUsingSingleSetter( Method setter, Class autoValueClass, Class builderClass, - Method newBuilderMethod, Object testSetterValue, Object testJavaTimeObjectValue, Object testThreetenObjectValue) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Object builder = newBuilderMethod.invoke(autoValueClass); + Object builder = autoValueClass.getDeclaredMethod("newBuilder").invoke(autoValueClass); + + // Some AutoValue classes need default values to be tested with. This section uses a special + // annotation field "defaultTestValue" and ensures the builder is set with such values + for (Entry defaultSetter : + getSettersWithDefaultValue(builderClass, setter).entrySet()) { + Object value = + javaTimeGetter.getReturnType().equals(java.time.Duration.class) + ? java.time.Duration.ofMillis(defaultSetter.getValue()) + : java.time.Instant.ofEpochMilli(defaultSetter.getValue()); + defaultSetter.getKey().invoke(builder, value); + } // Now we call the actual setter under test setter.invoke(builder, testSetterValue); @@ -165,6 +163,26 @@ private void confirmGetterAndSetterBehaviorUsingSingleSetter( assertEquals(testThreetenObjectValue, threetenGetter.invoke(builtObject)); } + private Map getSettersWithDefaultValue(Class builderClass, Method setterUnderTest) { + Map result = new HashMap<>(); + for (Method m : builderClass.getDeclaredMethods()) { + if (!m.isAnnotationPresent(ThreetenFieldUpgrade.class) + || m.getName() == setterUnderTest.getName()) { + continue; + } + ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); + if (annotation.defaultTestValue() == ThreetenFieldUpgrade.UNSET_DEFAULT_VALUE) { + continue; + } + assertEquals( + "defaulTestValue can only be used with JAVA_TIME_SETTER", + FieldRole.JAVA_TIME_SETTER, + annotation.role()); + result.put(m, annotation.defaultTestValue()); + } + return result; + } + private void confirmGetterAndSetterStructure(Map organizedMethods) { Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); @@ -265,21 +283,7 @@ private List> getAutoValueClassesWithThreetenMethods() { List methods = Arrays.asList(c.getDeclaredMethods()); boolean hasThreetenAnnotatedMethods = methods.stream().anyMatch(m -> m.isAnnotationPresent(ThreetenFieldUpgrade.class)); - if (!hasThreetenAnnotatedMethods) { - continue; - } - // Some AutoValue classes will have a child class declared in test-scope with, for example, a - // custom newBuilder() method. Such child classes will be annotated with - // @ThreetenTestAutoValueOverrideClass - Set> childrenClasses = reflections.getSubTypesOf(c); - boolean hasChildClassWithCustomBehavior = false; - for (Class child : childrenClasses) { - if (child.isAnnotationPresent(ThreetenTestAutoValueOverrideClass.class)) { - hasChildClassWithCustomBehavior = true; - result.add(child); - } - } - if (!hasChildClassWithCustomBehavior) { + if (hasThreetenAnnotatedMethods) { result.add(c); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java deleted file mode 100644 index f5654b408a..0000000000 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTestAutoValue.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.google.api.gax.retrying; - -import com.google.api.gax.util.ThreetenTestAutoValueOverrideClass; - -@ThreetenTestAutoValueOverrideClass -public abstract class RetrySettingsTestAutoValue extends RetrySettings { - - public static RetrySettings.Builder newBuilder() { - return RetrySettings.newBuilder() - .setMaxRpcTimeout(java.time.Duration.ofMillis(999999l)) - .setMaxRetryDelay(java.time.Duration.ofMillis(999999l)); - } -} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java deleted file mode 100644 index 5a282eeff9..0000000000 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTestAutoValue.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.google.api.gax.retrying; - - -import com.google.api.gax.util.ThreetenTestAutoValueOverrideClass; - -@ThreetenTestAutoValueOverrideClass -public abstract class TimedAttemptSettingsTestAutoValue extends TimedAttemptSettings { - - /** - * Custom builder with randon values used to confirm threeten overloaded methods - */ - public static TimedAttemptSettings.Builder newBuilder() { - return TimedAttemptSettings.newBuilder() - .setGlobalSettings(RetrySettings.newBuilder().build()) - .setRetryDelay(java.time.Duration.ofMillis(123l)) - .setRpcTimeout(java.time.Duration.ofMillis(5000l)) - .setAttemptCount(1) - .setFirstAttemptStartTimeNanos(123l) - .setRandomizedRetryDelay(java.time.Duration.ofMillis(5000l)); - } -} From 65769219cd0e3742aa569864cf2aec04e44141b2 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 23:18:47 +0000 Subject: [PATCH 057/141] Revert "add test for RetrySettings" This reverts commit 5dca441c1d2672fa7d2243460778fc9c98aa40f5. --- .../api/gax/retrying/RetrySettings.java | 179 ++++++++++++++---- .../api/gax/util/ThreetenFieldUpgrade.java | 4 - ...aluesWithDeprecatedThreetenFieldsTest.java | 51 +---- .../api/gax/retrying/RetrySettingsTest.java | 23 +-- 4 files changed, 154 insertions(+), 103 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 03e277061a..1298f1217e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -34,8 +34,6 @@ import com.google.api.core.BetaApi; import com.google.api.core.ObsoleteApi; -import com.google.api.gax.util.ThreetenFieldUpgrade; -import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; @@ -85,7 +83,6 @@ public abstract class RetrySettings implements Serializable { /** Backport of {@link #getTotalTimeoutDuration()} */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") - @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getTotalTimeout(); /** @@ -101,14 +98,12 @@ public abstract class RetrySettings implements Serializable { * Duration.ZERO} and LROs have a default total timeout value of {@code Duration.ofMillis(300000)} * (5 minutes). */ - @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getTotalTimeoutDuration() { return toJavaTimeDuration(getTotalTimeout()); } /** Backport of {@link #getInitialRetryDelayDuration()} */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") - @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getInitialRetryDelay(); /** @@ -119,7 +114,6 @@ public final java.time.Duration getTotalTimeoutDuration() { * Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ - @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getInitialRetryDelayDuration() { return toJavaTimeDuration(getInitialRetryDelay()); } @@ -136,7 +130,6 @@ public final java.time.Duration getInitialRetryDelayDuration() { /** Backport of {@link #getMaxRetryDelayDuration()} */ @ObsoleteApi("Use getMaxRetryDelayDuration()") - @ThreetenFieldUpgrade(key = "maxRetryDelay", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getMaxRetryDelay(); /** @@ -147,7 +140,6 @@ public final java.time.Duration getInitialRetryDelayDuration() { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ - @ThreetenFieldUpgrade(key = "maxRetryDelay", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getMaxRetryDelayDuration() { return toJavaTimeDuration(getMaxRetryDelay()); } @@ -183,7 +175,6 @@ public final java.time.Duration getMaxRetryDelayDuration() { /** Backport of {@link #getInitialRpcTimeoutDuration()} */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") - @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getInitialRpcTimeout(); /** @@ -199,7 +190,6 @@ public final java.time.Duration getMaxRetryDelayDuration() { *

    If there are no configurations, Retries have the default initial RPC timeout value of {@code * Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ - @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getInitialRpcTimeoutDuration() { return toJavaTimeDuration(getInitialRpcTimeout()); } @@ -215,7 +205,6 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { /** Backport of {@link #getMaxRpcTimeoutDuration()} */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") - @ThreetenFieldUpgrade(key = "maxRpcTimeout", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getMaxRpcTimeout(); /** @@ -225,7 +214,6 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ - @ThreetenFieldUpgrade(key = "maxRpcTimeout", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getMaxRpcTimeoutDuration() { return toJavaTimeDuration(getMaxRpcTimeout()); } @@ -254,7 +242,6 @@ public abstract static class Builder { /** Backport of {@link #setTotalTimeout(java.time.Duration)} */ @ObsoleteApi("Use setTotalTimeout(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); /** @@ -270,14 +257,12 @@ public abstract static class Builder { * Duration.ZERO} and LROs have a default total timeout value of {@code * Duration.ofMillis(300000)} (5 minutes). */ - @ThreetenFieldUpgrade(key = "totalTimeout", role = FieldRole.JAVA_TIME_SETTER) public final Builder setTotalTimeout(java.time.Duration totalTimeout) { return setTotalTimeout(toThreetenDuration(totalTimeout)); } /** Backport of {@link #setInitialRetryDelay(java.time.Duration)} */ @ObsoleteApi("Use setInitialRetryDelay(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); /** @@ -288,7 +273,6 @@ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ - @ThreetenFieldUpgrade(key = "initialRetryDelay", role = FieldRole.JAVA_TIME_SETTER) public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { return setInitialRetryDelay(toThreetenDuration(initialDelay)); } @@ -305,7 +289,6 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { /** Backport of {@link #setMaxRetryDelay(java.time.Duration)} */ @ObsoleteApi("Use setMaxRetryDelay(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "maxRetryDelay", role = FieldRole.THREETEN_SETTER) public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); /** @@ -316,10 +299,6 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ - @ThreetenFieldUpgrade( - key = "maxRetryDelay", - role = FieldRole.JAVA_TIME_SETTER, - defaultTestValue = 5000l) public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { return setMaxRetryDelay(toThreetenDuration(maxDelay)); } @@ -355,7 +334,6 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { /** Backport of {@link #setInitialRpcTimeout(java.time.Duration)} */ @ObsoleteApi("Use setInitialRpcTimeout(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); /** @@ -371,7 +349,6 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { *

    If there are no configurations, Retries have the default initial RPC timeout value of * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ - @ThreetenFieldUpgrade(key = "initialRpcTimeout", role = FieldRole.JAVA_TIME_SETTER) public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { return setInitialRpcTimeout(toThreetenDuration(initialTimeout)); } @@ -387,7 +364,6 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { /** Backport of {@link #setMaxRpcTimeout(java.time.Duration)} */ @ObsoleteApi("Use setMaxRpcTimeout(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "maxRpcTimeout", role = FieldRole.THREETEN_SETTER) public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); /** @@ -397,14 +373,153 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ - @ThreetenFieldUpgrade( - key = "maxRpcTimeout", - role = FieldRole.JAVA_TIME_SETTER, - defaultTestValue = 5000l) public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); } + /** Backport of {@link #getTotalTimeoutDuration()} */ + @ObsoleteApi("Use getTotalTimeoutDuration() instead") + public abstract org.threeten.bp.Duration getTotalTimeout(); + + /** + * TotalTimeout has ultimate control over how long the logic should keep trying the remote call + * until it gives up completely. The higher the total timeout, the more retries and polls can be + * attempted. If this value is {@code Duration.ZERO}, then the logic will instead use the number + * of attempts to determine retries. In the event that both maxAttempts and totalTimeout values + * are both 0, the logic will not retry. If this value is non-{@code Duration.ZERO}, and the + * retry duration has reaches the timeout value, the logic will give up retrying even the number + * of attempts is lower than the maxAttempts value. + * + *

    If there are no configurations, Retries have the default timeout value of {@code + * Duration.ZERO} and LROs have a default total timeout value of {@code + * Duration.ofMillis(300000)} (5 minutes). + */ + public final java.time.Duration getTotalTimeoutDuration() { + return toJavaTimeDuration(getTotalTimeout()); + } + + /** Backport of {@link #getInitialRetryDelayDuration()} */ + @ObsoleteApi("Use getInitialRetryDelayDuration() instead") + public abstract org.threeten.bp.Duration getInitialRetryDelay(); + + /** + * InitialRetryDelay controls the delay before the first retry/ poll. Subsequent retries and + * polls will use this value adjusted according to the RetryDelayMultiplier. + * + *

    If there are no configurations, Retries have the default initial retry delay value of + * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code + * Duration.ofMillis(5000)} (5 seconds). + */ + public final java.time.Duration getInitialRetryDelayDuration() { + return toJavaTimeDuration(getInitialRetryDelay()); + } + + /** + * RetryDelayMultiplier controls the change in delay before the next retry or poll. The retry + * delay of the previous call is multiplied by the RetryDelayMultiplier to calculate the retry + * delay for the next call. + * + *

    If there are no configurations, Retries have the default retry delay multiplier value of + * {@code 1.0} and LROs have a default retry delay multiplier of {@code 1.5}. + */ + public abstract double getRetryDelayMultiplier(); + + /** + * MaxAttempts defines the maximum number of retry attempts to perform. If this value is set to + * 0, the logic will instead use the totalTimeout value to determine retries. In the event that + * both the maxAttempts and totalTimeout values are both 0, the logic will not retry. If this + * value is greater than 0, and the number of attempts exceeds this limit, the logic will give + * up retrying even if the total retry time is still lower than totalTimeout. + * + *

    If there are no configurations, Retries and LROs have the default max attempt value of + * {@code 0}. LRO polling does not use this value by default. + * + *

    The first RPC invocation will be considered attempt #0. Subsequent calls (retries) will + * increment the number of attempts and the number of attempts will not exceed this value. + */ + public abstract int getMaxAttempts(); + + /** + * Jitter determines if the delay time should be randomized. In most cases, if jitter is set to + * {@code true} the actual delay time is calculated in the following way: + * + *

    {@code actualDelay = rand_between(0, min(maxRetryDelay, exponentialDelay))}
    + * + * The default value is {@code true}. + */ + public abstract boolean isJittered(); + + /** Backport of {@link #getMaxRetryDelayDuration()} */ + @ObsoleteApi("Use getMaxRetryDelayDuration() instead") + public abstract org.threeten.bp.Duration getMaxRetryDelay(); + + /** + * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier + * can't increase the retry delay higher than this amount. + * + *

    If there are no configurations, Retries have the default max retry delay value of {@code + * Duration.ZERO} and LROs have a default max poll retry delay value of {@code + * Duration.ofMillis(45000)} (45 seconds). + */ + public final java.time.Duration getMaxRetryDelayDuration() { + return toJavaTimeDuration(getMaxRetryDelay()); + } + + /** Backport of {@link #getInitialRpcTimeoutDuration()} */ + @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") + public abstract org.threeten.bp.Duration getInitialRpcTimeout(); + + /** + * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this + * value adjusted according to the RpcTimeoutMultiplier. RPC Timeout value of {@code + * Duration.ZERO} allows the RPC to continue indefinitely (until it hits a Connect Timeout or + * the connection has been terminated). + * + *

    {@link #getTotalTimeout()} caps how long the logic should keep trying the RPC until it + * gives up completely. If {@link #getTotalTimeout()} is set, initialRpcTimeout should be <= + * totalTimeout. + * + *

    If there are no configurations, Retries have the default initial RPC timeout value of + * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. + */ + public final java.time.Duration getInitialRpcTimeoutDuration() { + return toJavaTimeDuration(getInitialRpcTimeout()); + } + + /** + * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is + * multiplied by the RpcTimeoutMultiplier to calculate the timeout for the next call. + * + *

    If there are no configurations, Retries have the default RPC Timeout Multiplier value of + * {@code 1.0}. LRO polling does not use the RPC Timeout Multiplier value. + */ + public abstract double getRpcTimeoutMultiplier(); + + /** Backport of {@link #getMaxRpcTimeoutDuration()} */ + @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") + public abstract org.threeten.bp.Duration getMaxRpcTimeout(); + + /** + * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier + * can't increase the RPC timeout higher than this amount. + * + *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code + * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. + */ + public final java.time.Duration getMaxRpcTimeoutDuration() { + return toJavaTimeDuration(getMaxRpcTimeout()); + } + + /** + * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + @BetaApi + @ObsoleteApi("Use setLogicalTimeout(java.time.Duration) instead") + public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { + return setLogicalTimeout(toJavaTimeDuration(timeout)); + } + /** * Configures the timeout settings with the given timeout such that the logical call will take * no longer than the given timeout and each RPC attempt will use only the time remaining in the @@ -416,11 +531,6 @@ public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { */ @BetaApi public Builder setLogicalTimeout(java.time.Duration timeout) { - return setLogicalTimeout(toThreetenDuration(timeout)); - } - - /** Backport of {@link #setLogicalTimeout(java.time.Duration)} */ - public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { return setRpcTimeoutMultiplier(1) .setInitialRpcTimeout(timeout) .setMaxRpcTimeout(timeout) @@ -458,8 +568,7 @@ public RetrySettings build() { return params; } - public RetrySettings.Builder merge(RetrySettings.Builder newSettingsBuilder) { - RetrySettings newSettings = newSettingsBuilder.build(); + public RetrySettings.Builder merge(RetrySettings.Builder newSettings) { if (newSettings.getTotalTimeoutDuration() != null) { setTotalTimeout(newSettings.getTotalTimeoutDuration()); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java index 7f7ae5599a..60ae29997d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java @@ -19,11 +19,7 @@ enum FieldRole { THREETEN_SETTER } - final Long UNSET_DEFAULT_VALUE = Long.MIN_VALUE; - FieldRole role(); String key(); - - long defaultTestValue() default Long.MIN_VALUE; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java index 86400dd72f..886c945d2c 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java @@ -8,7 +8,6 @@ import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -140,49 +139,13 @@ private void confirmGetterAndSetterBehaviorUsingSingleSetter( Object testJavaTimeObjectValue, Object testThreetenObjectValue) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Object builder = autoValueClass.getDeclaredMethod("newBuilder").invoke(autoValueClass); - - // Some AutoValue classes need default values to be tested with. This section uses a special - // annotation field "defaultTestValue" and ensures the builder is set with such values - for (Entry defaultSetter : - getSettersWithDefaultValue(builderClass, setter).entrySet()) { - Object value = - javaTimeGetter.getReturnType().equals(java.time.Duration.class) - ? java.time.Duration.ofMillis(defaultSetter.getValue()) - : java.time.Instant.ofEpochMilli(defaultSetter.getValue()); - defaultSetter.getKey().invoke(builder, value); - } - - // Now we call the actual setter under test setter.invoke(builder, testSetterValue); Object builtObject = builderClass.getMethod("build").invoke(builder); - - // And we confirm on the created object that the getters behave the same assertEquals(testJavaTimeObjectValue, javaTimeGetter.invoke(builtObject)); assertEquals(testThreetenObjectValue, threetenGetter.invoke(builtObject)); } - private Map getSettersWithDefaultValue(Class builderClass, Method setterUnderTest) { - Map result = new HashMap<>(); - for (Method m : builderClass.getDeclaredMethods()) { - if (!m.isAnnotationPresent(ThreetenFieldUpgrade.class) - || m.getName() == setterUnderTest.getName()) { - continue; - } - ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); - if (annotation.defaultTestValue() == ThreetenFieldUpgrade.UNSET_DEFAULT_VALUE) { - continue; - } - assertEquals( - "defaulTestValue can only be used with JAVA_TIME_SETTER", - FieldRole.JAVA_TIME_SETTER, - annotation.role()); - result.put(m, annotation.defaultTestValue()); - } - return result; - } - private void confirmGetterAndSetterStructure(Map organizedMethods) { Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); @@ -256,16 +219,10 @@ private Map organizeMethods( result.containsKey(annotation.role())); result.put(annotation.role(), m); } - boolean hasMissingRoles = false; - for (FieldRole expectedRole : Sets.newHashSet(FieldRole.values())) { - if (!result.containsKey(expectedRole)) { - logger.severe( - String.format( - "Method group %s has missing FieldRole '%s'", groupName, expectedRole.name())); - hasMissingRoles = true; - } - } - assertFalse(hasMissingRoles); + assertEquals( + String.format("Method group %s does not contain all FieldRoles", groupName), + 4, + result.size()); return result; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index a674b2216b..1a437842c6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.retrying; -import com.google.common.collect.ImmutableList; import com.google.common.truth.Truth; import org.junit.Test; @@ -37,23 +36,13 @@ public class RetrySettingsTest { @Test public void retrySettingsSetLogicalTimeout() { - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(60000); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(60000); - RetrySettings javaTimeRetrySettings = - RetrySettings.newBuilder().setLogicalTimeout(javaTimeTimeout).build(); - RetrySettings threetenRetrySettings = - RetrySettings.newBuilder().setLogicalTimeout(threetenTimeout).build(); + java.time.Duration timeout = java.time.Duration.ofMillis(60000); + RetrySettings retrySettings = RetrySettings.newBuilder().setLogicalTimeout(timeout).build(); - for (RetrySettings retrySettings : - ImmutableList.of(javaTimeRetrySettings, threetenRetrySettings)) { - Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); - Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(threetenTimeout); - Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(threetenTimeout); - Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(javaTimeTimeout); - Truth.assertThat(retrySettings.getTotalTimeout()).isEqualTo(threetenTimeout); - } + Truth.assertThat(retrySettings.getRpcTimeoutMultiplier()).isEqualTo(1); + Truth.assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(timeout); + Truth.assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(timeout); } @Test From aa11c8855650c29acf9605a0119cfd75de1deeef Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 23:18:47 +0000 Subject: [PATCH 058/141] Revert "adapt tests of ThresholdBatcher" This reverts commit 4fd48d4e699fb893d350c611d2779f38e9efb44b. --- .../api/gax/grpc/GrpcCallContextTest.java | 24 ++++++++----- .../InstantiatingGrpcChannelProviderTest.java | 34 ++++++++----------- .../api/gax/httpjson/HttpJsonCallOptions.java | 3 +- .../gax/httpjson/HttpJsonClientCallImpl.java | 1 + .../api/gax/httpjson/HttpRequestRunnable.java | 1 + ...aluesWithDeprecatedThreetenValuesTest.java | 1 + .../gax/httpjson/HttpJsonCallContextTest.java | 24 ++++++++----- .../httpjson/HttpJsonClientCallImplTest.java | 4 +-- .../api/gax/batching/ThresholdBatcher.java | 8 ++--- .../gax/batching/ThresholdBatcherTest.java | 27 ++++++++++----- .../api/gax/util/TimeConversionTestUtils.java | 26 +++++--------- 11 files changed, 81 insertions(+), 72 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 5e22f0b547..5e6f419f78 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -130,11 +130,14 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { + final long millis = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( - 123l, - javaTimeTimeout -> context.withTimeout(javaTimeTimeout), - threetenTimeout -> context.withTimeout(threetenTimeout), + millis, + () -> context.withTimeout(javaTimeTimeout), + () -> context.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @@ -213,11 +216,14 @@ public void testMergeWithTimeout() { @Test public void testWithStreamingWaitTimeout() { + final long millis = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( - 123l, - javaTimeTimeout -> context.withStreamWaitTimeout(javaTimeTimeout), - threetenTimeout -> context.withStreamWaitTimeout(threetenTimeout), + millis, + () -> context.withStreamWaitTimeout(javaTimeTimeout), + () -> context.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -260,11 +266,13 @@ public void testMergeWithStreamingWaitTimeout() { @Test public void testWithStreamingIdleTimeout() { final long millis = 15; + java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - javaTimeTimeout -> context.withStreamIdleTimeout(javaTimeTimeout), - threetenTimeout -> context.withStreamIdleTimeout(threetenTimeout), + () -> context.withStreamIdleTimeout(javaTimeTimeout), + () -> context.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 59aaf8c72b..011b5172e0 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -42,6 +42,7 @@ import com.google.api.gax.rpc.mtls.MtlsProvider; import com.google.auth.oauth2.CloudShellCredentials; import com.google.auth.oauth2.ComputeEngineCredentials; +import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.grpc.ManagedChannel; @@ -57,7 +58,6 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.function.Function; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.stream.Collectors; @@ -96,21 +96,25 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { final long millis = 15; + java.time.Duration javaTimeKeepAliveTime = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenKeepAliveTime = org.threeten.bp.Duration.ofMillis(millis); + java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofMillis(millis); boolean keepaliveWithoutCalls = true; InstantiatingGrpcChannelProvider.Builder builder = InstantiatingGrpcChannelProvider.newBuilder(); - Function javaTimeProviderSupplier = - javaTimeValue -> + Supplier javaTimeProviderSupplier = + () -> builder - .setKeepAliveTime(javaTimeValue) - .setKeepAliveTimeout(javaTimeValue) + .setKeepAliveTime(javaTimeKeepAliveTime) + .setKeepAliveTimeout(javaTimeKeepAliveTimeout) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); - Function threetenProviderSupplier = - threetenValue -> + Supplier threetenProviderSupplier = + () -> builder - .setKeepAliveTime(threetenValue) - .setKeepAliveTimeout(threetenValue) + .setKeepAliveTime(threetenKeepAliveTime) + .setKeepAliveTimeout(threetenKeepAliveTimeout) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); testDurationMethod( @@ -125,16 +129,8 @@ public void testKeepAlive() { threetenProviderSupplier, c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); - assertEquals( - true, - javaTimeProviderSupplier - .apply(java.time.Duration.ofMillis(millis)) - .getKeepAliveWithoutCalls()); - assertEquals( - true, - threetenProviderSupplier - .apply(org.threeten.bp.Duration.ofMillis(millis)) - .getKeepAliveWithoutCalls()); + assertEquals(true, javaTimeProviderSupplier.get().getKeepAliveWithoutCalls()); + assertEquals(true, threetenProviderSupplier.get().getKeepAliveWithoutCalls()); } @Test diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index 43ac4315ab..cfef3cc6d7 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -94,8 +94,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { } if (inputOptions.getTimeout() != null) { - java.time.Duration newTimeout = - java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); + java.time.Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); if (newTimeout != null) { builder.setTimeout(newTimeout); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java index df9a507519..ddbb0dd970 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java @@ -40,6 +40,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.ArrayDeque; import java.util.Queue; import java.util.concurrent.CancellationException; diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index 2738844bd0..9b72d6cb6a 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -52,6 +52,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.List; import java.util.Map; import java.util.Map.Entry; diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java index 1c91860c4c..8d9056cedc 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java @@ -14,4 +14,5 @@ public void testAutoValueClassesWithThreetenMethods() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { new AutoValuesWithDeprecatedThreetenFieldsTest().testAutoValueClassesWithThreetenMethods(); } + } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 3fa23a849c..689a9d5bf2 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -118,11 +118,13 @@ public void testMergeWrongType() { @Test public void testStreamIdleTimeout() { final long millis = 3; + final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - javaTimeTimeout -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), - threetenTimeout -> defaultContext.withStreamIdleTimeout(threetenTimeout), + () -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), + () -> defaultContext.withStreamIdleTimeout(threetenTimeout), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } @@ -130,11 +132,13 @@ public void testStreamIdleTimeout() { @Test public void testStreamWaitTimeout() { final long millis = 3; + final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - javaTimeTimeout -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), - threetenTimeout -> defaultContext.withStreamWaitTimeout(threetenTimeout), + () -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), + () -> defaultContext.withStreamWaitTimeout(threetenTimeout), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -142,22 +146,26 @@ public void testStreamWaitTimeout() { @Test public void testTimeout() { final long millis = 3; + final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); + final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - javaTimeTimeout -> defaultContext.withTimeout(javaTimeTimeout), - threetenTimeout -> defaultContext.withTimeout(threetenTimeout), + () -> defaultContext.withTimeout(javaTimeTimeout), + () -> defaultContext.withTimeout(threetenTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @Test public void testNullTimeout() { + final java.time.Duration javaTimeTimeout = null; + final org.threeten.bp.Duration threetenTimeout = null; final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( null, - javaTimeTimeout -> defaultContext.withTimeout(javaTimeTimeout), - threetenTimeout -> defaultContext.withTimeout(threetenTimeout), + () -> defaultContext.withTimeout(javaTimeTimeout), + () -> defaultContext.withTimeout(javaTimeTimeout), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java index 7ba471ca6b..d9c8a74694 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java @@ -35,6 +35,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Reader; +import java.time.Duration; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -93,8 +94,7 @@ public void responseReceived_cancellationTaskExists_isCancelledProperly() deadlineSchedulerExecutor.setRemoveOnCancelPolicy(true); // Setting a timeout for this call will enqueue a timeout task - Mockito.when(httpJsonCallOptions.getTimeout()) - .thenReturn(org.threeten.bp.Duration.ofMinutes(10)); + Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(org.threeten.bp.Duration.ofMinutes(10)); String response = "Content"; InputStream inputStream = new ByteArrayInputStream(response.getBytes()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 235c80ac9b..1951f1d7c1 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -30,7 +30,6 @@ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.api.core.ApiFunction; @@ -102,14 +101,11 @@ private ThresholdBatcher(Builder builder) { resetThresholds(); } - public java.time.Duration getMaxDelayDuration() { + @VisibleForTesting + public java.time.Duration getMaxDelay() { return this.maxDelay; } - public org.threeten.bp.Duration getMaxDelay() { - return toThreetenDuration(this.maxDelay); - } - /** Builder for a ThresholdBatcher. */ public static class Builder { private Collection> thresholds; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 3d8af6833e..73e4f13fc3 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -29,12 +29,12 @@ */ package com.google.api.gax.batching; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -359,15 +359,24 @@ public void testBatchingFailedRPC() throws Exception { } @Test - public void testMaxDelay() { + public void testTimeObjectsEquivalence() throws NoSuchMethodException { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); - ThresholdBatcher.Builder builder = createSimpleBatcherBuidler(receiver); - testDurationMethod( - 123l, - jt -> builder.setMaxDelay(jt).build(), - tt -> builder.setMaxDelay(tt).build(), - c -> c.getMaxDelayDuration(), - c -> c.getMaxDelay()); + Method build = ThresholdBatcher.Builder.class.getMethod("build"); + Method getMaxDelay = ThresholdBatcher.class.getMethod("getMaxDelay"); + + // TimeConversionTestUtils.testDurationGetterAndSetter( + // java.time.Duration.ofNanos(123l), + // createSimpleBatcherBuidler(receiver), + // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", java.time.Duration.class), + // build, + // getMaxDelay); + // + // TimeConversionTestUtils.testDurationGetterAndSetter( + // org.threeten.bp.Duration.ofNanos(123l), + // createSimpleBatcherBuidler(receiver), + // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", org.threeten.bp.Duration.class), + // build, + // getMaxDelay); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index be14e13a6f..77f76aad88 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -33,22 +33,20 @@ import static org.junit.Assert.assertNull; import java.util.function.Function; +import java.util.function.Supplier; public class TimeConversionTestUtils { public static void testInstantMethod( Long testValue, - Function javaTimeTargetSupplier, - Function threetenTargetSupplier, + Supplier javaTimeTargetSupplier, + Supplier threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { - java.time.Instant testJavaTimeValue = java.time.Instant.ofEpochMilli(testValue); - org.threeten.bp.Instant testThreetenValue = org.threeten.bp.Instant.ofEpochMilli(testValue); Function javaTimeTester = value -> value.toEpochMilli(); Function threetenTester = value -> value.toEpochMilli(); testTimeObjectMethod( testValue, - testJavaTimeValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, @@ -56,7 +54,6 @@ public static void testInstantMethod( threetenTester); testTimeObjectMethod( testValue, - testThreetenValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, @@ -66,19 +63,14 @@ public static void testInstantMethod( public static void testDurationMethod( Long testValue, - Function javaTimeTargetSupplier, - Function threetenTargetSupplier, + Supplier javaTimeTargetSupplier, + Supplier threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { - java.time.Duration testJavaTimeValue = - testValue == null ? null : java.time.Duration.ofMillis(testValue); - org.threeten.bp.Duration testThreetenValue = - testValue == null ? null : org.threeten.bp.Duration.ofMillis(testValue); Function javaTimeTester = value -> value.toMillis(); Function threetenTester = value -> value.toMillis(); testTimeObjectMethod( testValue, - testJavaTimeValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, @@ -86,7 +78,6 @@ public static void testDurationMethod( threetenTester); testTimeObjectMethod( testValue, - testThreetenValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, @@ -94,15 +85,14 @@ public static void testDurationMethod( threetenTester); } - private static void testTimeObjectMethod( + private static void testTimeObjectMethod( Long testValue, - ForSupplier supplierValue, - Function targetSupplier, + Supplier targetSupplier, Function javaTimeGetter, Function threetenGetter, Function javaTimeTester, Function threetenTester) { - Target target = targetSupplier.apply(supplierValue); + Target target = targetSupplier.get(); JavaTime javaTimeValue = javaTimeGetter.apply(target); Threeten threetenValue = threetenGetter.apply(target); if (testValue == null) { From 203960a4444bb9980adeac5d8307f23fb28995ea Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 23:18:47 +0000 Subject: [PATCH 059/141] Revert "add reflection test for httpjson" This reverts commit 16fa545ddaaf58c5a1bf238afad2767d40326070. --- gax-java/gax-httpjson/pom.xml | 5 -- .../api/gax/httpjson/HttpJsonCallOptions.java | 30 ++--------- .../gax/httpjson/HttpJsonClientCallImpl.java | 2 +- .../api/gax/httpjson/HttpRequestRunnable.java | 2 +- ...aluesWithDeprecatedThreetenValuesTest.java | 18 ------- .../gax/httpjson/HttpJsonCallOptionsTest.java | 51 +++++++++++++++++++ .../httpjson/HttpJsonClientCallImplTest.java | 4 +- 7 files changed, 59 insertions(+), 53 deletions(-) delete mode 100644 gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java create mode 100644 gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java diff --git a/gax-java/gax-httpjson/pom.xml b/gax-java/gax-httpjson/pom.xml index 639764a99b..ff8930f609 100644 --- a/gax-java/gax-httpjson/pom.xml +++ b/gax-java/gax-httpjson/pom.xml @@ -87,11 +87,6 @@ test testlib - - org.reflections - reflections - test - diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index cfef3cc6d7..d54988bdc9 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -29,17 +29,14 @@ */ package com.google.api.gax.httpjson; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.ObsoleteApi; -import com.google.api.gax.util.ThreetenFieldUpgrade; -import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; +import java.time.Duration; import javax.annotation.Nullable; /** Options for an http-json call, including deadline and credentials. */ @@ -48,23 +45,13 @@ public abstract class HttpJsonCallOptions { public static final HttpJsonCallOptions DEFAULT = newBuilder().build(); @Nullable - @ObsoleteApi("Use getTimeoutDuration() instead") - @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.THREETEN_GETTER) - public abstract org.threeten.bp.Duration getTimeout(); - - @Nullable - @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.JAVA_TIME_GETTER) - public final java.time.Duration getTimeoutDuration() { - return toJavaTimeDuration(getTimeout()); - } + public abstract Duration getTimeout(); @Nullable @ObsoleteApi("Use getDeadlineInstant() instead") - @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Instant getDeadline(); @Nullable - @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Instant getDeadlineInstant() { return toJavaTimeInstant(getDeadline()); } @@ -94,7 +81,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { } if (inputOptions.getTimeout() != null) { - java.time.Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); + Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); if (newTimeout != null) { builder.setTimeout(newTimeout); } @@ -115,21 +102,12 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { @AutoValue.Builder public abstract static class Builder { - @ObsoleteApi("Use setTimeout(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.THREETEN_SETTER) - public abstract Builder setTimeout(org.threeten.bp.Duration value); - - @ThreetenFieldUpgrade(key = "timeout", role = FieldRole.JAVA_TIME_SETTER) - public Builder setTimeout(java.time.Duration value) { - return setTimeout(toThreetenDuration(value)); - } + public abstract Builder setTimeout(java.time.Duration value); /** Backport of {@link #setDeadline(java.time.Instant)} */ @ObsoleteApi("Use setDeadline(java.time.Instant) instead") - @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.THREETEN_SETTER) public abstract Builder setDeadline(org.threeten.bp.Instant value); - @ThreetenFieldUpgrade(key = "deadline", role = FieldRole.JAVA_TIME_SETTER) public final Builder setDeadline(java.time.Instant value) { return setDeadline(toThreetenInstant(value)); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java index ddbb0dd970..4ec7572216 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java @@ -178,7 +178,7 @@ public void start(Listener responseListener, HttpJsonMetadata request // Use the timeout duration value instead of calculating the future Instant // Only schedule the deadline if the RPC timeout has been set in the RetrySettings - java.time.Duration timeout = callOptions.getTimeoutDuration(); + Duration timeout = callOptions.getTimeout(); if (timeout != null) { // The future timeout value is guaranteed to not be a negative value as the // RetryAlgorithm will not retry diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index 9b72d6cb6a..b5597099d2 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -234,7 +234,7 @@ private HttpRequest buildRequest( httpRequest.getHeaders(), "X-HTTP-Method-Override", originalHttpMethod); } - java.time.Duration timeout = httpJsonCallOptions.getTimeoutDuration(); + Duration timeout = httpJsonCallOptions.getTimeout(); if (timeout != null) { long timeoutMs = timeout.toMillis(); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java deleted file mode 100644 index 8d9056cedc..0000000000 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonAutoValuesWithDeprecatedThreetenValuesTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.google.api.gax.httpjson; - -import com.google.api.gax.AutoValuesWithDeprecatedThreetenFieldsTest; -import java.lang.reflect.InvocationTargetException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class HttpJsonAutoValuesWithDeprecatedThreetenValuesTest { - - @Test - public void testAutoValueClassesWithThreetenMethods() - throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { - new AutoValuesWithDeprecatedThreetenFieldsTest().testAutoValueClassesWithThreetenMethods(); - } - -} diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java new file mode 100644 index 0000000000..fd56ec43bf --- /dev/null +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.gax.httpjson; + +import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; + +import org.junit.Test; + +public class HttpJsonCallOptionsTest { + + @Test + public void testDeadline() { + final long millis = 3; + final java.time.Instant javaTimeDeadline = java.time.Instant.ofEpochMilli(millis); + final org.threeten.bp.Instant threetenDeadline = org.threeten.bp.Instant.ofEpochMilli(millis); + final HttpJsonCallOptions.Builder defaultOptionsBuilder = HttpJsonCallOptions.newBuilder(); + testInstantMethod( + millis, + () -> defaultOptionsBuilder.setDeadline(javaTimeDeadline), + () -> defaultOptionsBuilder.setDeadline(threetenDeadline), + c -> c.build().getDeadlineInstant(), + c -> c.build().getDeadline()); + } +} diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java index d9c8a74694..0355dd0d4b 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java @@ -59,7 +59,7 @@ public class HttpJsonClientCallImplTest { public void responseReceived_noCancellationTask() { ScheduledThreadPoolExecutor deadlineSchedulerExecutor = new ScheduledThreadPoolExecutor(1); // Null timeout means no timeout task created - Mockito.when(httpJsonCallOptions.getTimeoutDuration()).thenReturn(null); + Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(null); HttpJsonClientCallImpl httpJsonClientCall = new HttpJsonClientCallImpl<>( @@ -94,7 +94,7 @@ public void responseReceived_cancellationTaskExists_isCancelledProperly() deadlineSchedulerExecutor.setRemoveOnCancelPolicy(true); // Setting a timeout for this call will enqueue a timeout task - Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(org.threeten.bp.Duration.ofMinutes(10)); + Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(Duration.ofMinutes(10)); String response = "Content"; InputStream inputStream = new ByteArrayInputStream(response.getBytes()); From 5c0702181062dd7a33844e7d4de56ad5940df4c7 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 23:19:42 +0000 Subject: [PATCH 060/141] Revert "add annotation based test for autovalue classes" This reverts commit c3bc83f2a571d43e7dc0d80bbe70358ec4b91c7c. --- gax-java/gax/pom.xml | 5 - .../api/gax/batching/BatchingSettings.java | 6 - .../api/gax/util/ThreetenFieldUpgrade.java | 25 -- ...aluesWithDeprecatedThreetenFieldsTest.java | 249 ------------------ gax-java/pom.xml | 5 - 5 files changed, 290 deletions(-) delete mode 100644 gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java delete mode 100644 gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 22e14d5780..07fb0d7006 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -62,11 +62,6 @@ opentelemetry-api true - - org.reflections - reflections - test - diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 76a356f2dc..216c521aff 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -34,8 +34,6 @@ import com.google.api.core.ObsoleteApi; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; -import com.google.api.gax.util.ThreetenFieldUpgrade; -import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import javax.annotation.Nullable; @@ -106,12 +104,10 @@ public abstract class BatchingSettings { /** Get the delay threshold to use for batching. */ @Nullable @ObsoleteApi("Use getDelayThresholdDuration() instead") - @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.THREETEN_GETTER) public abstract org.threeten.bp.Duration getDelayThreshold(); /** Get the delay threshold to use for batching. */ @Nullable - @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.JAVA_TIME_GETTER) public final java.time.Duration getDelayThresholdDuration() { return toJavaTimeDuration(getDelayThreshold()); } @@ -158,7 +154,6 @@ public abstract static class Builder { /** Backport of {@link #setDelayThreshold(java.time.Duration)} */ @ObsoleteApi("Use setDelayThreshold(java.time.Duration) instead") - @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.THREETEN_SETTER) public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); /** @@ -167,7 +162,6 @@ public abstract static class Builder { * value should not be set too high, usually on the order of milliseconds. Otherwise, calls * might appear to never complete. */ - @ThreetenFieldUpgrade(key = "delayThreshold", role = FieldRole.JAVA_TIME_SETTER) public final Builder setDelayThreshold(java.time.Duration delayThreshold) { return setDelayThreshold(toThreetenDuration(delayThreshold)); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java b/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java deleted file mode 100644 index 60ae29997d..0000000000 --- a/gax-java/gax/src/main/java/com/google/api/gax/util/ThreetenFieldUpgrade.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.google.api.gax.util; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation used to mark autovalue class method that refer to a deprecated threeten field Used in - * testing - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ThreetenFieldUpgrade { - enum FieldRole { - JAVA_TIME_GETTER, - THREETEN_GETTER, - JAVA_TIME_SETTER, - THREETEN_SETTER - } - - FieldRole role(); - - String key(); -} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java deleted file mode 100644 index 886c945d2c..0000000000 --- a/gax-java/gax/src/test/java/com/google/api/gax/AutoValuesWithDeprecatedThreetenFieldsTest.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.google.api.gax; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.google.api.gax.util.ThreetenFieldUpgrade; -import com.google.api.gax.util.ThreetenFieldUpgrade.FieldRole; -import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableList; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.logging.Logger; -import javax.annotation.Generated; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.reflections.Reflections; - -@RunWith(JUnit4.class) -public class AutoValuesWithDeprecatedThreetenFieldsTest { - - private static final Logger logger = - Logger.getLogger(AutoValuesWithDeprecatedThreetenFieldsTest.class.getSimpleName()); - - @Test - public void testAutoValueClassesWithThreetenMethods() - throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { - List> targetClasses = getAutoValueClassesWithThreetenMethods(); - for (Class c : targetClasses) { - testAutoValueClassWithThreetenMethods(c); - } - } - - private void testAutoValueClassWithThreetenMethods(Class autoValueClass) - throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { - logger.info(String.format("Testing threeten methods for class %s", autoValueClass.getName())); - - // We first group the methods by key. Each key should contain four methods corresponding to a - // type declared in the ThreetenFieldUpgrade.FieldRole enum. - Map> methodGroups = new HashMap<>(); - - // The FieldRole.JAVA_TIME_GETTER and FieldRole.THREETEN_GETTER methods are found in the main - // abstract class. This loop searchs for them. - for (Method m : autoValueClass.getDeclaredMethods()) { - addToMethodGroupIfHasThreetenFieldUpgrateAnnotation(methodGroups, m); - } - - // The FieldRole.JAVA_TIME_SETTER and FieldRole.THREETEN_SETTER methods are found in the builder - // nested class. - // We first obtain the Builder class - Class builderClass = - Arrays.stream(autoValueClass.getDeclaredClasses()) - .filter(b -> b.getSimpleName().contains("Builder")) - .findFirst() - .orElseThrow( - () -> - new IllegalStateException( - String.format( - "Failed to find Builder class for AutoValue class %s", - autoValueClass.getName()))); - - // Then we loop over the methods to group the methods annotated with ThreetenFieldUpgrade - for (Method m : builderClass.getDeclaredMethods()) { - addToMethodGroupIfHasThreetenFieldUpgrateAnnotation(methodGroups, m); - } - - assertFalse("No method groups could be constructed", methodGroups.isEmpty()); - - // Now, we confirm each method group is complete, sane, and we confirm its behavior by testing - // the getters and setters - for (Entry> methodGroup : methodGroups.entrySet()) { - String groupName = methodGroup.getKey(); - logger.info(String.format("Organizing methods for group '%s'", groupName)); - Map organizedMethods = - organizeMethods(groupName, methodGroup.getValue()); - logger.info(String.format("Confirming structure of method group '%s", groupName)); - confirmGetterAndSetterStructure(organizedMethods); - logger.info(String.format("Confirming behavior of method group '%s", groupName)); - confirmGetterAndSetterBehavior(organizedMethods, autoValueClass, builderClass); - } - } - - private void confirmGetterAndSetterBehavior( - Map organizedMethods, Class autoValueClass, Class builderClass) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); - Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); - Method javaTimeSetter = organizedMethods.get(FieldRole.JAVA_TIME_SETTER); - Method threetenSetter = organizedMethods.get(FieldRole.THREETEN_SETTER); - final long testValue = 123l; - // We use the java.time getter's return type to identify which time class (Duration or Instant) - // we are dealing with. At this point we already ensured consistency of return and parameter - // types - boolean isDuration = javaTimeGetter.getReturnType().equals(java.time.Duration.class); - final Object testJavaTimeObjectValue = - isDuration - ? java.time.Duration.ofMillis(testValue) - : java.time.Instant.ofEpochMilli(testValue); - final Object testThreetenObjectValue = - isDuration - ? org.threeten.bp.Duration.ofMillis(testValue) - : org.threeten.bp.Instant.ofEpochMilli(testValue); - - confirmGetterAndSetterBehaviorUsingSingleSetter( - javaTimeGetter, - threetenGetter, - javaTimeSetter, - autoValueClass, - builderClass, - testJavaTimeObjectValue, - testJavaTimeObjectValue, - testThreetenObjectValue); - confirmGetterAndSetterBehaviorUsingSingleSetter( - javaTimeGetter, - threetenGetter, - threetenSetter, - autoValueClass, - builderClass, - testThreetenObjectValue, - testJavaTimeObjectValue, - testThreetenObjectValue); - } - - private void confirmGetterAndSetterBehaviorUsingSingleSetter( - Method javaTimeGetter, - Method threetenGetter, - Method setter, - Class autoValueClass, - Class builderClass, - Object testSetterValue, - Object testJavaTimeObjectValue, - Object testThreetenObjectValue) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Object builder = autoValueClass.getDeclaredMethod("newBuilder").invoke(autoValueClass); - setter.invoke(builder, testSetterValue); - Object builtObject = builderClass.getMethod("build").invoke(builder); - assertEquals(testJavaTimeObjectValue, javaTimeGetter.invoke(builtObject)); - assertEquals(testThreetenObjectValue, threetenGetter.invoke(builtObject)); - } - - private void confirmGetterAndSetterStructure(Map organizedMethods) { - Method javaTimeGetter = organizedMethods.get(FieldRole.JAVA_TIME_GETTER); - Method threetenGetter = organizedMethods.get(FieldRole.THREETEN_GETTER); - Method javaTimeSetter = organizedMethods.get(FieldRole.JAVA_TIME_SETTER); - Method threetenSetter = organizedMethods.get(FieldRole.THREETEN_SETTER); - // We will inspect the java.time getter to see if we are dealing with Duration or Instant and - // will use this info to confirm consistency among the methods - Class javaTimeGetterReturnType = javaTimeGetter.getReturnType(); - assertTrue( - "The java.time getter should return either java.time.Duration or java.time.Instant", - ImmutableList.of("java.time.Duration", "java.time.Instant") - .contains(javaTimeGetterReturnType.getName())); - - // We will use the following variable to ensure that the rest of the methods are either Duration - // or Instant, depending on what we found about the java.time getter - String commonReturnTypeName = javaTimeGetterReturnType.getSimpleName(); - - assertEquals( - String.format("The threeten getter should return org.threeten.%s", commonReturnTypeName), - String.format("org.threeten.bp.%s", commonReturnTypeName), - threetenGetter.getReturnType().getName()); - assertEquals( - "AutoValue getters should have no parameters", 0, javaTimeGetter.getParameterCount()); - assertEquals( - "AutoValue getters should have no parameters", 0, threetenGetter.getParameterCount()); - assertEquals( - String.format( - "The java.time getter should be named the same as the threeten getter plus the %s suffix", - commonReturnTypeName), - threetenGetter.getName().concat(commonReturnTypeName), - javaTimeGetter.getName()); - - // now we confirm the setter structure - assertEquals( - "Setters should have the same name", javaTimeSetter.getName(), threetenSetter.getName()); - assertEquals("Setters should have a single parameter", 1, javaTimeSetter.getParameterCount()); - assertEquals("Setters should have a single parameter", 1, threetenSetter.getParameterCount()); - assertEquals( - String.format( - "The java.time setter should take a java.time.%s parameter", commonReturnTypeName), - "java.time.".concat(commonReturnTypeName), - javaTimeSetter.getParameterTypes()[0].getName()); - assertEquals( - String.format( - "The threeten setter should take a org.threeten.bp.%s parameter", commonReturnTypeName), - "org.threeten.bp.".concat(commonReturnTypeName), - threetenSetter.getParameterTypes()[0].getName()); - } - - private void addToMethodGroupIfHasThreetenFieldUpgrateAnnotation( - Map> storage, Method m) { - if (!m.isAnnotationPresent(ThreetenFieldUpgrade.class)) { - return; - } - ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); - if (!storage.containsKey(annotation.key())) { - storage.put(annotation.key(), new ArrayList<>()); - } - storage.get(annotation.key()).add(m); - } - - private Map organizeMethods( - String groupName, List methods) { - Map result = new HashMap<>(); - for (Method m : methods) { - ThreetenFieldUpgrade annotation = m.getAnnotation(ThreetenFieldUpgrade.class); - assertFalse( - String.format( - "Method group %s has two or more methods with the %s FieldRole", - groupName, annotation.role()), - result.containsKey(annotation.role())); - result.put(annotation.role(), m); - } - assertEquals( - String.format("Method group %s does not contain all FieldRoles", groupName), - 4, - result.size()); - return result; - } - - private List> getAutoValueClassesWithThreetenMethods() { - Reflections reflections = new Reflections("com.google.api.gax"); - Set> allAutoValues = reflections.getTypesAnnotatedWith(AutoValue.class); - List> result = new ArrayList<>(); - for (Class c : allAutoValues) { - // we don't want generated AutoValue_.* classes - boolean isAutoGenerated = - c.isAnnotationPresent(Generated.class) || c.getSimpleName().startsWith("AutoValue_"); - if (isAutoGenerated) { - continue; - } - List methods = Arrays.asList(c.getDeclaredMethods()); - boolean hasThreetenAnnotatedMethods = - methods.stream().anyMatch(m -> m.isAnnotationPresent(ThreetenFieldUpgrade.class)); - if (hasThreetenAnnotatedMethods) { - result.add(c); - } - } - return result; - } -} diff --git a/gax-java/pom.xml b/gax-java/pom.xml index b5178b9bdf..5966898fc4 100644 --- a/gax-java/pom.xml +++ b/gax-java/pom.xml @@ -165,11 +165,6 @@ pom import - - org.reflections - reflections - 0.10.2 - From 6c15c4ce651428e1bcab1e8d24da5dfc72450162 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 6 May 2024 23:46:19 +0000 Subject: [PATCH 061/141] simplify test helpers --- .../api/gax/grpc/GrpcCallContextTest.java | 18 ++++------ .../InstantiatingGrpcChannelProviderTest.java | 34 ++++++++++--------- .../gax/httpjson/HttpJsonCallContextTest.java | 24 +++++-------- .../gax/httpjson/HttpJsonCallOptionsTest.java | 6 ++-- .../api/gax/util/TimeConversionTestUtils.java | 28 +++++++++++---- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 5e6f419f78..766b7da669 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -131,13 +131,11 @@ public void testWithRequestParamsDynamicHeaderOption() { @Test public void testWithTimeout() { final long millis = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - () -> context.withTimeout(javaTimeTimeout), - () -> context.withTimeout(threetenTimeout), + jt -> context.withTimeout(jt), + tt -> context.withTimeout(tt), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @@ -217,13 +215,11 @@ public void testMergeWithTimeout() { @Test public void testWithStreamingWaitTimeout() { final long millis = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - () -> context.withStreamWaitTimeout(javaTimeTimeout), - () -> context.withStreamWaitTimeout(threetenTimeout), + jt -> context.withStreamWaitTimeout(jt), + tt -> context.withStreamWaitTimeout(tt), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -266,13 +262,11 @@ public void testMergeWithStreamingWaitTimeout() { @Test public void testWithStreamingIdleTimeout() { final long millis = 15; - java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - () -> context.withStreamIdleTimeout(javaTimeTimeout), - () -> context.withStreamIdleTimeout(threetenTimeout), + jt -> context.withStreamIdleTimeout(jt), + tt -> context.withStreamIdleTimeout(tt), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 011b5172e0..963d4c06e2 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -50,6 +50,7 @@ import io.grpc.alts.ComputeEngineChannelBuilder; import java.io.IOException; import java.security.GeneralSecurityException; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -58,6 +59,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.function.Function; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.stream.Collectors; @@ -96,25 +98,21 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { final long millis = 15; - java.time.Duration javaTimeKeepAliveTime = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenKeepAliveTime = org.threeten.bp.Duration.ofMillis(millis); - java.time.Duration javaTimeKeepAliveTimeout = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration threetenKeepAliveTimeout = org.threeten.bp.Duration.ofMillis(millis); boolean keepaliveWithoutCalls = true; InstantiatingGrpcChannelProvider.Builder builder = InstantiatingGrpcChannelProvider.newBuilder(); - Supplier javaTimeProviderSupplier = - () -> + Function javaTimeProviderSupplier = + jt -> builder - .setKeepAliveTime(javaTimeKeepAliveTime) - .setKeepAliveTimeout(javaTimeKeepAliveTimeout) + .setKeepAliveTime(jt) + .setKeepAliveTimeout(jt) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); - Supplier threetenProviderSupplier = - () -> + Function threetenProviderSupplier = + tt -> builder - .setKeepAliveTime(threetenKeepAliveTime) - .setKeepAliveTimeout(threetenKeepAliveTimeout) + .setKeepAliveTime(tt) + .setKeepAliveTimeout(tt) .setKeepAliveWithoutCalls(keepaliveWithoutCalls) .build(); testDurationMethod( @@ -129,8 +127,10 @@ public void testKeepAlive() { threetenProviderSupplier, c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); - assertEquals(true, javaTimeProviderSupplier.get().getKeepAliveWithoutCalls()); - assertEquals(true, threetenProviderSupplier.get().getKeepAliveWithoutCalls()); + assertEquals(true, javaTimeProviderSupplier.apply(java.time.Duration.ofMillis(millis)) + .getKeepAliveWithoutCalls()); + assertEquals(true, threetenProviderSupplier.apply(org.threeten.bp.Duration.ofMillis(millis)) + .getKeepAliveWithoutCalls()); } @Test @@ -651,10 +651,12 @@ public void publish(LogRecord record) { } @Override - public void flush() {} + public void flush() { + } @Override - public void close() throws SecurityException {} + public void close() throws SecurityException { + } List getAllMessages() { return records.stream().map(LogRecord::getMessage).collect(Collectors.toList()); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 689a9d5bf2..a4dd866a4b 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -118,13 +118,11 @@ public void testMergeWrongType() { @Test public void testStreamIdleTimeout() { final long millis = 3; - final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - () -> defaultContext.withStreamIdleTimeout(javaTimeTimeout), - () -> defaultContext.withStreamIdleTimeout(threetenTimeout), + jt -> defaultContext.withStreamIdleTimeout(jt), + tt -> defaultContext.withStreamIdleTimeout(tt), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); } @@ -132,13 +130,11 @@ public void testStreamIdleTimeout() { @Test public void testStreamWaitTimeout() { final long millis = 3; - final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - () -> defaultContext.withStreamWaitTimeout(javaTimeTimeout), - () -> defaultContext.withStreamWaitTimeout(threetenTimeout), + jt -> defaultContext.withStreamWaitTimeout(jt), + tt -> defaultContext.withStreamWaitTimeout(tt), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); } @@ -146,26 +142,22 @@ public void testStreamWaitTimeout() { @Test public void testTimeout() { final long millis = 3; - final java.time.Duration javaTimeTimeout = java.time.Duration.ofMillis(millis); - final org.threeten.bp.Duration threetenTimeout = org.threeten.bp.Duration.ofMillis(millis); final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - () -> defaultContext.withTimeout(javaTimeTimeout), - () -> defaultContext.withTimeout(threetenTimeout), + jt -> defaultContext.withTimeout(jt), + tt -> defaultContext.withTimeout(tt), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } @Test public void testNullTimeout() { - final java.time.Duration javaTimeTimeout = null; - final org.threeten.bp.Duration threetenTimeout = null; final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( null, - () -> defaultContext.withTimeout(javaTimeTimeout), - () -> defaultContext.withTimeout(javaTimeTimeout), + jt -> defaultContext.withTimeout(jt), + tt -> defaultContext.withTimeout(tt), c -> c.getTimeoutDuration(), c -> c.getTimeout()); } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java index fd56ec43bf..390646dacb 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -38,13 +38,11 @@ public class HttpJsonCallOptionsTest { @Test public void testDeadline() { final long millis = 3; - final java.time.Instant javaTimeDeadline = java.time.Instant.ofEpochMilli(millis); - final org.threeten.bp.Instant threetenDeadline = org.threeten.bp.Instant.ofEpochMilli(millis); final HttpJsonCallOptions.Builder defaultOptionsBuilder = HttpJsonCallOptions.newBuilder(); testInstantMethod( millis, - () -> defaultOptionsBuilder.setDeadline(javaTimeDeadline), - () -> defaultOptionsBuilder.setDeadline(threetenDeadline), + jt -> defaultOptionsBuilder.setDeadline(jt), + tt -> defaultOptionsBuilder.setDeadline(tt), c -> c.build().getDeadlineInstant(), c -> c.build().getDeadline()); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index 77f76aad88..487f8b65ae 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -32,6 +32,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; @@ -39,14 +40,19 @@ public class TimeConversionTestUtils { public static void testInstantMethod( Long testValue, - Supplier javaTimeTargetSupplier, - Supplier threetenTargetSupplier, + Function javaTimeTargetSupplier, + Function threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { Function javaTimeTester = value -> value.toEpochMilli(); Function threetenTester = value -> value.toEpochMilli(); + java.time.Instant javaTimeSupplierValue = + testValue == null ? null : java.time.Instant.ofEpochMilli(testValue); + org.threeten.bp.Instant threetenSupplierValue = + testValue == null ? null : org.threeten.bp.Instant.ofEpochMilli(testValue); testTimeObjectMethod( testValue, + javaTimeSupplierValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, @@ -54,6 +60,7 @@ public static void testInstantMethod( threetenTester); testTimeObjectMethod( testValue, + threetenSupplierValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, @@ -63,14 +70,19 @@ public static void testInstantMethod( public static void testDurationMethod( Long testValue, - Supplier javaTimeTargetSupplier, - Supplier threetenTargetSupplier, + Function javaTimeTargetSupplier, + Function threetenTargetSupplier, Function javaTimeGetter, Function threetenGetter) { Function javaTimeTester = value -> value.toMillis(); Function threetenTester = value -> value.toMillis(); + java.time.Duration javaTimeSupplierValue = + testValue == null ? null : java.time.Duration.ofMillis(testValue); + org.threeten.bp.Duration threetenSupplierValue = + testValue == null ? null : org.threeten.bp.Duration.ofMillis(testValue); testTimeObjectMethod( testValue, + javaTimeSupplierValue, javaTimeTargetSupplier, javaTimeGetter, threetenGetter, @@ -78,6 +90,7 @@ public static void testDurationMethod( threetenTester); testTimeObjectMethod( testValue, + threetenSupplierValue, threetenTargetSupplier, javaTimeGetter, threetenGetter, @@ -85,14 +98,15 @@ public static void testDurationMethod( threetenTester); } - private static void testTimeObjectMethod( + private static void testTimeObjectMethod( Long testValue, - Supplier targetSupplier, + SupplierType targetSupplierValue, + Function targetSupplier, Function javaTimeGetter, Function threetenGetter, Function javaTimeTester, Function threetenTester) { - Target target = targetSupplier.get(); + Target target = targetSupplier.apply(targetSupplierValue); JavaTime javaTimeValue = javaTimeGetter.apply(target); Threeten threetenValue = threetenGetter.apply(target); if (testValue == null) { From e48decf96582fe1d19536a9879a218ed5fd92c51 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 7 May 2024 16:39:29 +0000 Subject: [PATCH 062/141] add tests for HttpJsonCallOptions --- .../api/gax/httpjson/HttpJsonCallOptions.java | 22 ++++++++++++++----- .../gax/httpjson/HttpJsonClientCallImpl.java | 3 +-- .../api/gax/httpjson/HttpRequestRunnable.java | 2 +- .../gax/httpjson/HttpJsonCallOptionsTest.java | 19 +++++++++++++--- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index d54988bdc9..c07d41cf94 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -29,14 +29,15 @@ */ package com.google.api.gax.httpjson; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.ObsoleteApi; import com.google.auth.Credentials; import com.google.auto.value.AutoValue; import com.google.protobuf.TypeRegistry; -import java.time.Duration; import javax.annotation.Nullable; /** Options for an http-json call, including deadline and credentials. */ @@ -45,7 +46,13 @@ public abstract class HttpJsonCallOptions { public static final HttpJsonCallOptions DEFAULT = newBuilder().build(); @Nullable - public abstract Duration getTimeout(); + @ObsoleteApi("Use getTimeoutDuration() instead") + public abstract org.threeten.bp.Duration getTimeout(); + + @Nullable + public java.time.Duration getTimeoutDuration() { + return toJavaTimeDuration(getTimeout()); + } @Nullable @ObsoleteApi("Use getDeadlineInstant() instead") @@ -75,13 +82,13 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { Builder builder = this.toBuilder(); - org.threeten.bp.Instant newDeadline = inputOptions.getDeadline(); + java.time.Instant newDeadline = inputOptions.getDeadlineInstant(); if (newDeadline != null) { builder.setDeadline(newDeadline); } if (inputOptions.getTimeout() != null) { - Duration newTimeout = java.time.Duration.ofMillis(inputOptions.getTimeout().toMillis()); + java.time.Duration newTimeout = inputOptions.getTimeoutDuration(); if (newTimeout != null) { builder.setTimeout(newTimeout); } @@ -102,7 +109,12 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { @AutoValue.Builder public abstract static class Builder { - public abstract Builder setTimeout(java.time.Duration value); + @ObsoleteApi("Use setTimeout(java.time.Duration) instead") + public abstract Builder setTimeout(org.threeten.bp.Duration value); + + public Builder setTimeout(java.time.Duration value) { + return setTimeout(toThreetenDuration(value)); + } /** Backport of {@link #setDeadline(java.time.Instant)} */ @ObsoleteApi("Use setDeadline(java.time.Instant) instead") diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java index 4ec7572216..df9a507519 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java @@ -40,7 +40,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.ArrayDeque; import java.util.Queue; import java.util.concurrent.CancellationException; @@ -178,7 +177,7 @@ public void start(Listener responseListener, HttpJsonMetadata request // Use the timeout duration value instead of calculating the future Instant // Only schedule the deadline if the RPC timeout has been set in the RetrySettings - Duration timeout = callOptions.getTimeout(); + java.time.Duration timeout = callOptions.getTimeoutDuration(); if (timeout != null) { // The future timeout value is guaranteed to not be a negative value as the // RetryAlgorithm will not retry diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index b5597099d2..9b72d6cb6a 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -234,7 +234,7 @@ private HttpRequest buildRequest( httpRequest.getHeaders(), "X-HTTP-Method-Override", originalHttpMethod); } - Duration timeout = httpJsonCallOptions.getTimeout(); + java.time.Duration timeout = httpJsonCallOptions.getTimeoutDuration(); if (timeout != null) { long timeoutMs = timeout.toMillis(); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java index 390646dacb..e608ca91db 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -29,21 +29,34 @@ */ package com.google.api.gax.httpjson; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; import org.junit.Test; public class HttpJsonCallOptionsTest { + private final HttpJsonCallOptions.Builder OPTIONS_BUILDER = HttpJsonCallOptions.newBuilder(); @Test public void testDeadline() { final long millis = 3; - final HttpJsonCallOptions.Builder defaultOptionsBuilder = HttpJsonCallOptions.newBuilder(); testInstantMethod( millis, - jt -> defaultOptionsBuilder.setDeadline(jt), - tt -> defaultOptionsBuilder.setDeadline(tt), + jt -> OPTIONS_BUILDER.setDeadline(jt), + tt -> OPTIONS_BUILDER.setDeadline(tt), c -> c.build().getDeadlineInstant(), c -> c.build().getDeadline()); } + + @Test + public void testTimeout() { + final long millis = 3; + testDurationMethod( + millis, + jt -> OPTIONS_BUILDER.setTimeout(jt), + tt -> OPTIONS_BUILDER.setTimeout(tt), + c -> c.build().getTimeoutDuration(), + c -> c.build().getTimeout()); + } + } From 7c8a644e4a63d4ed712a939f766bccbe073ca102 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 7 May 2024 16:39:44 +0000 Subject: [PATCH 063/141] add tests for BatchingSettingsTest --- .../gax/batching/BatchingSettingsTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java new file mode 100644 index 0000000000..bded211321 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -0,0 +1,20 @@ +package com.google.api.gax.batching; + +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; + +import org.junit.Test; + +public class BatchingSettingsTest { + + private final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); + + @Test + public void testDelayThreshold() { + testDurationMethod(123l, + jt -> SETTINGS_BUILDER.setDelayThreshold(jt).build(), + tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), + o -> o.getDelayThresholdDuration(), + o -> o.getDelayThreshold() + ); + } +} From 21e42407a93b3d8a72541f3565c70eb7eaec65d6 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 7 May 2024 16:47:03 +0000 Subject: [PATCH 064/141] add test for ThresholdBatcher --- .../api/gax/batching/ThresholdBatcher.java | 8 ++++- .../gax/batching/ThresholdBatcherTest.java | 29 ++++++++----------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 1951f1d7c1..f8a75ed550 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -30,6 +30,7 @@ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.api.core.ApiFunction; @@ -102,7 +103,12 @@ private ThresholdBatcher(Builder builder) { } @VisibleForTesting - public java.time.Duration getMaxDelay() { + org.threeten.bp.Duration getMaxDelay() { + return toThreetenDuration(this.maxDelay); + } + + @VisibleForTesting + java.time.Duration getMaxDelayDuration() { return this.maxDelay; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 73e4f13fc3..ed4b423449 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.batching; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiFutures; @@ -37,6 +38,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledExecutorService; @@ -123,6 +125,7 @@ private List getIntegers() { } private static class SimpleBatchMerger implements BatchMerger { + @Override public void merge(SimpleBatch batch, SimpleBatch newBatch) { batch.merge(newBatch); @@ -359,24 +362,16 @@ public void testBatchingFailedRPC() throws Exception { } @Test - public void testTimeObjectsEquivalence() throws NoSuchMethodException { + public void testMaxDelay() { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); - Method build = ThresholdBatcher.Builder.class.getMethod("build"); - Method getMaxDelay = ThresholdBatcher.class.getMethod("getMaxDelay"); - - // TimeConversionTestUtils.testDurationGetterAndSetter( - // java.time.Duration.ofNanos(123l), - // createSimpleBatcherBuidler(receiver), - // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", java.time.Duration.class), - // build, - // getMaxDelay); - // - // TimeConversionTestUtils.testDurationGetterAndSetter( - // org.threeten.bp.Duration.ofNanos(123l), - // createSimpleBatcherBuidler(receiver), - // ThresholdBatcher.Builder.class.getMethod("setMaxDelay", org.threeten.bp.Duration.class), - // build, - // getMaxDelay); + final ThresholdBatcher.Builder builder = createSimpleBatcherBuidler(receiver) + .setThresholds(Collections.emptyList()); + testDurationMethod(123l, + jt -> builder.setMaxDelay(jt).build(), + tt -> builder.setMaxDelay(tt).build(), + o -> o.getMaxDelayDuration(), + o -> o.getMaxDelay() + ); } } From 8d96c6169b8538e9f87b2e78b7aa353cc5e6b7e8 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 7 May 2024 16:56:08 +0000 Subject: [PATCH 065/141] add tests for retry settings --- .../api/gax/retrying/RetrySettingsTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index 1a437842c6..ad89067b3c 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -29,10 +29,16 @@ */ package com.google.api.gax.retrying; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; + import com.google.common.truth.Truth; import org.junit.Test; public class RetrySettingsTest { + private static final RetrySettings.Builder DEFAULT_BUILDER = + RetrySettings.newBuilder() + .setMaxRpcTimeout(java.time.Duration.ofMillis(5000l)) + .setMaxRetryDelay(java.time.Duration.ofMillis(5000l)); @Test public void retrySettingsSetLogicalTimeout() { @@ -79,4 +85,54 @@ public void retrySettingsMerge() { Truth.assertThat(settingsA.getMaxRetryDelayDuration()) .isEqualTo(settingsB.getMaxRetryDelayDuration()); } + + @Test + public void testTotalTimeout() { + testDurationMethod( + 123l, + jt -> DEFAULT_BUILDER.setTotalTimeout(jt).build(), + tt -> DEFAULT_BUILDER.setTotalTimeout(tt).build(), + rs -> rs.getTotalTimeoutDuration(), + rs -> rs.getTotalTimeout()); + } + + @Test + public void testInitialRetryDelay() { + testDurationMethod( + 123l, + jt -> DEFAULT_BUILDER.setInitialRetryDelay(jt).build(), + tt -> DEFAULT_BUILDER.setInitialRetryDelay(tt).build(), + rs -> rs.getInitialRetryDelayDuration(), + rs -> rs.getInitialRetryDelay()); + } + + @Test + public void testMaxRetryDelay() { + testDurationMethod( + 123l, + jt -> DEFAULT_BUILDER.setMaxRetryDelay(jt).build(), + tt -> DEFAULT_BUILDER.setMaxRetryDelay(tt).build(), + rs -> rs.getMaxRetryDelayDuration(), + rs -> rs.getMaxRetryDelay()); + } + + @Test + public void testInitialRpcTimeout() { + testDurationMethod( + 123l, + jt -> DEFAULT_BUILDER.setInitialRpcTimeout(jt).build(), + tt -> DEFAULT_BUILDER.setInitialRpcTimeout(tt).build(), + rs -> rs.getInitialRpcTimeoutDuration(), + rs -> rs.getInitialRpcTimeout()); + } + + @Test + public void testMaxRpcTimeout() { + testDurationMethod( + 123l, + jt -> DEFAULT_BUILDER.setMaxRpcTimeout(jt).build(), + tt -> DEFAULT_BUILDER.setMaxRpcTimeout(tt).build(), + rs -> rs.getMaxRpcTimeoutDuration(), + rs -> rs.getMaxRpcTimeout()); + } } From eefff2a0584023b3654f2ae671e1332f9abaa013 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 7 May 2024 16:56:16 +0000 Subject: [PATCH 066/141] chore: reformat --- .../InstantiatingGrpcChannelProviderTest.java | 21 +++++++++++-------- .../api/gax/httpjson/HttpRequestRunnable.java | 1 - .../gax/httpjson/HttpJsonCallOptionsTest.java | 1 - .../gax/batching/BatchingSettingsTest.java | 6 +++--- .../gax/batching/ThresholdBatcherTest.java | 11 +++++----- .../api/gax/util/TimeConversionTestUtils.java | 2 -- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 963d4c06e2..f1e8d27582 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -42,7 +42,6 @@ import com.google.api.gax.rpc.mtls.MtlsProvider; import com.google.auth.oauth2.CloudShellCredentials; import com.google.auth.oauth2.ComputeEngineCredentials; -import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.grpc.ManagedChannel; @@ -127,10 +126,16 @@ public void testKeepAlive() { threetenProviderSupplier, c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); - assertEquals(true, javaTimeProviderSupplier.apply(java.time.Duration.ofMillis(millis)) - .getKeepAliveWithoutCalls()); - assertEquals(true, threetenProviderSupplier.apply(org.threeten.bp.Duration.ofMillis(millis)) - .getKeepAliveWithoutCalls()); + assertEquals( + true, + javaTimeProviderSupplier + .apply(java.time.Duration.ofMillis(millis)) + .getKeepAliveWithoutCalls()); + assertEquals( + true, + threetenProviderSupplier + .apply(org.threeten.bp.Duration.ofMillis(millis)) + .getKeepAliveWithoutCalls()); } @Test @@ -651,12 +656,10 @@ public void publish(LogRecord record) { } @Override - public void flush() { - } + public void flush() {} @Override - public void close() throws SecurityException { - } + public void close() throws SecurityException {} List getAllMessages() { return records.stream().map(LogRecord::getMessage).collect(Collectors.toList()); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java index 9b72d6cb6a..2738844bd0 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java @@ -52,7 +52,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.List; import java.util.Map; import java.util.Map.Entry; diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java index e608ca91db..bc6380204f 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -58,5 +58,4 @@ public void testTimeout() { c -> c.build().getTimeoutDuration(), c -> c.build().getTimeout()); } - } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index bded211321..fb894711c2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -10,11 +10,11 @@ public class BatchingSettingsTest { @Test public void testDelayThreshold() { - testDurationMethod(123l, + testDurationMethod( + 123l, jt -> SETTINGS_BUILDER.setDelayThreshold(jt).build(), tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), o -> o.getDelayThresholdDuration(), - o -> o.getDelayThreshold() - ); + o -> o.getDelayThreshold()); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index ed4b423449..2265ca6db1 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -35,7 +35,6 @@ import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -365,13 +364,13 @@ public void testBatchingFailedRPC() throws Exception { public void testMaxDelay() { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); - final ThresholdBatcher.Builder builder = createSimpleBatcherBuidler(receiver) - .setThresholds(Collections.emptyList()); - testDurationMethod(123l, + final ThresholdBatcher.Builder builder = + createSimpleBatcherBuidler(receiver).setThresholds(Collections.emptyList()); + testDurationMethod( + 123l, jt -> builder.setMaxDelay(jt).build(), tt -> builder.setMaxDelay(tt).build(), o -> o.getMaxDelayDuration(), - o -> o.getMaxDelay() - ); + o -> o.getMaxDelay()); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index 487f8b65ae..b097fcbb71 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -32,9 +32,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import java.util.Optional; import java.util.function.Function; -import java.util.function.Supplier; public class TimeConversionTestUtils { From 233ce62c302dab526a9f50c1e3219d9f5095ee35 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 7 May 2024 17:02:10 +0000 Subject: [PATCH 067/141] add tests for TimedAttemptSettings --- .../retrying/TimedAttemptSettingsTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java new file mode 100644 index 0000000000..643ec204b0 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java @@ -0,0 +1,46 @@ +package com.google.api.gax.retrying; + +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; + +import org.junit.Test; + +public class TimedAttemptSettingsTest { + + private static final TimedAttemptSettings.Builder SETTINGS_BUILDER = + TimedAttemptSettings.newBuilder() + .setGlobalSettings(RetrySettings.newBuilder().build()) + .setRpcTimeout(java.time.Duration.ofMillis(5000l)) + .setRandomizedRetryDelay(java.time.Duration.ofMillis(5000l)) + .setAttemptCount(123) + .setFirstAttemptStartTimeNanos(123l); + + @Test + public void testRetryDelay() { + testDurationMethod( + 123l, + jt -> SETTINGS_BUILDER.setRetryDelay(jt).build(), + tt -> SETTINGS_BUILDER.setRetryDelay(tt).build(), + o -> o.getRetryDelayDuration(), + o -> o.getRetryDelay()); + } + + @Test + public void testRandomizedRetryDelay() { + testDurationMethod( + 123l, + jt -> SETTINGS_BUILDER.setRandomizedRetryDelay(jt).build(), + tt -> SETTINGS_BUILDER.setRandomizedRetryDelay(tt).build(), + o -> o.getRandomizedRetryDelayDuration(), + o -> o.getRandomizedRetryDelay()); + } + + @Test + public void testRpcTimeout() { + testDurationMethod( + 123l, + jt -> SETTINGS_BUILDER.setRpcTimeout(jt).build(), + tt -> SETTINGS_BUILDER.setRpcTimeout(tt).build(), + o -> o.getRpcTimeoutDuration(), + o -> o.getRpcTimeout()); + } +} From f55cf096ba56fda68a82d9c9c053355bc972b7c1 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 20:06:49 -0400 Subject: [PATCH 068/141] fix HttpJsonClientCall test --- .../api/gax/httpjson/HttpJsonClientCallImplTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java index 0355dd0d4b..b4da5fa38c 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java @@ -35,7 +35,6 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Reader; -import java.time.Duration; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -60,6 +59,7 @@ public void responseReceived_noCancellationTask() { ScheduledThreadPoolExecutor deadlineSchedulerExecutor = new ScheduledThreadPoolExecutor(1); // Null timeout means no timeout task created Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(null); + Mockito.when(httpJsonCallOptions.getTimeoutDuration()).thenReturn(null); HttpJsonClientCallImpl httpJsonClientCall = new HttpJsonClientCallImpl<>( @@ -94,7 +94,10 @@ public void responseReceived_cancellationTaskExists_isCancelledProperly() deadlineSchedulerExecutor.setRemoveOnCancelPolicy(true); // Setting a timeout for this call will enqueue a timeout task - Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(Duration.ofMinutes(10)); + Mockito.when(httpJsonCallOptions.getTimeout()) + .thenReturn(org.threeten.bp.Duration.ofMinutes(10)); + Mockito.when(httpJsonCallOptions.getTimeoutDuration()) + .thenReturn(java.time.Duration.ofMinutes(10)); String response = "Content"; InputStream inputStream = new ByteArrayInputStream(response.getBytes()); From 6b437c129edb8a6a5579b79c6b5abbef0a6c6bd8 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 20:07:18 -0400 Subject: [PATCH 069/141] add license headers to tests --- .../gax/batching/BatchingSettingsTest.java | 29 +++++++++++++++++++ .../retrying/TimedAttemptSettingsTest.java | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index fb894711c2..0e4504caaf 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -1,3 +1,32 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java index 643ec204b0..b6b57c483d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java @@ -1,3 +1,32 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.google.api.gax.retrying; import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; From 11043d494a686b646d1afb20e354cbf0707d46b5 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 20:34:34 -0400 Subject: [PATCH 070/141] add tests for ClientContext --- .../com/google/api/gax/rpc/ClientContextTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 807a95a5c1..2354937cf5 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -46,6 +47,7 @@ import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.FixedExecutorProvider; import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.rpc.testing.FakeCallContext; import com.google.api.gax.rpc.testing.FakeChannel; import com.google.api.gax.rpc.testing.FakeClientSettings; import com.google.api.gax.rpc.testing.FakeStubSettings; @@ -1065,4 +1067,16 @@ public void testCreateClientContext_setUniverseDomain() throws IOException { ClientContext clientContext = ClientContext.create(clientSettings); assertThat(clientContext.getUniverseDomain()).isEqualTo(universeDomain); } + + @Test + public void testStreamWatchdogInterval_backportMethodsBehaveCorrectly() { + final ClientContext.Builder builder = + ClientContext.newBuilder().setDefaultCallContext(FakeCallContext.createDefault()); + testDurationMethod( + 123L, + jt -> builder.setStreamWatchdogCheckInterval(jt).build(), + tt -> builder.setStreamWatchdogCheckInterval(tt).build(), + ct -> ct.getStreamWatchdogCheckIntervalDuration(), + ct -> ct.getStreamWatchdogCheckInterval()); + } } From d3ebac5c3b777eebd579172cd938a7ab511c83df Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 20:34:44 -0400 Subject: [PATCH 071/141] add tests for ClientSettings --- .../api/gax/rpc/ClientSettingsTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java index c28d20edfc..5afa1e4d2b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static org.junit.Assert.fail; import com.google.api.core.ApiClock; @@ -54,6 +55,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledExecutorService; +import java.util.function.Function; +import java.util.function.Supplier; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -549,4 +552,25 @@ public void testBuilderFromClientContext_QuotaProjectId() { Truth.assertThat(builderQuotaFromAllSources.getQuotaProjectId()) .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT); } + + @Test + public void testWatchdogCheckInterval_backportMethodsBehaveCorrectly() { + final ClientSettings.Builder builder = new FakeClientSettings.Builder(); + // this helper lambda goes around the possible IOException thrown by + // ClientSettings.Builder.build() + final Function, ClientSettings> createClientSettings = + fn -> { + try { + return fn.get().build(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }; + testDurationMethod( + 123l, + jt -> createClientSettings.apply(() -> builder.setWatchdogCheckInterval(jt)), + tt -> createClientSettings.apply(() -> builder.setWatchdogCheckInterval(tt)), + cs -> cs.getWatchdogCheckIntervalDuration(), + cs -> cs.getWatchdogCheckInterval()); + } } From 50b0ffd110e8c883802fdbc61f39465c9cd398e3 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 20:44:46 -0400 Subject: [PATCH 072/141] add tests for FixedWatchdogProvider --- .../api/gax/rpc/FixedWatchdogProviderTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index 88206d9f28..eccad51b61 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -29,7 +29,9 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; import com.google.api.core.ApiClock; import java.util.concurrent.ScheduledExecutorService; @@ -96,4 +98,17 @@ public void testNoModifications() { } assertThat(actualError).isInstanceOf(UnsupportedOperationException.class); } + + @Test + public void testWithCheckInterval_backportMethodsBehaveCorrectly() { + final FixedWatchdogProvider provider = + (FixedWatchdogProvider) FixedWatchdogProvider.create(null); + long millis = 123l; + assertThrows( + UnsupportedOperationException.class, + () -> provider.withCheckInterval(java.time.Duration.ofMillis(millis))); + assertThrows( + UnsupportedOperationException.class, + () -> provider.withCheckInterval(org.threeten.bp.Duration.ofMillis(millis))); + } } From 21c03bd11a3c0f6ca26f1f23a9c4ff74de30baf3 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 20:53:23 -0400 Subject: [PATCH 073/141] fix internal java.time methods in WatchDog related classes --- .../google/api/gax/rpc/FixedWatchdogProvider.java | 7 ------- .../gax/rpc/InstantiatingWatchdogProvider.java | 15 --------------- .../com/google/api/gax/rpc/WatchdogProvider.java | 10 ++-------- .../api/gax/rpc/FixedWatchdogProviderTest.java | 15 --------------- 4 files changed, 2 insertions(+), 45 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java index 3c3e3a27b5..a21a2d61e4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java @@ -31,7 +31,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -70,12 +69,6 @@ public boolean needsCheckInterval() { return false; } - @Override - @ObsoleteApi("Use withCheckInterval(java.time.Duration) instead") - public WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval) { - throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); - } - @Override public WatchdogProvider withCheckInterval(java.time.Duration checkInterval) { throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index d4acdba4f4..6a7f8fc3f4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -29,11 +29,9 @@ */ package com.google.api.gax.rpc; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.common.base.Preconditions; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; @@ -80,19 +78,6 @@ public boolean needsCheckInterval() { return checkInterval == null; } - /** - * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - * - * @param checkInterval - * @return - */ - @Override - @ObsoleteApi("Use withCheckInterval(java.time.Duration) instead") - public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { - return withCheckInterval(toJavaTimeDuration(Preconditions.checkNotNull(checkInterval))); - } - @Override public WatchdogProvider withCheckInterval(@Nonnull java.time.Duration checkInterval) { return new InstantiatingWatchdogProvider( diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index a54ee53114..0951e95f5d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -30,10 +30,11 @@ package com.google.api.gax.rpc; import com.google.api.core.ApiClock; -import com.google.api.core.ObsoleteApi; +import com.google.api.core.InternalApi; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; +@InternalApi public interface WatchdogProvider { boolean needsClock(); @@ -41,13 +42,6 @@ public interface WatchdogProvider { boolean needsCheckInterval(); - /** - * Overload of {@link #withCheckInterval(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ - @ObsoleteApi("Use withCheckInterval(java.time.Duration) instead") - WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); - WatchdogProvider withCheckInterval(java.time.Duration checkInterval); boolean needsExecutor(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index eccad51b61..88206d9f28 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -29,9 +29,7 @@ */ package com.google.api.gax.rpc; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; import com.google.api.core.ApiClock; import java.util.concurrent.ScheduledExecutorService; @@ -98,17 +96,4 @@ public void testNoModifications() { } assertThat(actualError).isInstanceOf(UnsupportedOperationException.class); } - - @Test - public void testWithCheckInterval_backportMethodsBehaveCorrectly() { - final FixedWatchdogProvider provider = - (FixedWatchdogProvider) FixedWatchdogProvider.create(null); - long millis = 123l; - assertThrows( - UnsupportedOperationException.class, - () -> provider.withCheckInterval(java.time.Duration.ofMillis(millis))); - assertThrows( - UnsupportedOperationException.class, - () -> provider.withCheckInterval(org.threeten.bp.Duration.ofMillis(millis))); - } } From 16933f09e601ec32fe60b39c58ae698d6ceaf69c Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 21:03:53 -0400 Subject: [PATCH 074/141] add tests for ServerStreamingCallSettings --- .../rpc/InstantiatingWatchdogProvider.java | 1 - .../rpc/ServerStreamingCallSettingsTest.java | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index 6a7f8fc3f4..94dcd486bb 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.rpc; - import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.common.base.Preconditions; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java index 6856618914..642553edc4 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import com.google.api.gax.retrying.RetrySettings; @@ -151,4 +152,26 @@ public void testToString() { assertThat(serverCallSettings.toString()).contains("retryableCodes=" + retryableCodes); assertThat(serverCallSettings.toString()).contains("retrySettings=" + retrySettings); } + + @Test + public void testIdleTimeout_backportMethodsBehaveCorrectly() { + final ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); + testDurationMethod( + 123l, + jt -> builder.setIdleTimeout(jt).build(), + tt -> builder.setIdleTimeout(tt).build(), + cs -> cs.getIdleTimeoutDuration(), + cs -> cs.getIdleTimeout()); + } + + @Test + public void testWaitTimeout_backportMethodsBehaveCorrectly() { + final ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); + testDurationMethod( + 123l, + jt -> builder.setWaitTimeout(jt).build(), + tt -> builder.setWaitTimeout(tt).build(), + cs -> cs.getWaitTimeoutDuration(), + cs -> cs.getWaitTimeout()); + } } From 33a42bd4ceb828cfb0227ee796025695e45f359a Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 21:16:34 -0400 Subject: [PATCH 075/141] add tests for StubSettings --- .../com/google/api/gax/grpc/SettingsTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index 514838de88..4e7c26aec6 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.grpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static org.junit.Assert.assertEquals; import com.google.api.gax.batching.BatchingSettings; @@ -58,6 +59,9 @@ import com.google.common.collect.Lists; import com.google.common.truth.Truth; import java.io.IOException; +import java.util.function.Function; +import java.util.function.Supplier; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -362,4 +366,22 @@ public void callSettingsBuildFromTimeoutNoRetries() { assertEquals("UnaryCallSettings", settingsA, settingsB); } + + @Test + public void testWatchDogCheckInterval_backportMethodsBehaveCorrectly() { + final Function, StubSettings> build = + createBuilder -> { + try { + return createBuilder.get().build(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }; + testDurationMethod( + 123l, + jt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckInterval(jt)), + tt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckInterval(tt)), + ss -> ss.getStreamWatchdogCheckIntervalDuration(), + ss -> ss.getStreamWatchdogCheckInterval()); + } } From bca50673dc635c67b61273abf4dabcb936f8efd2 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 21:20:19 -0400 Subject: [PATCH 076/141] add test for UnaryCallSettings --- .../com/google/api/gax/rpc/UnaryCallSettingsTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index ce810e273e..c46d143781 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -147,4 +148,14 @@ public void testToString() { assertThat(unaryCallSettings.toString()).contains("retryableCodes=" + retryableCodes); assertThat(unaryCallSettings.toString()).contains("retrySettings=" + retrySettings); } + + @Test + public void testWatchDogCheckInterval_backportMethodsBehaveCorrectly() { + testDurationMethod( + 123l, + jt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(jt).build(), + tt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(tt).build(), + ucs -> ucs.getRetrySettings().getTotalTimeoutDuration(), + ucs -> ucs.getRetrySettings().getTotalTimeout()); + } } From c1b91ee2c8f2fb9c0718423d79b0685590cfb132 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 22:02:01 -0400 Subject: [PATCH 077/141] reformat settings test --- .../src/test/java/com/google/api/gax/grpc/SettingsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index 4e7c26aec6..74065f46b4 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -61,7 +61,6 @@ import java.io.IOException; import java.util.function.Function; import java.util.function.Supplier; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; From 173dc2eb649ea1f11aab26ee4c2b08aa926d5b45 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 22:02:13 -0400 Subject: [PATCH 078/141] add tests in tracing --- .../com/google/api/gax/tracing/ApiTracer.java | 9 +++ .../google/api/gax/tracing/BaseApiTracer.java | 10 +++ .../google/api/gax/tracing/MetricsTracer.java | 10 +++ .../api/gax/tracing/OpencensusTracer.java | 10 +++ .../api/gax/tracing/MetricsTestUtils.java | 20 ++++++ .../api/gax/tracing/MetricsTracerTest.java | 15 +++- .../api/gax/tracing/OpencensusTracerTest.java | 69 ++++++++++++++++--- 7 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index e6c20c40da..8cf3b83819 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -29,7 +29,10 @@ */ package com.google.api.gax.tracing; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; /** * Implementations of this class trace the logical flow of a google cloud client. @@ -107,6 +110,12 @@ default Scope inScope() { /** Add an annotation that the attempt was cancelled by the user. */ default void attemptCancelled() {}; + /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailed(error, toJavaTimeDuration(delay)); + }; + /** * Adds an annotation that the attempt failed, but another attempt will be made after the delay. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index 0495239173..f6c96fd19c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -29,7 +29,10 @@ */ package com.google.api.gax.tracing; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; /** * A base implementation of {@link ApiTracer} that does nothing. With the deprecation of Java 7 @@ -107,6 +110,13 @@ public void attemptFailed(Throwable error, java.time.Duration delay) { // noop } + /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + @Override + @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailed(error, toJavaTimeDuration(delay)); + } + @Override public void attemptFailedRetriesExhausted(Throwable error) { // noop diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java index 91e7d2f03c..19e52d20f3 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java @@ -30,8 +30,11 @@ package com.google.api.gax.tracing; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.StatusCode; import com.google.common.annotations.VisibleForTesting; @@ -176,6 +179,13 @@ public void attemptFailed(Throwable error, java.time.Duration delay) { metricsRecorder.recordAttemptCount(1, attributes); } + /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + @Override + @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailed(error, toJavaTimeDuration(delay)); + } + /** * Adds an annotation that the attempt failed and that no further attempts will be made because * retry limits have been reached. This extracts the error from the throwable and adds it to the diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java index e8bd6c56aa..cf74a122bd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java @@ -29,8 +29,11 @@ */ package com.google.api.gax.tracing; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.StatusCode.Code; @@ -356,6 +359,13 @@ public void attemptFailed(Throwable error, java.time.Duration delay) { lastConnectionId = null; } + /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + @Override + @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailed(error, toJavaTimeDuration(delay)); + } + /** {@inheritDoc} */ @Override public void attemptFailedRetriesExhausted(Throwable error) { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java new file mode 100644 index 0000000000..fa6e09cc99 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java @@ -0,0 +1,20 @@ +package com.google.api.gax.tracing; + +import static org.junit.Assert.fail; + +import java.lang.reflect.Method; + +public class MetricsTestUtils { + public static void reportFailedAttempt(ApiTracer tracer, Exception ex, Object delayValue) { + try { + Method attemptFailed = + tracer + .getClass() + .getDeclaredMethod("attemptFailed", Throwable.class, delayValue.getClass()); + attemptFailed.invoke(tracer, ex, delayValue); + } catch (Exception e) { + fail(); + throw new RuntimeException(e); + } + } +} diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java index 707735b0de..94c844adee 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTracerTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.tracing; +import static com.google.api.gax.tracing.MetricsTestUtils.reportFailedAttempt; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.anyDouble; @@ -136,7 +137,17 @@ public void testAttemptSucceeded_recordsAttributes() { } @Test - public void testAttemptFailed_recordsAttributes() { + public void testAttemptFailed_usingJavaTime_recordsAttributes() { + testAttemptFailed_recordsAttributes(java.time.Duration.ofMillis(2)); + } + + @Test + public void testAttemptFailed_usingThreeten_recordsAttributes() { + testAttemptFailed_recordsAttributes(org.threeten.bp.Duration.ofMillis(2)); + } + + public void testAttemptFailed_recordsAttributes(final Object attemptFailedValue) { + // initialize mock-request Object mockFailedRequest = new Object(); @@ -145,7 +156,7 @@ public void testAttemptFailed_recordsAttributes() { ApiException error0 = new NotFoundException( "invalid argument", null, new FakeStatusCode(Code.INVALID_ARGUMENT), false); - metricsTracer.attemptFailed(error0, java.time.Duration.ofMillis(2)); + reportFailedAttempt(metricsTracer, error0, attemptFailedValue); Map attributes = getAttributes(Code.INVALID_ARGUMENT); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java index 6726f216b9..e3382adf4f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/OpencensusTracerTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.tracing; +import static com.google.api.gax.tracing.MetricsTestUtils.reportFailedAttempt; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.verify; @@ -78,13 +79,22 @@ public void setUp() { } @Test - public void testUnarySuccessExample() { + public void testUnarySuccessExample_javaTime() { + testUnarySuccessExample(java.time.Duration.ofMillis(5)); + } + + @Test + public void testUnarySuccessExample_threeten() { + testUnarySuccessExample(org.threeten.bp.Duration.ofMillis(5)); + } + + public void testUnarySuccessExample(Object attemptFailedValue) { tracer.attemptStarted(0); tracer.connectionSelected("1"); ApiException error0 = new DeadlineExceededException( "deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true); - tracer.attemptFailed(error0, java.time.Duration.ofMillis(5)); + reportFailedAttempt(tracer, error0, attemptFailedValue); tracer.attemptStarted(1); tracer.connectionSelected("2"); @@ -130,12 +140,21 @@ public void testBatchExample() { } @Test - public void testLongRunningExample() { + public void testLongRunningExample_javaTime() { + testLongRunningExample(java.time.Duration.ofMillis(5)); + } + + @Test + public void testLongRunningExample_threeten() { + testLongRunningExample(org.threeten.bp.Duration.ofMillis(5)); + } + + public void testLongRunningExample(Object attemptFailedValue) { tracer = new OpencensusTracer(internalTracer, span, OperationType.LongRunning); // Initial poll of the initial rpc tracer.attemptStarted(0); - tracer.attemptFailed(null, java.time.Duration.ofMillis(5)); + reportFailedAttempt(tracer, null, attemptFailedValue); // Initial rpc finished tracer.lroStartSucceeded(); @@ -254,12 +273,21 @@ public void testFailureExample() { } @Test - public void testResponseCount() { + public void testResponseCount_javaTime() { + testResponseCount(java.time.Duration.ofMillis(5)); + } + + @Test + public void testResponseCount_threeten() { + testResponseCount(java.time.Duration.ofMillis(5)); + } + + public void testResponseCount(Object attemptFailedValue) { // Initial attempt got 2 messages, then failed tracer.attemptStarted(0); tracer.responseReceived(); tracer.responseReceived(); - tracer.attemptFailed(new RuntimeException(), java.time.Duration.ofMillis(1)); + reportFailedAttempt(tracer, new RuntimeException(), attemptFailedValue); // Next attempt got 1 message, then successfully finished the attempt and the logical operation. tracer.attemptStarted(1); @@ -282,12 +310,21 @@ public void testResponseCount() { } @Test - public void testRequestCount() { + public void testRequestCount_javaTime() { + testRequestCount(java.time.Duration.ofMillis(2)); + } + + @Test + public void testRequestCount_threeten() { + testRequestCount(org.threeten.bp.Duration.ofMillis(2)); + } + + public void testRequestCount(Object attemptFailedValue) { // Initial attempt sent 2 messages, then failed tracer.attemptStarted(0); tracer.requestSent(); tracer.requestSent(); - tracer.attemptFailed(new RuntimeException(), java.time.Duration.ofMillis(1)); + reportFailedAttempt(tracer, new RuntimeException(), attemptFailedValue); // Next attempt sent 1 message, then successfully finished the attempt and the logical // operation. @@ -311,9 +348,18 @@ public void testRequestCount() { } @Test - public void testAttemptNumber() { + public void testAttemptNumber_javaTime() { + testAttemptNumber(java.time.Duration.ofMillis(5)); + } + + @Test + public void testAttemptNumber_threeten() { + testAttemptNumber(org.threeten.bp.Duration.ofMillis(5)); + } + + public void testAttemptNumber(Object attemptFailedValue) { tracer.attemptStarted(0); - tracer.attemptFailed(new RuntimeException(), java.time.Duration.ofMillis(1)); + reportFailedAttempt(tracer, new RuntimeException(), attemptFailedValue); tracer.attemptStarted(1); tracer.attemptSucceeded(); tracer.operationSucceeded(); @@ -335,7 +381,8 @@ public void testAttemptNumber() { @Test public void testStatusCode() { tracer.attemptStarted(0); - tracer.attemptFailed( + reportFailedAttempt( + tracer, new DeadlineExceededException( "deadline exceeded", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true), java.time.Duration.ofMillis(1)); From 6abced36335e3cf02cdc5fec3b9723db40f4c291 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 22:46:10 -0400 Subject: [PATCH 079/141] remove unnecessary mocks --- .../google/api/gax/httpjson/HttpJsonClientCallImplTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java index b4da5fa38c..a99f566c63 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientCallImplTest.java @@ -58,7 +58,6 @@ public class HttpJsonClientCallImplTest { public void responseReceived_noCancellationTask() { ScheduledThreadPoolExecutor deadlineSchedulerExecutor = new ScheduledThreadPoolExecutor(1); // Null timeout means no timeout task created - Mockito.when(httpJsonCallOptions.getTimeout()).thenReturn(null); Mockito.when(httpJsonCallOptions.getTimeoutDuration()).thenReturn(null); HttpJsonClientCallImpl httpJsonClientCall = @@ -94,8 +93,6 @@ public void responseReceived_cancellationTaskExists_isCancelledProperly() deadlineSchedulerExecutor.setRemoveOnCancelPolicy(true); // Setting a timeout for this call will enqueue a timeout task - Mockito.when(httpJsonCallOptions.getTimeout()) - .thenReturn(org.threeten.bp.Duration.ofMinutes(10)); Mockito.when(httpJsonCallOptions.getTimeoutDuration()) .thenReturn(java.time.Duration.ofMinutes(10)); From 31792f7f5207a35ee21b0d8a8e9564c600a65af5 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 22:48:33 -0400 Subject: [PATCH 080/141] add license for metrics test utils --- .../api/gax/tracing/MetricsTestUtils.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java index fa6e09cc99..2618b0217d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java @@ -1,3 +1,32 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.google.api.gax.tracing; import static org.junit.Assert.fail; From a67cca55a3d8149be3a7a8f9e761d148132785a6 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 7 May 2024 23:00:40 -0400 Subject: [PATCH 081/141] add clirr ignore for api tracer --- gax-java/gax/clirr-ignored-differences.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gax-java/gax/clirr-ignored-differences.xml b/gax-java/gax/clirr-ignored-differences.xml index fe5f4ad4a7..69c789d80b 100644 --- a/gax-java/gax/clirr-ignored-differences.xml +++ b/gax-java/gax/clirr-ignored-differences.xml @@ -55,6 +55,11 @@ com/google/api/gax/*/* * *(java.time.Duration) + + 7012 + com/google/api/gax/tracing/* + * attemptFailed(java.lang.Throwable, java.time.Duration) + 7002 com/google/api/gax/*/* From a87d2b8eef349508578d76083648a1bcbed95ae0 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 16:30:06 -0400 Subject: [PATCH 082/141] rename overloaded setters in ApiContext --- .../google/api/gax/grpc/GrpcCallContext.java | 27 +++++++----- .../api/gax/grpc/GrpcCallContextTest.java | 42 ++++++++++--------- .../api/gax/grpc/GrpcClientCallsTest.java | 7 ++-- .../api/gax/httpjson/HttpJsonCallContext.java | 27 +++++++----- .../gax/httpjson/HttpJsonCallContextTest.java | 27 ++++++------ .../HttpJsonClientInterceptorTest.java | 2 +- .../httpjson/HttpJsonDirectCallableTest.java | 4 +- ...JsonDirectServerStreamingCallableTest.java | 2 +- .../api/gax/retrying/RetrySettings.java | 2 +- .../google/api/gax/rpc/ApiCallContext.java | 25 ++++++----- .../google/api/gax/rpc/AttemptCallable.java | 2 +- .../com/google/api/gax/rpc/Callables.java | 4 +- .../api/gax/rpc/CheckingAttemptCallable.java | 2 +- .../rpc/ServerStreamingAttemptCallable.java | 2 +- .../api/gax/rpc/AttemptCallableTest.java | 3 +- .../com/google/api/gax/rpc/CallableTest.java | 8 ++-- .../gax/rpc/OperationCallableImplTest.java | 2 +- .../ServerStreamingAttemptCallableTest.java | 10 ++--- .../api/gax/rpc/testing/FakeCallContext.java | 14 ++++--- 19 files changed, 116 insertions(+), 96 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 3abb5aaef4..42b0557126 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -231,15 +231,18 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) { endpointContext); } - /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ + /** + * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ @Override @ObsoleteApi("Use withTimeout(java.time.Duration) instead") public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { - return withTimeout(toJavaTimeDuration(timeout)); + return withTimeoutDuration(toJavaTimeDuration(timeout)); } @Override - public GrpcCallContext withTimeout(@Nullable java.time.Duration timeout) { + public GrpcCallContext withTimeoutDuration(@Nullable java.time.Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; @@ -279,18 +282,19 @@ public java.time.Duration getTimeoutDuration() { } /** - * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link + * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") public GrpcCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { - return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); + return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout)); } @Override - public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout) { + public GrpcCallContext withStreamWaitTimeoutDuration( + @Nullable java.time.Duration streamWaitTimeout) { if (streamWaitTimeout != null) { Preconditions.checkArgument( streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); @@ -312,7 +316,7 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration stream } /** - * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link + * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} * * @param streamIdleTimeout @@ -322,11 +326,12 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable java.time.Duration stream @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") public GrpcCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { - return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); + return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout)); } @Override - public GrpcCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout) { + public GrpcCallContext withStreamIdleTimeoutDuration( + @Nullable java.time.Duration streamIdleTimeout) { if (streamIdleTimeout != null) { Preconditions.checkArgument( streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); @@ -549,7 +554,7 @@ public org.threeten.bp.Duration getStreamWaitTimeout() { /** * The stream wait timeout set for this context. * - * @see ApiCallContext#withStreamWaitTimeout(java.time.Duration) + * @see ApiCallContext#withStreamWaitTimeoutDuration(java.time.Duration) */ @Override @Nullable @@ -566,7 +571,7 @@ public org.threeten.bp.Duration getStreamIdleTimeout() { /** * The stream idle timeout set for this context. * - * @see ApiCallContext#withStreamIdleTimeout(java.time.Duration) + * @see ApiCallContext#withStreamIdleTimeoutDuration(java.time.Duration) */ @Override @Nullable diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java index 766b7da669..e7584e4ecc 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallContextTest.java @@ -134,7 +134,7 @@ public void testWithTimeout() { GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - jt -> context.withTimeout(jt), + jt -> context.withTimeoutDuration(jt), tt -> context.withTimeout(tt), c -> c.getTimeoutDuration(), c -> c.getTimeout()); @@ -144,7 +144,7 @@ public void testWithTimeout() { public void testWithNegativeTimeout() { assertNull( GrpcCallContext.createDefault() - .withTimeout(java.time.Duration.ofSeconds(-1L)) + .withTimeoutDuration(java.time.Duration.ofSeconds(-1L)) .getTimeoutDuration()); } @@ -152,14 +152,14 @@ public void testWithNegativeTimeout() { public void testWithZeroTimeout() { assertNull( GrpcCallContext.createDefault() - .withTimeout(java.time.Duration.ofSeconds(0L)) + .withTimeoutDuration(java.time.Duration.ofSeconds(0L)) .getTimeoutDuration()); } @Test public void testWithShorterTimeout() { GrpcCallContext ctxWithLongTimeout = - GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); + GrpcCallContext.createDefault().withTimeoutDuration(java.time.Duration.ofSeconds(10)); // Sanity check Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()) @@ -167,7 +167,7 @@ public void testWithShorterTimeout() { // Shorten the timeout and make sure it changed GrpcCallContext ctxWithShorterTimeout = - ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); + ctxWithLongTimeout.withTimeoutDuration(java.time.Duration.ofSeconds(5)); Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(5)); } @@ -175,7 +175,7 @@ public void testWithShorterTimeout() { @Test public void testWithLongerTimeout() { GrpcCallContext ctxWithShortTimeout = - GrpcCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); + GrpcCallContext.createDefault().withTimeoutDuration(java.time.Duration.ofSeconds(5)); // Sanity check Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()) @@ -183,7 +183,7 @@ public void testWithLongerTimeout() { // Try to extend the timeout and verify that it was ignored GrpcCallContext ctxWithUnchangedTimeout = - ctxWithShortTimeout.withTimeout(java.time.Duration.ofSeconds(10)); + ctxWithShortTimeout.withTimeoutDuration(java.time.Duration.ofSeconds(10)); Truth.assertThat(ctxWithUnchangedTimeout.getTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(5)); } @@ -191,14 +191,14 @@ public void testWithLongerTimeout() { @Test public void testMergeWithNullTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(10); - GrpcCallContext baseContext = GrpcCallContext.createDefault().withTimeout(timeout); + GrpcCallContext baseContext = GrpcCallContext.createDefault().withTimeoutDuration(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeoutDuration()).isEqualTo(timeout); java.time.Duration callContextTimeout = null; GrpcCallContext explicitNullOverlay = - GrpcCallContext.createDefault().withTimeout(callContextTimeout); + GrpcCallContext.createDefault().withTimeoutDuration(callContextTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()) .isEqualTo(timeout); } @@ -207,7 +207,7 @@ public void testMergeWithNullTimeout() { public void testMergeWithTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); - GrpcCallContext ctx2 = GrpcCallContext.createDefault().withTimeout(timeout); + GrpcCallContext ctx2 = GrpcCallContext.createDefault().withTimeoutDuration(timeout); Truth.assertThat(ctx1.merge(ctx2).getTimeoutDuration()).isEqualTo(timeout); } @@ -218,7 +218,7 @@ public void testWithStreamingWaitTimeout() { GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - jt -> context.withStreamWaitTimeout(jt), + jt -> context.withStreamWaitTimeoutDuration(jt), tt -> context.withStreamWaitTimeout(tt), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); @@ -227,7 +227,8 @@ public void testWithStreamingWaitTimeout() { @Test public void testMergeWithNullStreamingWaitTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(10); - GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); + GrpcCallContext baseContext = + GrpcCallContext.createDefault().withStreamWaitTimeoutDuration(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeoutDuration()) @@ -235,7 +236,7 @@ public void testMergeWithNullStreamingWaitTimeout() { java.time.Duration streamWaitTimeout = null; GrpcCallContext explicitNullOverlay = - GrpcCallContext.createDefault().withStreamWaitTimeout(streamWaitTimeout); + GrpcCallContext.createDefault().withStreamWaitTimeoutDuration(streamWaitTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamWaitTimeoutDuration()) .isEqualTo(timeout); } @@ -245,7 +246,7 @@ public void testWithZeroStreamingWaitTimeout() { java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( GrpcCallContext.createDefault() - .withStreamWaitTimeout(timeout) + .withStreamWaitTimeoutDuration(timeout) .getStreamWaitTimeoutDuration()) .isEqualTo(timeout); } @@ -254,7 +255,7 @@ public void testWithZeroStreamingWaitTimeout() { public void testMergeWithStreamingWaitTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); - GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); + GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamWaitTimeoutDuration(timeout); Truth.assertThat(ctx1.merge(ctx2).getStreamWaitTimeoutDuration()).isEqualTo(timeout); } @@ -265,7 +266,7 @@ public void testWithStreamingIdleTimeout() { GrpcCallContext context = GrpcCallContext.createDefault(); testDurationMethod( millis, - jt -> context.withStreamIdleTimeout(jt), + jt -> context.withStreamIdleTimeoutDuration(jt), tt -> context.withStreamIdleTimeout(tt), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); @@ -274,7 +275,8 @@ public void testWithStreamingIdleTimeout() { @Test public void testMergeWithNullStreamingIdleTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(10); - GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); + GrpcCallContext baseContext = + GrpcCallContext.createDefault().withStreamIdleTimeoutDuration(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeoutDuration()) @@ -282,7 +284,7 @@ public void testMergeWithNullStreamingIdleTimeout() { java.time.Duration idleTimeout = null; GrpcCallContext explicitNullOverlay = - GrpcCallContext.createDefault().withStreamIdleTimeout(idleTimeout); + GrpcCallContext.createDefault().withStreamIdleTimeoutDuration(idleTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamIdleTimeoutDuration()) .isEqualTo(timeout); } @@ -292,7 +294,7 @@ public void testWithZeroStreamingIdleTimeout() { java.time.Duration timeout = java.time.Duration.ZERO; Truth.assertThat( GrpcCallContext.createDefault() - .withStreamIdleTimeout(timeout) + .withStreamIdleTimeoutDuration(timeout) .getStreamIdleTimeoutDuration()) .isEqualTo(timeout); } @@ -301,7 +303,7 @@ public void testWithZeroStreamingIdleTimeout() { public void testMergeWithStreamingIdleTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); - GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); + GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamIdleTimeoutDuration(timeout); Truth.assertThat(ctx1.merge(ctx2).getStreamIdleTimeoutDuration()).isEqualTo(timeout); } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java index 55eab0b951..1b6f332dc8 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcClientCallsTest.java @@ -197,7 +197,8 @@ public void testTimeoutToDeadlineConversion() throws IOException { java.time.Duration timeout = java.time.Duration.ofSeconds(10); Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS); - GrpcCallContext context = defaultCallContext.withChannel(mockChannel).withTimeout(timeout); + GrpcCallContext context = + defaultCallContext.withChannel(mockChannel).withTimeoutDuration(timeout); GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata()); @@ -232,7 +233,7 @@ public void testTimeoutAfterDeadline() throws IOException { defaultCallContext .withChannel(mockChannel) .withCallOptions(CallOptions.DEFAULT.withDeadline(priorDeadline)) - .withTimeout(timeout); + .withTimeoutDuration(timeout); GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata()); @@ -266,7 +267,7 @@ public void testTimeoutBeforeDeadline() throws IOException { defaultCallContext .withChannel(mockChannel) .withCallOptions(CallOptions.DEFAULT.withDeadline(subsequentDeadline)) - .withTimeout(timeout); + .withTimeoutDuration(timeout); GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata()); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 02ab94a682..1ce058fdcb 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -254,11 +254,14 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } - /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ + /** + * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ @Override @ObsoleteApi("Use withTimeout(java.time.Duration) instead") public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { - return withTimeout(toJavaTimeDuration(timeout)); + return withTimeoutDuration(toJavaTimeDuration(timeout)); } @Override @@ -279,7 +282,7 @@ public HttpJsonCallContext withEndpointContext(EndpointContext endpointContext) } @Override - public HttpJsonCallContext withTimeout(java.time.Duration timeout) { + public HttpJsonCallContext withTimeoutDuration(java.time.Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; @@ -319,18 +322,19 @@ public java.time.Duration getTimeoutDuration() { } /** - * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link + * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") public HttpJsonCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { - return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); + return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout)); } @Override - public HttpJsonCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout) { + public HttpJsonCallContext withStreamWaitTimeoutDuration( + @Nullable java.time.Duration streamWaitTimeout) { if (streamWaitTimeout != null) { Preconditions.checkArgument( streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); @@ -361,7 +365,7 @@ public org.threeten.bp.Duration getStreamWaitTimeout() { /** * The stream wait timeout set for this context. * - * @see ApiCallContext#withStreamWaitTimeout(java.time.Duration) + * @see ApiCallContext#withStreamWaitTimeoutDuration(java.time.Duration) */ @Override @Nullable @@ -370,18 +374,19 @@ public java.time.Duration getStreamWaitTimeoutDuration() { } /** - * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link + * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") public HttpJsonCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { - return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); + return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout)); } @Override - public HttpJsonCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout) { + public HttpJsonCallContext withStreamIdleTimeoutDuration( + @Nullable java.time.Duration streamIdleTimeout) { if (streamIdleTimeout != null) { Preconditions.checkArgument( streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); @@ -412,7 +417,7 @@ public org.threeten.bp.Duration getStreamIdleTimeout() { /** * The stream idle timeout set for this context. * - * @see ApiCallContext#withStreamIdleTimeout(java.time.Duration) + * @see ApiCallContext#withStreamIdleTimeoutDuration(java.time.Duration) */ @Override @Nullable diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index a4dd866a4b..f0dd092065 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -121,7 +121,7 @@ public void testStreamIdleTimeout() { final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - jt -> defaultContext.withStreamIdleTimeout(jt), + jt -> defaultContext.withStreamIdleTimeoutDuration(jt), tt -> defaultContext.withStreamIdleTimeout(tt), c -> c.getStreamIdleTimeoutDuration(), c -> c.getStreamIdleTimeout()); @@ -133,7 +133,7 @@ public void testStreamWaitTimeout() { final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - jt -> defaultContext.withStreamWaitTimeout(jt), + jt -> defaultContext.withStreamWaitTimeoutDuration(jt), tt -> defaultContext.withStreamWaitTimeout(tt), c -> c.getStreamWaitTimeoutDuration(), c -> c.getStreamWaitTimeout()); @@ -145,7 +145,7 @@ public void testTimeout() { final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( millis, - jt -> defaultContext.withTimeout(jt), + jt -> defaultContext.withTimeoutDuration(jt), tt -> defaultContext.withTimeout(tt), c -> c.getTimeoutDuration(), c -> c.getTimeout()); @@ -156,7 +156,7 @@ public void testNullTimeout() { final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); testDurationMethod( null, - jt -> defaultContext.withTimeout(jt), + jt -> defaultContext.withTimeoutDuration(jt), tt -> defaultContext.withTimeout(tt), c -> c.getTimeoutDuration(), c -> c.getTimeout()); @@ -166,7 +166,7 @@ public void testNullTimeout() { public void testWithNegativeTimeout() { assertNull( HttpJsonCallContext.createDefault() - .withTimeout(java.time.Duration.ofSeconds(-1L)) + .withTimeoutDuration(java.time.Duration.ofSeconds(-1L)) .getTimeoutDuration()); } @@ -174,14 +174,14 @@ public void testWithNegativeTimeout() { public void testWithZeroTimeout() { assertNull( HttpJsonCallContext.createDefault() - .withTimeout(java.time.Duration.ofSeconds(0L)) + .withTimeoutDuration(java.time.Duration.ofSeconds(0L)) .getTimeoutDuration()); } @Test public void testWithShorterTimeout() { HttpJsonCallContext ctxWithLongTimeout = - HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(10)); + HttpJsonCallContext.createDefault().withTimeoutDuration(java.time.Duration.ofSeconds(10)); // Sanity check Truth.assertThat(ctxWithLongTimeout.getTimeoutDuration()) @@ -189,7 +189,7 @@ public void testWithShorterTimeout() { // Shorten the timeout and make sure it changed HttpJsonCallContext ctxWithShorterTimeout = - ctxWithLongTimeout.withTimeout(java.time.Duration.ofSeconds(5)); + ctxWithLongTimeout.withTimeoutDuration(java.time.Duration.ofSeconds(5)); Truth.assertThat(ctxWithShorterTimeout.getTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(5)); } @@ -197,7 +197,7 @@ public void testWithShorterTimeout() { @Test public void testWithLongerTimeout() { HttpJsonCallContext ctxWithShortTimeout = - HttpJsonCallContext.createDefault().withTimeout(java.time.Duration.ofSeconds(5)); + HttpJsonCallContext.createDefault().withTimeoutDuration(java.time.Duration.ofSeconds(5)); // Sanity check Truth.assertThat(ctxWithShortTimeout.getTimeoutDuration()) @@ -205,7 +205,7 @@ public void testWithLongerTimeout() { // Try to extend the timeout and verify that it was ignored HttpJsonCallContext ctxWithUnchangedTimeout = - ctxWithShortTimeout.withTimeout(java.time.Duration.ofSeconds(10)); + ctxWithShortTimeout.withTimeoutDuration(java.time.Duration.ofSeconds(10)); Truth.assertThat(ctxWithUnchangedTimeout.getTimeoutDuration()) .isEqualTo(java.time.Duration.ofSeconds(5)); } @@ -213,14 +213,15 @@ public void testWithLongerTimeout() { @Test public void testMergeWithNullTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(10); - HttpJsonCallContext baseContext = HttpJsonCallContext.createDefault().withTimeout(timeout); + HttpJsonCallContext baseContext = + HttpJsonCallContext.createDefault().withTimeoutDuration(timeout); HttpJsonCallContext defaultOverlay = HttpJsonCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getTimeoutDuration()).isEqualTo(timeout); java.time.Duration callContextTimeout = null; HttpJsonCallContext explicitNullOverlay = - HttpJsonCallContext.createDefault().withTimeout(callContextTimeout); + HttpJsonCallContext.createDefault().withTimeoutDuration(callContextTimeout); Truth.assertThat(baseContext.merge(explicitNullOverlay).getTimeoutDuration()) .isEqualTo(timeout); } @@ -229,7 +230,7 @@ public void testMergeWithNullTimeout() { public void testMergeWithTimeout() { java.time.Duration timeout = java.time.Duration.ofSeconds(19); HttpJsonCallContext ctx1 = HttpJsonCallContext.createDefault(); - HttpJsonCallContext ctx2 = HttpJsonCallContext.createDefault().withTimeout(timeout); + HttpJsonCallContext ctx2 = HttpJsonCallContext.createDefault().withTimeoutDuration(timeout); Truth.assertThat(ctx1.merge(ctx2).getTimeoutDuration()).isEqualTo(timeout); } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java index 50d62a2179..c41fbc7201 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java @@ -193,7 +193,7 @@ public void testCustomInterceptor() throws ExecutionException, InterruptedExcept HttpJsonCallContext callContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(java.time.Duration.ofSeconds(30)) + .withTimeoutDuration(java.time.Duration.ofSeconds(30)) .withEndpointContext(endpointContext); Field request; diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java index 770c588198..3cdbb96aab 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java @@ -128,7 +128,7 @@ public static void initialize() throws IOException { defaultCallContext = HttpJsonCallContext.createDefault() .withChannel(channel) - .withTimeout(java.time.Duration.ofSeconds(30)) + .withTimeoutDuration(java.time.Duration.ofSeconds(30)) .withEndpointContext(endpointContext); } @@ -335,7 +335,7 @@ public void testDeadlineExceededResponse() throws InterruptedException { new HttpJsonDirectCallable<>(FAKE_METHOD_DESCRIPTOR); HttpJsonCallContext callContext = - defaultCallContext.withTimeout(java.time.Duration.ofSeconds(3)); + defaultCallContext.withTimeoutDuration(java.time.Duration.ofSeconds(3)); Field response = createTestMessage(10); MOCK_SERVICE.addResponse(response, java.time.Duration.ofSeconds(5)); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java index 8109e6fe4e..de46afb5a1 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectServerStreamingCallableTest.java @@ -149,7 +149,7 @@ public void initialize(java.time.Duration timeout) throws IOException { .setTransportChannel(HttpJsonTransportChannel.create(channel)) .setDefaultCallContext( HttpJsonCallContext.of(channel, HttpJsonCallOptions.DEFAULT) - .withTimeout(timeout) + .withTimeoutDuration(timeout) .withEndpointContext(endpointContext)) .build(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 1298f1217e..1ab25b4216 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -68,7 +68,7 @@ * *

    Server streaming RPCs interpret RPC timeouts a bit differently. For server streaming RPCs, the * RPC timeout gets converted into a wait timeout {@link - * com.google.api.gax.rpc.ApiCallContext#withStreamWaitTimeout(java.time.Duration)}. + * com.google.api.gax.rpc.ApiCallContext#withStreamWaitTimeoutDuration(java.time.Duration)}. * *

    In Cloud Client Libraries, Retry and LRO Retry Settings may be configured for each RPC in a * service. These values are chosen by the service teams and may be found by looking at the diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index b8767ba0a1..af52bf3c72 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -63,13 +63,16 @@ public interface ApiCallContext extends RetryingContext { /** Returns a new ApiCallContext with the given channel set. */ ApiCallContext withTransportChannel(TransportChannel channel); - /** Overload of {@link #withTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} */ - @ObsoleteApi("Use withTimeout(java.time.Duration) instead") - ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); - /** Returns a new ApiCallContext with the given Endpoint Context. */ ApiCallContext withEndpointContext(EndpointContext endpointContext); + /** + * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} + */ + @ObsoleteApi("Use withTimeout(java.time.Duration) instead") + ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); + /** * Returns a new ApiCallContext with the given timeout set. * @@ -82,7 +85,7 @@ public interface ApiCallContext extends RetryingContext { *

    If a method has default {@link com.google.api.gax.retrying.RetrySettings}, the max attempts * and/or total timeout is still respected when scheduling each RPC attempt. */ - ApiCallContext withTimeout(@Nullable java.time.Duration timeout); + ApiCallContext withTimeoutDuration(@Nullable java.time.Duration timeout); /** Backport of {@link #getTimeoutDuration()} */ @Nullable @@ -94,7 +97,7 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getTimeoutDuration(); /** - * Overload of {@link #withStreamWaitTimeout(java.time.Duration)} using {@link + * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration } */ @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") @@ -117,7 +120,7 @@ public interface ApiCallContext extends RetryingContext { *

    Please note that this timeout is best effort and the maximum resolution is configured in * {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. */ - ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout); + ApiCallContext withStreamWaitTimeoutDuration(@Nullable java.time.Duration streamWaitTimeout); /** Backport of {@link #getStreamWaitTimeoutDuration()} */ @Nullable @@ -127,13 +130,13 @@ public interface ApiCallContext extends RetryingContext { /** * Return the stream wait timeout set for this context. * - * @see #withStreamWaitTimeout(java.time.Duration) + * @see #withStreamWaitTimeoutDuration(java.time.Duration) */ @Nullable java.time.Duration getStreamWaitTimeoutDuration(); /** - * Overload of {@link #withStreamIdleTimeout(java.time.Duration)} using {@link + * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") @@ -157,7 +160,7 @@ public interface ApiCallContext extends RetryingContext { *

    Please note that this timeout is best effort and the maximum resolution is configured in * {@link StubSettings#getStreamWatchdogCheckIntervalDuration()}. */ - ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout); + ApiCallContext withStreamIdleTimeoutDuration(@Nullable java.time.Duration streamIdleTimeout); /** Backport of {@link #getStreamIdleTimeoutDuration()} */ @Nullable @@ -167,7 +170,7 @@ public interface ApiCallContext extends RetryingContext { /** * The stream idle timeout set for this context. * - * @see #withStreamIdleTimeout(java.time.Duration) + * @see #withStreamIdleTimeoutDuration(java.time.Duration) */ @Nullable java.time.Duration getStreamIdleTimeoutDuration(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java index d34aaddb05..1fb461c5bb 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java @@ -71,7 +71,7 @@ public ResponseT call() { // Set the RPC timeout if the caller did not provide their own. java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero() && callContext.getTimeoutDuration() == null) { - callContext = callContext.withTimeout(rpcTimeout); + callContext = callContext.withTimeoutDuration(rpcTimeout); } externalFuture.setAttemptFuture(new NonCancellableFuture()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index b760c13e0f..10d355b829 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -156,8 +156,8 @@ public static ServerStreamingCallable callable.withDefaultCallContext( clientContext .getDefaultCallContext() - .withStreamIdleTimeout(callSettings.getIdleTimeoutDuration()) - .withStreamWaitTimeout(callSettings.getWaitTimeoutDuration())); + .withStreamIdleTimeoutDuration(callSettings.getIdleTimeoutDuration()) + .withStreamWaitTimeoutDuration(callSettings.getWaitTimeoutDuration())); return callable; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java index 53c20b911b..6e307d1f81 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/CheckingAttemptCallable.java @@ -67,7 +67,7 @@ public ResponseT call() { try { java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero()) { - callContext = callContext.withTimeout(rpcTimeout); + callContext = callContext.withTimeoutDuration(rpcTimeout); } externalFuture.setAttemptFuture(new NonCancellableFuture()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java index 3273f52442..da0c8de632 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingAttemptCallable.java @@ -211,7 +211,7 @@ public Void call() { if (!outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration().isZero() && attemptContext.getTimeoutDuration() == null) { attemptContext = - attemptContext.withTimeout( + attemptContext.withTimeoutDuration( outerRetryingFuture.getAttemptSettings().getRpcTimeoutDuration()); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 0e207782c6..4b5de1a516 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -105,7 +105,8 @@ public void testRpcTimeout() { @Test public void testRpcTimeoutIsNotErased() { java.time.Duration callerTimeout = java.time.Duration.ofMillis(10); - ApiCallContext callerCallContext = FakeCallContext.createDefault().withTimeout(callerTimeout); + ApiCallContext callerCallContext = + FakeCallContext.createDefault().withTimeoutDuration(callerTimeout); java.time.Duration timeout = java.time.Duration.ofMillis(5); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 561969967a..bfd3afe6e8 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -100,7 +100,7 @@ public void testNonRetriedCallable() throws Exception { assertEquals(expectedRequest, argumentCaptor.getValue()); verify(callContext, atLeastOnce()).getRetrySettings(); verify(callContext).getTimeoutDuration(); - verify(callContext).withTimeout(timeout); + verify(callContext).withTimeoutDuration(timeout); assertEquals(expectedResponse, futureResponse.get()); } @@ -134,7 +134,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { verify(callContextWithRetrySettings, atLeastOnce()).getRetrySettings(); verify(callContextWithRetrySettings).getTimeoutDuration(); - verify(callContextWithRetrySettings).withTimeout(timeout); + verify(callContextWithRetrySettings).withTimeoutDuration(timeout); assertEquals(expectedResponse, futureResponse.get()); } @@ -150,7 +150,7 @@ public void testNonRetriedServerStreamingCallable() throws Exception { verify(callContext, atLeastOnce()).getRetrySettings(); verify(callContext).getTimeoutDuration(); - verify(callContext).withTimeout(timeout); + verify(callContext).withTimeoutDuration(timeout); } @Test @@ -168,6 +168,6 @@ public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exce verify(callContextWithRetrySettings, atLeastOnce()).getRetrySettings(); verify(callContextWithRetrySettings).getTimeoutDuration(); - verify(callContextWithRetrySettings).withTimeout(timeout); + verify(callContextWithRetrySettings).withTimeoutDuration(timeout); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 6bc6495bd0..032948bda3 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -563,7 +563,7 @@ public void testFutureCallContextPropagation() throws Exception { initialCallable, callSettings, initialContext, longRunningClient); ApiCallContext callContext = - FakeCallContext.createDefault().withTimeout(java.time.Duration.ofMillis(10)); + FakeCallContext.createDefault().withTimeoutDuration(java.time.Duration.ofMillis(10)); callable.futureCall(2, callContext).get(10, TimeUnit.SECONDS); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index 70128775f7..b7b8f06f76 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -101,9 +101,9 @@ public void testUserProvidedContextTimeout() { // Ensure that the callable did not overwrite the user provided timeouts Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeoutDuration(); - Mockito.verify(mockedCallContext, Mockito.never()).withTimeout(totalTimeout); + Mockito.verify(mockedCallContext, Mockito.never()).withTimeoutDuration(totalTimeout); Mockito.verify(mockedCallContext, Mockito.never()) - .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); + .withStreamWaitTimeoutDuration(Mockito.any(java.time.Duration.class)); // Should notify outer observer Truth.assertThat(observer.controller).isNotNull(); @@ -129,10 +129,10 @@ public void testNoUserProvidedContextTimeout() { Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer(); Mockito.doReturn(null).when(mockedCallContext).getTimeoutDuration(); Mockito.doReturn(null).when(mockedCallContext).getStreamWaitTimeoutDuration(); - Mockito.doReturn(mockedCallContext).when(mockedCallContext).withTimeout(attemptTimeout); + Mockito.doReturn(mockedCallContext).when(mockedCallContext).withTimeoutDuration(attemptTimeout); Mockito.doReturn(mockedCallContext) .when(mockedCallContext) - .withStreamWaitTimeout(Mockito.any(java.time.Duration.class)); + .withStreamWaitTimeoutDuration(Mockito.any(java.time.Duration.class)); ServerStreamingAttemptCallable callable = createCallable(mockedCallContext); callable.start(); @@ -140,7 +140,7 @@ public void testNoUserProvidedContextTimeout() { // Ensure that the callable configured the timeouts via the Settings in the // absence of user-defined timeouts. Mockito.verify(mockedCallContext, Mockito.times(1)).getTimeoutDuration(); - Mockito.verify(mockedCallContext, Mockito.times(1)).withTimeout(attemptTimeout); + Mockito.verify(mockedCallContext, Mockito.times(1)).withTimeoutDuration(attemptTimeout); // Should notify outer observer Truth.assertThat(observer.controller).isNotNull(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java index 768f79da0b..1cdefe435d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/testing/FakeCallContext.java @@ -249,7 +249,7 @@ public java.time.Duration getTimeoutDuration() { @Override public ApiCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { - return withStreamWaitTimeout(toJavaTimeDuration(streamWaitTimeout)); + return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout)); } @Nullable @@ -261,7 +261,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { @Override public ApiCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { - return withStreamIdleTimeout(toJavaTimeDuration(streamIdleTimeout)); + return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout)); } @Nullable @@ -316,7 +316,7 @@ public FakeCallContext withEndpointContext(EndpointContext endpointContext) { @Override public FakeCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { - return withTimeout(toJavaTimeDuration(timeout)); + return withTimeoutDuration(toJavaTimeDuration(timeout)); } public FakeCallContext withChannel(FakeChannel channel) { @@ -335,7 +335,7 @@ public FakeCallContext withChannel(FakeChannel channel) { } @Override - public FakeCallContext withTimeout(java.time.Duration timeout) { + public FakeCallContext withTimeoutDuration(java.time.Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; @@ -367,7 +367,8 @@ public org.threeten.bp.Duration getTimeout() { } @Override - public ApiCallContext withStreamWaitTimeout(@Nullable java.time.Duration streamWaitTimeout) { + public ApiCallContext withStreamWaitTimeoutDuration( + @Nullable java.time.Duration streamWaitTimeout) { return new FakeCallContext( this.credentials, this.channel, @@ -389,7 +390,8 @@ public org.threeten.bp.Duration getStreamWaitTimeout() { } @Override - public ApiCallContext withStreamIdleTimeout(@Nullable java.time.Duration streamIdleTimeout) { + public ApiCallContext withStreamIdleTimeoutDuration( + @Nullable java.time.Duration streamIdleTimeout) { Preconditions.checkNotNull(streamIdleTimeout); return new FakeCallContext( this.credentials, From 3b3d45a915e36224fdc80641eb5010952af38268 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 16:36:29 -0400 Subject: [PATCH 083/141] rename overload method in InstantiatingGrpcChannelProvider --- .../InstantiatingGrpcChannelProvider.java | 12 ++++++------ .../InstantiatingGrpcChannelProviderTest.java | 19 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 46f64ccb96..889c71c1a6 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -658,12 +658,12 @@ public Integer getMaxInboundMetadataSize() { * Overload of {@link #setKeepAliveTime(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use setKeepAliveTime(java.time.Duration) instead") + @ObsoleteApi("Use setKeepAliveTimeDuration(java.time.Duration) instead") public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { - return setKeepAliveTime(toJavaTimeDuration(duration)); + return setKeepAliveTimeDuration(toJavaTimeDuration(duration)); } /** The time without read activity before sending a keepalive ping. */ - public Builder setKeepAliveTime(java.time.Duration duration) { + public Builder setKeepAliveTimeDuration(java.time.Duration duration) { this.keepAliveTime = duration; return this; } @@ -679,13 +679,13 @@ public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } - @ObsoleteApi("Use setKeepAliveTimeout(java.time.Duration) instead") + @ObsoleteApi("Use setKeepAliveTimeoutDuration(java.time.Duration) instead") public Builder setKeepAliveTimeout(org.threeten.bp.Duration duration) { - return setKeepAliveTimeout(toJavaTimeDuration(duration)); + return setKeepAliveTimeoutDuration(toJavaTimeDuration(duration)); } /** The time without read activity after sending a keepalive ping. */ - public Builder setKeepAliveTimeout(java.time.Duration duration) { + public Builder setKeepAliveTimeoutDuration(java.time.Duration duration) { this.keepAliveTimeout = duration; return this; } diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index f1e8d27582..ae421232f1 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -97,22 +97,21 @@ public void testEndpointBadPort() { @Test public void testKeepAlive() { final long millis = 15; - boolean keepaliveWithoutCalls = true; InstantiatingGrpcChannelProvider.Builder builder = InstantiatingGrpcChannelProvider.newBuilder(); Function javaTimeProviderSupplier = jt -> builder - .setKeepAliveTime(jt) - .setKeepAliveTimeout(jt) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .setKeepAliveTimeDuration(jt) + .setKeepAliveTimeoutDuration(jt) + .setKeepAliveWithoutCalls(Boolean.TRUE) .build(); Function threetenProviderSupplier = tt -> builder .setKeepAliveTime(tt) .setKeepAliveTimeout(tt) - .setKeepAliveWithoutCalls(keepaliveWithoutCalls) + .setKeepAliveWithoutCalls(Boolean.TRUE) .build(); testDurationMethod( millis, @@ -127,12 +126,12 @@ public void testKeepAlive() { c -> c.getKeepAliveTimeoutDuration(), c -> c.getKeepAliveTimeout()); assertEquals( - true, + Boolean.TRUE, javaTimeProviderSupplier .apply(java.time.Duration.ofMillis(millis)) .getKeepAliveWithoutCalls()); assertEquals( - true, + Boolean.TRUE, threetenProviderSupplier .apply(org.threeten.bp.Duration.ofMillis(millis)) .getKeepAliveWithoutCalls()); @@ -198,9 +197,9 @@ public void testToBuilder() { .setEndpoint("fake.endpoint:443") .setMaxInboundMessageSize(12345678) .setMaxInboundMetadataSize(4096) - .setKeepAliveTime(keepaliveTime) - .setKeepAliveTimeout(keepaliveTimeout) - .setKeepAliveWithoutCalls(true) + .setKeepAliveTimeDuration(keepaliveTime) + .setKeepAliveTimeoutDuration(keepaliveTimeout) + .setKeepAliveWithoutCalls(Boolean.TRUE) .setChannelConfigurator(channelConfigurator) .setChannelsPerCpu(2.5) .setDirectPathServiceConfig(directPathServiceConfig) From eea294ea417d045daf70be9c8eee0997445141b6 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 16:40:16 -0400 Subject: [PATCH 084/141] fix obsolete api annotations in apicallcontext --- .../main/java/com/google/api/gax/grpc/GrpcCallContext.java | 6 +++--- .../com/google/api/gax/httpjson/HttpJsonCallContext.java | 6 +++--- .../main/java/com/google/api/gax/rpc/ApiCallContext.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 42b0557126..7d7fab0ee2 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -236,7 +236,7 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) { * org.threeten.bp.Duration} */ @Override - @ObsoleteApi("Use withTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { return withTimeoutDuration(toJavaTimeDuration(timeout)); } @@ -286,7 +286,7 @@ public java.time.Duration getTimeoutDuration() { * org.threeten.bp.Duration} */ @Override - @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout)); @@ -323,7 +323,7 @@ public GrpcCallContext withStreamWaitTimeoutDuration( * @return */ @Override - @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout)); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 1ce058fdcb..a1a344ca4a 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -259,7 +259,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { * org.threeten.bp.Duration} */ @Override - @ObsoleteApi("Use withTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { return withTimeoutDuration(toJavaTimeDuration(timeout)); } @@ -326,7 +326,7 @@ public java.time.Duration getTimeoutDuration() { * org.threeten.bp.Duration} */ @Override - @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withStreamWaitTimeout( @Nullable org.threeten.bp.Duration streamWaitTimeout) { return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout)); @@ -378,7 +378,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { * org.threeten.bp.Duration} */ @Override - @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withStreamIdleTimeout( @Nullable org.threeten.bp.Duration streamIdleTimeout) { return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index af52bf3c72..0b45b722bf 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -70,7 +70,7 @@ public interface ApiCallContext extends RetryingContext { * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use withTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); /** @@ -100,7 +100,7 @@ public interface ApiCallContext extends RetryingContext { * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration } */ - @ObsoleteApi("Use withStreamWaitTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") ApiCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout); /** @@ -139,7 +139,7 @@ public interface ApiCallContext extends RetryingContext { * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use withStreamIdleTimeout(java.time.Duration) instead") + @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") ApiCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout); /** From 48cd5e9dd2ddf51447e3da729f458d7066317f83 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 16:45:54 -0400 Subject: [PATCH 085/141] rename overload of HttpJsonCallOptions --- .../api/gax/httpjson/HttpJsonCallOptions.java | 15 ++++++++------- .../api/gax/httpjson/HttpJsonClientCalls.java | 2 +- .../api/gax/httpjson/HttpJsonCallOptionsTest.java | 4 ++-- .../api/gax/httpjson/HttpRequestRunnableTest.java | 6 ++++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index c07d41cf94..4634a38c16 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -84,13 +84,13 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { java.time.Instant newDeadline = inputOptions.getDeadlineInstant(); if (newDeadline != null) { - builder.setDeadline(newDeadline); + builder.setDeadlineInstant(newDeadline); } if (inputOptions.getTimeout() != null) { java.time.Duration newTimeout = inputOptions.getTimeoutDuration(); if (newTimeout != null) { - builder.setTimeout(newTimeout); + builder.setTimeoutDuration(newTimeout); } } @@ -109,18 +109,19 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { @AutoValue.Builder public abstract static class Builder { - @ObsoleteApi("Use setTimeout(java.time.Duration) instead") + /** Backport of {@link #setTimeoutDuration(java.time.Duration)} */ + @ObsoleteApi("Use setTimeoutDuration(java.time.Duration) instead") public abstract Builder setTimeout(org.threeten.bp.Duration value); - public Builder setTimeout(java.time.Duration value) { + public Builder setTimeoutDuration(java.time.Duration value) { return setTimeout(toThreetenDuration(value)); } - /** Backport of {@link #setDeadline(java.time.Instant)} */ - @ObsoleteApi("Use setDeadline(java.time.Instant) instead") + /** Backport of {@link #setDeadlineInstant(java.time.Instant)} */ + @ObsoleteApi("Use setDeadlineInstant(java.time.Instant) instead") public abstract Builder setDeadline(org.threeten.bp.Instant value); - public final Builder setDeadline(java.time.Instant value) { + public final Builder setDeadlineInstant(java.time.Instant value) { return setDeadline(toThreetenInstant(value)); } diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index de15722a5b..c573d786f6 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -65,7 +65,7 @@ public static HttpJsonClientCall newC callOptions = callOptions .toBuilder() - .setTimeout( + .setTimeoutDuration( java.time.Duration.ofMillis(httpJsonContext.getTimeoutDuration().toMillis())) .build(); } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java index bc6380204f..a761045459 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -42,7 +42,7 @@ public void testDeadline() { final long millis = 3; testInstantMethod( millis, - jt -> OPTIONS_BUILDER.setDeadline(jt), + jt -> OPTIONS_BUILDER.setDeadlineInstant(jt), tt -> OPTIONS_BUILDER.setDeadline(tt), c -> c.build().getDeadlineInstant(), c -> c.build().getDeadline()); @@ -53,7 +53,7 @@ public void testTimeout() { final long millis = 3; testDurationMethod( millis, - jt -> OPTIONS_BUILDER.setTimeout(jt), + jt -> OPTIONS_BUILDER.setTimeoutDuration(jt), tt -> OPTIONS_BUILDER.setTimeout(tt), c -> c.build().getTimeoutDuration(), c -> c.build().getTimeout()); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpRequestRunnableTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpRequestRunnableTest.java index b6d4b0943f..f95eaf6e5f 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpRequestRunnableTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpRequestRunnableTest.java @@ -259,7 +259,9 @@ public void testUpdateRunnableTimeout_shouldNotUpdate() throws IOException { requestMessage, methodDescriptor, "www.googleapis.com/animals/v1/projects", - HttpJsonCallOptions.newBuilder().setTimeout(java.time.Duration.ofMillis(5000L)).build(), + HttpJsonCallOptions.newBuilder() + .setTimeoutDuration(java.time.Duration.ofMillis(5000L)) + .build(), new MockHttpTransport(), HttpJsonMetadata.newBuilder().build(), (result) -> {}); @@ -285,7 +287,7 @@ public void testUpdateRunnableTimeout_shouldUpdate() throws IOException { methodDescriptor, "www.googleapis.com/animals/v1/projects", HttpJsonCallOptions.newBuilder() - .setTimeout(java.time.Duration.ofMillis(30000L)) + .setTimeoutDuration(java.time.Duration.ofMillis(30000L)) .build(), new MockHttpTransport(), HttpJsonMetadata.newBuilder().build(), From 060c1fa9e51a64e810ff130a22b7ffab120d09b1 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 16:56:51 -0400 Subject: [PATCH 086/141] rename overload of BatchingSettings --- .../java/com/google/api/gax/grpc/SettingsTest.java | 2 +- .../google/api/gax/batching/BatchingSettings.java | 8 ++++---- .../com/google/api/gax/batching/BatcherImplTest.java | 12 ++++++------ .../api/gax/batching/BatchingCallSettingsTest.java | 2 +- .../api/gax/batching/BatchingSettingsTest.java | 2 +- .../com/google/api/gax/rpc/BatcherFactoryTest.java | 2 +- .../com/google/api/gax/rpc/BatchingCallableTest.java | 2 +- .../java/com/google/api/gax/rpc/BatchingTest.java | 8 ++++---- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index 74065f46b4..fcca37daaa 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -226,7 +226,7 @@ private static Builder createDefault() { BatchingSettings.newBuilder() .setElementCountThreshold(800L) .setRequestByteThreshold(8388608L) - .setDelayThreshold(java.time.Duration.ofMillis(100)) + .setDelayThresholdDuration(java.time.Duration.ofMillis(100)) .build()); builder .fakeMethodBatching() diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 216c521aff..0f69a17024 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -124,7 +124,7 @@ public static Builder newBuilder() { .setIsEnabled(true) .setElementCountThreshold(1L) .setRequestByteThreshold(1L) - .setDelayThreshold(java.time.Duration.ofMillis(1)) + .setDelayThresholdDuration(java.time.Duration.ofMillis(1)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) @@ -152,8 +152,8 @@ public abstract static class Builder { */ public abstract Builder setRequestByteThreshold(Long requestByteThreshold); - /** Backport of {@link #setDelayThreshold(java.time.Duration)} */ - @ObsoleteApi("Use setDelayThreshold(java.time.Duration) instead") + /** Backport of {@link #setDelayThresholdDuration(java.time.Duration)} */ + @ObsoleteApi("Use setDelayThresholdDuration(java.time.Duration) instead") public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); /** @@ -162,7 +162,7 @@ public abstract static class Builder { * value should not be set too high, usually on the order of milliseconds. Otherwise, calls * might appear to never complete. */ - public final Builder setDelayThreshold(java.time.Duration delayThreshold) { + public final Builder setDelayThresholdDuration(java.time.Duration delayThreshold) { return setDelayThreshold(toThreetenDuration(delayThreshold)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index 4c7572ce73..ce62cd3ba4 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -95,7 +95,7 @@ public class BatcherImplTest { BatchingSettings.newBuilder() .setElementCountThreshold(1000L) .setRequestByteThreshold(1000L) - .setDelayThreshold(java.time.Duration.ofSeconds(1000)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1000)) .build(); @After @@ -374,7 +374,7 @@ public void testWhenThresholdIsDisabled() throws Exception { BatchingSettings.newBuilder() .setElementCountThreshold(null) .setRequestByteThreshold(null) - .setDelayThreshold((java.time.Duration) null) + .setDelayThresholdDuration(null) .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(2); @@ -386,7 +386,7 @@ public void testWhenThresholdIsDisabled() throws Exception { @Test public void testWhenDelayThresholdExceeds() throws Exception { BatchingSettings settings = - batchingSettings.toBuilder().setDelayThreshold(java.time.Duration.ofMillis(100)).build(); + batchingSettings.toBuilder().setDelayThresholdDuration(java.time.Duration.ofMillis(100)).build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(6); assertThat(result.isDone()).isFalse(); @@ -417,7 +417,7 @@ public ApiFuture> futureCall( } }; BatchingSettings settings = - batchingSettings.toBuilder().setDelayThreshold(java.time.Duration.ofMillis(50)).build(); + batchingSettings.toBuilder().setDelayThresholdDuration(java.time.Duration.ofMillis(50)).build(); try (final BatcherImpl> batcherTest = new BatcherImpl<>(SQUARER_BATCHING_DESC_V2, callable, labeledIntList, settings, EXECUTOR)) { @@ -463,7 +463,7 @@ public void testPushCurrentBatchRunnable() throws Exception { BatchingSettings settings = batchingSettings .toBuilder() - .setDelayThreshold(java.time.Duration.ofMillis(DELAY_TIME)) + .setDelayThresholdDuration(java.time.Duration.ofMillis(DELAY_TIME)) .build(); BatcherImpl> batcher = createDefaultBatcherImpl(settings, null); @@ -1027,7 +1027,7 @@ public ApiFuture futureCall(Object o, ApiCallContext apiCallContext) { Object prototype = new Object(); BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(100L) .setRequestByteThreshold(100L) .setFlowControlSettings(FlowControlSettings.getDefaultInstance()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java index 51e8a1a8be..ee79939708 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java @@ -49,7 +49,7 @@ public class BatchingCallSettingsTest { BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(20L) - .setDelayThreshold(java.time.Duration.ofMillis(5)) + .setDelayThresholdDuration(java.time.Duration.ofMillis(5)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100L) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index 0e4504caaf..07c3bc5a8e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -41,7 +41,7 @@ public class BatchingSettingsTest { public void testDelayThreshold() { testDurationMethod( 123l, - jt -> SETTINGS_BUILDER.setDelayThreshold(jt).build(), + jt -> SETTINGS_BUILDER.setDelayThresholdDuration(jt).build(), tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), o -> o.getDelayThresholdDuration(), o -> o.getDelayThreshold()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java index ca5e771876..3ea1ecf3ca 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java @@ -66,7 +66,7 @@ public void tearDown() { public void testGetPushingBatcher() { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java index c10a36c845..8ac84bade4 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallableTest.java @@ -67,7 +67,7 @@ public void testBatchedCall() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(10)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(10)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java index a1cd2b77a5..03170a64f6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingTest.java @@ -81,7 +81,7 @@ public void teardown() { public void batching() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -101,7 +101,7 @@ public void batching() throws Exception { public void batchingWithFlowControl() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(4L) .setRequestByteThreshold(null) .setFlowControlSettings( @@ -179,7 +179,7 @@ public void batchingDisabled() throws Exception { public void batchingWithBlockingCallThreshold() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = @@ -208,7 +208,7 @@ public ApiFuture> futureCall(LabeledIntList request, ApiCallContex public void batchingException() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() - .setDelayThreshold(java.time.Duration.ofSeconds(1)) + .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings> batchingCallSettings = From 67000c71ad67fab7b3045c1b94ccf17031f15509 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 18:58:32 -0400 Subject: [PATCH 087/141] modify overload of ThresholdBatcher --- .../com/google/api/gax/batching/ThresholdBatcher.java | 8 ++++---- .../main/java/com/google/api/gax/rpc/BatcherFactory.java | 2 +- .../com/google/api/gax/batching/ThresholdBatcherTest.java | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index f8a75ed550..384cf52393 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -130,15 +130,15 @@ public Builder setExecutor(ScheduledExecutorService executor) { } /** Set the max delay for a batch. This is counted from the first item added to a batch. */ - public Builder setMaxDelay(java.time.Duration maxDelay) { + public Builder setMaxDelayDuration(java.time.Duration maxDelay) { this.maxDelay = maxDelay; return this; } - /** Set the max delay for a batch. This is counted from the first item added to a batch. */ - @ObsoleteApi("Use setMaxDelay(java.time.Duration) instead") + /** Overload of {@link #setMaxDelayDuration(java.time.Duration} */ + @ObsoleteApi("Use setMaxDelayDuration(java.time.Duration) instead") public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { - return setMaxDelay(toJavaTimeDuration(maxDelay)); + return setMaxDelayDuration(toJavaTimeDuration(maxDelay)); } /** Set the thresholds for the ThresholdBatcher. */ diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java index a703afd078..e324a21760 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/BatcherFactory.java @@ -113,7 +113,7 @@ private ThresholdBatcher> createBatcher(PartitionKey return ThresholdBatcher.>newBuilder() .setThresholds(getThresholds(batchingSettings)) .setExecutor(executor) - .setMaxDelay(batchingSettings.getDelayThresholdDuration()) + .setMaxDelayDuration(batchingSettings.getDelayThresholdDuration()) .setReceiver(processor) .setFlowController(batchingFlowController) .setBatchMerger(new BatchMergerImpl()) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 2265ca6db1..2000599443 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -136,7 +136,7 @@ private static ThresholdBatcher.Builder createSimpleBatcherBuidler( return ThresholdBatcher.newBuilder() .setThresholds(BatchingThresholds.create(100)) .setExecutor(EXECUTOR) - .setMaxDelay(java.time.Duration.ofMillis(10000)) + .setMaxDelayDuration(java.time.Duration.ofMillis(10000)) .setReceiver(receiver) .setFlowController(ThresholdBatcherTest.getDisabledBatchingFlowController()) .setBatchMerger(new SimpleBatchMerger()); @@ -196,7 +196,7 @@ public void testBatchingWithDelay() throws Exception { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); ThresholdBatcher batcher = - createSimpleBatcherBuidler(receiver).setMaxDelay(java.time.Duration.ofMillis(100)).build(); + createSimpleBatcherBuidler(receiver).setMaxDelayDuration(java.time.Duration.ofMillis(100)).build(); batcher.add(SimpleBatch.fromInteger(3)); batcher.add(SimpleBatch.fromInteger(5)); @@ -222,7 +222,7 @@ public void testExceptionWithNullFlowController() { ThresholdBatcher.newBuilder() .setThresholds(BatchingThresholds.create(100)) .setExecutor(EXECUTOR) - .setMaxDelay(java.time.Duration.ofMillis(10000)) + .setMaxDelayDuration(java.time.Duration.ofMillis(10000)) .setReceiver( new AccumulatingBatchReceiver(ApiFutures.immediateFuture(null))) .setBatchMerger(new SimpleBatchMerger()) @@ -368,7 +368,7 @@ public void testMaxDelay() { createSimpleBatcherBuidler(receiver).setThresholds(Collections.emptyList()); testDurationMethod( 123l, - jt -> builder.setMaxDelay(jt).build(), + jt -> builder.setMaxDelayDuration(jt).build(), tt -> builder.setMaxDelay(tt).build(), o -> o.getMaxDelayDuration(), o -> o.getMaxDelay()); From 9266ad05a02885944071f8aec8661c287862de04 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:01:47 -0400 Subject: [PATCH 088/141] fix wrong getter name in exp retry algo --- .../google/api/gax/retrying/ExponentialRetryAlgorithm.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index 865af00bff..cfb8e3e7b4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -69,7 +69,7 @@ public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) .setRetryDelay(java.time.Duration.ZERO) - .setRpcTimeout(getInitialTimeoutDuration(globalSettings)) + .setRpcTimeout(getInitialTimeout(globalSettings)) .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) @@ -98,7 +98,7 @@ public TimedAttemptSettings createFirstAttempt(RetryingContext context) { // Attempts created using the TimedAttemptSettings built here will use these // retrySettings, but a new call will not (unless overridden again). .setGlobalSettings(retrySettings) - .setRpcTimeout(getInitialTimeoutDuration(retrySettings)) + .setRpcTimeout(getInitialTimeout(retrySettings)) .setRetryDelay(java.time.Duration.ZERO) .setRandomizedRetryDelay(java.time.Duration.ZERO) .setAttemptCount(0) @@ -272,7 +272,7 @@ protected long nextRandomLong(long bound) { * Returns the timeout of the first attempt. The initial timeout will be min(initialRpcTimeout, * totalTimeout) if totalTimeout is set. */ - private java.time.Duration getInitialTimeoutDuration(RetrySettings retrySettings) { + private java.time.Duration getInitialTimeout(RetrySettings retrySettings) { // If the totalTimeout is zero (not set), then retries are capped by the max attempt // number. The first attempt will use the initialRpcTimeout value for RPC timeout. long totalTimeout = retrySettings.getTotalTimeout().toMillis(); From 4ee554f79ecc915315d39ef37a561a6bacc5d31e Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:14:12 -0400 Subject: [PATCH 089/141] modify overloads in RetrySettings --- .../api/gax/retrying/RetrySettings.java | 56 +++++++++---------- .../gax/rpc/ServerStreamingCallSettings.java | 10 ++-- .../google/api/gax/rpc/UnaryCallSettings.java | 10 ++-- .../batching/BatchingCallSettingsTest.java | 2 +- .../AbstractRetryingExecutorTest.java | 14 ++--- .../ExponentialRetryAlgorithmTest.java | 44 +++++++-------- .../api/gax/retrying/FailingCallable.java | 20 +++---- .../api/gax/retrying/RetrySettingsTest.java | 24 ++++---- .../ScheduledRetryingExecutorTest.java | 18 +++--- .../api/gax/rpc/BatchingCallSettingsTest.java | 16 +++--- .../com/google/api/gax/rpc/CallableTest.java | 6 +- .../google/api/gax/rpc/CancellationTest.java | 20 +++---- .../gax/rpc/OperationCallableImplTest.java | 30 +++++----- .../api/gax/rpc/PagedCallSettingsTest.java | 16 +++--- .../com/google/api/gax/rpc/RetryingTest.java | 28 +++++----- .../ServerStreamingAttemptCallableTest.java | 2 +- .../rpc/ServerStreamingCallSettingsTest.java | 18 +++--- .../gax/rpc/StreamingRetryAlgorithmTest.java | 20 +++---- .../api/gax/rpc/UnaryCallSettingsTest.java | 18 +++--- 19 files changed, 186 insertions(+), 186 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 1ab25b4216..ce3bcab9f4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -220,15 +220,15 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() - .setTotalTimeout(java.time.Duration.ZERO) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(java.time.Duration.ZERO) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(0) .setJittered(true) - .setInitialRpcTimeout(java.time.Duration.ZERO) + .setInitialRpcTimeoutDuration(java.time.Duration.ZERO) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(java.time.Duration.ZERO); + .setMaxRpcTimeoutDuration(java.time.Duration.ZERO); } public abstract Builder toBuilder(); @@ -240,8 +240,8 @@ public static Builder newBuilder() { @AutoValue.Builder public abstract static class Builder { - /** Backport of {@link #setTotalTimeout(java.time.Duration)} */ - @ObsoleteApi("Use setTotalTimeout(java.time.Duration) instead") + /** Backport of {@link #setTotalTimeoutDuration(java.time.Duration)} */ + @ObsoleteApi("Use setTotalTimeoutDuration(java.time.Duration) instead") public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); /** @@ -257,12 +257,12 @@ public abstract static class Builder { * Duration.ZERO} and LROs have a default total timeout value of {@code * Duration.ofMillis(300000)} (5 minutes). */ - public final Builder setTotalTimeout(java.time.Duration totalTimeout) { + public final Builder setTotalTimeoutDuration(java.time.Duration totalTimeout) { return setTotalTimeout(toThreetenDuration(totalTimeout)); } - /** Backport of {@link #setInitialRetryDelay(java.time.Duration)} */ - @ObsoleteApi("Use setInitialRetryDelay(java.time.Duration) instead") + /** Backport of {@link #setInitialRetryDelayDuration(java.time.Duration)} */ + @ObsoleteApi("Use setInitialRetryDelayDuration(java.time.Duration) instead") public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); /** @@ -273,7 +273,7 @@ public final Builder setTotalTimeout(java.time.Duration totalTimeout) { * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ - public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { + public final Builder setInitialRetryDelayDuration(java.time.Duration initialDelay) { return setInitialRetryDelay(toThreetenDuration(initialDelay)); } @@ -287,8 +287,8 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { */ public abstract Builder setRetryDelayMultiplier(double multiplier); - /** Backport of {@link #setMaxRetryDelay(java.time.Duration)} */ - @ObsoleteApi("Use setMaxRetryDelay(java.time.Duration) instead") + /** Backport of {@link #setMaxRetryDelayDuration(java.time.Duration)} */ + @ObsoleteApi("Use setMaxRetryDelayDuration(java.time.Duration) instead") public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); /** @@ -299,7 +299,7 @@ public final Builder setInitialRetryDelay(java.time.Duration initialDelay) { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ - public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { + public final Builder setMaxRetryDelayDuration(java.time.Duration maxDelay) { return setMaxRetryDelay(toThreetenDuration(maxDelay)); } @@ -332,8 +332,8 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { @VisibleForTesting public abstract Builder setJittered(boolean jittered); - /** Backport of {@link #setInitialRpcTimeout(java.time.Duration)} */ - @ObsoleteApi("Use setInitialRpcTimeout(java.time.Duration) instead") + /** Backport of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} */ + @ObsoleteApi("Use setInitialRpcTimeoutDuration(java.time.Duration) instead") public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); /** @@ -349,7 +349,7 @@ public final Builder setMaxRetryDelay(java.time.Duration maxDelay) { *

    If there are no configurations, Retries have the default initial RPC timeout value of * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ - public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { + public final Builder setInitialRpcTimeoutDuration(java.time.Duration initialTimeout) { return setInitialRpcTimeout(toThreetenDuration(initialTimeout)); } @@ -362,8 +362,8 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { */ public abstract Builder setRpcTimeoutMultiplier(double multiplier); - /** Backport of {@link #setMaxRpcTimeout(java.time.Duration)} */ - @ObsoleteApi("Use setMaxRpcTimeout(java.time.Duration) instead") + /** Backport of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} */ + @ObsoleteApi("Use setMaxRpcTimeoutDuration(java.time.Duration) instead") public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); /** @@ -373,7 +373,7 @@ public final Builder setInitialRpcTimeout(java.time.Duration initialTimeout) { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ - public final Builder setMaxRpcTimeout(java.time.Duration maxTimeout) { + public final Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout) { return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); } @@ -532,9 +532,9 @@ public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { @BetaApi public Builder setLogicalTimeout(java.time.Duration timeout) { return setRpcTimeoutMultiplier(1) - .setInitialRpcTimeout(timeout) - .setMaxRpcTimeout(timeout) - .setTotalTimeout(timeout); + .setInitialRpcTimeoutDuration(timeout) + .setMaxRpcTimeoutDuration(timeout) + .setTotalTimeoutDuration(timeout); } abstract RetrySettings autoBuild(); @@ -570,27 +570,27 @@ public RetrySettings build() { public RetrySettings.Builder merge(RetrySettings.Builder newSettings) { if (newSettings.getTotalTimeoutDuration() != null) { - setTotalTimeout(newSettings.getTotalTimeoutDuration()); + setTotalTimeoutDuration(newSettings.getTotalTimeoutDuration()); } if (newSettings.getInitialRetryDelayDuration() != null) { - setInitialRetryDelay(newSettings.getInitialRetryDelayDuration()); + setInitialRetryDelayDuration(newSettings.getInitialRetryDelayDuration()); } if (newSettings.getRetryDelayMultiplier() >= 1) { setRetryDelayMultiplier(newSettings.getRetryDelayMultiplier()); } if (newSettings.getMaxRetryDelayDuration() != null) { - setMaxRetryDelay(newSettings.getMaxRetryDelayDuration()); + setMaxRetryDelayDuration(newSettings.getMaxRetryDelayDuration()); } setMaxAttempts(newSettings.getMaxAttempts()); setJittered(newSettings.isJittered()); if (newSettings.getInitialRpcTimeoutDuration() != null) { - setInitialRpcTimeout(newSettings.getInitialRpcTimeoutDuration()); + setInitialRpcTimeoutDuration(newSettings.getInitialRpcTimeoutDuration()); } if (newSettings.getRpcTimeoutMultiplier() >= 1) { setRpcTimeoutMultiplier(newSettings.getRpcTimeoutMultiplier()); } if (newSettings.getMaxRpcTimeoutDuration() != null) { - setMaxRpcTimeout(newSettings.getMaxRpcTimeoutDuration()); + setMaxRpcTimeoutDuration(newSettings.getMaxRpcTimeoutDuration()); } return this; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 90101cd00e..6679934e44 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -275,13 +275,13 @@ public Builder setSimpleTimeoutNoRetries( setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(timeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(timeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ZERO) - .setInitialRpcTimeout(timeout) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) + .setInitialRpcTimeoutDuration(timeout) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(timeout) + .setMaxRpcTimeoutDuration(timeout) .setMaxAttempts(1) .build()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 31ae80e185..fa297e93ea 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -209,13 +209,13 @@ public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( setRetryableCodes(); setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(timeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(timeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ZERO) - .setInitialRpcTimeout(timeout) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) + .setInitialRpcTimeoutDuration(timeout) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(timeout) + .setMaxRpcTimeoutDuration(timeout) .setMaxAttempts(1) .build()); return this; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java index ee79939708..d4d1bf6796 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingCallSettingsTest.java @@ -90,7 +90,7 @@ public void testBuilderFromSettings() { BatchingCallSettings.Builder> builder = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC_V2); RetrySettings retrySettings = - RetrySettings.newBuilder().setTotalTimeout(java.time.Duration.ofMinutes(1)).build(); + RetrySettings.newBuilder().setTotalTimeoutDuration(java.time.Duration.ofMinutes(1)).build(); builder .setBatchingSettings(BATCHING_SETTINGS) .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java index 9f354afb24..3dd72f2045 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java @@ -198,8 +198,8 @@ public void testTotalTimeoutExceeded() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); boolean useContextRetrySettings = retryingContext.getRetrySettings() != null; RetryingExecutorWithContext executor = @@ -232,9 +232,9 @@ public void testCancelOuterFutureBeforeStart() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setTotalTimeout(java.time.Duration.ofMillis(10_000L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(10_000L)) .build(); RetryingExecutorWithContext executor = getExecutor(getAlgorithm(retrySettings, 0, null)); @@ -297,8 +297,8 @@ public void testPollExceptionByPollAlgorithm() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); boolean useContextRetrySettings = retryingContext.getRetrySettings() != null; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java index 967936b65a..d3be4ab5f6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ExponentialRetryAlgorithmTest.java @@ -46,26 +46,26 @@ public class ExponentialRetryAlgorithmTest { private final RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(1L)) .setRpcTimeoutMultiplier(2.0) - .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) - .setTotalTimeout(java.time.Duration.ofMillis(200L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(8L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(200L)) .build(); private final ExponentialRetryAlgorithm algorithm = new ExponentialRetryAlgorithm(retrySettings, clock); private final RetrySettings retrySettingsOverride = RetrySettings.newBuilder() .setMaxAttempts(3) - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(3.0) - .setMaxRetryDelay(java.time.Duration.ofMillis(18L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(18L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(3.0) - .setMaxRpcTimeout(java.time.Duration.ofMillis(18L)) - .setTotalTimeout(java.time.Duration.ofMillis(300L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(18L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(300L)) .build(); private final RetryingContext retryingContext = FakeCallContext.createDefault().withRetrySettings(retrySettingsOverride); @@ -104,13 +104,13 @@ public void testCreateFirstAttemptHasCorrectTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(2.0) - .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(rpcTimeout)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(rpcTimeout)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(java.time.Duration.ofMillis(rpcTimeout)) - .setTotalTimeout(java.time.Duration.ofMillis(totalTimeout)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(rpcTimeout)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(totalTimeout)) .build(); ExponentialRetryAlgorithm algorithm = new ExponentialRetryAlgorithm(retrySettings, clock); @@ -123,9 +123,9 @@ public void testCreateFirstAttemptHasCorrectTimeout() { RetrySettings retrySettingsOverride = retrySettings .toBuilder() - .setInitialRpcTimeout(java.time.Duration.ofMillis(overrideRpcTimeout)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(overrideRpcTimeout)) - .setTotalTimeout(java.time.Duration.ofMillis(overrideTotalTimeout)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(overrideRpcTimeout)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(overrideRpcTimeout)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(overrideTotalTimeout)) .build(); RetryingContext retryingContext = FakeCallContext.createDefault().withRetrySettings(retrySettingsOverride); @@ -134,7 +134,7 @@ public void testCreateFirstAttemptHasCorrectTimeout() { java.time.Duration.ofMillis(overrideTotalTimeout), attempt.getRpcTimeoutDuration()); RetrySettings noTotalTimeout = - retrySettings.toBuilder().setTotalTimeout(java.time.Duration.ZERO).build(); + retrySettings.toBuilder().setTotalTimeoutDuration(java.time.Duration.ZERO).build(); algorithm = new ExponentialRetryAlgorithm(noTotalTimeout, clock); attempt = algorithm.createFirstAttempt(); @@ -180,9 +180,9 @@ public void testTruncateToTotalTimeout() { RetrySettings timeoutSettings = retrySettings .toBuilder() - .setInitialRpcTimeout(java.time.Duration.ofSeconds(4L)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(4L)) - .setTotalTimeout(java.time.Duration.ofSeconds(4L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofSeconds(4L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofSeconds(4L)) + .setTotalTimeoutDuration(java.time.Duration.ofSeconds(4L)) .build(); ExponentialRetryAlgorithm timeoutAlg = new ExponentialRetryAlgorithm(timeoutSettings, clock); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java index de5804c6cc..a14f927c03 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/FailingCallable.java @@ -39,24 +39,24 @@ class FailingCallable implements Callable { static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(java.time.Duration.ofMillis(8L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(8L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(8L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(8L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(8L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(8L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(8L)) - .setTotalTimeout(java.time.Duration.ofMillis(400L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(8L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(400L)) .build(); static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(java.time.Duration.ofNanos(1L)) + .setInitialRetryDelayDuration(java.time.Duration.ofNanos(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofNanos(1L)) - .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRetryDelayDuration(java.time.Duration.ofNanos(1L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) - .setTotalTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofNanos(1L)) + .setTotalTimeoutDuration(java.time.Duration.ofNanos(1L)) .build(); private AtomicInteger attemptsCount = new AtomicInteger(0); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java index ad89067b3c..582de93439 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/RetrySettingsTest.java @@ -37,8 +37,8 @@ public class RetrySettingsTest { private static final RetrySettings.Builder DEFAULT_BUILDER = RetrySettings.newBuilder() - .setMaxRpcTimeout(java.time.Duration.ofMillis(5000l)) - .setMaxRetryDelay(java.time.Duration.ofMillis(5000l)); + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(5000l)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(5000l)); @Test public void retrySettingsSetLogicalTimeout() { @@ -55,13 +55,13 @@ public void retrySettingsSetLogicalTimeout() { public void retrySettingsMerge() { RetrySettings.Builder builder = RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(45000)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2000)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(45000)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(2000)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(java.time.Duration.ofMillis(30000)) - .setInitialRetryDelay(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(30000)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(100)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(java.time.Duration.ofMillis(1000)); + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1000)); RetrySettings.Builder mergedBuilder = RetrySettings.newBuilder(); mergedBuilder.merge(builder); @@ -90,7 +90,7 @@ public void retrySettingsMerge() { public void testTotalTimeout() { testDurationMethod( 123l, - jt -> DEFAULT_BUILDER.setTotalTimeout(jt).build(), + jt -> DEFAULT_BUILDER.setTotalTimeoutDuration(jt).build(), tt -> DEFAULT_BUILDER.setTotalTimeout(tt).build(), rs -> rs.getTotalTimeoutDuration(), rs -> rs.getTotalTimeout()); @@ -100,7 +100,7 @@ public void testTotalTimeout() { public void testInitialRetryDelay() { testDurationMethod( 123l, - jt -> DEFAULT_BUILDER.setInitialRetryDelay(jt).build(), + jt -> DEFAULT_BUILDER.setInitialRetryDelayDuration(jt).build(), tt -> DEFAULT_BUILDER.setInitialRetryDelay(tt).build(), rs -> rs.getInitialRetryDelayDuration(), rs -> rs.getInitialRetryDelay()); @@ -110,7 +110,7 @@ public void testInitialRetryDelay() { public void testMaxRetryDelay() { testDurationMethod( 123l, - jt -> DEFAULT_BUILDER.setMaxRetryDelay(jt).build(), + jt -> DEFAULT_BUILDER.setMaxRetryDelayDuration(jt).build(), tt -> DEFAULT_BUILDER.setMaxRetryDelay(tt).build(), rs -> rs.getMaxRetryDelayDuration(), rs -> rs.getMaxRetryDelay()); @@ -120,7 +120,7 @@ public void testMaxRetryDelay() { public void testInitialRpcTimeout() { testDurationMethod( 123l, - jt -> DEFAULT_BUILDER.setInitialRpcTimeout(jt).build(), + jt -> DEFAULT_BUILDER.setInitialRpcTimeoutDuration(jt).build(), tt -> DEFAULT_BUILDER.setInitialRpcTimeout(tt).build(), rs -> rs.getInitialRpcTimeoutDuration(), rs -> rs.getInitialRpcTimeout()); @@ -130,7 +130,7 @@ public void testInitialRpcTimeout() { public void testMaxRpcTimeout() { testDurationMethod( 123l, - jt -> DEFAULT_BUILDER.setMaxRpcTimeout(jt).build(), + jt -> DEFAULT_BUILDER.setMaxRpcTimeoutDuration(jt).build(), tt -> DEFAULT_BUILDER.setMaxRpcTimeout(tt).build(), rs -> rs.getMaxRpcTimeoutDuration(), rs -> rs.getMaxRpcTimeout()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java index e200bd0ad9..0989f73005 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java @@ -93,7 +93,7 @@ public void testSuccessWithFailuresPeekAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -144,7 +144,7 @@ public void testSuccessWithFailuresGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -198,7 +198,7 @@ public void testCancelGetAttempt() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(1000L)) .setMaxAttempts(maxRetries) .build(); @@ -258,10 +258,10 @@ public void testCancelOuterFutureAfterStart() throws Exception { // once) but does not complete before it is cancelled. Assuming no computation time, // it would take 25 + 100 + 400 + 1000 = 1525ms for the future to complete, which should // be more than enough time to cancel the future. - .setInitialRetryDelay(java.time.Duration.ofMillis(25L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1000L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(25L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1000L)) .setRetryDelayMultiplier(4.0) - .setTotalTimeout(java.time.Duration.ofMillis(60000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(60000L)) // Set this test to not use jitter as the randomized retry delay (RRD) may introduce // flaky results. For example, if every RRD value is calculated to be a small value // (i.e. 2ms), four retries would result a "SUCCESS" result after 8ms, far below @@ -310,9 +310,9 @@ public void testCancelProxiedFutureAfterStart() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1_000L)) - .setTotalTimeout(java.time.Duration.ofMillis(10_0000L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1_000L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1_000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(10_0000L)) .build(); RetryingExecutorWithContext executor = getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java index 47d39731fe..e21e729a00 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatchingCallSettingsTest.java @@ -84,11 +84,11 @@ public void testBuilder() { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -128,11 +128,11 @@ public void testBuilderFromSettings() throws Exception { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index bfd3afe6e8..8a7269096e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -61,9 +61,9 @@ public class CallableTest { private RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRpcTimeout(java.time.Duration.ofMillis(5L)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(5L)) - .setTotalTimeout(java.time.Duration.ofMillis(10L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(5L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(5L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(10L)) .build(); @Spy private ApiCallContext callContext = FakeCallContext.createDefault(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java index 7914ab876d..2003aa6189 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CancellationTest.java @@ -62,24 +62,24 @@ public class CancellationTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) - .setTotalTimeout(java.time.Duration.ofMillis(20L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(20L)) .build(); private static final RetrySettings SLOW_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(3000L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(3000L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(3000L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(3000L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(3000L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(3000L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(3000L)) - .setTotalTimeout(java.time.Duration.ofMillis(3000L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(3000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(3000L)) .build(); private FakeApiClock fakeClock; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java index 032948bda3..5e55e32242 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/OperationCallableImplTest.java @@ -79,31 +79,31 @@ public class OperationCallableImplTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) - .setTotalTimeout(java.time.Duration.ofMillis(10L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAST_RECHECKING_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) - .setInitialRpcTimeout( + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration( java.time.Duration .ZERO) // supposed to be ignored, but are not actually, so we set to zero .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier( 1) // supposed to be ignored, but are not actually, so we set to one - .setMaxRpcTimeout( + .setMaxRpcTimeoutDuration( java.time.Duration .ZERO) // supposed to be ignored, but are not actually, so we set to zero - .setTotalTimeout(java.time.Duration.ofMillis(5L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(5L)) .build(); private FakeChannel initialChannel; @@ -485,10 +485,10 @@ public void testFutureCallPollRPCTimeout() throws Exception { // for LRO polling. They are not actually ignored in code, so they changing them // here has an actual affect. This test verifies that they work as such, but in // practice generated clients set the RPC timeouts to 0 to be ignored. - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(1)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(2) - .setTotalTimeout(java.time.Duration.ofSeconds(5L)) + .setTotalTimeoutDuration(java.time.Duration.ofSeconds(5L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -593,7 +593,7 @@ public void testFutureCallPollDoneOnMany() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(iterationsCount)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(iterationsCount)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); @@ -703,7 +703,7 @@ public void testFutureCallPollCancelOnLongTimeoutExceeded() throws Exception { OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(1000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(1000L)) .build(), clock); callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java index 687b2895cb..038ade9231 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/PagedCallSettingsTest.java @@ -74,11 +74,11 @@ public void testBuilder() { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -107,11 +107,11 @@ public void testBuilderFromSettings() throws Exception { Set retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java index da6639cb54..d8c5b02796 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java @@ -68,24 +68,24 @@ public class RetryingTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(2L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(2L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(2L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(2L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(2L)) - .setTotalTimeout(java.time.Duration.ofMillis(10L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(2L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(10L)) .build(); private static final RetrySettings FAILING_RETRY_SETTINGS = RetrySettings.newBuilder() .setMaxAttempts(2) - .setInitialRetryDelay(java.time.Duration.ofNanos(0L)) + .setInitialRetryDelayDuration(java.time.Duration.ofNanos(0L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(0L)) - .setInitialRpcTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(0L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofNanos(1L)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofNanos(1L)) - .setTotalTimeout(java.time.Duration.ofNanos(1L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofNanos(1L)) + .setTotalTimeoutDuration(java.time.Duration.ofNanos(1L)) .build(); @Before @@ -151,8 +151,8 @@ public void retryTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); assertRetrying(retrySettings); @@ -169,8 +169,8 @@ public void retryUsingContextTotalTimeoutExceeded() { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) - .setMaxRetryDelay(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(Integer.MAX_VALUE)) .build(); try { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index b7b8f06f76..c5df6ea235 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -474,7 +474,7 @@ private static class FakeRetryingFuture extends AbstractApiFuture this.attemptCallable = attemptCallable; attemptSettings = TimedAttemptSettings.newBuilder() - .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build()) + .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeoutDuration(totalTimeout).build()) .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java index 642553edc4..c54231f643 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java @@ -66,11 +66,11 @@ public void retryableCodesVarArgs() { public void retryableSettingsAreNotLost() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -116,11 +116,11 @@ public void waitTimeoutIsNotLost() { public void testRetrySettingsBuilder() { RetrySettings initialSettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -129,7 +129,7 @@ public void testRetrySettingsBuilder() { ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder().setRetrySettings(initialSettings); - builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); + builder.retrySettings().setMaxRetryDelayDuration(java.time.Duration.ofMinutes(1)); assertThat(builder.getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java index 6e4c582cc2..c45704eac5 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/StreamingRetryAlgorithmTest.java @@ -51,26 +51,26 @@ public class StreamingRetryAlgorithmTest { private static final RetrySettings DEFAULT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(10L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(10L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100L)) .setMaxAttempts(10) - .setMaxRetryDelay(java.time.Duration.ofSeconds(10L)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(30L)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(10L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofSeconds(30L)) .setRetryDelayMultiplier(1.4) .setRpcTimeoutMultiplier(1.5) - .setTotalTimeout(java.time.Duration.ofMinutes(10L)) + .setTotalTimeoutDuration(java.time.Duration.ofMinutes(10L)) .build(); private static final RetrySettings CONTEXT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(20L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(200L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(20L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(200L)) .setMaxAttempts(10) - .setMaxRetryDelay(java.time.Duration.ofSeconds(20L)) - .setMaxRpcTimeout(java.time.Duration.ofSeconds(60L)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(20L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofSeconds(60L)) .setRetryDelayMultiplier(2.4) .setRpcTimeoutMultiplier(2.5) - .setTotalTimeout(java.time.Duration.ofMinutes(20L)) + .setTotalTimeoutDuration(java.time.Duration.ofMinutes(20L)) .build(); @Test diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index c46d143781..894f00b6b0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -78,11 +78,11 @@ public void testEquals() { public void testEquals_retrySettings() { RetrySettings initialSettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -115,11 +115,11 @@ public void testEquals_retryableCodes() { public void testRetrySettingsBuilder() { RetrySettings initialSettings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(5)) - .setMaxRetryDelay(java.time.Duration.ofSeconds(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofSeconds(1)) .setRetryDelayMultiplier(2) - .setInitialRpcTimeout(java.time.Duration.ofMillis(100)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(200)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(100)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(200)) .setRpcTimeoutMultiplier(1.1) .setJittered(true) .setMaxAttempts(10) @@ -128,7 +128,7 @@ public void testRetrySettingsBuilder() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder().setRetrySettings(initialSettings); - builder.retrySettings().setMaxRetryDelay(java.time.Duration.ofMinutes(1)); + builder.retrySettings().setMaxRetryDelayDuration(java.time.Duration.ofMinutes(1)); assertThat(builder.getRetrySettings().getMaxRetryDelayDuration()) .isEqualTo(java.time.Duration.ofMinutes(1)); From 75668a5b609c30e70c4883abc7f0ca269d53d196 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:17:56 -0400 Subject: [PATCH 090/141] modify overloads in TimedAttemptSettings --- .../retrying/ExponentialRetryAlgorithm.java | 18 +++++++++--------- .../api/gax/retrying/TimedAttemptSettings.java | 18 +++++++++--------- .../gax/retrying/TimedAttemptSettingsTest.java | 10 +++++----- .../api/gax/rpc/AttemptCallableTest.java | 12 ++++++------ .../gax/rpc/CheckingAttemptCallableTest.java | 12 ++++++------ .../ServerStreamingAttemptCallableTest.java | 6 +++--- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index cfb8e3e7b4..6a4a892bd2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -68,9 +68,9 @@ public ExponentialRetryAlgorithm(RetrySettings globalSettings, ApiClock clock) { public TimedAttemptSettings createFirstAttempt() { return TimedAttemptSettings.newBuilder() .setGlobalSettings(globalSettings) - .setRetryDelay(java.time.Duration.ZERO) - .setRpcTimeout(getInitialTimeout(globalSettings)) - .setRandomizedRetryDelay(java.time.Duration.ZERO) + .setRetryDelayDuration(java.time.Duration.ZERO) + .setRpcTimeoutDuration(getInitialTimeout(globalSettings)) + .setRandomizedRetryDelayDuration(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -98,9 +98,9 @@ public TimedAttemptSettings createFirstAttempt(RetryingContext context) { // Attempts created using the TimedAttemptSettings built here will use these // retrySettings, but a new call will not (unless overridden again). .setGlobalSettings(retrySettings) - .setRpcTimeout(getInitialTimeout(retrySettings)) - .setRetryDelay(java.time.Duration.ZERO) - .setRandomizedRetryDelay(java.time.Duration.ZERO) + .setRpcTimeoutDuration(getInitialTimeout(retrySettings)) + .setRetryDelayDuration(java.time.Duration.ZERO) + .setRandomizedRetryDelayDuration(java.time.Duration.ZERO) .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(clock.nanoTime()) @@ -163,9 +163,9 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSetti return TimedAttemptSettings.newBuilder() .setGlobalSettings(previousSettings.getGlobalSettings()) - .setRetryDelay(java.time.Duration.ofMillis(newRetryDelay)) - .setRpcTimeout(java.time.Duration.ofMillis(newRpcTimeout)) - .setRandomizedRetryDelay(randomDelay) + .setRetryDelayDuration(java.time.Duration.ofMillis(newRetryDelay)) + .setRpcTimeoutDuration(java.time.Duration.ofMillis(newRpcTimeout)) + .setRandomizedRetryDelayDuration(randomDelay) .setAttemptCount(previousSettings.getAttemptCount() + 1) .setOverallAttemptCount(previousSettings.getOverallAttemptCount() + 1) .setFirstAttemptStartTimeNanos(previousSettings.getFirstAttemptStartTimeNanos()) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index ef79a46b20..69083890ba 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -107,42 +107,42 @@ public abstract static class Builder { public abstract Builder setGlobalSettings(RetrySettings value); /** - * Backport of {@link #setRetryDelay(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Backport of {@link #setRetryDelayDuration(java.time.Duration)} using {@link org.threeten.bp.Duration} */ - @ObsoleteApi("Use setRetryDelay(java.time.Duration) instead") + @ObsoleteApi("Use setRetryDelayDuration(java.time.Duration) instead") public abstract Builder setRetryDelay(org.threeten.bp.Duration value); /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public final Builder setRetryDelay(java.time.Duration value) { + public final Builder setRetryDelayDuration(java.time.Duration value) { return setRetryDelay(toThreetenDuration(value)); } /** - * Backport of {@link #setRpcTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Backport of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link org.threeten.bp.Duration} */ - @ObsoleteApi("Use setRpcTimeout(java.time.Duration) instead") + @ObsoleteApi("Use setRpcTimeoutDuration(java.time.Duration) instead") public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); /** Sets rpc timeout used for this attempt. */ - public final Builder setRpcTimeout(java.time.Duration value) { + public final Builder setRpcTimeoutDuration(java.time.Duration value) { return setRpcTimeout(toThreetenDuration(value)); } /** - * Backport of {@link #setRandomizedRetryDelay(java.time.Duration)} using {@link + * Backport of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use setRandomizedRetryDelay(java.time.Duration) instead") + @ObsoleteApi("Use setRandomizedRetryDelayDuration(java.time.Duration) instead") public abstract Builder setRandomizedRetryDelay(org.threeten.bp.Duration value); /** * Sets randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public final Builder setRandomizedRetryDelay(java.time.Duration value) { + public final Builder setRandomizedRetryDelayDuration(java.time.Duration value) { return setRandomizedRetryDelay(toThreetenDuration(value)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java index b6b57c483d..a8b0d80d1e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java @@ -38,8 +38,8 @@ public class TimedAttemptSettingsTest { private static final TimedAttemptSettings.Builder SETTINGS_BUILDER = TimedAttemptSettings.newBuilder() .setGlobalSettings(RetrySettings.newBuilder().build()) - .setRpcTimeout(java.time.Duration.ofMillis(5000l)) - .setRandomizedRetryDelay(java.time.Duration.ofMillis(5000l)) + .setRpcTimeoutDuration(java.time.Duration.ofMillis(5000l)) + .setRandomizedRetryDelayDuration(java.time.Duration.ofMillis(5000l)) .setAttemptCount(123) .setFirstAttemptStartTimeNanos(123l); @@ -47,7 +47,7 @@ public class TimedAttemptSettingsTest { public void testRetryDelay() { testDurationMethod( 123l, - jt -> SETTINGS_BUILDER.setRetryDelay(jt).build(), + jt -> SETTINGS_BUILDER.setRetryDelayDuration(jt).build(), tt -> SETTINGS_BUILDER.setRetryDelay(tt).build(), o -> o.getRetryDelayDuration(), o -> o.getRetryDelay()); @@ -57,7 +57,7 @@ public void testRetryDelay() { public void testRandomizedRetryDelay() { testDurationMethod( 123l, - jt -> SETTINGS_BUILDER.setRandomizedRetryDelay(jt).build(), + jt -> SETTINGS_BUILDER.setRandomizedRetryDelayDuration(jt).build(), tt -> SETTINGS_BUILDER.setRandomizedRetryDelay(tt).build(), o -> o.getRandomizedRetryDelayDuration(), o -> o.getRandomizedRetryDelay()); @@ -67,7 +67,7 @@ public void testRandomizedRetryDelay() { public void testRpcTimeout() { testDurationMethod( 123l, - jt -> SETTINGS_BUILDER.setRpcTimeout(jt).build(), + jt -> SETTINGS_BUILDER.setRpcTimeoutDuration(jt).build(), tt -> SETTINGS_BUILDER.setRpcTimeout(tt).build(), o -> o.getRpcTimeoutDuration(), o -> o.getRpcTimeout()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 4b5de1a516..9f6cc138c2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -65,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(java.time.Duration.ofSeconds(1)) - .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) - .setRpcTimeout(java.time.Duration.ZERO) + .setRetryDelayDuration(java.time.Duration.ofSeconds(1)) + .setRandomizedRetryDelayDuration(java.time.Duration.ofSeconds(1)) + .setRpcTimeoutDuration(java.time.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) @@ -88,7 +88,7 @@ public void testRpcTimeout() { // Make sure that the rpc timeout is set java.time.Duration timeout = java.time.Duration.ofSeconds(10); - currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); + currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); callable.call(); @@ -97,7 +97,7 @@ public void testRpcTimeout() { // Make sure that subsequent attempts can extend the time out java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = - currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); + currentAttemptSettings.toBuilder().setRpcTimeoutDuration(longerTimeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } @@ -109,7 +109,7 @@ public void testRpcTimeoutIsNotErased() { FakeCallContext.createDefault().withTimeoutDuration(callerTimeout); java.time.Duration timeout = java.time.Duration.ofMillis(5); - currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); + currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); AttemptCallable callable = new AttemptCallable<>(mockInnerCallable, "fake-request", callerCallContext); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index 922fd62044..f82ef9c789 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -65,9 +65,9 @@ public void setUp() { .setAttemptCount(0) .setOverallAttemptCount(0) .setFirstAttemptStartTimeNanos(0) - .setRetryDelay(java.time.Duration.ofSeconds(1)) - .setRandomizedRetryDelay(java.time.Duration.ofSeconds(1)) - .setRpcTimeout(java.time.Duration.ZERO) + .setRetryDelayDuration(java.time.Duration.ofSeconds(1)) + .setRandomizedRetryDelayDuration(java.time.Duration.ofSeconds(1)) + .setRpcTimeoutDuration(java.time.Duration.ZERO) .build(); Mockito.when(mockExternalFuture.getAttemptSettings()) @@ -88,16 +88,16 @@ public void testRpcTimeout() { // Make sure that the rpc timeout is set java.time.Duration timeout = java.time.Duration.ofSeconds(10); - currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); + currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(timeout); - // Make sure that subsequent attempts can extend the time out + // Make sure that subsequent attempts can extend the timeout java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = - currentAttemptSettings.toBuilder().setRpcTimeout(longerTimeout).build(); + currentAttemptSettings.toBuilder().setRpcTimeoutDuration(longerTimeout).build(); callable.call(); assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index c5df6ea235..1a2db0df13 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -478,9 +478,9 @@ private static class FakeRetryingFuture extends AbstractApiFuture .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) - .setRandomizedRetryDelay(java.time.Duration.ofMillis(1)) - .setRetryDelay(java.time.Duration.ofMillis(1)) - .setRpcTimeout(java.time.Duration.ofMinutes(1)) + .setRandomizedRetryDelayDuration(java.time.Duration.ofMillis(1)) + .setRetryDelayDuration(java.time.Duration.ofMillis(1)) + .setRpcTimeoutDuration(java.time.Duration.ofMinutes(1)) .build(); } From 964625f4558d8fe5deed0b4acd5dd15c83a3bcb2 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:21:01 -0400 Subject: [PATCH 091/141] modify overloads of ClientContext --- .../main/java/com/google/api/gax/rpc/ClientContext.java | 9 +++++---- .../java/com/google/api/gax/rpc/ClientContextTest.java | 2 +- .../java/com/google/api/gax/rpc/ClientSettingsTest.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 5f4600b04e..da1a8f698e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -147,7 +147,7 @@ public static Builder newBuilder() { .setInternalHeaders(Collections.emptyMap()) .setClock(NanoClock.getDefaultClock()) .setStreamWatchdog(null) - .setStreamWatchdogCheckInterval(java.time.Duration.ZERO) + .setStreamWatchdogCheckIntervalDuration(java.time.Duration.ZERO) .setTracerFactory(BaseApiTracerFactory.getInstance()) .setQuotaProjectId(null) .setGdchApiAudience(null) @@ -288,7 +288,7 @@ public static ClientContext create(StubSettings settings) throws IOException { .setEndpoint(settings.getEndpoint()) .setQuotaProjectId(settings.getQuotaProjectId()) .setStreamWatchdog(watchdog) - .setStreamWatchdogCheckInterval(settings.getStreamWatchdogCheckIntervalDuration()) + .setStreamWatchdogCheckIntervalDuration(settings.getStreamWatchdogCheckIntervalDuration()) .setTracerFactory(settings.getTracerFactory()) .setEndpointContext(endpointContext) .build(); @@ -359,10 +359,11 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); - @ObsoleteApi("Use setStreamWatchdogCheckInterval(java.time.Duration) instead") + /** Backport of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} */ + @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") public abstract Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration); - public final Builder setStreamWatchdogCheckInterval(java.time.Duration duration) { + public final Builder setStreamWatchdogCheckIntervalDuration(java.time.Duration duration) { return setStreamWatchdogCheckInterval(toThreetenDuration(duration)); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 2354937cf5..efddb9cc75 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -1074,7 +1074,7 @@ public void testStreamWatchdogInterval_backportMethodsBehaveCorrectly() { ClientContext.newBuilder().setDefaultCallContext(FakeCallContext.createDefault()); testDurationMethod( 123L, - jt -> builder.setStreamWatchdogCheckInterval(jt).build(), + jt -> builder.setStreamWatchdogCheckIntervalDuration(jt).build(), tt -> builder.setStreamWatchdogCheckInterval(tt).build(), ct -> ct.getStreamWatchdogCheckIntervalDuration(), ct -> ct.getStreamWatchdogCheckInterval()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java index 5afa1e4d2b..341e055044 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java @@ -230,7 +230,7 @@ public void testBuilderFromClientContext() throws Exception { .setDefaultCallContext(callContext) .setHeaders(headers) .setStreamWatchdog(watchdog) - .setStreamWatchdogCheckInterval(watchdogCheckInterval) + .setStreamWatchdogCheckIntervalDuration(watchdogCheckInterval) .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT) .build(); From 1c0df2336452336d5a79f8b6768f74f0f040b83b Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:23:58 -0400 Subject: [PATCH 092/141] modify overloads in ClientSettings --- .../main/java/com/google/api/gax/rpc/ClientSettings.java | 5 +++-- .../test/java/com/google/api/gax/rpc/ClientContextTest.java | 4 ++-- .../java/com/google/api/gax/rpc/ClientSettingsTest.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 4005bfb542..e0f718dd05 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -278,13 +278,14 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { return self(); } - @ObsoleteApi("Use setWatchdogCheckInterval(java.time.Duration) instead") + /** Backport of {@link #setWatchdogCheckIntervalDuration(java.time.Duration)} */ + @ObsoleteApi("Use setWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { stubSettings.setStreamWatchdogCheckInterval(checkInterval); return self(); } - public B setWatchdogCheckInterval(@Nullable java.time.Duration checkInterval) { + public B setWatchdogCheckIntervalDuration(@Nullable java.time.Duration checkInterval) { stubSettings.setStreamWatchdogCheckInterval(checkInterval); return self(); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index efddb9cc75..4e06f8f8e9 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -295,7 +295,7 @@ private void runTest( builder.setTransportChannelProvider(transportProvider); builder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)); builder.setWatchdogProvider(FixedWatchdogProvider.create(watchdog)); - builder.setWatchdogCheckInterval(watchdogCheckInterval); + builder.setWatchdogCheckIntervalDuration(watchdogCheckInterval); builder.setClock(clock); HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); @@ -370,7 +370,7 @@ public void testWatchdogProvider() throws IOException { .withClock(clock) .withCheckInterval(watchdogCheckInterval) .withExecutor(executor)); - builder.setWatchdogCheckInterval(watchdogCheckInterval); + builder.setWatchdogCheckIntervalDuration(watchdogCheckInterval); HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of("k1", "v1")); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java index 341e055044..96aa3e1931 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java @@ -177,7 +177,7 @@ public void testBuilder() throws Exception { builder.setInternalHeaderProvider(internalHeaderProvider); builder.setClock(clock); builder.setWatchdogProvider(watchdogProvider); - builder.setWatchdogCheckInterval(watchdogCheckInterval); + builder.setWatchdogCheckIntervalDuration(watchdogCheckInterval); builder.setQuotaProjectId(quotaProjectId); // For backward compatibility, backgroundExecutorProvider is set to executorProvider @@ -274,7 +274,7 @@ public void testBuilderFromSettings() throws Exception { builder.setHeaderProvider(headerProvider); builder.setInternalHeaderProvider(internalHeaderProvider); builder.setWatchdogProvider(watchdogProvider); - builder.setWatchdogCheckInterval(watchdogCheckInterval); + builder.setWatchdogCheckIntervalDuration(watchdogCheckInterval); builder.setQuotaProjectId(quotaProjectId); FakeClientSettings settings = builder.build(); @@ -568,7 +568,7 @@ public void testWatchdogCheckInterval_backportMethodsBehaveCorrectly() { }; testDurationMethod( 123l, - jt -> createClientSettings.apply(() -> builder.setWatchdogCheckInterval(jt)), + jt -> createClientSettings.apply(() -> builder.setWatchdogCheckIntervalDuration(jt)), tt -> createClientSettings.apply(() -> builder.setWatchdogCheckInterval(tt)), cs -> cs.getWatchdogCheckIntervalDuration(), cs -> cs.getWatchdogCheckInterval()); From 53d2131562919ace5aacb0ff0e1ed9cabfb33b48 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:39:52 -0400 Subject: [PATCH 093/141] modify overloads for watchdogs --- .../com/google/api/gax/rpc/ClientContext.java | 2 +- .../api/gax/rpc/FixedWatchdogProvider.java | 10 ++++++++- .../rpc/InstantiatingWatchdogProvider.java | 14 +++++++++++-- .../java/com/google/api/gax/rpc/Watchdog.java | 12 +++++++++++ .../google/api/gax/rpc/WatchdogProvider.java | 8 ++++++- .../google/api/gax/rpc/ClientContextTest.java | 2 +- .../gax/rpc/FixedWatchdogProviderTest.java | 12 ++++++++++- .../InstantiatingWatchdogProviderTest.java | 21 ++++++++++++++++--- 8 files changed, 71 insertions(+), 10 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index da1a8f698e..fd9da82262 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -252,7 +252,7 @@ public static ClientContext create(StubSettings settings) throws IOException { if (watchdogProvider != null) { if (watchdogProvider.needsCheckInterval()) { watchdogProvider = - watchdogProvider.withCheckInterval(settings.getStreamWatchdogCheckIntervalDuration()); + watchdogProvider.withCheckIntervalDuration(settings.getStreamWatchdogCheckIntervalDuration()); } if (watchdogProvider.needsClock()) { watchdogProvider = watchdogProvider.withClock(clock); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java index a21a2d61e4..e8cba4234c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java @@ -31,6 +31,8 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; + import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -70,7 +72,13 @@ public boolean needsCheckInterval() { } @Override - public WatchdogProvider withCheckInterval(java.time.Duration checkInterval) { + @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") + public WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval) { + throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); + } + + @Override + public WatchdogProvider withCheckIntervalDuration(java.time.Duration checkInterval) { throw new UnsupportedOperationException("FixedWatchdogProvider doesn't need a checkInterval"); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index 94dcd486bb..927271502c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -31,11 +31,14 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.common.base.Preconditions; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + /** * A watchdog provider which instantiates a new provider on every request. * @@ -77,10 +80,17 @@ public boolean needsCheckInterval() { return checkInterval == null; } + /** Backport of {@link #withCheckIntervalDuration(java.time.Duration)} */ + @Override + @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") + public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { + return withCheckIntervalDuration(toJavaTimeDuration(checkInterval)); + } + @Override - public WatchdogProvider withCheckInterval(@Nonnull java.time.Duration checkInterval) { + public WatchdogProvider withCheckIntervalDuration(@Nonnull java.time.Duration checkInterval) { return new InstantiatingWatchdogProvider( - clock, executor, Preconditions.checkNotNull(checkInterval)); + clock, executor, Preconditions.checkNotNull(checkInterval)); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 9a9bd2b694..7cf458452e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -30,10 +30,12 @@ package com.google.api.gax.rpc; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import com.google.api.core.ApiClock; import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.BackgroundResource; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.errorprone.annotations.concurrent.GuardedBy; import java.util.Iterator; @@ -185,6 +187,16 @@ public void close() { shutdown(); } + @VisibleForTesting + java.time.Duration getScheduleIntervalDuration() { + return this.scheduleInterval; + } + + @VisibleForTesting + org.threeten.bp.Duration getScheduleInterval() { + return toThreetenDuration(this.scheduleInterval); + } + enum State { /** Stream has been started, but doesn't have any outstanding requests. */ IDLE, diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index 0951e95f5d..5a300657d8 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -31,6 +31,8 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; + import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; @@ -42,7 +44,11 @@ public interface WatchdogProvider { boolean needsCheckInterval(); - WatchdogProvider withCheckInterval(java.time.Duration checkInterval); + /** Backport of {@link #withCheckIntervalDuration(java.time.Duration)} */ + @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") + WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); + + WatchdogProvider withCheckIntervalDuration(java.time.Duration checkInterval); boolean needsExecutor(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 4e06f8f8e9..1e28a6e32a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -368,7 +368,7 @@ public void testWatchdogProvider() throws IOException { builder.setWatchdogProvider( InstantiatingWatchdogProvider.create() .withClock(clock) - .withCheckInterval(watchdogCheckInterval) + .withCheckIntervalDuration(watchdogCheckInterval) .withExecutor(executor)); builder.setWatchdogCheckIntervalDuration(watchdogCheckInterval); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index 88206d9f28..1212b42410 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -29,7 +29,9 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; import com.google.api.core.ApiClock; import java.util.concurrent.ScheduledExecutorService; @@ -74,7 +76,7 @@ public void testNoModifications() { Throwable actualError = null; try { - provider.withCheckInterval(java.time.Duration.ofSeconds(10)); + provider.withCheckIntervalDuration(java.time.Duration.ofSeconds(10)); } catch (Throwable t) { actualError = t; } @@ -96,4 +98,12 @@ public void testNoModifications() { } assertThat(actualError).isInstanceOf(UnsupportedOperationException.class); } + + @Test + public void testWithCheckInterval_backportMethodsBehaveTheSame() { + assertThrows(UnsupportedOperationException.class, () -> FixedWatchdogProvider.create(null) + .withCheckIntervalDuration(java.time.Duration.ofMillis(123l))); + assertThrows(UnsupportedOperationException.class, () -> FixedWatchdogProvider.create(null) + .withCheckInterval(org.threeten.bp.Duration.ofMillis(123l))); + } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java index e0464b3d0e..dcd5b9cd5f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java @@ -29,6 +29,7 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import com.google.api.core.ApiClock; @@ -57,7 +58,7 @@ public void happyPath() { provider = provider.withClock(clock); assertThat(provider.needsCheckInterval()).isTrue(); - provider = provider.withCheckInterval(checkInterval); + provider = provider.withCheckIntervalDuration(checkInterval); assertThat(provider.shouldAutoClose()).isTrue(); @@ -70,7 +71,7 @@ public void happyPath() { @Test public void requiresExecutor() { WatchdogProvider provider = - InstantiatingWatchdogProvider.create().withCheckInterval(checkInterval).withClock(clock); + InstantiatingWatchdogProvider.create().withCheckIntervalDuration(checkInterval).withClock(clock); Throwable actualError = null; try { @@ -100,7 +101,7 @@ public void requiresClock() { WatchdogProvider provider = InstantiatingWatchdogProvider.create() .withExecutor(executor) - .withCheckInterval(checkInterval); + .withCheckIntervalDuration(checkInterval); Throwable actualError = null; try { @@ -110,4 +111,18 @@ public void requiresClock() { } assertThat(actualError).isInstanceOf(IllegalStateException.class); } + + @Test + public void testCheckInterval_backportMethodsBehaveCorrectly() { + final InstantiatingWatchdogProvider baseProvider = (InstantiatingWatchdogProvider) InstantiatingWatchdogProvider.create() + .withClock(clock) + .withExecutor(executor); + testDurationMethod( + 123l, + jt -> baseProvider.withCheckIntervalDuration(jt), + tt -> baseProvider.withCheckInterval(tt), + wp -> wp.getWatchdog().getScheduleIntervalDuration(), + wp -> wp.getWatchdog().getScheduleInterval() + ); + } } From 587f0601019e0286845579fc84a386832d6d56c7 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 19:56:29 -0400 Subject: [PATCH 094/141] modify overloads of ServerStreamingCallSettings --- .../com/google/api/gax/rpc/Callables.java | 2 +- .../gax/rpc/ServerStreamingCallSettings.java | 24 +++++++++---------- .../com/google/api/gax/rpc/CallableTest.java | 4 ++-- .../rpc/ServerStreamingCallSettingsTest.java | 10 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 10d355b829..9d4b1a7475 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -129,7 +129,7 @@ public static ServerStreamingCallable settings = settings .toBuilder() - .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeoutDuration()) + .setSimpleTimeoutNoRetriesDuration(settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 6679934e44..0cc1ba37d6 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -260,17 +260,17 @@ public RetrySettings getRetrySettings() { } /** - * Overload of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} using {@link + * Overload of {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use setSimpleTimeoutNoRetries(java.time.Duration) instead") + @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { - return setSimpleTimeoutNoRetries(toJavaTimeDuration(timeout)); + return setSimpleTimeoutNoRetriesDuration(toJavaTimeDuration(timeout)); } /** Disables retries and sets the overall timeout. */ - public Builder setSimpleTimeoutNoRetries( + public Builder setSimpleTimeoutNoRetriesDuration( @Nonnull java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( @@ -317,19 +317,19 @@ public java.time.Duration getIdleTimeoutDuration() { } /** - * Overlad of {@link #setIdleTimeout(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overlad of {@link #setIdleTimeoutDuration(java.time.Duration)} using {@link org.threeten.bp.Duration} */ - @ObsoleteApi("Use setIdleTimeout(java.time.Duration) instead") + @ObsoleteApi("Use setIdleTimeoutDuration(java.time.Duration) instead") public Builder setIdleTimeout( @Nonnull org.threeten.bp.Duration idleTimeout) { - return setIdleTimeout(toJavaTimeDuration(idleTimeout)); + return setIdleTimeoutDuration(toJavaTimeDuration(idleTimeout)); } /** * Set how long to wait before considering the stream orphaned by the user and closing it. * {@link java.time.Duration#ZERO} disables the check for abandoned streams. */ - public Builder setIdleTimeout(@Nonnull java.time.Duration idleTimeout) { + public Builder setIdleTimeoutDuration(@Nonnull java.time.Duration idleTimeout) { this.idleTimeout = Preconditions.checkNotNull(idleTimeout); return this; } @@ -347,20 +347,20 @@ public java.time.Duration getWaitTimeoutDuration() { } /** - * Overload of {@link #setWaitTimeout(java.time.Duration)} using {@link + * Overload of {@link #setWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use setWaitTimeout(java.time.Duration) instead") + @ObsoleteApi("Use setWaitTimeoutDuration(java.time.Duration) instead") public Builder setWaitTimeout( @Nonnull org.threeten.bp.Duration waitTimeout) { - return setWaitTimeout(toJavaTimeDuration(waitTimeout)); + return setWaitTimeoutDuration(toJavaTimeDuration(waitTimeout)); } /** * Set the maximum amount of time to wait for the next message from the server. {@link * java.time.Duration#ZERO} disables the check for abandoned streams. */ - public Builder setWaitTimeout(@Nonnull java.time.Duration waitTimeout) { + public Builder setWaitTimeoutDuration(@Nonnull java.time.Duration waitTimeout) { this.waitTimeout = waitTimeout; return this; } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 8a7269096e..a53258159e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -142,7 +142,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { public void testNonRetriedServerStreamingCallable() throws Exception { java.time.Duration timeout = java.time.Duration.ofMillis(5L); ServerStreamingCallSettings callSettings = - ServerStreamingCallSettings.newBuilder().setSimpleTimeoutNoRetries(timeout).build(); + ServerStreamingCallSettings.newBuilder().setSimpleTimeoutNoRetriesDuration(timeout).build(); ServerStreamingCallable callable = Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); @@ -157,7 +157,7 @@ public void testNonRetriedServerStreamingCallable() throws Exception { public void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exception { ServerStreamingCallSettings callSettings = ServerStreamingCallSettings.newBuilder() - .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetriesDuration(java.time.Duration.ofMillis(10L)) .build(); ServerStreamingCallable callable = Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java index c54231f643..5469ea78f2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingCallSettingsTest.java @@ -91,7 +91,7 @@ public void idleTimeoutIsNotLost() { ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); - builder.setIdleTimeout(idleTimeout); + builder.setIdleTimeoutDuration(idleTimeout); assertThat(builder.getIdleTimeoutDuration()).isEqualTo(idleTimeout); assertThat(builder.build().getIdleTimeoutDuration()).isEqualTo(idleTimeout); @@ -105,7 +105,7 @@ public void waitTimeoutIsNotLost() { ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); - builder.setWaitTimeout(waitTimeout); + builder.setWaitTimeoutDuration(waitTimeout); assertThat(builder.getWaitTimeoutDuration()).isEqualTo(waitTimeout); assertThat(builder.build().getWaitTimeoutDuration()).isEqualTo(waitTimeout); @@ -146,7 +146,7 @@ public void testToString() { ServerStreamingCallSettings.newBuilder() .setRetrySettings(retrySettings) .setRetryableCodes(retryableCodes) - .setIdleTimeout(idleTime) + .setIdleTimeoutDuration(idleTime) .build(); assertThat(serverCallSettings.toString()).contains("idleTimeout=" + idleTime); assertThat(serverCallSettings.toString()).contains("retryableCodes=" + retryableCodes); @@ -158,7 +158,7 @@ public void testIdleTimeout_backportMethodsBehaveCorrectly() { final ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); testDurationMethod( 123l, - jt -> builder.setIdleTimeout(jt).build(), + jt -> builder.setIdleTimeoutDuration(jt).build(), tt -> builder.setIdleTimeout(tt).build(), cs -> cs.getIdleTimeoutDuration(), cs -> cs.getIdleTimeout()); @@ -169,7 +169,7 @@ public void testWaitTimeout_backportMethodsBehaveCorrectly() { final ServerStreamingCallSettings.Builder builder = ServerStreamingCallSettings.newBuilder(); testDurationMethod( 123l, - jt -> builder.setWaitTimeout(jt).build(), + jt -> builder.setWaitTimeoutDuration(jt).build(), tt -> builder.setWaitTimeout(tt).build(), cs -> cs.getWaitTimeoutDuration(), cs -> cs.getWaitTimeout()); From 427d295c525ab85c943f8f20f0a58a1cde4382fd Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:00:51 -0400 Subject: [PATCH 095/141] modify overloads of StubSettings --- .../java/com/google/api/gax/grpc/SettingsTest.java | 14 +++++++------- .../com/google/api/gax/rpc/ClientSettings.java | 7 ++++--- .../java/com/google/api/gax/rpc/StubSettings.java | 8 ++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index fcca37daaa..891939ccde 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -114,7 +114,7 @@ private static class FakeStubSettings extends StubSettings { RetrySettings settings = null; settings = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(100L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(100L)) .setRetryDelayMultiplier(1.2) .setMaxRetryDelay(java.time.Duration.ofMillis(1000L)) .setInitialRpcTimeout(java.time.Duration.ofMillis(2000L)) @@ -352,13 +352,13 @@ public void callSettingsBuildFromTimeoutNoRetries() { .setRetryableCodes() .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(timeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(timeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ZERO) - .setInitialRpcTimeout(timeout) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) + .setInitialRpcTimeoutDuration(timeout) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(timeout) + .setMaxRpcTimeoutDuration(timeout) .setMaxAttempts(1) .build()); UnaryCallSettings settingsB = builderB.build(); @@ -378,7 +378,7 @@ public void testWatchDogCheckInterval_backportMethodsBehaveCorrectly() { }; testDurationMethod( 123l, - jt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckInterval(jt)), + jt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckIntervalDuration(jt)), tt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckInterval(tt)), ss -> ss.getStreamWatchdogCheckIntervalDuration(), ss -> ss.getStreamWatchdogCheckInterval()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index e0f718dd05..68bd815cfa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -40,6 +40,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + /** * A base settings class to configure a client class. * @@ -281,12 +283,11 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { /** Backport of {@link #setWatchdogCheckIntervalDuration(java.time.Duration)} */ @ObsoleteApi("Use setWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { - stubSettings.setStreamWatchdogCheckInterval(checkInterval); - return self(); + return setWatchdogCheckIntervalDuration(toJavaTimeDuration(checkInterval)); } public B setWatchdogCheckIntervalDuration(@Nullable java.time.Duration checkInterval) { - stubSettings.setStreamWatchdogCheckInterval(checkInterval); + stubSettings.setStreamWatchdogCheckIntervalDuration(checkInterval); return self(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index a3a5ce99a8..25241ba260 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -532,19 +532,19 @@ public B setQuotaProjectId(String quotaProjectId) { } /** - * Overload of {@link #setStreamWatchdogCheckInterval(java.time.Duration)} using {@link + * Overload of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ - @ObsoleteApi("Use setStreamWatchdogCheckInterval(java.time.Duration) instead") + @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { - return setStreamWatchdogCheckInterval(toJavaTimeDuration(checkInterval)); + return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(checkInterval)); } /** * Sets how often the {@link Watchdog} will check ongoing streaming RPCs. Defaults to 10 secs. * Use {@link java.time.Duration#ZERO} to disable. */ - public B setStreamWatchdogCheckInterval(@Nonnull java.time.Duration checkInterval) { + public B setStreamWatchdogCheckIntervalDuration(@Nonnull java.time.Duration checkInterval) { Preconditions.checkNotNull(checkInterval); this.streamWatchdogCheckInterval = checkInterval; return self(); From 9f518222cbf802378880d7a6c033923c59f7c7ea Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:03:56 -0400 Subject: [PATCH 096/141] modify overloads for UnaryCallSettings --- .../src/main/java/com/google/api/gax/rpc/Callables.java | 2 +- .../java/com/google/api/gax/rpc/UnaryCallSettings.java | 8 ++++---- .../test/java/com/google/api/gax/rpc/CallableTest.java | 4 ++-- .../com/google/api/gax/rpc/UnaryCallSettingsTest.java | 8 ++++---- .../com/google/api/gax/tracing/TracedCallableTest.java | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 9d4b1a7475..9d6cc6a692 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -105,7 +105,7 @@ private static ScheduledRetryingExecutor getRetryingExecu settings = settings .toBuilder() - .setSimpleTimeoutNoRetries(settings.getRetrySettings().getTotalTimeoutDuration()) + .setSimpleTimeoutNoRetriesDuration(settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index fa297e93ea..43fa461425 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -196,15 +196,15 @@ public UnaryCallSettings.Builder setRetrySettings( return this; } - /** Backport of {@link #setSimpleTimeoutNoRetries(java.time.Duration)} */ - @ObsoleteApi("Use setSimpleTimeoutNoRetries(java.time.Duration) instead") + /** Backport of {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} */ + @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { - return setSimpleTimeoutNoRetries(toJavaTimeDuration(timeout)); + return setSimpleTimeoutNoRetriesDuration(toJavaTimeDuration(timeout)); } /** Disables retries and sets the RPC timeout. */ - public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( + public UnaryCallSettings.Builder setSimpleTimeoutNoRetriesDuration( java.time.Duration timeout) { setRetryableCodes(); setRetrySettings( diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index a53258159e..4fee68f626 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -86,7 +86,7 @@ public void testNonRetriedCallable() throws Exception { RequestMutator requestMutator = (request -> modifiedRequest); UnaryCallSettings callSettings = - UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(timeout).build(); + UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetriesDuration(timeout).build(); UnaryCallable callable = Callables.retrying(innerCallable, callSettings, clientContext, requestMutator); String expectedResponse = "No, my refrigerator is not running!"; @@ -115,7 +115,7 @@ public void testNonRetriedCallableWithRetrySettings() throws Exception { UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(10L)) + .setSimpleTimeoutNoRetriesDuration(java.time.Duration.ofMillis(10L)) .build(); UnaryCallable callable = Callables.retrying(innerCallable, callSettings, clientContext, requestMutator); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index 894f00b6b0..367f21571e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -47,7 +47,7 @@ public class UnaryCallSettingsTest { @Test public void testSetSimpleTimeoutNoRetries() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetriesDuration(java.time.Duration.ofSeconds(13)); assertThat(builder.getRetryableCodes().size()).isEqualTo(0); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); @@ -58,7 +58,7 @@ public void testSetSimpleTimeoutNoRetries() { @Test public void testEquals() { UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder(); - builder.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(13)); + builder.setSimpleTimeoutNoRetriesDuration(java.time.Duration.ofSeconds(13)); UnaryCallSettings settings13 = builder.build(); assertEquals(settings13, settings13); @@ -67,7 +67,7 @@ public void testEquals() { assertEquals(settings13.hashCode(), settings13.hashCode()); UnaryCallSettings.Builder builder5 = new UnaryCallSettings.Builder(); - builder5.setSimpleTimeoutNoRetries(java.time.Duration.ofSeconds(5)); + builder5.setSimpleTimeoutNoRetriesDuration(java.time.Duration.ofSeconds(5)); UnaryCallSettings settings5 = builder5.build(); assertNotEquals(settings13, settings5); @@ -153,7 +153,7 @@ public void testToString() { public void testWatchDogCheckInterval_backportMethodsBehaveCorrectly() { testDurationMethod( 123l, - jt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(jt).build(), + jt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetriesDuration(jt).build(), tt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(tt).build(), ucs -> ucs.getRetrySettings().getTotalTimeoutDuration(), ucs -> ucs.getRetrySettings().getTotalTimeout()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java index 07d1fd2b13..3e87d648ab 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/TracedCallableTest.java @@ -102,7 +102,7 @@ public void testNonRetriedCallable() throws Exception { // Verify that callables configured to not retry have the appropriate tracer interactions. UnaryCallSettings callSettings = UnaryCallSettings.newUnaryCallSettingsBuilder() - .setSimpleTimeoutNoRetries(java.time.Duration.ofMillis(5L)) + .setSimpleTimeoutNoRetriesDuration(java.time.Duration.ofMillis(5L)) .build(); UnaryCallable callable = setupTracedUnaryCallable(callSettings); innerResult.set("No, my refrigerator is not running!"); From 2a4949bac0eec2b3ebe89d185a28f3cfe02a2760 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:09:51 -0400 Subject: [PATCH 097/141] modify overloads in ApiTracer --- .../com/google/api/gax/retrying/BasicRetryingFuture.java | 2 +- .../main/java/com/google/api/gax/tracing/ApiTracer.java | 8 ++++---- .../java/com/google/api/gax/tracing/BaseApiTracer.java | 6 +++--- .../java/com/google/api/gax/tracing/MetricsTracer.java | 8 ++++---- .../java/com/google/api/gax/tracing/OpencensusTracer.java | 8 ++++---- .../api/gax/retrying/AbstractRetryingExecutorTest.java | 8 ++++---- .../google/api/gax/retrying/BasicRetryingFutureTest.java | 2 +- .../java/com/google/api/gax/tracing/MetricsTestUtils.java | 3 ++- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java index cb47a845cb..247039d977 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java @@ -187,7 +187,7 @@ void handleAttempt(Throwable throwable, ResponseT response) { "retriableException: " + throwable }); } - tracer.attemptFailed(throwable, nextAttemptSettings.getRandomizedRetryDelayDuration()); + tracer.attemptFailedDuration(throwable, nextAttemptSettings.getRandomizedRetryDelayDuration()); attemptSettings = nextAttemptSettings; setAttemptResult(throwable, response, true); // a new attempt will be (must be) scheduled by an external executor diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index 8cf3b83819..005d707b9d 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -110,10 +110,10 @@ default Scope inScope() { /** Add an annotation that the attempt was cancelled by the user. */ default void attemptCancelled() {}; - /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ - @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailed(error, toJavaTimeDuration(delay)); + attemptFailedDuration(error, toJavaTimeDuration(delay)); }; /** @@ -122,7 +122,7 @@ default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { * @param error the transient error that caused the attempt to fail. * @param delay the amount of time to wait before the next attempt will start. */ - default void attemptFailed(Throwable error, java.time.Duration delay) {}; + default void attemptFailedDuration(Throwable error, java.time.Duration delay) {}; /** * Adds an annotation that the attempt failed and that no further attempts will be made because diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index f6c96fd19c..6867ccee83 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -106,15 +106,15 @@ public void attemptCancelled() { } @Override - public void attemptFailed(Throwable error, java.time.Duration delay) { + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { // noop } - /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ @Override @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailed(error, toJavaTimeDuration(delay)); + attemptFailedDuration(error, toJavaTimeDuration(delay)); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java index 19e52d20f3..090f1a594e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java @@ -173,17 +173,17 @@ public void attemptCancelled() { * key. */ @Override - public void attemptFailed(Throwable error, java.time.Duration delay) { + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { attributes.put(STATUS_ATTRIBUTE, extractStatus(error)); metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.MILLISECONDS), attributes); metricsRecorder.recordAttemptCount(1, attributes); } - /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ @Override - @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailed(error, toJavaTimeDuration(delay)); + attemptFailedDuration(error, toJavaTimeDuration(delay)); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java index cf74a122bd..ec1523d186 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java @@ -344,7 +344,7 @@ public void attemptCancelled() { /** {@inheritDoc} */ @Override - public void attemptFailed(Throwable error, java.time.Duration delay) { + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { Map attributes = baseAttemptAttributes(); attributes.put("delay ms", AttributeValue.longAttributeValue(delay.toMillis())); populateError(attributes, error); @@ -359,11 +359,11 @@ public void attemptFailed(Throwable error, java.time.Duration delay) { lastConnectionId = null; } - /** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */ + /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ @Override - @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailed(error, toJavaTimeDuration(delay)); + attemptFailedDuration(error, toJavaTimeDuration(delay)); } /** {@inheritDoc} */ diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java index 3dd72f2045..cd5ab7ad82 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java @@ -143,7 +143,7 @@ public void testSuccessWithFailures() throws Exception { assertEquals(5, future.getAttemptSettings().getAttemptCount()); verify(tracer, times(6)).attemptStarted(eq("request"), anyInt()); - verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(5)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); verify(tracer, times(1)).attemptSucceeded(); verifyNoMoreInteractions(tracer); } @@ -188,7 +188,7 @@ public void testMaxRetriesExceeded() throws Exception { assertEquals(5, future.getAttemptSettings().getAttemptCount()); verify(tracer, times(6)).attemptStarted(eq("request"), anyInt()); - verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(5)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); verify(tracer, times(1)).attemptFailedRetriesExhausted(any(Throwable.class)); verifyNoMoreInteractions(tracer); } @@ -266,7 +266,7 @@ public void testCancelByRetryingAlgorithm() throws Exception { verify(tracer, times(5)).attemptStarted(eq("request"), anyInt()); // Pre-apocalypse failures - verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(4)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); // Apocalypse failure verify(tracer, times(1)).attemptFailedRetriesExhausted(any(CancellationException.class)); verifyNoMoreInteractions(tracer); @@ -286,7 +286,7 @@ public void testUnexpectedExceptionFromRetryAlgorithm() throws Exception { verify(tracer, times(5)).attemptStarted(eq("request"), anyInt()); // Pre-apocalypse failures - verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(4)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); // Apocalypse failure verify(tracer, times(1)).attemptPermanentFailure(any(RuntimeException.class)); verifyNoMoreInteractions(tracer); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java index 68bb2457fc..970d841693 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java @@ -95,7 +95,7 @@ public void testHandleAttemptDoesNotThrowNPEWhenLogLevelLowerThanFiner() throws future.handleAttempt(null, null); Mockito.verify(tracer) - .attemptFailed( + .attemptFailedDuration( ArgumentMatchers.any(), ArgumentMatchers.any()); Mockito.verifyNoMoreInteractions(tracer); } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java index 2618b0217d..8ada7484b4 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java @@ -36,10 +36,11 @@ public class MetricsTestUtils { public static void reportFailedAttempt(ApiTracer tracer, Exception ex, Object delayValue) { try { + final String methodName = delayValue.getClass().getName().startsWith("java.time") ? "attemptFailedDuration" : "attemptFailed"; Method attemptFailed = tracer .getClass() - .getDeclaredMethod("attemptFailed", Throwable.class, delayValue.getClass()); + .getDeclaredMethod(methodName, Throwable.class, delayValue.getClass()); attemptFailed.invoke(tracer, ex, delayValue); } catch (Exception e) { fail(); From 60a43dd083d0b92de9cc860444190cf47694e1ee Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:11:16 -0400 Subject: [PATCH 098/141] reformat --- .../com/google/api/gax/grpc/SettingsTest.java | 4 +++- .../api/gax/retrying/BasicRetryingFuture.java | 3 ++- .../gax/retrying/TimedAttemptSettings.java | 6 ++++-- .../com/google/api/gax/rpc/Callables.java | 6 ++++-- .../com/google/api/gax/rpc/ClientContext.java | 3 ++- .../google/api/gax/rpc/ClientSettings.java | 4 ++-- .../api/gax/rpc/FixedWatchdogProvider.java | 1 - .../rpc/InstantiatingWatchdogProvider.java | 6 +++--- .../gax/rpc/ServerStreamingCallSettings.java | 9 +++++--- .../google/api/gax/rpc/WatchdogProvider.java | 1 - .../api/gax/batching/BatcherImplTest.java | 10 +++++++-- .../gax/batching/ThresholdBatcherTest.java | 4 +++- .../AbstractRetryingExecutorTest.java | 12 +++++++---- .../api/gax/rpc/AttemptCallableTest.java | 6 ++++-- .../com/google/api/gax/rpc/CallableTest.java | 4 +++- .../gax/rpc/CheckingAttemptCallableTest.java | 3 ++- .../gax/rpc/FixedWatchdogProviderTest.java | 15 ++++++++----- .../InstantiatingWatchdogProviderTest.java | 21 ++++++++++--------- .../ServerStreamingAttemptCallableTest.java | 3 ++- .../api/gax/rpc/UnaryCallSettingsTest.java | 5 ++++- .../api/gax/tracing/MetricsTestUtils.java | 9 ++++---- 21 files changed, 86 insertions(+), 49 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index 891939ccde..a556a4ddc3 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -378,7 +378,9 @@ public void testWatchDogCheckInterval_backportMethodsBehaveCorrectly() { }; testDurationMethod( 123l, - jt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckIntervalDuration(jt)), + jt -> + build.apply( + () -> FakeStubSettings.newBuilder().setStreamWatchdogCheckIntervalDuration(jt)), tt -> build.apply(() -> FakeStubSettings.newBuilder().setStreamWatchdogCheckInterval(tt)), ss -> ss.getStreamWatchdogCheckIntervalDuration(), ss -> ss.getStreamWatchdogCheckInterval()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java index 247039d977..c1a7ad8898 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java @@ -187,7 +187,8 @@ void handleAttempt(Throwable throwable, ResponseT response) { "retriableException: " + throwable }); } - tracer.attemptFailedDuration(throwable, nextAttemptSettings.getRandomizedRetryDelayDuration()); + tracer.attemptFailedDuration( + throwable, nextAttemptSettings.getRandomizedRetryDelayDuration()); attemptSettings = nextAttemptSettings; setAttemptResult(throwable, response, true); // a new attempt will be (must be) scheduled by an external executor diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index 69083890ba..ce4b69bdd2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -107,7 +107,8 @@ public abstract static class Builder { public abstract Builder setGlobalSettings(RetrySettings value); /** - * Backport of {@link #setRetryDelayDuration(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Backport of {@link #setRetryDelayDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRetryDelayDuration(java.time.Duration) instead") public abstract Builder setRetryDelay(org.threeten.bp.Duration value); @@ -121,7 +122,8 @@ public final Builder setRetryDelayDuration(java.time.Duration value) { } /** - * Backport of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Backport of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRpcTimeoutDuration(java.time.Duration) instead") public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java index 9d6cc6a692..aad0d894ca 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Callables.java @@ -105,7 +105,8 @@ private static ScheduledRetryingExecutor getRetryingExecu settings = settings .toBuilder() - .setSimpleTimeoutNoRetriesDuration(settings.getRetrySettings().getTotalTimeoutDuration()) + .setSimpleTimeoutNoRetriesDuration( + settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } @@ -129,7 +130,8 @@ public static ServerStreamingCallable settings = settings .toBuilder() - .setSimpleTimeoutNoRetriesDuration(settings.getRetrySettings().getTotalTimeoutDuration()) + .setSimpleTimeoutNoRetriesDuration( + settings.getRetrySettings().getTotalTimeoutDuration()) .build(); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index fd9da82262..450156e19f 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -252,7 +252,8 @@ public static ClientContext create(StubSettings settings) throws IOException { if (watchdogProvider != null) { if (watchdogProvider.needsCheckInterval()) { watchdogProvider = - watchdogProvider.withCheckIntervalDuration(settings.getStreamWatchdogCheckIntervalDuration()); + watchdogProvider.withCheckIntervalDuration( + settings.getStreamWatchdogCheckIntervalDuration()); } if (watchdogProvider.needsClock()) { watchdogProvider = watchdogProvider.withClock(clock); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 68bd815cfa..04cbbc2dab 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -29,6 +29,8 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.ApiClock; import com.google.api.core.ApiFunction; import com.google.api.core.ObsoleteApi; @@ -40,8 +42,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; - /** * A base settings class to configure a client class. * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java index e8cba4234c..a35940adfd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java @@ -32,7 +32,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; - import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index 927271502c..aca98b8ffb 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -29,6 +29,8 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; @@ -37,8 +39,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; - /** * A watchdog provider which instantiates a new provider on every request. * @@ -90,7 +90,7 @@ public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration chec @Override public WatchdogProvider withCheckIntervalDuration(@Nonnull java.time.Duration checkInterval) { return new InstantiatingWatchdogProvider( - clock, executor, Preconditions.checkNotNull(checkInterval)); + clock, executor, Preconditions.checkNotNull(checkInterval)); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 0cc1ba37d6..a942af0b02 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -317,7 +317,8 @@ public java.time.Duration getIdleTimeoutDuration() { } /** - * Overlad of {@link #setIdleTimeoutDuration(java.time.Duration)} using {@link org.threeten.bp.Duration} + * Overlad of {@link #setIdleTimeoutDuration(java.time.Duration)} using {@link + * org.threeten.bp.Duration} */ @ObsoleteApi("Use setIdleTimeoutDuration(java.time.Duration) instead") public Builder setIdleTimeout( @@ -329,7 +330,8 @@ public Builder setIdleTimeout( * Set how long to wait before considering the stream orphaned by the user and closing it. * {@link java.time.Duration#ZERO} disables the check for abandoned streams. */ - public Builder setIdleTimeoutDuration(@Nonnull java.time.Duration idleTimeout) { + public Builder setIdleTimeoutDuration( + @Nonnull java.time.Duration idleTimeout) { this.idleTimeout = Preconditions.checkNotNull(idleTimeout); return this; } @@ -360,7 +362,8 @@ public Builder setWaitTimeout( * Set the maximum amount of time to wait for the next message from the server. {@link * java.time.Duration#ZERO} disables the check for abandoned streams. */ - public Builder setWaitTimeoutDuration(@Nonnull java.time.Duration waitTimeout) { + public Builder setWaitTimeoutDuration( + @Nonnull java.time.Duration waitTimeout) { this.waitTimeout = waitTimeout; return this; } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index 5a300657d8..852e2992c2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -32,7 +32,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; - import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index ce62cd3ba4..1901dc77e2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -386,7 +386,10 @@ public void testWhenThresholdIsDisabled() throws Exception { @Test public void testWhenDelayThresholdExceeds() throws Exception { BatchingSettings settings = - batchingSettings.toBuilder().setDelayThresholdDuration(java.time.Duration.ofMillis(100)).build(); + batchingSettings + .toBuilder() + .setDelayThresholdDuration(java.time.Duration.ofMillis(100)) + .build(); underTest = createDefaultBatcherImpl(settings, null); Future result = underTest.add(6); assertThat(result.isDone()).isFalse(); @@ -417,7 +420,10 @@ public ApiFuture> futureCall( } }; BatchingSettings settings = - batchingSettings.toBuilder().setDelayThresholdDuration(java.time.Duration.ofMillis(50)).build(); + batchingSettings + .toBuilder() + .setDelayThresholdDuration(java.time.Duration.ofMillis(50)) + .build(); try (final BatcherImpl> batcherTest = new BatcherImpl<>(SQUARER_BATCHING_DESC_V2, callable, labeledIntList, settings, EXECUTOR)) { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 2000599443..aa97650974 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -196,7 +196,9 @@ public void testBatchingWithDelay() throws Exception { AccumulatingBatchReceiver receiver = new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); ThresholdBatcher batcher = - createSimpleBatcherBuidler(receiver).setMaxDelayDuration(java.time.Duration.ofMillis(100)).build(); + createSimpleBatcherBuidler(receiver) + .setMaxDelayDuration(java.time.Duration.ofMillis(100)) + .build(); batcher.add(SimpleBatch.fromInteger(3)); batcher.add(SimpleBatch.fromInteger(5)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java index cd5ab7ad82..82ea52250e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java @@ -143,7 +143,8 @@ public void testSuccessWithFailures() throws Exception { assertEquals(5, future.getAttemptSettings().getAttemptCount()); verify(tracer, times(6)).attemptStarted(eq("request"), anyInt()); - verify(tracer, times(5)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(5)) + .attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); verify(tracer, times(1)).attemptSucceeded(); verifyNoMoreInteractions(tracer); } @@ -188,7 +189,8 @@ public void testMaxRetriesExceeded() throws Exception { assertEquals(5, future.getAttemptSettings().getAttemptCount()); verify(tracer, times(6)).attemptStarted(eq("request"), anyInt()); - verify(tracer, times(5)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(5)) + .attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); verify(tracer, times(1)).attemptFailedRetriesExhausted(any(Throwable.class)); verifyNoMoreInteractions(tracer); } @@ -266,7 +268,8 @@ public void testCancelByRetryingAlgorithm() throws Exception { verify(tracer, times(5)).attemptStarted(eq("request"), anyInt()); // Pre-apocalypse failures - verify(tracer, times(4)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(4)) + .attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); // Apocalypse failure verify(tracer, times(1)).attemptFailedRetriesExhausted(any(CancellationException.class)); verifyNoMoreInteractions(tracer); @@ -286,7 +289,8 @@ public void testUnexpectedExceptionFromRetryAlgorithm() throws Exception { verify(tracer, times(5)).attemptStarted(eq("request"), anyInt()); // Pre-apocalypse failures - verify(tracer, times(4)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); + verify(tracer, times(4)) + .attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class)); // Apocalypse failure verify(tracer, times(1)).attemptPermanentFailure(any(RuntimeException.class)); verifyNoMoreInteractions(tracer); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 9f6cc138c2..39250d507c 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -88,7 +88,8 @@ public void testRpcTimeout() { // Make sure that the rpc timeout is set java.time.Duration timeout = java.time.Duration.ofSeconds(10); - currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); + currentAttemptSettings = + currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); callable.call(); @@ -109,7 +110,8 @@ public void testRpcTimeoutIsNotErased() { FakeCallContext.createDefault().withTimeoutDuration(callerTimeout); java.time.Duration timeout = java.time.Duration.ofMillis(5); - currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); + currentAttemptSettings = + currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); AttemptCallable callable = new AttemptCallable<>(mockInnerCallable, "fake-request", callerCallContext); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 4fee68f626..0bf780d483 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -86,7 +86,9 @@ public void testNonRetriedCallable() throws Exception { RequestMutator requestMutator = (request -> modifiedRequest); UnaryCallSettings callSettings = - UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetriesDuration(timeout).build(); + UnaryCallSettings.newUnaryCallSettingsBuilder() + .setSimpleTimeoutNoRetriesDuration(timeout) + .build(); UnaryCallable callable = Callables.retrying(innerCallable, callSettings, clientContext, requestMutator); String expectedResponse = "No, my refrigerator is not running!"; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index f82ef9c789..10f5618d6b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -88,7 +88,8 @@ public void testRpcTimeout() { // Make sure that the rpc timeout is set java.time.Duration timeout = java.time.Duration.ofSeconds(10); - currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); + currentAttemptSettings = + currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); callable.call(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index 1212b42410..0d6070b056 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.rpc; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; @@ -101,9 +100,15 @@ public void testNoModifications() { @Test public void testWithCheckInterval_backportMethodsBehaveTheSame() { - assertThrows(UnsupportedOperationException.class, () -> FixedWatchdogProvider.create(null) - .withCheckIntervalDuration(java.time.Duration.ofMillis(123l))); - assertThrows(UnsupportedOperationException.class, () -> FixedWatchdogProvider.create(null) - .withCheckInterval(org.threeten.bp.Duration.ofMillis(123l))); + assertThrows( + UnsupportedOperationException.class, + () -> + FixedWatchdogProvider.create(null) + .withCheckIntervalDuration(java.time.Duration.ofMillis(123l))); + assertThrows( + UnsupportedOperationException.class, + () -> + FixedWatchdogProvider.create(null) + .withCheckInterval(org.threeten.bp.Duration.ofMillis(123l))); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java index dcd5b9cd5f..0da5098e28 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/InstantiatingWatchdogProviderTest.java @@ -71,7 +71,9 @@ public void happyPath() { @Test public void requiresExecutor() { WatchdogProvider provider = - InstantiatingWatchdogProvider.create().withCheckIntervalDuration(checkInterval).withClock(clock); + InstantiatingWatchdogProvider.create() + .withCheckIntervalDuration(checkInterval) + .withClock(clock); Throwable actualError = null; try { @@ -114,15 +116,14 @@ public void requiresClock() { @Test public void testCheckInterval_backportMethodsBehaveCorrectly() { - final InstantiatingWatchdogProvider baseProvider = (InstantiatingWatchdogProvider) InstantiatingWatchdogProvider.create() - .withClock(clock) - .withExecutor(executor); + final InstantiatingWatchdogProvider baseProvider = + (InstantiatingWatchdogProvider) + InstantiatingWatchdogProvider.create().withClock(clock).withExecutor(executor); testDurationMethod( - 123l, - jt -> baseProvider.withCheckIntervalDuration(jt), - tt -> baseProvider.withCheckInterval(tt), - wp -> wp.getWatchdog().getScheduleIntervalDuration(), - wp -> wp.getWatchdog().getScheduleInterval() - ); + 123l, + jt -> baseProvider.withCheckIntervalDuration(jt), + tt -> baseProvider.withCheckInterval(tt), + wp -> wp.getWatchdog().getScheduleIntervalDuration(), + wp -> wp.getWatchdog().getScheduleInterval()); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java index 1a2db0df13..0036906ff2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ServerStreamingAttemptCallableTest.java @@ -474,7 +474,8 @@ private static class FakeRetryingFuture extends AbstractApiFuture this.attemptCallable = attemptCallable; attemptSettings = TimedAttemptSettings.newBuilder() - .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeoutDuration(totalTimeout).build()) + .setGlobalSettings( + RetrySettings.newBuilder().setTotalTimeoutDuration(totalTimeout).build()) .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java index 367f21571e..5d88246e8e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/UnaryCallSettingsTest.java @@ -153,7 +153,10 @@ public void testToString() { public void testWatchDogCheckInterval_backportMethodsBehaveCorrectly() { testDurationMethod( 123l, - jt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetriesDuration(jt).build(), + jt -> + UnaryCallSettings.newUnaryCallSettingsBuilder() + .setSimpleTimeoutNoRetriesDuration(jt) + .build(), tt -> UnaryCallSettings.newUnaryCallSettingsBuilder().setSimpleTimeoutNoRetries(tt).build(), ucs -> ucs.getRetrySettings().getTotalTimeoutDuration(), ucs -> ucs.getRetrySettings().getTotalTimeout()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java index 8ada7484b4..0e04196c21 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java @@ -36,11 +36,12 @@ public class MetricsTestUtils { public static void reportFailedAttempt(ApiTracer tracer, Exception ex, Object delayValue) { try { - final String methodName = delayValue.getClass().getName().startsWith("java.time") ? "attemptFailedDuration" : "attemptFailed"; + final String methodName = + delayValue.getClass().getName().startsWith("java.time") + ? "attemptFailedDuration" + : "attemptFailed"; Method attemptFailed = - tracer - .getClass() - .getDeclaredMethod(methodName, Throwable.class, delayValue.getClass()); + tracer.getClass().getDeclaredMethod(methodName, Throwable.class, delayValue.getClass()); attemptFailed.invoke(tracer, ex, delayValue); } catch (Exception e) { fail(); From 24c1566946f9764b8485e98c4f37214d3696bc94 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:13:34 -0400 Subject: [PATCH 099/141] reset java-core and showcase to main --- .../clirr-ignored-differences.xml | 6 ---- .../java/com/google/cloud/RetryOption.java | 33 ++++--------------- .../java/com/google/cloud/ServiceOptions.java | 11 ++++--- .../cloud/testing/BaseEmulatorHelper.java | 13 ++++---- .../com/google/cloud/RetryOptionTest.java | 25 +++++++------- .../com/google/cloud/SerializationTest.java | 3 +- .../cloud/testing/BaseEmulatorHelperTest.java | 12 +++---- .../v1beta1/it/ITDynamicRoutingHeaders.java | 15 +++++++-- 8 files changed, 54 insertions(+), 64 deletions(-) diff --git a/java-core/google-cloud-core/clirr-ignored-differences.xml b/java-core/google-cloud-core/clirr-ignored-differences.xml index e1bb7bcc78..0f7f80a7b4 100644 --- a/java-core/google-cloud-core/clirr-ignored-differences.xml +++ b/java-core/google-cloud-core/clirr-ignored-differences.xml @@ -12,10 +12,4 @@ com/google/cloud/ReadChannel long limit() - - 7005 - com/google/cloud/testing/* - * *(org.threeten.bp.Duration) - * - diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java index 51e87be750..a1069b48a2 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/RetryOption.java @@ -16,13 +16,12 @@ package com.google.cloud; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.core.BetaApi; -import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.RetrySettings; import java.io.Serializable; +import org.threeten.bp.Duration; /** * This class represents an options wrapper around the {@link RetrySettings} class and is an @@ -53,43 +52,25 @@ private RetryOption(OptionType type, Object value) { } /** See {@link RetrySettings#getTotalTimeout()}. */ - @ObsoleteApi("Use totalTimeout(java.time.Duration) instead") - public static RetryOption totalTimeout(org.threeten.bp.Duration totalTimeout) { + public static RetryOption totalTimeout(Duration totalTimeout) { return new RetryOption(OptionType.TOTAL_TIMEOUT, totalTimeout); } - /** See {@link RetrySettings#getTotalTimeout()}. */ - public static RetryOption totalTimeout(java.time.Duration totalTimeout) { - return totalTimeout(toThreetenDuration(totalTimeout)); - } - /** See {@link RetrySettings#getInitialRetryDelay()}. */ - @ObsoleteApi("Use initialRetryDelay(java.time.Duration) instead") - public static RetryOption initialRetryDelay(org.threeten.bp.Duration initialRetryDelay) { + public static RetryOption initialRetryDelay(Duration initialRetryDelay) { return new RetryOption(OptionType.INITIAL_RETRY_DELAY, initialRetryDelay); } - /** See {@link RetrySettings#getInitialRetryDelay()}. */ - public static RetryOption initialRetryDelay(java.time.Duration initialRetryDelay) { - return initialRetryDelay(toThreetenDuration(initialRetryDelay)); - } - /** See {@link RetrySettings#getRetryDelayMultiplier()}. */ public static RetryOption retryDelayMultiplier(double retryDelayMultiplier) { return new RetryOption(OptionType.RETRY_DELAY_MULTIPLIER, retryDelayMultiplier); } /** See {@link RetrySettings#getMaxRetryDelay()}. */ - @ObsoleteApi("Use maxRetryDelay(java.time.Duration) instead") - public static RetryOption maxRetryDelay(org.threeten.bp.Duration maxRetryDelay) { + public static RetryOption maxRetryDelay(Duration maxRetryDelay) { return new RetryOption(OptionType.MAX_RETRY_DELAY, maxRetryDelay); } - /** See {@link RetrySettings#getMaxRetryDelay()}. */ - public static RetryOption maxRetryDelay(java.time.Duration maxRetryDelay) { - return maxRetryDelay(toThreetenDuration(maxRetryDelay)); - } - /** See {@link RetrySettings#getMaxAttempts()}. */ public static RetryOption maxAttempts(int maxAttempts) { return new RetryOption(OptionType.MAX_ATTEMPTS, maxAttempts); @@ -143,16 +124,16 @@ public static RetrySettings mergeToSettings(RetrySettings settings, RetryOption. for (RetryOption option : options) { switch (option.type) { case TOTAL_TIMEOUT: - builder.setTotalTimeout((org.threeten.bp.Duration) option.value); + builder.setTotalTimeout((Duration) option.value); break; case INITIAL_RETRY_DELAY: - builder.setInitialRetryDelay((org.threeten.bp.Duration) option.value); + builder.setInitialRetryDelay((Duration) option.value); break; case RETRY_DELAY_MULTIPLIER: builder.setRetryDelayMultiplier((Double) option.value); break; case MAX_RETRY_DELAY: - builder.setMaxRetryDelay((org.threeten.bp.Duration) option.value); + builder.setMaxRetryDelay((Duration) option.value); break; case MAX_ATTEMPTS: builder.setMaxAttempts((Integer) option.value); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 5c9a16f0d4..985fac4804 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -70,6 +70,7 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.threeten.bp.Duration; /** * Abstract class representing service options. @@ -786,13 +787,13 @@ public static RetrySettings getNoRetrySettings() { private static RetrySettings.Builder getDefaultRetrySettingsBuilder() { return RetrySettings.newBuilder() .setMaxAttempts(6) - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(1000L)) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMillis(32_000L)) + .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setMaxRetryDelay(Duration.ofMillis(32_000L)) .setRetryDelayMultiplier(2.0) - .setTotalTimeout(org.threeten.bp.Duration.ofMillis(50_000L)) - .setInitialRpcTimeout(org.threeten.bp.Duration.ofMillis(50_000L)) + .setTotalTimeout(Duration.ofMillis(50_000L)) + .setInitialRpcTimeout(Duration.ofMillis(50_000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(50_000L)); + .setMaxRpcTimeout(Duration.ofMillis(50_000L)); } protected abstract Set getScopes(); diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java index a6bd70d5f3..9679c6299c 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java @@ -56,6 +56,7 @@ import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.threeten.bp.Duration; /** Utility class to start and stop a local service which is used by unit testing. */ @InternalApi @@ -115,7 +116,7 @@ protected final void startProcess(String blockUntilOutput) * Waits for the local service's subprocess to terminate, and stop any possible thread listening * for its output. */ - protected final int waitForProcess(java.time.Duration timeout) + protected final int waitForProcess(Duration timeout) throws IOException, InterruptedException, TimeoutException { if (activeRunner != null) { int exitCode = activeRunner.waitFor(timeout); @@ -129,7 +130,7 @@ protected final int waitForProcess(java.time.Duration timeout) return 0; } - private static int waitForProcess(final Process process, java.time.Duration timeout) + private static int waitForProcess(final Process process, Duration timeout) throws InterruptedException, TimeoutException { if (process == null) { return 0; @@ -180,7 +181,7 @@ public String getProjectId() { public abstract void start() throws IOException, InterruptedException; /** Stops the local emulator. */ - public abstract void stop(java.time.Duration timeout) + public abstract void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException; /** Resets the internal state of the emulator. */ @@ -226,7 +227,7 @@ protected interface EmulatorRunner { void start() throws IOException; /** Wait for the emulator associated to this runner to terminate, returning the exit status. */ - int waitFor(java.time.Duration timeout) throws InterruptedException, TimeoutException; + int waitFor(Duration timeout) throws InterruptedException, TimeoutException; /** Returns the process associated to the emulator, if any. */ Process getProcess(); @@ -264,7 +265,7 @@ public void start() throws IOException { } @Override - public int waitFor(java.time.Duration timeout) throws InterruptedException, TimeoutException { + public int waitFor(Duration timeout) throws InterruptedException, TimeoutException { return waitForProcess(process, timeout); } @@ -374,7 +375,7 @@ public Path call() throws IOException { } @Override - public int waitFor(java.time.Duration timeout) throws InterruptedException, TimeoutException { + public int waitFor(Duration timeout) throws InterruptedException, TimeoutException { return waitForProcess(process, timeout); } diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java index aa2cc3e6b8..ebea89f2fc 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/RetryOptionTest.java @@ -21,25 +21,26 @@ import com.google.api.gax.retrying.RetrySettings; import org.junit.Test; +import org.threeten.bp.Duration; public class RetryOptionTest { private static final RetryOption TOTAL_TIMEOUT = - RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); + RetryOption.totalTimeout(Duration.ofMillis(420L)); private static final RetryOption INITIAL_RETRY_DELAY = - RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); + RetryOption.initialRetryDelay(Duration.ofMillis(42L)); private static final RetryOption RETRY_DELAY_MULTIPLIER = RetryOption.retryDelayMultiplier(1.5); private static final RetryOption MAX_RETRY_DELAY = - RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); + RetryOption.maxRetryDelay(Duration.ofMillis(100)); private static final RetryOption MAX_ATTEMPTS = RetryOption.maxAttempts(100); private static final RetryOption JITTERED = RetryOption.jittered(false); private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofMillis(420L)) - .setInitialRetryDelay(java.time.Duration.ofMillis(42L)) + .setTotalTimeout(Duration.ofMillis(420L)) + .setInitialRetryDelay(Duration.ofMillis(42L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(java.time.Duration.ofMillis(100)) + .setMaxRetryDelay(Duration.ofMillis(100)) .setMaxAttempts(100) .setJittered(false) .build(); @@ -60,10 +61,10 @@ public void testEqualsAndHashCode() { assertNotEquals(MAX_ATTEMPTS, MAX_RETRY_DELAY); assertNotEquals(JITTERED, MAX_ATTEMPTS); - RetryOption totalTimeout = RetryOption.totalTimeout(java.time.Duration.ofMillis(420L)); - RetryOption initialRetryDelay = RetryOption.initialRetryDelay(java.time.Duration.ofMillis(42L)); + RetryOption totalTimeout = RetryOption.totalTimeout(Duration.ofMillis(420L)); + RetryOption initialRetryDelay = RetryOption.initialRetryDelay(Duration.ofMillis(42L)); RetryOption retryDelayMultiplier = RetryOption.retryDelayMultiplier(1.5); - RetryOption maxRetryDelay = RetryOption.maxRetryDelay(java.time.Duration.ofMillis(100)); + RetryOption maxRetryDelay = RetryOption.maxRetryDelay(Duration.ofMillis(100)); RetryOption maxAttempts = RetryOption.maxAttempts(100); RetryOption jittered = RetryOption.jittered(false); @@ -100,17 +101,17 @@ public void testMergeToSettings() { assertEquals(retrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setTotalTimeout(java.time.Duration.ofMillis(420L)).build(); + defRetrySettings.toBuilder().setTotalTimeout(Duration.ofMillis(420L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setMaxRetryDelay(java.time.Duration.ofMillis(100)).build(); + defRetrySettings.toBuilder().setMaxRetryDelay(Duration.ofMillis(100)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = - defRetrySettings.toBuilder().setInitialRetryDelay(java.time.Duration.ofMillis(42L)).build(); + defRetrySettings.toBuilder().setInitialRetryDelay(Duration.ofMillis(42L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 996efecca1..6c35c665b5 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.io.Serializable; +import org.threeten.bp.Duration; public class SerializationTest extends BaseSerializationTest { @@ -36,7 +37,7 @@ public class SerializationTest extends BaseSerializationTest { private static final Role SOME_ROLE = Role.viewer(); private static final Policy SOME_IAM_POLICY = Policy.newBuilder().build(); private static final RetryOption CHECKING_PERIOD = - RetryOption.initialRetryDelay(java.time.Duration.ofSeconds(42)); + RetryOption.initialRetryDelay(Duration.ofSeconds(42)); private static final LabelDescriptor LABEL_DESCRIPTOR = new LabelDescriptor("project_id", ValueType.STRING, "The project id"); private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java index db3f17dc36..2c6d7495be 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/testing/BaseEmulatorHelperTest.java @@ -33,6 +33,7 @@ import java.util.logging.Logger; import org.easymock.EasyMock; import org.junit.Test; +import org.threeten.bp.Duration; public class BaseEmulatorHelperTest { @@ -70,8 +71,7 @@ public void start() throws IOException, InterruptedException { } @Override - public void stop(java.time.Duration timeout) - throws IOException, InterruptedException, TimeoutException { + public void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException { waitForProcess(timeout); } @@ -91,13 +91,13 @@ public void testEmulatorHelper() throws IOException, InterruptedException, Timeo emulatorRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(emulatorRunner.getProcess()).andReturn(process); - emulatorRunner.waitFor(java.time.Duration.ofMinutes(1)); + emulatorRunner.waitFor(Duration.ofMinutes(1)); EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, emulatorRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(emulatorRunner), BLOCK_UNTIL); helper.start(); - helper.stop(java.time.Duration.ofMinutes(1)); + helper.stop(Duration.ofMinutes(1)); EasyMock.verify(); } @@ -157,13 +157,13 @@ public void testEmulatorHelperMultipleRunners() secondRunner.start(); EasyMock.expectLastCall(); EasyMock.expect(secondRunner.getProcess()).andReturn(process); - secondRunner.waitFor(java.time.Duration.ofMinutes(1)); + secondRunner.waitFor(Duration.ofMinutes(1)); EasyMock.expectLastCall().andReturn(0); EasyMock.replay(process, secondRunner); TestEmulatorHelper helper = new TestEmulatorHelper(ImmutableList.of(firstRunner, secondRunner), BLOCK_UNTIL); helper.start(); - helper.stop(java.time.Duration.ofMinutes(1)); + helper.stop(Duration.ofMinutes(1)); EasyMock.verify(); } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java index 326de3c61f..bafe8730d0 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java @@ -43,6 +43,7 @@ import io.grpc.MethodDescriptor; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.junit.After; import org.junit.Before; @@ -153,11 +154,21 @@ public void createClients() throws Exception { } @After - public void destroyClient() { + public void destroyClient() throws InterruptedException { grpcClient.close(); - httpJsonClient.close(); grpcComplianceClient.close(); + + httpJsonClient.close(); httpJsonComplianceClient.close(); + + grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + grpcComplianceClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + + httpJsonClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + httpJsonComplianceClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @Test From 786c915f4b76c2049e02b0e0206c84fadbc87fe0 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:14:06 -0400 Subject: [PATCH 100/141] remove showcase IT --- .../it/ITTimeObjectsPropagationTest.java | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java deleted file mode 100644 index 050f167044..0000000000 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.google.showcase.v1beta1.it; - -import static org.junit.Assert.assertEquals; - -import com.google.api.gax.retrying.RetrySettings; -import org.junit.Test; - -/** - * Tests to confirm that usage of retry settings can be done regardless of whether threeten or - * java.time is being used - */ -public class ITTimeObjectsPropagationTest { - @Test - public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { - java.time.Duration javaTimeCommonValue = java.time.Duration.ofMillis(123l); - org.threeten.bp.Duration threetenConvertedValue = - org.threeten.bp.Duration.ofMillis(javaTimeCommonValue.toMillis()); - RetrySettings javaTimeRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(javaTimeCommonValue) - .setMaxRetryDelay(javaTimeCommonValue) - .setInitialRpcTimeout(javaTimeCommonValue) - .setMaxRpcTimeout(javaTimeCommonValue) - .setTotalTimeout(javaTimeCommonValue) - .build(); - - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRetryDelay()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRetryDelay()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRpcTimeout()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRpcTimeout()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getTotalTimeout()); - } - - @Test - public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { - java.time.Duration threetenCommonValue = java.time.Duration.ofMillis(123l); - org.threeten.bp.Duration javaTimeConvertedValue = - org.threeten.bp.Duration.ofMillis(threetenCommonValue.toMillis()); - RetrySettings threetenRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(threetenCommonValue) - .setMaxRetryDelay(threetenCommonValue) - .setInitialRpcTimeout(threetenCommonValue) - .setMaxRpcTimeout(threetenCommonValue) - .setTotalTimeout(threetenCommonValue) - .build(); - - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRetryDelay()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRetryDelay()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRpcTimeout()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRpcTimeout()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getTotalTimeout()); - } - -} From a99d3c1acd4b25a28bd571c8c6f7f7f5d74e1365 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:19:13 -0400 Subject: [PATCH 101/141] fix clirr and compilation --- .../longrunning/stub/OperationsStubSettings.java | 10 +++++----- gax-java/gax/clirr-ignored-differences.xml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java index 853242eedd..47c3a981b8 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java @@ -242,13 +242,13 @@ public static class Builder extends StubSettings.Builder 7012 com/google/api/gax/tracing/* - * attemptFailed(java.lang.Throwable, java.time.Duration) + * attemptFailedDuration(java.lang.Throwable, java.time.Duration) 7002 From 7e64fc10a7bc60a29d3ee20644accd48671f19e6 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:27:17 -0400 Subject: [PATCH 102/141] fix compileation issues --- .../api/gax/grpc/GrpcCallableFactoryTest.java | 4 +- .../grpc/GrpcDirectStreamControllerTest.java | 10 +-- .../api/gax/grpc/GrpcLongRunningTest.java | 10 +-- .../com/google/api/gax/grpc/SettingsTest.java | 10 +-- .../com/google/api/gax/grpc/TimeoutTest.java | 76 +++++++++---------- .../stub/OperationsStubSettings.java | 10 +-- .../google/api/gax/httpjson/RetryingTest.java | 14 ++-- 7 files changed, 67 insertions(+), 67 deletions(-) diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java index 6a38229274..cf58eddb0c 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java @@ -105,7 +105,7 @@ public void createServerStreamingCallableRetryableExceptions() { ServerStreamingCallSettings.newBuilder() .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofSeconds(1)) + .setTotalTimeoutDuration(java.time.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); @@ -130,7 +130,7 @@ public void createServerStreamingCallableRetryableExceptions() { .setRetryableCodes(Code.INVALID_ARGUMENT) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofSeconds(1)) + .setTotalTimeoutDuration(java.time.Duration.ofSeconds(1)) .setMaxAttempts(1) .build()) .build(); diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java index 082b2a15ef..e0e51405ef 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java @@ -100,11 +100,11 @@ public boolean canResume() { .setRetryableCodes(StatusCode.Code.DEADLINE_EXCEEDED) .setRetrySettings( RetrySettings.newBuilder() - .setTotalTimeout(java.time.Duration.ofMinutes(1)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(1)) - .setMaxRpcTimeout(java.time.Duration.ofMillis(1)) - .setInitialRetryDelay(java.time.Duration.ofMillis(1)) - .setMaxRetryDelay(java.time.Duration.ofMillis(1)) + .setTotalTimeoutDuration(java.time.Duration.ofMinutes(1)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(1)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(1)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1)) .build()) .build(); // Store a list of resources to manually close at the end of the test diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java index ecb1148420..f37817fadb 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcLongRunningTest.java @@ -77,15 +77,15 @@ public class GrpcLongRunningTest { private static final RetrySettings FAST_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(java.time.Duration.ofMillis(1L)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(1L)) .setRetryDelayMultiplier(1) - .setMaxRetryDelay(java.time.Duration.ofMillis(1L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(1L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(1L)) .setMaxAttempts(0) .setJittered(false) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(java.time.Duration.ofMillis(1L)) - .setTotalTimeout(java.time.Duration.ofMillis(5L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(1L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(5L)) .build(); private ManagedChannel channel; diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java index a556a4ddc3..5ede5e0960 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/SettingsTest.java @@ -116,11 +116,11 @@ private static class FakeStubSettings extends StubSettings { RetrySettings.newBuilder() .setInitialRetryDelayDuration(java.time.Duration.ofMillis(100L)) .setRetryDelayMultiplier(1.2) - .setMaxRetryDelay(java.time.Duration.ofMillis(1000L)) - .setInitialRpcTimeout(java.time.Duration.ofMillis(2000L)) + .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1000L)) + .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(2000L)) .setRpcTimeoutMultiplier(1.5) - .setMaxRpcTimeout(java.time.Duration.ofMillis(30000L)) - .setTotalTimeout(java.time.Duration.ofMillis(45000L)) + .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(java.time.Duration.ofMillis(45000L)) .build(); definitions.put("default", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -343,7 +343,7 @@ public void callSettingsBuildFromTimeoutNoRetries() { UnaryCallSettings.Builder builderA = UnaryCallSettings.newUnaryCallSettingsBuilder(); - builderA.setSimpleTimeoutNoRetries(timeout); + builderA.setSimpleTimeoutNoRetriesDuration(timeout); UnaryCallSettings settingsA = builderA.build(); UnaryCallSettings.Builder builderB = diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java index d4c60d5c31..aec0ba3cfb 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/TimeoutTest.java @@ -103,15 +103,15 @@ public static void setUp() throws IOException { public void testNonRetryUnarySettings() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) - .setInitialRpcTimeout(initialRpcTimeout) + .setInitialRpcTimeoutDuration(initialRpcTimeout) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(maxRpcTimeout) + .setMaxRpcTimeoutDuration(maxRpcTimeout) .build(); CallOptions callOptionsUsed = setupUnaryCallable(retrySettings, emptyRetryCodes, defaultCallContext); @@ -129,22 +129,22 @@ public void testNonRetryUnarySettings() { public void testNonRetryUnarySettingsContextWithRetry() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) - .setInitialRpcTimeout(initialRpcTimeout) + .setInitialRpcTimeoutDuration(initialRpcTimeout) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(maxRpcTimeout) + .setMaxRpcTimeoutDuration(maxRpcTimeout) .build(); java.time.Duration newTimeout = java.time.Duration.ofSeconds(5); RetrySettings contextRetrySettings = retrySettings .toBuilder() - .setInitialRpcTimeout(newTimeout) - .setMaxRpcTimeout(newTimeout) + .setInitialRpcTimeoutDuration(newTimeout) + .setMaxRpcTimeoutDuration(newTimeout) .setMaxAttempts(3) .build(); GrpcCallContext retryingContext = @@ -169,14 +169,14 @@ public void testNonRetryUnarySettingsContextWithRetry() { public void testNonRetryUnarySettingsWithoutInitialRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(maxRpcTimeout) + .setMaxRpcTimeoutDuration(maxRpcTimeout) .build(); CallOptions callOptionsUsed = setupUnaryCallable(retrySettings, emptyRetryCodes, defaultCallContext); @@ -194,10 +194,10 @@ public void testNonRetryUnarySettingsWithoutInitialRpcTimeout() { public void testNonRetryUnarySettingsWithoutIndividualRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) @@ -218,15 +218,15 @@ public void testNonRetryUnarySettingsWithoutIndividualRpcTimeout() { public void testNonRetryServerStreamingSettings() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) - .setInitialRpcTimeout(initialRpcTimeout) + .setInitialRpcTimeoutDuration(initialRpcTimeout) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(maxRpcTimeout) + .setMaxRpcTimeoutDuration(maxRpcTimeout) .build(); CallOptions callOptionsUsed = setupServerStreamingCallable(retrySettings, emptyRetryCodes, defaultCallContext); @@ -244,22 +244,22 @@ public void testNonRetryServerStreamingSettings() { public void testNonRetryServerStreamingSettingsContextWithRetry() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) - .setInitialRpcTimeout(initialRpcTimeout) + .setInitialRpcTimeoutDuration(initialRpcTimeout) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(maxRpcTimeout) + .setMaxRpcTimeoutDuration(maxRpcTimeout) .build(); java.time.Duration newTimeout = java.time.Duration.ofSeconds(5); RetrySettings contextRetrySettings = retrySettings .toBuilder() - .setInitialRpcTimeout(newTimeout) - .setMaxRpcTimeout(newTimeout) + .setInitialRpcTimeoutDuration(newTimeout) + .setMaxRpcTimeoutDuration(newTimeout) .setMaxAttempts(3) .build(); GrpcCallContext retryingContext = @@ -284,14 +284,14 @@ public void testNonRetryServerStreamingSettingsContextWithRetry() { public void testNonRetryServerStreamingSettingsWithoutInitialRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(maxRpcTimeout) + .setMaxRpcTimeoutDuration(maxRpcTimeout) .build(); CallOptions callOptionsUsed = setupServerStreamingCallable(retrySettings, emptyRetryCodes, defaultCallContext); @@ -309,10 +309,10 @@ public void testNonRetryServerStreamingSettingsWithoutInitialRpcTimeout() { public void testNonRetryServerStreamingSettingsWithoutIndividualRpcTimeout() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(totalTimeout) - .setInitialRetryDelay(java.time.Duration.ZERO) + .setTotalTimeoutDuration(totalTimeout) + .setInitialRetryDelayDuration(java.time.Duration.ZERO) .setRetryDelayMultiplier(1.0) - .setMaxRetryDelay(java.time.Duration.ZERO) + .setMaxRetryDelayDuration(java.time.Duration.ZERO) .setMaxAttempts(1) .setJittered(true) .setRpcTimeoutMultiplier(1.0) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java index b47755b714..b1664088a5 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/longrunning/stub/OperationsStubSettings.java @@ -292,13 +292,13 @@ public static class Builder extends StubSettings.Builder callSettings = createSettings(retryable, retrySettings); UnaryCallable callable = From 75d038c66a3555e4f85e29a94f0a295043cef2c5 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 8 May 2024 20:32:40 -0400 Subject: [PATCH 103/141] fix comments --- .../java/com/google/api/gax/grpc/GrpcCallContext.java | 6 +++--- .../api/gax/grpc/InstantiatingGrpcChannelProvider.java | 2 +- .../com/google/api/gax/httpjson/HttpJsonCallContext.java | 8 ++++---- .../com/google/api/gax/batching/ThresholdBatcher.java | 2 +- .../java/com/google/api/gax/retrying/RetrySettings.java | 2 +- .../main/java/com/google/api/gax/rpc/ApiCallContext.java | 6 +++--- .../google/api/gax/rpc/ServerStreamingCallSettings.java | 4 ++-- .../main/java/com/google/api/gax/rpc/StubSettings.java | 2 +- .../src/main/java/com/google/api/gax/rpc/Watchdog.java | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 7d7fab0ee2..9d3252499a 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -232,7 +232,7 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) { } /** - * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @@ -282,7 +282,7 @@ public java.time.Duration getTimeoutDuration() { } /** - * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @@ -316,7 +316,7 @@ public GrpcCallContext withStreamWaitTimeoutDuration( } /** - * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} * * @param streamIdleTimeout diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 889c71c1a6..e8968b68e0 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -655,7 +655,7 @@ public Integer getMaxInboundMetadataSize() { } /** - * Overload of {@link #setKeepAliveTime(java.time.Duration)} using {@link + * Backport of {@link #setKeepAliveTime(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use setKeepAliveTimeDuration(java.time.Duration) instead") diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index a1a344ca4a..428e3b4d14 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -255,7 +255,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { } /** - * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @@ -322,7 +322,7 @@ public java.time.Duration getTimeoutDuration() { } /** - * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @@ -374,7 +374,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { } /** - * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @Override @@ -600,7 +600,7 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { this.endpointContext); } - /** Overload of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} */ + /** Backport of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} */ @Deprecated @ObsoleteApi("Use withDeadline(java.time.Instant) instead") public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 384cf52393..78227023cb 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -135,7 +135,7 @@ public Builder setMaxDelayDuration(java.time.Duration maxDelay) { return this; } - /** Overload of {@link #setMaxDelayDuration(java.time.Duration} */ + /** Backport of {@link #setMaxDelayDuration(java.time.Duration} */ @ObsoleteApi("Use setMaxDelayDuration(java.time.Duration) instead") public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { return setMaxDelayDuration(toJavaTimeDuration(maxDelay)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index ce3bcab9f4..70ebb8d284 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -511,7 +511,7 @@ public final java.time.Duration getMaxRpcTimeoutDuration() { } /** - * Overload of {@link #setLogicalTimeout(java.time.Duration)} using {@link + * Backport of {@link #setLogicalTimeout(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @BetaApi diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 0b45b722bf..9f20a1e49b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -67,7 +67,7 @@ public interface ApiCallContext extends RetryingContext { ApiCallContext withEndpointContext(EndpointContext endpointContext); /** - * Overload of {@link #withTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") @@ -97,7 +97,7 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getTimeoutDuration(); /** - * Overload of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration } */ @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") @@ -136,7 +136,7 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getStreamWaitTimeoutDuration(); /** - * Overload of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index a942af0b02..c87b23dcec 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -260,7 +260,7 @@ public RetrySettings getRetrySettings() { } /** - * Overload of {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} using {@link + * Backport of {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") @@ -349,7 +349,7 @@ public java.time.Duration getWaitTimeoutDuration() { } /** - * Overload of {@link #setWaitTimeoutDuration(java.time.Duration)} using {@link + * Backport of {@link #setWaitTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use setWaitTimeoutDuration(java.time.Duration) instead") diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index 25241ba260..62cb930f71 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -532,7 +532,7 @@ public B setQuotaProjectId(String quotaProjectId) { } /** - * Overload of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} using {@link + * Backport of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 7cf458452e..ea63d11867 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -101,7 +101,7 @@ private void start() { } /** - * Overload of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using + * Backport of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using * {@link org.threeten.bp.Duration} */ @ObsoleteApi("Use watch(ResponseObserver, java.time.Duration, java.time.Duration) instead") From f450e33ffb91d5453a61acfba08aec10cc1ced85 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Sat, 11 May 2024 01:32:33 -0400 Subject: [PATCH 104/141] Revert "remove showcase IT" This reverts commit 786c915f4b76c2049e02b0e0206c84fadbc87fe0. --- .../it/ITTimeObjectsPropagationTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java new file mode 100644 index 0000000000..050f167044 --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java @@ -0,0 +1,53 @@ +package com.google.showcase.v1beta1.it; + +import static org.junit.Assert.assertEquals; + +import com.google.api.gax.retrying.RetrySettings; +import org.junit.Test; + +/** + * Tests to confirm that usage of retry settings can be done regardless of whether threeten or + * java.time is being used + */ +public class ITTimeObjectsPropagationTest { + @Test + public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { + java.time.Duration javaTimeCommonValue = java.time.Duration.ofMillis(123l); + org.threeten.bp.Duration threetenConvertedValue = + org.threeten.bp.Duration.ofMillis(javaTimeCommonValue.toMillis()); + RetrySettings javaTimeRetrySettings = RetrySettings.newBuilder() + .setInitialRetryDelay(javaTimeCommonValue) + .setMaxRetryDelay(javaTimeCommonValue) + .setInitialRpcTimeout(javaTimeCommonValue) + .setMaxRpcTimeout(javaTimeCommonValue) + .setTotalTimeout(javaTimeCommonValue) + .build(); + + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRetryDelay()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRetryDelay()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRpcTimeout()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRpcTimeout()); + assertEquals(threetenConvertedValue, javaTimeRetrySettings.getTotalTimeout()); + } + + @Test + public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { + java.time.Duration threetenCommonValue = java.time.Duration.ofMillis(123l); + org.threeten.bp.Duration javaTimeConvertedValue = + org.threeten.bp.Duration.ofMillis(threetenCommonValue.toMillis()); + RetrySettings threetenRetrySettings = RetrySettings.newBuilder() + .setInitialRetryDelay(threetenCommonValue) + .setMaxRetryDelay(threetenCommonValue) + .setInitialRpcTimeout(threetenCommonValue) + .setMaxRpcTimeout(threetenCommonValue) + .setTotalTimeout(threetenCommonValue) + .build(); + + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRetryDelay()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRetryDelay()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRpcTimeout()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRpcTimeout()); + assertEquals(javaTimeConvertedValue, threetenRetrySettings.getTotalTimeout()); + } + +} From b276f076078859dff204c368b568c7d1d1c431e3 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Sat, 11 May 2024 01:33:58 -0400 Subject: [PATCH 105/141] reformat showcase test --- .../it/ITTimeObjectsPropagationTest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java index 050f167044..f2aff8da1a 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java @@ -15,13 +15,14 @@ public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { java.time.Duration javaTimeCommonValue = java.time.Duration.ofMillis(123l); org.threeten.bp.Duration threetenConvertedValue = org.threeten.bp.Duration.ofMillis(javaTimeCommonValue.toMillis()); - RetrySettings javaTimeRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(javaTimeCommonValue) - .setMaxRetryDelay(javaTimeCommonValue) - .setInitialRpcTimeout(javaTimeCommonValue) - .setMaxRpcTimeout(javaTimeCommonValue) - .setTotalTimeout(javaTimeCommonValue) - .build(); + RetrySettings javaTimeRetrySettings = + RetrySettings.newBuilder() + .setInitialRetryDelay(javaTimeCommonValue) + .setMaxRetryDelay(javaTimeCommonValue) + .setInitialRpcTimeout(javaTimeCommonValue) + .setMaxRpcTimeout(javaTimeCommonValue) + .setTotalTimeout(javaTimeCommonValue) + .build(); assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRetryDelay()); assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRetryDelay()); @@ -35,13 +36,14 @@ public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { java.time.Duration threetenCommonValue = java.time.Duration.ofMillis(123l); org.threeten.bp.Duration javaTimeConvertedValue = org.threeten.bp.Duration.ofMillis(threetenCommonValue.toMillis()); - RetrySettings threetenRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(threetenCommonValue) - .setMaxRetryDelay(threetenCommonValue) - .setInitialRpcTimeout(threetenCommonValue) - .setMaxRpcTimeout(threetenCommonValue) - .setTotalTimeout(threetenCommonValue) - .build(); + RetrySettings threetenRetrySettings = + RetrySettings.newBuilder() + .setInitialRetryDelay(threetenCommonValue) + .setMaxRetryDelay(threetenCommonValue) + .setInitialRpcTimeout(threetenCommonValue) + .setMaxRpcTimeout(threetenCommonValue) + .setTotalTimeout(threetenCommonValue) + .build(); assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRetryDelay()); assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRetryDelay()); @@ -49,5 +51,4 @@ public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRpcTimeout()); assertEquals(javaTimeConvertedValue, threetenRetrySettings.getTotalTimeout()); } - } From bd273a53efc31c8094db625ae60c236508b9fd57 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Sat, 11 May 2024 02:18:34 -0400 Subject: [PATCH 106/141] use java.time internal variables --- .../api/gax/httpjson/HttpJsonCallContext.java | 17 +-- .../api/gax/httpjson/HttpJsonCallOptions.java | 32 ++--- .../gax/httpjson/HttpJsonCallContextTest.java | 12 ++ .../api/gax/batching/BatchingSettings.java | 16 +-- .../api/gax/retrying/RetrySettings.java | 120 +++++++++--------- .../gax/retrying/TimedAttemptSettings.java | 50 ++++---- .../com/google/api/gax/rpc/ClientContext.java | 16 +-- 7 files changed, 138 insertions(+), 125 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 428e3b4d14..3fc2718ea2 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -53,6 +53,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.io.IOException; +import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Objects; @@ -513,13 +514,13 @@ public HttpJsonCallOptions getCallOptions() { @Nullable @ObsoleteApi("Use getDeadlineInstant() instead") public org.threeten.bp.Instant getDeadline() { - return getCallOptions() != null ? getCallOptions().getDeadline() : null; + return toThreetenInstant(getDeadlineInstant()); } @Deprecated @Nullable public java.time.Instant getDeadlineInstant() { - return toJavaTimeInstant(getDeadline()); + return getCallOptions() != null ? getCallOptions().getDeadlineInstant() : null; } @Deprecated @@ -600,18 +601,18 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { this.endpointContext); } - /** Backport of {@link #withDeadline(java.time.Instant)} using {@link org.threeten.bp.Instant} */ + /** Backport of {@link #withDeadlineInstant(java.time.Instant)} using {@link org.threeten.bp.Instant} */ @Deprecated @ObsoleteApi("Use withDeadline(java.time.Instant) instead") public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { - HttpJsonCallOptions.Builder builder = - callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); - return withCallOptions(builder.setDeadline(newDeadline).build()); + return withDeadlineInstant(toJavaTimeInstant(newDeadline)); } @Deprecated - public HttpJsonCallContext withDeadline(java.time.Instant newDeadline) { - return withDeadline(toThreetenInstant(newDeadline)); + public HttpJsonCallContext withDeadlineInstant(java.time.Instant newDeadline) { + HttpJsonCallOptions.Builder builder = + callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); + return withCallOptions(builder.setDeadlineInstant(newDeadline).build()); } @Nonnull diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index 4634a38c16..1b24aa3384 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -47,21 +47,21 @@ public abstract class HttpJsonCallOptions { @Nullable @ObsoleteApi("Use getTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getTimeout(); + public final org.threeten.bp.Duration getTimeout() { + return toThreetenDuration(getTimeoutDuration()); + } @Nullable - public java.time.Duration getTimeoutDuration() { - return toJavaTimeDuration(getTimeout()); - } + public abstract java.time.Duration getTimeoutDuration(); @Nullable @ObsoleteApi("Use getDeadlineInstant() instead") - public abstract org.threeten.bp.Instant getDeadline(); + public final org.threeten.bp.Instant getDeadline() { + return toThreetenInstant(getDeadlineInstant()); + } @Nullable - public final java.time.Instant getDeadlineInstant() { - return toJavaTimeInstant(getDeadline()); - } + public abstract java.time.Instant getDeadlineInstant(); @Nullable public abstract Credentials getCredentials(); @@ -111,20 +111,20 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { public abstract static class Builder { /** Backport of {@link #setTimeoutDuration(java.time.Duration)} */ @ObsoleteApi("Use setTimeoutDuration(java.time.Duration) instead") - public abstract Builder setTimeout(org.threeten.bp.Duration value); - - public Builder setTimeoutDuration(java.time.Duration value) { - return setTimeout(toThreetenDuration(value)); + public final Builder setTimeout(org.threeten.bp.Duration value) { + return setTimeoutDuration(toJavaTimeDuration(value)); } + public abstract Builder setTimeoutDuration(java.time.Duration value); + /** Backport of {@link #setDeadlineInstant(java.time.Instant)} */ @ObsoleteApi("Use setDeadlineInstant(java.time.Instant) instead") - public abstract Builder setDeadline(org.threeten.bp.Instant value); - - public final Builder setDeadlineInstant(java.time.Instant value) { - return setDeadline(toThreetenInstant(value)); + public final Builder setDeadline(org.threeten.bp.Instant value) { + return setDeadlineInstant(toJavaTimeInstant(value)); } + public abstract Builder setDeadlineInstant(java.time.Instant value); + public abstract Builder setCredentials(Credentials value); public abstract Builder setTypeRegistry(TypeRegistry value); diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index f0dd092065..9789245fee 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -30,6 +30,7 @@ package com.google.api.gax.httpjson; import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; +import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -139,6 +140,17 @@ public void testStreamWaitTimeout() { c -> c.getStreamWaitTimeout()); } + @Test + public void testDeadline() { + final long millis = 3; + final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); + testInstantMethod( millis, + jt -> defaultContext.withDeadlineInstant(jt), + tt -> defaultContext.withDeadline(tt), + c -> c.getDeadlineInstant(), + c -> c.getDeadline()); + } + @Test public void testTimeout() { final long millis = 3; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 0f69a17024..b3ee99f9e2 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -104,13 +104,13 @@ public abstract class BatchingSettings { /** Get the delay threshold to use for batching. */ @Nullable @ObsoleteApi("Use getDelayThresholdDuration() instead") - public abstract org.threeten.bp.Duration getDelayThreshold(); + public org.threeten.bp.Duration getDelayThreshold() { + return toThreetenDuration(getDelayThresholdDuration()); + } /** Get the delay threshold to use for batching. */ @Nullable - public final java.time.Duration getDelayThresholdDuration() { - return toJavaTimeDuration(getDelayThreshold()); - } + public abstract java.time.Duration getDelayThresholdDuration(); /** Returns the Boolean object to indicate if the batching is enabled. Default to true */ public abstract Boolean getIsEnabled(); @@ -154,7 +154,9 @@ public abstract static class Builder { /** Backport of {@link #setDelayThresholdDuration(java.time.Duration)} */ @ObsoleteApi("Use setDelayThresholdDuration(java.time.Duration) instead") - public abstract Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold); + public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) { + return setDelayThresholdDuration(toJavaTimeDuration(delayThreshold)); + } /** * Set the delay threshold to use for batching. After this amount of time has elapsed (counting @@ -162,9 +164,7 @@ public abstract static class Builder { * value should not be set too high, usually on the order of milliseconds. Otherwise, calls * might appear to never complete. */ - public final Builder setDelayThresholdDuration(java.time.Duration delayThreshold) { - return setDelayThreshold(toThreetenDuration(delayThreshold)); - } + public abstract Builder setDelayThresholdDuration(java.time.Duration delayThreshold); /** * Set if the batch should be enabled. If set to false, the batch logic will be disabled and the diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 70ebb8d284..8c402f924a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -83,7 +83,9 @@ public abstract class RetrySettings implements Serializable { /** Backport of {@link #getTotalTimeoutDuration()} */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getTotalTimeout(); + public org.threeten.bp.Duration getTotalTimeout() { + return toThreetenDuration(getTotalTimeoutDuration()); + }; /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call @@ -98,13 +100,13 @@ public abstract class RetrySettings implements Serializable { * Duration.ZERO} and LROs have a default total timeout value of {@code Duration.ofMillis(300000)} * (5 minutes). */ - public final java.time.Duration getTotalTimeoutDuration() { - return toJavaTimeDuration(getTotalTimeout()); - } + public abstract java.time.Duration getTotalTimeoutDuration(); /** Backport of {@link #getInitialRetryDelayDuration()} */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getInitialRetryDelay(); + public org.threeten.bp.Duration getInitialRetryDelay() { + return toThreetenDuration(getInitialRetryDelayDuration()); + } /** * InitialRetryDelay controls the delay before the first retry/ poll. Subsequent retries and polls @@ -114,9 +116,7 @@ public final java.time.Duration getTotalTimeoutDuration() { * Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ - public final java.time.Duration getInitialRetryDelayDuration() { - return toJavaTimeDuration(getInitialRetryDelay()); - } + public abstract java.time.Duration getInitialRetryDelayDuration(); /** * RetryDelayMultiplier controls the change in delay before the next retry or poll. The retry @@ -130,7 +130,9 @@ public final java.time.Duration getInitialRetryDelayDuration() { /** Backport of {@link #getMaxRetryDelayDuration()} */ @ObsoleteApi("Use getMaxRetryDelayDuration()") - public abstract org.threeten.bp.Duration getMaxRetryDelay(); + public org.threeten.bp.Duration getMaxRetryDelay() { + return toThreetenDuration(getMaxRetryDelayDuration()); + } /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier @@ -140,9 +142,7 @@ public final java.time.Duration getInitialRetryDelayDuration() { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ - public final java.time.Duration getMaxRetryDelayDuration() { - return toJavaTimeDuration(getMaxRetryDelay()); - } + public abstract java.time.Duration getMaxRetryDelayDuration(); /** * MaxAttempts defines the maximum number of retry attempts to perform. If this value is set to 0, @@ -175,7 +175,9 @@ public final java.time.Duration getMaxRetryDelayDuration() { /** Backport of {@link #getInitialRpcTimeoutDuration()} */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getInitialRpcTimeout(); + public final org.threeten.bp.Duration getInitialRpcTimeout() { + return toThreetenDuration(getInitialRpcTimeoutDuration()); + } /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this @@ -190,9 +192,7 @@ public final java.time.Duration getMaxRetryDelayDuration() { *

    If there are no configurations, Retries have the default initial RPC timeout value of {@code * Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ - public final java.time.Duration getInitialRpcTimeoutDuration() { - return toJavaTimeDuration(getInitialRpcTimeout()); - } + public abstract java.time.Duration getInitialRpcTimeoutDuration(); /** * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is @@ -205,7 +205,9 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { /** Backport of {@link #getMaxRpcTimeoutDuration()} */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getMaxRpcTimeout(); + public final org.threeten.bp.Duration getMaxRpcTimeout() { + return toThreetenDuration(getMaxRpcTimeoutDuration()); + } /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier @@ -214,9 +216,7 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ - public final java.time.Duration getMaxRpcTimeoutDuration() { - return toJavaTimeDuration(getMaxRpcTimeout()); - } + public abstract java.time.Duration getMaxRpcTimeoutDuration(); public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() @@ -242,7 +242,9 @@ public abstract static class Builder { /** Backport of {@link #setTotalTimeoutDuration(java.time.Duration)} */ @ObsoleteApi("Use setTotalTimeoutDuration(java.time.Duration) instead") - public abstract Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout); + public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { + return setTotalTimeoutDuration(toJavaTimeDuration(totalTimeout)); + } /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call @@ -257,13 +259,13 @@ public abstract static class Builder { * Duration.ZERO} and LROs have a default total timeout value of {@code * Duration.ofMillis(300000)} (5 minutes). */ - public final Builder setTotalTimeoutDuration(java.time.Duration totalTimeout) { - return setTotalTimeout(toThreetenDuration(totalTimeout)); - } + public abstract Builder setTotalTimeoutDuration(java.time.Duration totalTimeout); /** Backport of {@link #setInitialRetryDelayDuration(java.time.Duration)} */ @ObsoleteApi("Use setInitialRetryDelayDuration(java.time.Duration) instead") - public abstract Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay); + public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { + return setInitialRetryDelayDuration(toJavaTimeDuration(initialDelay)); + } /** * InitialRetryDelay controls the delay before the first retry/ poll. Subsequent retries and @@ -273,9 +275,7 @@ public final Builder setTotalTimeoutDuration(java.time.Duration totalTimeout) { * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ - public final Builder setInitialRetryDelayDuration(java.time.Duration initialDelay) { - return setInitialRetryDelay(toThreetenDuration(initialDelay)); - } + public abstract Builder setInitialRetryDelayDuration(java.time.Duration initialDelay); /** * RetryDelayMultiplier controls the change in delay before the next retry or poll. The retry @@ -289,7 +289,9 @@ public final Builder setInitialRetryDelayDuration(java.time.Duration initialDela /** Backport of {@link #setMaxRetryDelayDuration(java.time.Duration)} */ @ObsoleteApi("Use setMaxRetryDelayDuration(java.time.Duration) instead") - public abstract Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay); + public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { + return setMaxRetryDelayDuration(toJavaTimeDuration(maxDelay)); + } /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier @@ -299,9 +301,7 @@ public final Builder setInitialRetryDelayDuration(java.time.Duration initialDela * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ - public final Builder setMaxRetryDelayDuration(java.time.Duration maxDelay) { - return setMaxRetryDelay(toThreetenDuration(maxDelay)); - } + public abstract Builder setMaxRetryDelayDuration(java.time.Duration maxDelay); /** * MaxAttempts defines the maximum number of retry attempts to perform. If this value is set to @@ -334,7 +334,9 @@ public final Builder setMaxRetryDelayDuration(java.time.Duration maxDelay) { /** Backport of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} */ @ObsoleteApi("Use setInitialRpcTimeoutDuration(java.time.Duration) instead") - public abstract Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout); + public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { + return setInitialRpcTimeoutDuration(toJavaTimeDuration(initialTimeout)); + } /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this @@ -349,9 +351,7 @@ public final Builder setMaxRetryDelayDuration(java.time.Duration maxDelay) { *

    If there are no configurations, Retries have the default initial RPC timeout value of * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ - public final Builder setInitialRpcTimeoutDuration(java.time.Duration initialTimeout) { - return setInitialRpcTimeout(toThreetenDuration(initialTimeout)); - } + public abstract Builder setInitialRpcTimeoutDuration(java.time.Duration initialTimeout); /** * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is @@ -364,7 +364,9 @@ public final Builder setInitialRpcTimeoutDuration(java.time.Duration initialTime /** Backport of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} */ @ObsoleteApi("Use setMaxRpcTimeoutDuration(java.time.Duration) instead") - public abstract Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout); + public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { + return setMaxRpcTimeoutDuration(toJavaTimeDuration(maxTimeout)); + } /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier @@ -373,13 +375,13 @@ public final Builder setInitialRpcTimeoutDuration(java.time.Duration initialTime *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ - public final Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout) { - return setMaxRpcTimeout(toThreetenDuration(maxTimeout)); - } + public abstract Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout); /** Backport of {@link #getTotalTimeoutDuration()} */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getTotalTimeout(); + public final org.threeten.bp.Duration getTotalTimeout() { + return toThreetenDuration(getTotalTimeoutDuration()); + } /** * TotalTimeout has ultimate control over how long the logic should keep trying the remote call @@ -394,13 +396,13 @@ public final Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout) { * Duration.ZERO} and LROs have a default total timeout value of {@code * Duration.ofMillis(300000)} (5 minutes). */ - public final java.time.Duration getTotalTimeoutDuration() { - return toJavaTimeDuration(getTotalTimeout()); - } + public abstract java.time.Duration getTotalTimeoutDuration(); /** Backport of {@link #getInitialRetryDelayDuration()} */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getInitialRetryDelay(); + public final org.threeten.bp.Duration getInitialRetryDelay() { + return toThreetenDuration(getInitialRetryDelayDuration()); + } /** * InitialRetryDelay controls the delay before the first retry/ poll. Subsequent retries and @@ -410,9 +412,7 @@ public final java.time.Duration getTotalTimeoutDuration() { * {@code Duration.ZERO} and LROs have a default initial poll delay value of {@code * Duration.ofMillis(5000)} (5 seconds). */ - public final java.time.Duration getInitialRetryDelayDuration() { - return toJavaTimeDuration(getInitialRetryDelay()); - } + public abstract java.time.Duration getInitialRetryDelayDuration(); /** * RetryDelayMultiplier controls the change in delay before the next retry or poll. The retry @@ -451,7 +451,9 @@ public final java.time.Duration getInitialRetryDelayDuration() { /** Backport of {@link #getMaxRetryDelayDuration()} */ @ObsoleteApi("Use getMaxRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getMaxRetryDelay(); + public final org.threeten.bp.Duration getMaxRetryDelay() { + return toThreetenDuration(getMaxRetryDelayDuration()); + } /** * MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier @@ -461,13 +463,13 @@ public final java.time.Duration getInitialRetryDelayDuration() { * Duration.ZERO} and LROs have a default max poll retry delay value of {@code * Duration.ofMillis(45000)} (45 seconds). */ - public final java.time.Duration getMaxRetryDelayDuration() { - return toJavaTimeDuration(getMaxRetryDelay()); - } + public abstract java.time.Duration getMaxRetryDelayDuration(); /** Backport of {@link #getInitialRpcTimeoutDuration()} */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getInitialRpcTimeout(); + public final org.threeten.bp.Duration getInitialRpcTimeout() { + return toThreetenDuration(getInitialRpcTimeoutDuration()); + } /** * InitialRpcTimeout controls the timeout for the initial RPC. Subsequent calls will use this @@ -482,9 +484,7 @@ public final java.time.Duration getMaxRetryDelayDuration() { *

    If there are no configurations, Retries have the default initial RPC timeout value of * {@code Duration.ZERO}. LRO polling does not use the Initial RPC Timeout value. */ - public final java.time.Duration getInitialRpcTimeoutDuration() { - return toJavaTimeDuration(getInitialRpcTimeout()); - } + public abstract java.time.Duration getInitialRpcTimeoutDuration(); /** * RpcTimeoutMultiplier controls the change in RPC timeout. The timeout of the previous call is @@ -497,7 +497,9 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { /** Backport of {@link #getMaxRpcTimeoutDuration()} */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getMaxRpcTimeout(); + public final org.threeten.bp.Duration getMaxRpcTimeout() { + return toThreetenDuration(getMaxRpcTimeoutDuration()); + } /** * MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier @@ -506,9 +508,7 @@ public final java.time.Duration getInitialRpcTimeoutDuration() { *

    If there are no configurations, Retries have the default Max RPC Timeout value of {@code * Duration.ZERO}. LRO polling does not use the Max RPC Timeout value. */ - public final java.time.Duration getMaxRpcTimeoutDuration() { - return toJavaTimeDuration(getMaxRpcTimeout()); - } + public abstract java.time.Duration getMaxRpcTimeoutDuration(); /** * Backport of {@link #setLogicalTimeout(java.time.Duration)} using {@link diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index ce4b69bdd2..4dd11a5d15 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -45,36 +45,36 @@ public abstract class TimedAttemptSettings { /** Backport of {@link #getRetryDelayDuration()} */ @ObsoleteApi("Use getRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getRetryDelay(); + public final org.threeten.bp.Duration getRetryDelay() { + return toThreetenDuration(getRetryDelayDuration()); + } /** * Returns the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public final java.time.Duration getRetryDelayDuration() { - return toJavaTimeDuration(getRetryDelay()); - } + public abstract java.time.Duration getRetryDelayDuration(); /** Backport of {@link #getRpcTimeoutDuration()} */ @ObsoleteApi("Use getRpcTimeoutDuration() instead") - public abstract org.threeten.bp.Duration getRpcTimeout(); + public final org.threeten.bp.Duration getRpcTimeout() { + return toThreetenDuration(getRpcTimeoutDuration()); + } /** Returns rpc timeout used for this attempt. */ - public final java.time.Duration getRpcTimeoutDuration() { - return toJavaTimeDuration(getRpcTimeout()); - } + public abstract java.time.Duration getRpcTimeoutDuration(); /** Backport of {@link #getRandomizedRetryDelayDuration()} */ @ObsoleteApi("Use getRandomizedRetryDelayDuration() instead") - public abstract org.threeten.bp.Duration getRandomizedRetryDelay(); + public final org.threeten.bp.Duration getRandomizedRetryDelay() { + return toThreetenDuration(getRandomizedRetryDelayDuration()); + } /** * Returns randomized attempt delay. By default this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public final java.time.Duration getRandomizedRetryDelayDuration() { - return toJavaTimeDuration(getRandomizedRetryDelay()); - } + public abstract java.time.Duration getRandomizedRetryDelayDuration(); /** * The attempt count. It is a zero-based value (first attempt will have this value set to 0). For @@ -111,42 +111,42 @@ public abstract static class Builder { * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRetryDelayDuration(java.time.Duration) instead") - public abstract Builder setRetryDelay(org.threeten.bp.Duration value); + public final Builder setRetryDelay(org.threeten.bp.Duration value) { + return setRetryDelayDuration(toJavaTimeDuration(value)); + } /** * Sets the calculated retry delay. Note that the actual delay used for retry scheduling may be * different (randomized, based on this value). */ - public final Builder setRetryDelayDuration(java.time.Duration value) { - return setRetryDelay(toThreetenDuration(value)); - } + public abstract Builder setRetryDelayDuration(java.time.Duration value); /** * Backport of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRpcTimeoutDuration(java.time.Duration) instead") - public abstract Builder setRpcTimeout(org.threeten.bp.Duration value); + public final Builder setRpcTimeout(org.threeten.bp.Duration value) { + return setRpcTimeoutDuration(toJavaTimeDuration(value)); + } /** Sets rpc timeout used for this attempt. */ - public final Builder setRpcTimeoutDuration(java.time.Duration value) { - return setRpcTimeout(toThreetenDuration(value)); - } + public abstract Builder setRpcTimeoutDuration(java.time.Duration value); /** * Backport of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link * org.threeten.bp.Duration} */ @ObsoleteApi("Use setRandomizedRetryDelayDuration(java.time.Duration) instead") - public abstract Builder setRandomizedRetryDelay(org.threeten.bp.Duration value); + public final Builder setRandomizedRetryDelay(org.threeten.bp.Duration value) { + return setRandomizedRetryDelayDuration(toJavaTimeDuration(value)); + } /** - * Sets randomized attempt delay. By default this value is calculated based on the {@code + * Sets randomized attempt delay. By default, this value is calculated based on the {@code * retryDelay} value, and is used as the actual attempt execution delay. */ - public final Builder setRandomizedRetryDelayDuration(java.time.Duration value) { - return setRandomizedRetryDelay(toThreetenDuration(value)); - } + public abstract Builder setRandomizedRetryDelayDuration(java.time.Duration value); /** * Set the attempt count. It is a zero-based value (first attempt will have this value set to diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 450156e19f..ce996d1a7a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -107,12 +107,12 @@ public abstract class ClientContext { */ @Nonnull @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") - public abstract org.threeten.bp.Duration getStreamWatchdogCheckInterval(); + public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { + return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); + } @Nonnull - public final java.time.Duration getStreamWatchdogCheckIntervalDuration() { - return toJavaTimeDuration(getStreamWatchdogCheckInterval()); - } + public abstract java.time.Duration getStreamWatchdogCheckIntervalDuration(); @Nullable public abstract String getUniverseDomain(); @@ -362,12 +362,12 @@ public abstract static class Builder { /** Backport of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} */ @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") - public abstract Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration); - - public final Builder setStreamWatchdogCheckIntervalDuration(java.time.Duration duration) { - return setStreamWatchdogCheckInterval(toThreetenDuration(duration)); + public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { + return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(duration)); } + public abstract Builder setStreamWatchdogCheckIntervalDuration(java.time.Duration duration); + /** * Set the {@link ApiTracerFactory} that will be used to generate traces for operations. * From 5dbff0f481fcdab2e4eca623b4e40067fcd93d87 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 13:09:01 -0400 Subject: [PATCH 107/141] remove overloads for deprecated method in HttpJsonCallContext --- .../api/gax/httpjson/HttpJsonCallContext.java | 19 ++----------------- .../gax/httpjson/HttpJsonCallContextTest.java | 11 ----------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 3fc2718ea2..ce0d3cea2d 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -509,18 +509,10 @@ public HttpJsonCallOptions getCallOptions() { return callOptions; } - /** Backport of {@link #getDeadlineInstant()} */ @Deprecated @Nullable - @ObsoleteApi("Use getDeadlineInstant() instead") public org.threeten.bp.Instant getDeadline() { - return toThreetenInstant(getDeadlineInstant()); - } - - @Deprecated - @Nullable - public java.time.Instant getDeadlineInstant() { - return getCallOptions() != null ? getCallOptions().getDeadlineInstant() : null; + return getCallOptions() != null ? getCallOptions().getDeadline() : null; } @Deprecated @@ -601,18 +593,11 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { this.endpointContext); } - /** Backport of {@link #withDeadlineInstant(java.time.Instant)} using {@link org.threeten.bp.Instant} */ @Deprecated - @ObsoleteApi("Use withDeadline(java.time.Instant) instead") public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { - return withDeadlineInstant(toJavaTimeInstant(newDeadline)); - } - - @Deprecated - public HttpJsonCallContext withDeadlineInstant(java.time.Instant newDeadline) { HttpJsonCallOptions.Builder builder = callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); - return withCallOptions(builder.setDeadlineInstant(newDeadline).build()); + return withCallOptions(builder.setDeadline(newDeadline).build()); } @Nonnull diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index 9789245fee..bb50c51235 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -140,17 +140,6 @@ public void testStreamWaitTimeout() { c -> c.getStreamWaitTimeout()); } - @Test - public void testDeadline() { - final long millis = 3; - final HttpJsonCallContext defaultContext = HttpJsonCallContext.createDefault(); - testInstantMethod( millis, - jt -> defaultContext.withDeadlineInstant(jt), - tt -> defaultContext.withDeadline(tt), - c -> c.getDeadlineInstant(), - c -> c.getDeadline()); - } - @Test public void testTimeout() { final long millis = 3; From a579c0d1243912657e52397b05a1d26d8e9d3393 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 13:21:35 -0400 Subject: [PATCH 108/141] Add overload for Watchdog.create --- .../src/main/java/com/google/api/gax/rpc/Watchdog.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index ea63d11867..7a17bc90fd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -79,6 +79,16 @@ public final class Watchdog implements Runnable, BackgroundResource { private final ScheduledExecutorService executor; private ScheduledFuture future; + /** + * Backport of {@link #create(ApiClock, java.time.Duration, ScheduledExecutorService)} using + * {@link org.threeten.bp.Duration} + */ + @ObsoleteApi("Use create(ApiClock, java.time.Duration, ScheduledExecutorService) instead") + public static Watchdog create( + ApiClock clock, org.threeten.bp.Duration scheduleInterval, ScheduledExecutorService executor) { + return create(clock, toJavaTimeDuration(scheduleInterval), executor); + } + /** returns a Watchdog which is scheduled at the provided interval. */ public static Watchdog create( ApiClock clock, java.time.Duration scheduleInterval, ScheduledExecutorService executor) { From 6755cb83ab2963c02e637b836db570821e755604 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 13:22:37 -0400 Subject: [PATCH 109/141] remove InternalApi from WatchdogProvider --- .../src/main/java/com/google/api/gax/rpc/WatchdogProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index 852e2992c2..a9976d45c3 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -35,7 +35,6 @@ import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; -@InternalApi public interface WatchdogProvider { boolean needsClock(); From 5d3df797a38a7de0a8a5c4594ea1ccf04e38f509 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 13:24:19 -0400 Subject: [PATCH 110/141] Noop for ApiTracer.attemptFailed --- .../src/main/java/com/google/api/gax/tracing/ApiTracer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index 005d707b9d..50e303e86a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -112,9 +112,7 @@ default Scope inScope() { /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") - default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailedDuration(error, toJavaTimeDuration(delay)); - }; + default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {}; /** * Adds an annotation that the attempt failed, but another attempt will be made after the delay. From 175aeb32404999bc558860f5853e3d7e9508a5f1 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 13:24:48 -0400 Subject: [PATCH 111/141] Noop for BaseApiTracer.attemptFailed --- .../src/main/java/com/google/api/gax/tracing/BaseApiTracer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index 6867ccee83..09ed9099ae 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -114,7 +114,7 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { @Override @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailedDuration(error, toJavaTimeDuration(delay)); + // noop } @Override From f9ece6f085c519335f217902d19f76597f8b450f Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 16:47:02 -0400 Subject: [PATCH 112/141] remove testing getters in ThresholdBatcher --- .../api/gax/batching/ThresholdBatcher.java | 12 ---- .../gax/batching/ThresholdBatcherTest.java | 60 +++++++++++++++---- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 78227023cb..175dca5053 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -30,7 +30,6 @@ package com.google.api.gax.batching; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import com.google.api.core.ApiFunction; @@ -102,16 +101,6 @@ private ThresholdBatcher(Builder builder) { resetThresholds(); } - @VisibleForTesting - org.threeten.bp.Duration getMaxDelay() { - return toThreetenDuration(this.maxDelay); - } - - @VisibleForTesting - java.time.Duration getMaxDelayDuration() { - return this.maxDelay; - } - /** Builder for a ThresholdBatcher. */ public static class Builder { private Collection> thresholds; @@ -152,7 +141,6 @@ public Builder setReceiver(ThresholdBatchReceiver receiver) { this.receiver = receiver; return this; } - /** Set the flow controller for the ThresholdBatcher. */ public Builder setFlowController(BatchingFlowController flowController) { this.flowController = flowController; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index aa97650974..004ce631d8 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -29,18 +29,26 @@ */ package com.google.api.gax.batching; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import com.google.common.collect.ImmutableList; +import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import org.junit.Assert; import org.junit.Test; @@ -142,6 +150,22 @@ private static ThresholdBatcher.Builder createSimpleBatcherBuidler( .setBatchMerger(new SimpleBatchMerger()); } + private static SimpleEntry + createSimpleBatcherBuilderWithMockExecutor(long customThreshold) { + AccumulatingBatchReceiver receiver = + new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); + ScheduledExecutorService executor = mock(ScheduledThreadPoolExecutor.class); + when(executor.schedule((Runnable) any(), anyLong(), any())) + .thenReturn(mock(ScheduledFuture.class)); + BatchingThreshold threshold = new NumericThreshold<>(customThreshold, e -> 1); + + ThresholdBatcher.Builder builder = + createSimpleBatcherBuidler(receiver) + .setExecutor(executor) + .setThresholds(ImmutableList.of(threshold)); + return new SimpleEntry<>(builder, executor); + } + @Test public void testAdd() throws Exception { AccumulatingBatchReceiver receiver = @@ -363,16 +387,26 @@ public void testBatchingFailedRPC() throws Exception { } @Test - public void testMaxDelay() { - AccumulatingBatchReceiver receiver = - new AccumulatingBatchReceiver<>(ApiFutures.immediateFuture(null)); - final ThresholdBatcher.Builder builder = - createSimpleBatcherBuidler(receiver).setThresholds(Collections.emptyList()); - testDurationMethod( - 123l, - jt -> builder.setMaxDelayDuration(jt).build(), - tt -> builder.setMaxDelay(tt).build(), - o -> o.getMaxDelayDuration(), - o -> o.getMaxDelay()); + public void testMaxDelay() throws FlowControlException { + + final long MILLIS = 123l; + final SimpleBatch TEST_BATCH = SimpleBatch.fromInteger(1); + java.time.Duration javaTimeDuration = java.time.Duration.ofMillis(MILLIS); + org.threeten.bp.Duration threetenDuration = org.threeten.bp.Duration.ofMillis(MILLIS); + + SimpleEntry container = + createSimpleBatcherBuilderWithMockExecutor(1000l); + ThresholdBatcher.Builder builder = container.getKey(); + ScheduledExecutorService executor = container.getValue(); + + builder.setMaxDelayDuration(javaTimeDuration).build().add(TEST_BATCH); + verify(executor, times(1)).schedule((Runnable) any(), eq(MILLIS), any()); + + container = createSimpleBatcherBuilderWithMockExecutor(1000l); + builder = container.getKey(); + executor = container.getValue(); + + builder.setMaxDelay(threetenDuration).build().add(TEST_BATCH); + verify(executor, times(1)).schedule((Runnable) any(), eq(MILLIS), any()); } } From 02833c3365e2a3188425bf08dca1cfc4f0c56a1c Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 29 May 2024 16:47:37 -0400 Subject: [PATCH 113/141] format --- .../com/google/api/gax/httpjson/HttpJsonCallContext.java | 5 +---- .../com/google/api/gax/httpjson/HttpJsonCallContextTest.java | 1 - .../main/java/com/google/api/gax/retrying/RetrySettings.java | 2 +- .../gax/src/main/java/com/google/api/gax/rpc/Watchdog.java | 4 +++- .../main/java/com/google/api/gax/rpc/WatchdogProvider.java | 1 - .../src/main/java/com/google/api/gax/tracing/ApiTracer.java | 1 - .../main/java/com/google/api/gax/tracing/BaseApiTracer.java | 1 - 7 files changed, 5 insertions(+), 10 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index ce0d3cea2d..79c5033a36 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -30,9 +30,7 @@ package com.google.api.gax.httpjson; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; @@ -53,7 +51,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.io.IOException; -import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Objects; @@ -596,7 +593,7 @@ public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions) { @Deprecated public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) { HttpJsonCallOptions.Builder builder = - callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); + callOptions != null ? callOptions.toBuilder() : HttpJsonCallOptions.newBuilder(); return withCallOptions(builder.setDeadline(newDeadline).build()); } diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java index bb50c51235..f0dd092065 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallContextTest.java @@ -30,7 +30,6 @@ package com.google.api.gax.httpjson; import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; -import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 8c402f924a..cbc2c81456 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -131,7 +131,7 @@ public org.threeten.bp.Duration getInitialRetryDelay() { /** Backport of {@link #getMaxRetryDelayDuration()} */ @ObsoleteApi("Use getMaxRetryDelayDuration()") public org.threeten.bp.Duration getMaxRetryDelay() { - return toThreetenDuration(getMaxRetryDelayDuration()); + return toThreetenDuration(getMaxRetryDelayDuration()); } /** diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 7a17bc90fd..febfba6395 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -85,7 +85,9 @@ public final class Watchdog implements Runnable, BackgroundResource { */ @ObsoleteApi("Use create(ApiClock, java.time.Duration, ScheduledExecutorService) instead") public static Watchdog create( - ApiClock clock, org.threeten.bp.Duration scheduleInterval, ScheduledExecutorService executor) { + ApiClock clock, + org.threeten.bp.Duration scheduleInterval, + ScheduledExecutorService executor) { return create(clock, toJavaTimeDuration(scheduleInterval), executor); } diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index a9976d45c3..1d3c420611 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -30,7 +30,6 @@ package com.google.api.gax.rpc; import com.google.api.core.ApiClock; -import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index 50e303e86a..fa491513a0 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.tracing; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index 09ed9099ae..1d337b07aa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.tracing; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; From 389a5205c814d28d3d56963326cfd4bfdcfb1ba2 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Jun 2024 20:22:08 -0400 Subject: [PATCH 114/141] suggest alternative method in javadoc --- .../google/api/gax/grpc/GrpcCallContext.java | 14 +++----- .../InstantiatingGrpcChannelProvider.java | 6 ++-- .../api/gax/httpjson/HttpJsonCallContext.java | 18 ++++------ .../api/gax/httpjson/HttpJsonCallOptions.java | 4 +-- .../api/gax/batching/BatchingSettings.java | 7 ++-- .../api/gax/batching/ThresholdBatcher.java | 6 +++- .../api/gax/retrying/RetrySettings.java | 34 +++++++++---------- .../gax/retrying/TimedAttemptSettings.java | 15 ++++---- .../google/api/gax/rpc/ApiCallContext.java | 18 ++++------ .../com/google/api/gax/rpc/ClientContext.java | 6 ++-- .../google/api/gax/rpc/ClientSettings.java | 6 ++-- .../rpc/InstantiatingWatchdogProvider.java | 2 +- .../gax/rpc/ServerStreamingCallSettings.java | 16 ++++----- .../com/google/api/gax/rpc/StubSettings.java | 6 ++-- .../google/api/gax/rpc/UnaryCallSettings.java | 2 +- .../java/com/google/api/gax/rpc/Watchdog.java | 8 ++--- .../google/api/gax/rpc/WatchdogProvider.java | 2 +- .../com/google/api/gax/tracing/ApiTracer.java | 2 +- .../google/api/gax/tracing/BaseApiTracer.java | 2 +- .../google/api/gax/tracing/MetricsTracer.java | 2 +- .../api/gax/tracing/OpencensusTracer.java | 2 +- 21 files changed, 74 insertions(+), 104 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 9d3252499a..3098bf8eae 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -232,9 +232,7 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) { } /** - * Backport of {@link #withTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { @@ -282,9 +280,7 @@ public java.time.Duration getTimeoutDuration() { } /** - * Backport of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withStreamWaitTimeout( @@ -316,9 +312,7 @@ public GrpcCallContext withStreamWaitTimeoutDuration( } /** - * Backport of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - * + *

    This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} instead.

    */ * @param streamIdleTimeout * @return */ @@ -543,7 +537,7 @@ public CallOptions getCallOptions() { return callOptions; } - /** Backport of {@link #getStreamWaitTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead.

    */ @Override @Nullable @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index e8968b68e0..0312da2889 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -655,9 +655,7 @@ public Integer getMaxInboundMetadataSize() { } /** - * Backport of {@link #setKeepAliveTime(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #setKeepAliveTime(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setKeepAliveTimeDuration(java.time.Duration) instead") public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { return setKeepAliveTimeDuration(toJavaTimeDuration(duration)); @@ -668,7 +666,7 @@ public Builder setKeepAliveTimeDuration(java.time.Duration duration) { return this; } - /** Backport of {@link #getKeepAliveTimeDuration()} */ + /**

    This method is obsolete. Use {@link #getKeepAliveTimeDuration()} instead.

    */ @ObsoleteApi("Use getKeepAliveTimeDuration() instead") public org.threeten.bp.Duration getKeepAliveTime() { return toThreetenDuration(getKeepAliveTimeDuration()); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 79c5033a36..8af8b5cf32 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -253,9 +253,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { } /** - * Backport of {@link #withTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { @@ -305,7 +303,7 @@ public HttpJsonCallContext withTimeoutDuration(java.time.Duration timeout) { this.endpointContext); } - /** Backport of {@link #getTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getTimeoutDuration()} instead.

    */ @Nullable @Override @ObsoleteApi("Use getTimeoutDuration instead") @@ -320,9 +318,7 @@ public java.time.Duration getTimeoutDuration() { } /** - * Backport of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withStreamWaitTimeout( @@ -352,7 +348,7 @@ public HttpJsonCallContext withStreamWaitTimeoutDuration( this.endpointContext); } - /** Backport of {@link #getStreamWaitTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead.

    */ @Override @Nullable @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") @@ -372,9 +368,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { } /** - * Backport of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withStreamIdleTimeout( @@ -404,7 +398,7 @@ public HttpJsonCallContext withStreamIdleTimeoutDuration( this.endpointContext); } - /** Backport of {@link #getStreamIdleTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead.

    */ @Override @Nullable @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index 1b24aa3384..802c0ad4e2 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -109,7 +109,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { @AutoValue.Builder public abstract static class Builder { - /** Backport of {@link #setTimeoutDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setTimeoutDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setTimeoutDuration(java.time.Duration) instead") public final Builder setTimeout(org.threeten.bp.Duration value) { return setTimeoutDuration(toJavaTimeDuration(value)); @@ -117,7 +117,7 @@ public final Builder setTimeout(org.threeten.bp.Duration value) { public abstract Builder setTimeoutDuration(java.time.Duration value); - /** Backport of {@link #setDeadlineInstant(java.time.Instant)} */ + /**

    This method is obsolete. Use {@link #setDeadlineInstant(java.time.Instant)} instead.

    */ @ObsoleteApi("Use setDeadlineInstant(java.time.Instant) instead") public final Builder setDeadline(org.threeten.bp.Instant value) { return setDeadlineInstant(toJavaTimeInstant(value)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index b3ee99f9e2..2a597034ad 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -37,6 +37,7 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import javax.annotation.Nullable; +import java.time.Duration; /** * Represents the batching settings to use for an API method that is capable of batching. @@ -101,7 +102,7 @@ public abstract class BatchingSettings { @Nullable public abstract Long getRequestByteThreshold(); - /** Get the delay threshold to use for batching. */ + /**

    This method is obsolete. Use {@link #getDelayThresholdDuration() } instead

    */ @Nullable @ObsoleteApi("Use getDelayThresholdDuration() instead") public org.threeten.bp.Duration getDelayThreshold() { @@ -152,7 +153,9 @@ public abstract static class Builder { */ public abstract Builder setRequestByteThreshold(Long requestByteThreshold); - /** Backport of {@link #setDelayThresholdDuration(java.time.Duration)} */ + /** + *

    This method is obsolete. Use {@link #setDelayThresholdDuration(Duration)} instead

    + */ @ObsoleteApi("Use setDelayThresholdDuration(java.time.Duration) instead") public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) { return setDelayThresholdDuration(toJavaTimeDuration(delayThreshold)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index 175dca5053..e587625b17 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -41,6 +41,8 @@ import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; + +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.concurrent.Future; @@ -124,7 +126,9 @@ public Builder setMaxDelayDuration(java.time.Duration maxDelay) { return this; } - /** Backport of {@link #setMaxDelayDuration(java.time.Duration} */ + /** + *

    This method is obsolete. Use {@link #setMaxDelayDuration(Duration)} instead

    + */ @ObsoleteApi("Use setMaxDelayDuration(java.time.Duration) instead") public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { return setMaxDelayDuration(toJavaTimeDuration(maxDelay)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index cbc2c81456..10f3732bd5 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -37,6 +37,7 @@ import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; +import java.time.Duration; /** * Holds the parameters for retry or poll logic with jitter, timeout and exponential @@ -81,7 +82,7 @@ public abstract class RetrySettings implements Serializable { private static final long serialVersionUID = 8258475264439710899L; - /** Backport of {@link #getTotalTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getTotalTimeoutDuration()} instead

    */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") public org.threeten.bp.Duration getTotalTimeout() { return toThreetenDuration(getTotalTimeoutDuration()); @@ -102,7 +103,7 @@ public org.threeten.bp.Duration getTotalTimeout() { */ public abstract java.time.Duration getTotalTimeoutDuration(); - /** Backport of {@link #getInitialRetryDelayDuration()} */ + /**

    This method is obsolete. Use {@link #getInitialRetryDelayDuration()} instead

    */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public org.threeten.bp.Duration getInitialRetryDelay() { return toThreetenDuration(getInitialRetryDelayDuration()); @@ -128,7 +129,7 @@ public org.threeten.bp.Duration getInitialRetryDelay() { */ public abstract double getRetryDelayMultiplier(); - /** Backport of {@link #getMaxRetryDelayDuration()} */ + /**

    This method is obsolete. Use {@link #getMaxRetryDelayDuration()} instead */ @ObsoleteApi("Use getMaxRetryDelayDuration()") public org.threeten.bp.Duration getMaxRetryDelay() { return toThreetenDuration(getMaxRetryDelayDuration()); @@ -173,7 +174,7 @@ public org.threeten.bp.Duration getMaxRetryDelay() { @VisibleForTesting public abstract boolean isJittered(); - /** Backport of {@link #getInitialRpcTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getInitialRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getInitialRpcTimeout() { return toThreetenDuration(getInitialRpcTimeoutDuration()); @@ -203,7 +204,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { */ public abstract double getRpcTimeoutMultiplier(); - /** Backport of {@link #getMaxRpcTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getMaxRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getMaxRpcTimeout() { return toThreetenDuration(getMaxRpcTimeoutDuration()); @@ -240,7 +241,7 @@ public static Builder newBuilder() { @AutoValue.Builder public abstract static class Builder { - /** Backport of {@link #setTotalTimeoutDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setTotalTimeoutDuration(java.time.Duration)} instead */ @ObsoleteApi("Use setTotalTimeoutDuration(java.time.Duration) instead") public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { return setTotalTimeoutDuration(toJavaTimeDuration(totalTimeout)); @@ -261,7 +262,7 @@ public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { */ public abstract Builder setTotalTimeoutDuration(java.time.Duration totalTimeout); - /** Backport of {@link #setInitialRetryDelayDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setInitialRetryDelayDuration(java.time.Duration)} instead */ @ObsoleteApi("Use setInitialRetryDelayDuration(java.time.Duration) instead") public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { return setInitialRetryDelayDuration(toJavaTimeDuration(initialDelay)); @@ -287,7 +288,7 @@ public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) */ public abstract Builder setRetryDelayMultiplier(double multiplier); - /** Backport of {@link #setMaxRetryDelayDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setMaxRetryDelayDuration(java.time.Duration)} instead */ @ObsoleteApi("Use setMaxRetryDelayDuration(java.time.Duration) instead") public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { return setMaxRetryDelayDuration(toJavaTimeDuration(maxDelay)); @@ -332,7 +333,7 @@ public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { @VisibleForTesting public abstract Builder setJittered(boolean jittered); - /** Backport of {@link #setInitialRpcTimeoutDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setInitialRpcTimeoutDuration(java.time.Duration)} instead */ @ObsoleteApi("Use setInitialRpcTimeoutDuration(java.time.Duration) instead") public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { return setInitialRpcTimeoutDuration(toJavaTimeDuration(initialTimeout)); @@ -362,7 +363,7 @@ public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeou */ public abstract Builder setRpcTimeoutMultiplier(double multiplier); - /** Backport of {@link #setMaxRpcTimeoutDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setMaxRpcTimeoutDuration(java.time.Duration)} instead */ @ObsoleteApi("Use setMaxRpcTimeoutDuration(java.time.Duration) instead") public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { return setMaxRpcTimeoutDuration(toJavaTimeDuration(maxTimeout)); @@ -377,7 +378,7 @@ public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { */ public abstract Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout); - /** Backport of {@link #getTotalTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getTotalTimeoutDuration()} instead */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") public final org.threeten.bp.Duration getTotalTimeout() { return toThreetenDuration(getTotalTimeoutDuration()); @@ -398,7 +399,7 @@ public final org.threeten.bp.Duration getTotalTimeout() { */ public abstract java.time.Duration getTotalTimeoutDuration(); - /** Backport of {@link #getInitialRetryDelayDuration()} */ + /**

    This method is obsolete. Use {@link #getInitialRetryDelayDuration()} instead */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public final org.threeten.bp.Duration getInitialRetryDelay() { return toThreetenDuration(getInitialRetryDelayDuration()); @@ -449,7 +450,7 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { */ public abstract boolean isJittered(); - /** Backport of {@link #getMaxRetryDelayDuration()} */ + /**

    This method is obsolete. Use {@link #getMaxRetryDelayDuration()} instead */ @ObsoleteApi("Use getMaxRetryDelayDuration() instead") public final org.threeten.bp.Duration getMaxRetryDelay() { return toThreetenDuration(getMaxRetryDelayDuration()); @@ -465,7 +466,7 @@ public final org.threeten.bp.Duration getMaxRetryDelay() { */ public abstract java.time.Duration getMaxRetryDelayDuration(); - /** Backport of {@link #getInitialRpcTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getInitialRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getInitialRpcTimeout() { return toThreetenDuration(getInitialRpcTimeoutDuration()); @@ -495,7 +496,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { */ public abstract double getRpcTimeoutMultiplier(); - /** Backport of {@link #getMaxRpcTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getMaxRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getMaxRpcTimeout() { return toThreetenDuration(getMaxRpcTimeoutDuration()); @@ -511,8 +512,7 @@ public final org.threeten.bp.Duration getMaxRpcTimeout() { public abstract java.time.Duration getMaxRpcTimeoutDuration(); /** - * Backport of {@link #setLogicalTimeout(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + *

    This method is obsolete. Use {@link #setLogicalTimeout(java.time.Duration)} instead. */ @BetaApi @ObsoleteApi("Use setLogicalTimeout(java.time.Duration) instead") diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index 4dd11a5d15..a991070694 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -43,7 +43,7 @@ public abstract class TimedAttemptSettings { /** Returns global (attempt-independent) retry settings. */ public abstract RetrySettings getGlobalSettings(); - /** Backport of {@link #getRetryDelayDuration()} */ + /**

    This method is obsolete. Use {@link #getRetryDelayDuration()} instead */ @ObsoleteApi("Use getRetryDelayDuration() instead") public final org.threeten.bp.Duration getRetryDelay() { return toThreetenDuration(getRetryDelayDuration()); @@ -55,7 +55,7 @@ public final org.threeten.bp.Duration getRetryDelay() { */ public abstract java.time.Duration getRetryDelayDuration(); - /** Backport of {@link #getRpcTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getRpcTimeout() { return toThreetenDuration(getRpcTimeoutDuration()); @@ -64,7 +64,7 @@ public final org.threeten.bp.Duration getRpcTimeout() { /** Returns rpc timeout used for this attempt. */ public abstract java.time.Duration getRpcTimeoutDuration(); - /** Backport of {@link #getRandomizedRetryDelayDuration()} */ + /**

    This method is obsolete. Use {@link #getRandomizedRetryDelayDuration()} instead */ @ObsoleteApi("Use getRandomizedRetryDelayDuration() instead") public final org.threeten.bp.Duration getRandomizedRetryDelay() { return toThreetenDuration(getRandomizedRetryDelayDuration()); @@ -107,8 +107,7 @@ public abstract static class Builder { public abstract Builder setGlobalSettings(RetrySettings value); /** - * Backport of {@link #setRetryDelayDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + *

    This method is obsolete. Use {@link #setRetryDelayDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setRetryDelayDuration(java.time.Duration) instead") public final Builder setRetryDelay(org.threeten.bp.Duration value) { @@ -122,8 +121,7 @@ public final Builder setRetryDelay(org.threeten.bp.Duration value) { public abstract Builder setRetryDelayDuration(java.time.Duration value); /** - * Backport of {@link #setRpcTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + * This methods is obsolete. Use {@link #setRpcTimeoutDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setRpcTimeoutDuration(java.time.Duration) instead") public final Builder setRpcTimeout(org.threeten.bp.Duration value) { @@ -134,8 +132,7 @@ public final Builder setRpcTimeout(org.threeten.bp.Duration value) { public abstract Builder setRpcTimeoutDuration(java.time.Duration value); /** - * Backport of {@link #setRandomizedRetryDelayDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} + *

    This method is obsolete. Use {@link #setRandomizedRetryDelayDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setRandomizedRetryDelayDuration(java.time.Duration) instead") public final Builder setRandomizedRetryDelay(org.threeten.bp.Duration value) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 9f20a1e49b..4ee6eea6d5 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -67,9 +67,7 @@ public interface ApiCallContext extends RetryingContext { ApiCallContext withEndpointContext(EndpointContext endpointContext); /** - * Backport of {@link #withTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); @@ -87,7 +85,7 @@ public interface ApiCallContext extends RetryingContext { */ ApiCallContext withTimeoutDuration(@Nullable java.time.Duration timeout); - /** Backport of {@link #getTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getTimeoutDuration()} instead.

    */ @Nullable @ObsoleteApi("Use getTimeoutDuration() instead") org.threeten.bp.Duration getTimeout(); @@ -97,9 +95,7 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getTimeoutDuration(); /** - * Backport of {@link #withStreamWaitTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration } - */ + *

    This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") ApiCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout); @@ -122,7 +118,7 @@ public interface ApiCallContext extends RetryingContext { */ ApiCallContext withStreamWaitTimeoutDuration(@Nullable java.time.Duration streamWaitTimeout); - /** Backport of {@link #getStreamWaitTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead.

    */ @Nullable @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") org.threeten.bp.Duration getStreamWaitTimeout(); @@ -136,9 +132,7 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getStreamWaitTimeoutDuration(); /** - * Backport of {@link #withStreamIdleTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") ApiCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout); @@ -162,7 +156,7 @@ public interface ApiCallContext extends RetryingContext { */ ApiCallContext withStreamIdleTimeoutDuration(@Nullable java.time.Duration streamIdleTimeout); - /** Backport of {@link #getStreamIdleTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead.

    */ @Nullable @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") org.threeten.bp.Duration getStreamIdleTimeout(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index ce996d1a7a..f2e2fa133c 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -101,9 +101,7 @@ public abstract class ClientContext { public abstract Watchdog getStreamWatchdog(); /** - * Backport of {@link #getStreamWatchdogCheckIntervalDuration()} - * - * @return + * This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead. */ @Nonnull @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") @@ -360,7 +358,7 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); - /** Backport of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(duration)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index 04cbbc2dab..bf90aeb16b 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -113,9 +113,7 @@ public final WatchdogProvider getWatchdogProvider() { } /** - * Backport of {@link #getWatchdogCheckIntervalDuration()} - * - * @return + * This method is obsolete. Use {@link #getWatchdogCheckIntervalDuration()} instead. */ @Nonnull @ObsoleteApi("Use getWatchdogCheckIntervalDuration() instead") @@ -280,7 +278,7 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { return self(); } - /** Backport of {@link #setWatchdogCheckIntervalDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setWatchdogCheckIntervalDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { return setWatchdogCheckIntervalDuration(toJavaTimeDuration(checkInterval)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index aca98b8ffb..6dd170cd66 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -80,7 +80,7 @@ public boolean needsCheckInterval() { return checkInterval == null; } - /** Backport of {@link #withCheckIntervalDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #withCheckIntervalDuration(java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index c87b23dcec..7484b96159 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -121,7 +121,7 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } - /** Backport of {@link #getIdleTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getIdleTimeoutDuration()} instead.

    */ @Nonnull @ObsoleteApi("Use getIdleTimeoutDuration() instead") public org.threeten.bp.Duration getIdleTimeout() { @@ -137,7 +137,7 @@ public java.time.Duration getIdleTimeoutDuration() { return idleTimeout; } - /** Backport of {@link #getWaitTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getWaitTimeoutDuration()} instead.

    */ @Nonnull @ObsoleteApi("Use getWaitTimeoutDuration() instead") public org.threeten.bp.Duration getWaitTimeout() { @@ -260,9 +260,7 @@ public RetrySettings getRetrySettings() { } /** - * Backport of {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { @@ -304,7 +302,7 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } - /** Backport of {@link #getIdleTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getIdleTimeoutDuration()} instead.

    */ @Nonnull @ObsoleteApi("Use getIdleTimeoutDuration() instead") public org.threeten.bp.Duration getIdleTimeout() { @@ -336,7 +334,7 @@ public Builder setIdleTimeoutDuration( return this; } - /** Backport of {@link #getWaitTimeoutDuration()} */ + /**

    This method is obsolete. Use {@link #getWaitTimeoutDuration()} instead.

    */ @Nonnull @ObsoleteApi("Use getWaitTimeoutDuration() instead") public org.threeten.bp.Duration getWaitTimeout() { @@ -349,9 +347,7 @@ public java.time.Duration getWaitTimeoutDuration() { } /** - * Backport of {@link #setWaitTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #setWaitTimeoutDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setWaitTimeoutDuration(java.time.Duration) instead") public Builder setWaitTimeout( @Nonnull org.threeten.bp.Duration waitTimeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index 62cb930f71..cd56bb09c0 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -206,7 +206,7 @@ public final WatchdogProvider getStreamWatchdogProvider() { return streamWatchdogProvider; } - /** Backport of {@link #getStreamWatchdogCheckIntervalDuration()} */ + /**

    This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead.

    */ @Nonnull @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { @@ -532,9 +532,7 @@ public B setQuotaProjectId(String quotaProjectId) { } /** - * Backport of {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(checkInterval)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 43fa461425..9089be38ad 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -196,7 +196,7 @@ public UnaryCallSettings.Builder setRetrySettings( return this; } - /** Backport of {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index febfba6395..901b6fc2f9 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -80,9 +80,7 @@ public final class Watchdog implements Runnable, BackgroundResource { private ScheduledFuture future; /** - * Backport of {@link #create(ApiClock, java.time.Duration, ScheduledExecutorService)} using - * {@link org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #create(ApiClock, java.time.Duration, ScheduledExecutorService)} instead.

    */ @ObsoleteApi("Use create(ApiClock, java.time.Duration, ScheduledExecutorService) instead") public static Watchdog create( ApiClock clock, @@ -113,9 +111,7 @@ private void start() { } /** - * Backport of {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} using - * {@link org.threeten.bp.Duration} - */ + *

    This method is obsolete. Use {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} instead.

    */ @ObsoleteApi("Use watch(ResponseObserver, java.time.Duration, java.time.Duration) instead") public ResponseObserver watch( ResponseObserver innerObserver, diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index 1d3c420611..8157c007c4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -41,7 +41,7 @@ public interface WatchdogProvider { boolean needsCheckInterval(); - /** Backport of {@link #withCheckIntervalDuration(java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #withCheckIntervalDuration(java.time.Duration)} instead.

    */ @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index fa491513a0..16696eba46 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -109,7 +109,7 @@ default Scope inScope() { /** Add an annotation that the attempt was cancelled by the user. */ default void attemptCancelled() {}; - /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} instead.

    */ @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {}; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index 1d337b07aa..316f458957 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -109,7 +109,7 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { // noop } - /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ + /**

    This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} instead.

    */ @Override @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java index 090f1a594e..8937d6b007 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java @@ -179,7 +179,7 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { metricsRecorder.recordAttemptCount(1, attributes); } - /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ + /**

    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) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java index ec1523d186..7eed51e8af 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java @@ -359,7 +359,7 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { lastConnectionId = null; } - /** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */ + /**

    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) { From 5d945b30f3f6c38c31e257864a7d548c5c4149e4 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Jun 2024 21:12:39 -0400 Subject: [PATCH 115/141] more javadoc editions --- .../google/api/gax/grpc/GrpcCallContext.java | 16 ++++--- .../InstantiatingGrpcChannelProvider.java | 11 ++++- .../api/gax/httpjson/HttpJsonCallContext.java | 17 ++++--- .../api/gax/httpjson/HttpJsonCallOptions.java | 6 ++- .../api/gax/batching/BatchingSettings.java | 8 ++-- .../api/gax/batching/ThresholdBatcher.java | 5 +-- .../api/gax/retrying/RetrySettings.java | 45 +++++++++++-------- .../gax/retrying/TimedAttemptSettings.java | 17 +++---- .../google/api/gax/rpc/ApiCallContext.java | 17 ++++--- .../com/google/api/gax/rpc/ClientContext.java | 9 ++-- .../google/api/gax/rpc/ClientSettings.java | 10 +++-- .../api/gax/rpc/FixedWatchdogProvider.java | 2 + .../rpc/InstantiatingWatchdogProvider.java | 4 +- .../gax/rpc/ServerStreamingCallSettings.java | 21 +++++---- .../com/google/api/gax/rpc/StubSettings.java | 7 ++- .../google/api/gax/rpc/UnaryCallSettings.java | 5 ++- .../java/com/google/api/gax/rpc/Watchdog.java | 8 +++- .../google/api/gax/rpc/WatchdogProvider.java | 4 +- .../com/google/api/gax/tracing/ApiTracer.java | 6 ++- .../google/api/gax/tracing/BaseApiTracer.java | 6 ++- .../google/api/gax/tracing/MetricsTracer.java | 5 ++- .../api/gax/tracing/OpencensusTracer.java | 5 ++- 22 files changed, 139 insertions(+), 95 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java index 3098bf8eae..137060595d 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java @@ -231,8 +231,7 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) { endpointContext); } - /** - *

    This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead.

    */ + /** This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead. */ @Override @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { @@ -266,6 +265,7 @@ public GrpcCallContext withTimeoutDuration(@Nullable java.time.Duration timeout) endpointContext); } + /** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */ @Nullable @Override @ObsoleteApi("Use getTimeoutDuration() instead") @@ -280,7 +280,9 @@ public java.time.Duration getTimeoutDuration() { } /** - *

    This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} + * instead. + */ @Override @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") public GrpcCallContext withStreamWaitTimeout( @@ -312,9 +314,8 @@ public GrpcCallContext withStreamWaitTimeoutDuration( } /** - *

    This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} instead.

    */ - * @param streamIdleTimeout - * @return + * This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} + * instead. */ @Override @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") @@ -537,7 +538,7 @@ public CallOptions getCallOptions() { return callOptions; } - /**

    This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */ @Override @Nullable @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") @@ -556,6 +557,7 @@ public java.time.Duration getStreamWaitTimeoutDuration() { return streamWaitTimeout; } + /** This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead. */ @Override @Nullable @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 0312da2889..2df530b5ee 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -455,6 +455,7 @@ public String getEndpoint() { return endpoint; } + /** This method is obsolete. Use {@link #getKeepAliveTimeDuration()} instead. */ @ObsoleteApi("Use getKeepAliveTimeDuration() instead") public org.threeten.bp.Duration getKeepAliveTime() { return toThreetenDuration(getKeepAliveTimeDuration()); @@ -465,6 +466,7 @@ public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } + /** This method is obsolete. Use {@link #getKeepAliveTimeoutDuration()} instead */ @ObsoleteApi("Use getKeepAliveTimeoutDuration() instead") public org.threeten.bp.Duration getKeepAliveTimeout() { return toThreetenDuration(getKeepAliveTimeoutDuration()); @@ -655,7 +657,8 @@ public Integer getMaxInboundMetadataSize() { } /** - *

    This method is obsolete. Use {@link #setKeepAliveTime(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #setKeepAliveTimeDuration(java.time.Duration)} instead. + */ @ObsoleteApi("Use setKeepAliveTimeDuration(java.time.Duration) instead") public Builder setKeepAliveTime(org.threeten.bp.Duration duration) { return setKeepAliveTimeDuration(toJavaTimeDuration(duration)); @@ -666,7 +669,7 @@ public Builder setKeepAliveTimeDuration(java.time.Duration duration) { return this; } - /**

    This method is obsolete. Use {@link #getKeepAliveTimeDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getKeepAliveTimeDuration()} instead. */ @ObsoleteApi("Use getKeepAliveTimeDuration() instead") public org.threeten.bp.Duration getKeepAliveTime() { return toThreetenDuration(getKeepAliveTimeDuration()); @@ -677,6 +680,10 @@ public java.time.Duration getKeepAliveTimeDuration() { return keepAliveTime; } + /** + * This method is obsolete. Use {@link #setKeepAliveTimeoutDuration(java.time.Duration)} + * instead. + */ @ObsoleteApi("Use setKeepAliveTimeoutDuration(java.time.Duration) instead") public Builder setKeepAliveTimeout(org.threeten.bp.Duration duration) { return setKeepAliveTimeoutDuration(toJavaTimeDuration(duration)); diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java index 8af8b5cf32..2b2d675a2a 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java @@ -252,8 +252,7 @@ public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel) { return withChannel(transportChannel.getChannel()); } - /** - *

    This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead.

    */ + /** This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead. */ @Override @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withTimeout(org.threeten.bp.Duration timeout) { @@ -303,7 +302,7 @@ public HttpJsonCallContext withTimeoutDuration(java.time.Duration timeout) { this.endpointContext); } - /**

    This method is obsolete. Use {@link #getTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */ @Nullable @Override @ObsoleteApi("Use getTimeoutDuration instead") @@ -318,7 +317,9 @@ public java.time.Duration getTimeoutDuration() { } /** - *

    This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} + * instead. + */ @Override @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withStreamWaitTimeout( @@ -348,7 +349,7 @@ public HttpJsonCallContext withStreamWaitTimeoutDuration( this.endpointContext); } - /**

    This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */ @Override @Nullable @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") @@ -368,7 +369,9 @@ public java.time.Duration getStreamWaitTimeoutDuration() { } /** - *

    This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} + * instead. + */ @Override @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") public HttpJsonCallContext withStreamIdleTimeout( @@ -398,7 +401,7 @@ public HttpJsonCallContext withStreamIdleTimeoutDuration( this.endpointContext); } - /**

    This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead. */ @Override @Nullable @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java index 802c0ad4e2..4c2d8ae55e 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallOptions.java @@ -45,6 +45,7 @@ public abstract class HttpJsonCallOptions { public static final HttpJsonCallOptions DEFAULT = newBuilder().build(); + /** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */ @Nullable @ObsoleteApi("Use getTimeoutDuration() instead") public final org.threeten.bp.Duration getTimeout() { @@ -54,6 +55,7 @@ public final org.threeten.bp.Duration getTimeout() { @Nullable public abstract java.time.Duration getTimeoutDuration(); + /** This method is obsolete. Use {@link #getDeadlineInstant()} instead. */ @Nullable @ObsoleteApi("Use getDeadlineInstant() instead") public final org.threeten.bp.Instant getDeadline() { @@ -109,7 +111,7 @@ public HttpJsonCallOptions merge(HttpJsonCallOptions inputOptions) { @AutoValue.Builder public abstract static class Builder { - /**

    This method is obsolete. Use {@link #setTimeoutDuration(java.time.Duration)} instead.

    */ + /** This method is obsolete. Use {@link #setTimeoutDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setTimeoutDuration(java.time.Duration) instead") public final Builder setTimeout(org.threeten.bp.Duration value) { return setTimeoutDuration(toJavaTimeDuration(value)); @@ -117,7 +119,7 @@ public final Builder setTimeout(org.threeten.bp.Duration value) { public abstract Builder setTimeoutDuration(java.time.Duration value); - /**

    This method is obsolete. Use {@link #setDeadlineInstant(java.time.Instant)} instead.

    */ + /** This method is obsolete. Use {@link #setDeadlineInstant(java.time.Instant)} instead. */ @ObsoleteApi("Use setDeadlineInstant(java.time.Instant) instead") public final Builder setDeadline(org.threeten.bp.Instant value) { return setDeadlineInstant(toJavaTimeInstant(value)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java index 2a597034ad..7507f6c284 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java @@ -36,8 +36,8 @@ import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; -import javax.annotation.Nullable; import java.time.Duration; +import javax.annotation.Nullable; /** * Represents the batching settings to use for an API method that is capable of batching. @@ -102,7 +102,7 @@ public abstract class BatchingSettings { @Nullable public abstract Long getRequestByteThreshold(); - /**

    This method is obsolete. Use {@link #getDelayThresholdDuration() } instead

    */ + /** This method is obsolete. Use {@link #getDelayThresholdDuration() } instead */ @Nullable @ObsoleteApi("Use getDelayThresholdDuration() instead") public org.threeten.bp.Duration getDelayThreshold() { @@ -153,9 +153,7 @@ public abstract static class Builder { */ public abstract Builder setRequestByteThreshold(Long requestByteThreshold); - /** - *

    This method is obsolete. Use {@link #setDelayThresholdDuration(Duration)} instead

    - */ + /** This method is obsolete. Use {@link #setDelayThresholdDuration(Duration)} instead */ @ObsoleteApi("Use setDelayThresholdDuration(java.time.Duration) instead") public final Builder setDelayThreshold(org.threeten.bp.Duration delayThreshold) { return setDelayThresholdDuration(toJavaTimeDuration(delayThreshold)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java index e587625b17..0afc3018bd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/batching/ThresholdBatcher.java @@ -41,7 +41,6 @@ import com.google.api.gax.batching.FlowController.FlowControlException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; - import java.time.Duration; import java.util.ArrayList; import java.util.Collection; @@ -126,9 +125,7 @@ public Builder setMaxDelayDuration(java.time.Duration maxDelay) { return this; } - /** - *

    This method is obsolete. Use {@link #setMaxDelayDuration(Duration)} instead

    - */ + /** This method is obsolete. Use {@link #setMaxDelayDuration(Duration)} instead */ @ObsoleteApi("Use setMaxDelayDuration(java.time.Duration) instead") public Builder setMaxDelay(org.threeten.bp.Duration maxDelay) { return setMaxDelayDuration(toJavaTimeDuration(maxDelay)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index 10f3732bd5..b9c284d70e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -37,7 +37,6 @@ import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; -import java.time.Duration; /** * Holds the parameters for retry or poll logic with jitter, timeout and exponential @@ -82,7 +81,7 @@ public abstract class RetrySettings implements Serializable { private static final long serialVersionUID = 8258475264439710899L; - /**

    This method is obsolete. Use {@link #getTotalTimeoutDuration()} instead

    */ + /** This method is obsolete. Use {@link #getTotalTimeoutDuration()} instead */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") public org.threeten.bp.Duration getTotalTimeout() { return toThreetenDuration(getTotalTimeoutDuration()); @@ -103,7 +102,7 @@ public org.threeten.bp.Duration getTotalTimeout() { */ public abstract java.time.Duration getTotalTimeoutDuration(); - /**

    This method is obsolete. Use {@link #getInitialRetryDelayDuration()} instead

    */ + /** This method is obsolete. Use {@link #getInitialRetryDelayDuration()} instead */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public org.threeten.bp.Duration getInitialRetryDelay() { return toThreetenDuration(getInitialRetryDelayDuration()); @@ -129,7 +128,7 @@ public org.threeten.bp.Duration getInitialRetryDelay() { */ public abstract double getRetryDelayMultiplier(); - /**

    This method is obsolete. Use {@link #getMaxRetryDelayDuration()} instead */ + /** This method is obsolete. Use {@link #getMaxRetryDelayDuration()} instead */ @ObsoleteApi("Use getMaxRetryDelayDuration()") public org.threeten.bp.Duration getMaxRetryDelay() { return toThreetenDuration(getMaxRetryDelayDuration()); @@ -174,7 +173,7 @@ public org.threeten.bp.Duration getMaxRetryDelay() { @VisibleForTesting public abstract boolean isJittered(); - /**

    This method is obsolete. Use {@link #getInitialRpcTimeoutDuration()} instead */ + /** This method is obsolete. Use {@link #getInitialRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getInitialRpcTimeout() { return toThreetenDuration(getInitialRpcTimeoutDuration()); @@ -204,7 +203,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { */ public abstract double getRpcTimeoutMultiplier(); - /**

    This method is obsolete. Use {@link #getMaxRpcTimeoutDuration()} instead */ + /** This method is obsolete. Use {@link #getMaxRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getMaxRpcTimeout() { return toThreetenDuration(getMaxRpcTimeoutDuration()); @@ -241,7 +240,7 @@ public static Builder newBuilder() { @AutoValue.Builder public abstract static class Builder { - /**

    This method is obsolete. Use {@link #setTotalTimeoutDuration(java.time.Duration)} instead */ + /** This method is obsolete. Use {@link #setTotalTimeoutDuration(java.time.Duration)} instead */ @ObsoleteApi("Use setTotalTimeoutDuration(java.time.Duration) instead") public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { return setTotalTimeoutDuration(toJavaTimeDuration(totalTimeout)); @@ -262,7 +261,10 @@ public final Builder setTotalTimeout(org.threeten.bp.Duration totalTimeout) { */ public abstract Builder setTotalTimeoutDuration(java.time.Duration totalTimeout); - /**

    This method is obsolete. Use {@link #setInitialRetryDelayDuration(java.time.Duration)} instead */ + /** + * This method is obsolete. Use {@link #setInitialRetryDelayDuration(java.time.Duration)} + * instead + */ @ObsoleteApi("Use setInitialRetryDelayDuration(java.time.Duration) instead") public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) { return setInitialRetryDelayDuration(toJavaTimeDuration(initialDelay)); @@ -288,7 +290,9 @@ public final Builder setInitialRetryDelay(org.threeten.bp.Duration initialDelay) */ public abstract Builder setRetryDelayMultiplier(double multiplier); - /**

    This method is obsolete. Use {@link #setMaxRetryDelayDuration(java.time.Duration)} instead */ + /** + * This method is obsolete. Use {@link #setMaxRetryDelayDuration(java.time.Duration)} instead + */ @ObsoleteApi("Use setMaxRetryDelayDuration(java.time.Duration) instead") public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { return setMaxRetryDelayDuration(toJavaTimeDuration(maxDelay)); @@ -333,7 +337,10 @@ public final Builder setMaxRetryDelay(org.threeten.bp.Duration maxDelay) { @VisibleForTesting public abstract Builder setJittered(boolean jittered); - /**

    This method is obsolete. Use {@link #setInitialRpcTimeoutDuration(java.time.Duration)} instead */ + /** + * This method is obsolete. Use {@link #setInitialRpcTimeoutDuration(java.time.Duration)} + * instead + */ @ObsoleteApi("Use setInitialRpcTimeoutDuration(java.time.Duration) instead") public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeout) { return setInitialRpcTimeoutDuration(toJavaTimeDuration(initialTimeout)); @@ -363,7 +370,9 @@ public final Builder setInitialRpcTimeout(org.threeten.bp.Duration initialTimeou */ public abstract Builder setRpcTimeoutMultiplier(double multiplier); - /**

    This method is obsolete. Use {@link #setMaxRpcTimeoutDuration(java.time.Duration)} instead */ + /** + * This method is obsolete. Use {@link #setMaxRpcTimeoutDuration(java.time.Duration)} instead + */ @ObsoleteApi("Use setMaxRpcTimeoutDuration(java.time.Duration) instead") public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { return setMaxRpcTimeoutDuration(toJavaTimeDuration(maxTimeout)); @@ -378,7 +387,7 @@ public final Builder setMaxRpcTimeout(org.threeten.bp.Duration maxTimeout) { */ public abstract Builder setMaxRpcTimeoutDuration(java.time.Duration maxTimeout); - /**

    This method is obsolete. Use {@link #getTotalTimeoutDuration()} instead */ + /** This method is obsolete. Use {@link #getTotalTimeoutDuration()} instead */ @ObsoleteApi("Use getTotalTimeoutDuration() instead") public final org.threeten.bp.Duration getTotalTimeout() { return toThreetenDuration(getTotalTimeoutDuration()); @@ -399,7 +408,7 @@ public final org.threeten.bp.Duration getTotalTimeout() { */ public abstract java.time.Duration getTotalTimeoutDuration(); - /**

    This method is obsolete. Use {@link #getInitialRetryDelayDuration()} instead */ + /** This method is obsolete. Use {@link #getInitialRetryDelayDuration()} instead */ @ObsoleteApi("Use getInitialRetryDelayDuration() instead") public final org.threeten.bp.Duration getInitialRetryDelay() { return toThreetenDuration(getInitialRetryDelayDuration()); @@ -450,7 +459,7 @@ public final org.threeten.bp.Duration getInitialRetryDelay() { */ public abstract boolean isJittered(); - /**

    This method is obsolete. Use {@link #getMaxRetryDelayDuration()} instead */ + /** This method is obsolete. Use {@link #getMaxRetryDelayDuration()} instead */ @ObsoleteApi("Use getMaxRetryDelayDuration() instead") public final org.threeten.bp.Duration getMaxRetryDelay() { return toThreetenDuration(getMaxRetryDelayDuration()); @@ -466,7 +475,7 @@ public final org.threeten.bp.Duration getMaxRetryDelay() { */ public abstract java.time.Duration getMaxRetryDelayDuration(); - /**

    This method is obsolete. Use {@link #getInitialRpcTimeoutDuration()} instead */ + /** This method is obsolete. Use {@link #getInitialRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getInitialRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getInitialRpcTimeout() { return toThreetenDuration(getInitialRpcTimeoutDuration()); @@ -496,7 +505,7 @@ public final org.threeten.bp.Duration getInitialRpcTimeout() { */ public abstract double getRpcTimeoutMultiplier(); - /**

    This method is obsolete. Use {@link #getMaxRpcTimeoutDuration()} instead */ + /** This method is obsolete. Use {@link #getMaxRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getMaxRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getMaxRpcTimeout() { return toThreetenDuration(getMaxRpcTimeoutDuration()); @@ -511,9 +520,7 @@ public final org.threeten.bp.Duration getMaxRpcTimeout() { */ public abstract java.time.Duration getMaxRpcTimeoutDuration(); - /** - *

    This method is obsolete. Use {@link #setLogicalTimeout(java.time.Duration)} instead. - */ + /** This method is obsolete. Use {@link #setLogicalTimeout(java.time.Duration)} instead. */ @BetaApi @ObsoleteApi("Use setLogicalTimeout(java.time.Duration) instead") public Builder setLogicalTimeout(org.threeten.bp.Duration timeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java index a991070694..7b6a09b685 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/retrying/TimedAttemptSettings.java @@ -43,7 +43,7 @@ public abstract class TimedAttemptSettings { /** Returns global (attempt-independent) retry settings. */ public abstract RetrySettings getGlobalSettings(); - /**

    This method is obsolete. Use {@link #getRetryDelayDuration()} instead */ + /** This method is obsolete. Use {@link #getRetryDelayDuration()} instead */ @ObsoleteApi("Use getRetryDelayDuration() instead") public final org.threeten.bp.Duration getRetryDelay() { return toThreetenDuration(getRetryDelayDuration()); @@ -55,7 +55,7 @@ public final org.threeten.bp.Duration getRetryDelay() { */ public abstract java.time.Duration getRetryDelayDuration(); - /**

    This method is obsolete. Use {@link #getRpcTimeoutDuration()} instead */ + /** This method is obsolete. Use {@link #getRpcTimeoutDuration()} instead */ @ObsoleteApi("Use getRpcTimeoutDuration() instead") public final org.threeten.bp.Duration getRpcTimeout() { return toThreetenDuration(getRpcTimeoutDuration()); @@ -64,7 +64,7 @@ public final org.threeten.bp.Duration getRpcTimeout() { /** Returns rpc timeout used for this attempt. */ public abstract java.time.Duration getRpcTimeoutDuration(); - /**

    This method is obsolete. Use {@link #getRandomizedRetryDelayDuration()} instead */ + /** This method is obsolete. Use {@link #getRandomizedRetryDelayDuration()} instead */ @ObsoleteApi("Use getRandomizedRetryDelayDuration() instead") public final org.threeten.bp.Duration getRandomizedRetryDelay() { return toThreetenDuration(getRandomizedRetryDelayDuration()); @@ -106,9 +106,7 @@ public abstract static class Builder { /** Sets global (attempt-independent) retry settings. */ public abstract Builder setGlobalSettings(RetrySettings value); - /** - *

    This method is obsolete. Use {@link #setRetryDelayDuration(java.time.Duration)} instead. - */ + /** This method is obsolete. Use {@link #setRetryDelayDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setRetryDelayDuration(java.time.Duration) instead") public final Builder setRetryDelay(org.threeten.bp.Duration value) { return setRetryDelayDuration(toJavaTimeDuration(value)); @@ -120,9 +118,7 @@ public final Builder setRetryDelay(org.threeten.bp.Duration value) { */ public abstract Builder setRetryDelayDuration(java.time.Duration value); - /** - * This methods is obsolete. Use {@link #setRpcTimeoutDuration(java.time.Duration)} instead. - */ + /** This method is obsolete. Use {@link #setRpcTimeoutDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setRpcTimeoutDuration(java.time.Duration) instead") public final Builder setRpcTimeout(org.threeten.bp.Duration value) { return setRpcTimeoutDuration(toJavaTimeDuration(value)); @@ -132,7 +128,8 @@ public final Builder setRpcTimeout(org.threeten.bp.Duration value) { public abstract Builder setRpcTimeoutDuration(java.time.Duration value); /** - *

    This method is obsolete. Use {@link #setRandomizedRetryDelayDuration(java.time.Duration)} instead. + * This method is obsolete. Use {@link #setRandomizedRetryDelayDuration(java.time.Duration)} + * instead. */ @ObsoleteApi("Use setRandomizedRetryDelayDuration(java.time.Duration) instead") public final Builder setRandomizedRetryDelay(org.threeten.bp.Duration value) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 4ee6eea6d5..4ad517f4b3 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -66,8 +66,7 @@ public interface ApiCallContext extends RetryingContext { /** Returns a new ApiCallContext with the given Endpoint Context. */ ApiCallContext withEndpointContext(EndpointContext endpointContext); - /** - *

    This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead.

    */ + /** This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") ApiCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout); @@ -85,7 +84,7 @@ public interface ApiCallContext extends RetryingContext { */ ApiCallContext withTimeoutDuration(@Nullable java.time.Duration timeout); - /**

    This method is obsolete. Use {@link #getTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */ @Nullable @ObsoleteApi("Use getTimeoutDuration() instead") org.threeten.bp.Duration getTimeout(); @@ -95,7 +94,9 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getTimeoutDuration(); /** - *

    This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)} + * instead. + */ @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") ApiCallContext withStreamWaitTimeout(@Nullable org.threeten.bp.Duration streamWaitTimeout); @@ -118,7 +119,7 @@ public interface ApiCallContext extends RetryingContext { */ ApiCallContext withStreamWaitTimeoutDuration(@Nullable java.time.Duration streamWaitTimeout); - /**

    This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */ @Nullable @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") org.threeten.bp.Duration getStreamWaitTimeout(); @@ -132,7 +133,9 @@ public interface ApiCallContext extends RetryingContext { java.time.Duration getStreamWaitTimeoutDuration(); /** - *

    This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)} + * instead. + */ @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") ApiCallContext withStreamIdleTimeout(@Nullable org.threeten.bp.Duration streamIdleTimeout); @@ -156,7 +159,7 @@ public interface ApiCallContext extends RetryingContext { */ ApiCallContext withStreamIdleTimeoutDuration(@Nullable java.time.Duration streamIdleTimeout); - /**

    This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead. */ @Nullable @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") org.threeten.bp.Duration getStreamIdleTimeout(); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index f2e2fa133c..09c05b7838 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -100,9 +100,7 @@ public abstract class ClientContext { @Nullable public abstract Watchdog getStreamWatchdog(); - /** - * This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead. - */ + /** This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead. */ @Nonnull @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { @@ -358,7 +356,10 @@ public abstract static class Builder { public abstract Builder setStreamWatchdog(Watchdog watchdog); - /**

    This method is obsolete. Use {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link + * #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} instead. + */ @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") public final Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration duration) { return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(duration)); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java index bf90aeb16b..b5e54484dd 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java @@ -112,9 +112,7 @@ public final WatchdogProvider getWatchdogProvider() { return stubSettings.getStreamWatchdogProvider(); } - /** - * This method is obsolete. Use {@link #getWatchdogCheckIntervalDuration()} instead. - */ + /** This method is obsolete. Use {@link #getWatchdogCheckIntervalDuration()} instead. */ @Nonnull @ObsoleteApi("Use getWatchdogCheckIntervalDuration() instead") public final org.threeten.bp.Duration getWatchdogCheckInterval() { @@ -278,7 +276,10 @@ public B setWatchdogProvider(@Nullable WatchdogProvider watchdogProvider) { return self(); } - /**

    This method is obsolete. Use {@link #setWatchdogCheckIntervalDuration(java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link #setWatchdogCheckIntervalDuration(java.time.Duration)} + * instead. + */ @ObsoleteApi("Use setWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setWatchdogCheckInterval(@Nullable org.threeten.bp.Duration checkInterval) { return setWatchdogCheckIntervalDuration(toJavaTimeDuration(checkInterval)); @@ -363,6 +364,7 @@ public WatchdogProvider getWatchdogProvider() { return stubSettings.getStreamWatchdogProvider(); } + /** This method is obsolete. Use {@link #getWatchdogCheckIntervalDuration()} instead */ @Nullable @ObsoleteApi("Use getWatchdogCheckIntervalDuration() instead") public org.threeten.bp.Duration getWatchdogCheckInterval() { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java index a35940adfd..170e820c03 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/FixedWatchdogProvider.java @@ -32,6 +32,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; +import java.time.Duration; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -70,6 +71,7 @@ public boolean needsCheckInterval() { return false; } + /** This method is obsolete. Use {@link #withCheckIntervalDuration(Duration)} instead. */ @Override @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") public WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index 6dd170cd66..e3a5be5185 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -80,7 +80,9 @@ public boolean needsCheckInterval() { return checkInterval == null; } - /**

    This method is obsolete. Use {@link #withCheckIntervalDuration(java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link #withCheckIntervalDuration(java.time.Duration)} instead. + */ @Override @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") public WatchdogProvider withCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java index 7484b96159..cbba46485f 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ServerStreamingCallSettings.java @@ -41,6 +41,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; +import java.time.Duration; import java.util.Set; import javax.annotation.Nonnull; @@ -121,7 +122,7 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } - /**

    This method is obsolete. Use {@link #getIdleTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getIdleTimeoutDuration()} instead. */ @Nonnull @ObsoleteApi("Use getIdleTimeoutDuration() instead") public org.threeten.bp.Duration getIdleTimeout() { @@ -137,7 +138,7 @@ public java.time.Duration getIdleTimeoutDuration() { return idleTimeout; } - /**

    This method is obsolete. Use {@link #getWaitTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getWaitTimeoutDuration()} instead. */ @Nonnull @ObsoleteApi("Use getWaitTimeoutDuration() instead") public org.threeten.bp.Duration getWaitTimeout() { @@ -260,7 +261,9 @@ public RetrySettings getRetrySettings() { } /** - *

    This method is obsolete. Use {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} + * instead. + */ @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") public Builder setSimpleTimeoutNoRetries( @Nonnull org.threeten.bp.Duration timeout) { @@ -302,7 +305,7 @@ public StreamResumptionStrategy getResumptionStrategy() { return resumptionStrategy; } - /**

    This method is obsolete. Use {@link #getIdleTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getIdleTimeoutDuration()} instead. */ @Nonnull @ObsoleteApi("Use getIdleTimeoutDuration() instead") public org.threeten.bp.Duration getIdleTimeout() { @@ -314,10 +317,7 @@ public java.time.Duration getIdleTimeoutDuration() { return idleTimeout; } - /** - * Overlad of {@link #setIdleTimeoutDuration(java.time.Duration)} using {@link - * org.threeten.bp.Duration} - */ + /** This method is obsolete. Use {@link #setIdleTimeoutDuration(Duration)} instead. */ @ObsoleteApi("Use setIdleTimeoutDuration(java.time.Duration) instead") public Builder setIdleTimeout( @Nonnull org.threeten.bp.Duration idleTimeout) { @@ -334,7 +334,7 @@ public Builder setIdleTimeoutDuration( return this; } - /**

    This method is obsolete. Use {@link #getWaitTimeoutDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getWaitTimeoutDuration()} instead. */ @Nonnull @ObsoleteApi("Use getWaitTimeoutDuration() instead") public org.threeten.bp.Duration getWaitTimeout() { @@ -346,8 +346,7 @@ public java.time.Duration getWaitTimeoutDuration() { return waitTimeout; } - /** - *

    This method is obsolete. Use {@link #setWaitTimeoutDuration(java.time.Duration)} instead.

    */ + /** This method is obsolete. Use {@link #setWaitTimeoutDuration(java.time.Duration)} instead. */ @ObsoleteApi("Use setWaitTimeoutDuration(java.time.Duration) instead") public Builder setWaitTimeout( @Nonnull org.threeten.bp.Duration waitTimeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index cd56bb09c0..d1199b11b5 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -206,7 +206,7 @@ public final WatchdogProvider getStreamWatchdogProvider() { return streamWatchdogProvider; } - /**

    This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead.

    */ + /** This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead. */ @Nonnull @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() { @@ -532,7 +532,9 @@ public B setQuotaProjectId(String quotaProjectId) { } /** - *

    This method is obsolete. Use {@link #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link + * #setStreamWatchdogCheckIntervalDuration(java.time.Duration)} instead. + */ @ObsoleteApi("Use setStreamWatchdogCheckIntervalDuration(java.time.Duration) instead") public B setStreamWatchdogCheckInterval(@Nonnull org.threeten.bp.Duration checkInterval) { return setStreamWatchdogCheckIntervalDuration(toJavaTimeDuration(checkInterval)); @@ -638,6 +640,7 @@ public String getQuotaProjectId() { return quotaProjectId; } + /** This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead */ @ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead") public org.threeten.bp.Duration getStreamWatchdogCheckInterval() { return toThreetenDuration(getStreamWatchdogCheckIntervalDuration()); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java index 9089be38ad..f985650a59 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/UnaryCallSettings.java @@ -196,7 +196,10 @@ public UnaryCallSettings.Builder setRetrySettings( return this; } - /**

    This method is obsolete. Use {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link #setSimpleTimeoutNoRetriesDuration(java.time.Duration)} + * instead. + */ @ObsoleteApi("Use setSimpleTimeoutNoRetriesDuration(java.time.Duration) instead") public UnaryCallSettings.Builder setSimpleTimeoutNoRetries( org.threeten.bp.Duration timeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 901b6fc2f9..189e226f61 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -80,7 +80,9 @@ public final class Watchdog implements Runnable, BackgroundResource { private ScheduledFuture future; /** - *

    This method is obsolete. Use {@link #create(ApiClock, java.time.Duration, ScheduledExecutorService)} instead.

    */ + * This method is obsolete. Use {@link #create(ApiClock, java.time.Duration, + * ScheduledExecutorService)} instead. + */ @ObsoleteApi("Use create(ApiClock, java.time.Duration, ScheduledExecutorService) instead") public static Watchdog create( ApiClock clock, @@ -111,7 +113,9 @@ private void start() { } /** - *

    This method is obsolete. Use {@link #watch(ResponseObserver, java.time.Duration, java.time.Duration)} instead.

    */ + * This method is obsolete. Use {@link #watch(ResponseObserver, java.time.Duration, + * java.time.Duration)} instead. + */ @ObsoleteApi("Use watch(ResponseObserver, java.time.Duration, java.time.Duration) instead") public ResponseObserver watch( ResponseObserver innerObserver, diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index 8157c007c4..e2830ef86e 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -41,7 +41,9 @@ public interface WatchdogProvider { boolean needsCheckInterval(); - /**

    This method is obsolete. Use {@link #withCheckIntervalDuration(java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link #withCheckIntervalDuration(java.time.Duration)} instead. + */ @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java index 16696eba46..4407f79a85 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.tracing; - import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; @@ -109,7 +108,10 @@ default Scope inScope() { /** Add an annotation that the attempt was cancelled by the user. */ default void attemptCancelled() {}; - /**

    This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} + * instead. + */ @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {}; diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java index 316f458957..73ead433ec 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java @@ -29,7 +29,6 @@ */ package com.google.api.gax.tracing; - import com.google.api.core.InternalApi; import com.google.api.core.ObsoleteApi; @@ -109,7 +108,10 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { // noop } - /**

    This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} instead.

    */ + /** + * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} + * instead. + */ @Override @ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead") public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java index 8937d6b007..29fee8ecaf 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java @@ -179,7 +179,10 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { metricsRecorder.recordAttemptCount(1, attributes); } - /**

    This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} instead.

    */ + /** + * 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) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java index 7eed51e8af..c9f6b7cfc7 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java @@ -359,7 +359,10 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { lastConnectionId = null; } - /**

    This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} instead.

    */ + /** + * 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) { From a21c6781a10f701f48e1b2769347f37cc484524b Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Jun 2024 21:30:20 -0400 Subject: [PATCH 116/141] fix public methods in Watchdog --- .../rpc/InstantiatingWatchdogProvider.java | 2 +- .../java/com/google/api/gax/rpc/Watchdog.java | 17 +++++++------- .../rpc/WatchdogServerStreamingCallable.java | 2 +- .../google/api/gax/rpc/ClientContextTest.java | 2 +- .../api/gax/rpc/ClientSettingsTest.java | 2 +- .../gax/rpc/FixedWatchdogProviderTest.java | 4 ++-- .../com/google/api/gax/rpc/WatchdogTest.java | 23 ++++++++++--------- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java index e3a5be5185..5b06f882a3 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/InstantiatingWatchdogProvider.java @@ -119,7 +119,7 @@ public Watchdog getWatchdog() { return null; } - return Watchdog.create(clock, checkInterval, executor); + return Watchdog.createDuration(clock, checkInterval, executor); } @Override diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 189e226f61..58f1e34628 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -80,19 +80,19 @@ public final class Watchdog implements Runnable, BackgroundResource { private ScheduledFuture future; /** - * This method is obsolete. Use {@link #create(ApiClock, java.time.Duration, + * This method is obsolete. Use {@link #createDuration(ApiClock, java.time.Duration, * ScheduledExecutorService)} instead. */ @ObsoleteApi("Use create(ApiClock, java.time.Duration, ScheduledExecutorService) instead") - public static Watchdog create( + public static Watchdog createDuration( ApiClock clock, org.threeten.bp.Duration scheduleInterval, ScheduledExecutorService executor) { - return create(clock, toJavaTimeDuration(scheduleInterval), executor); + return createDuration(clock, toJavaTimeDuration(scheduleInterval), executor); } /** returns a Watchdog which is scheduled at the provided interval. */ - public static Watchdog create( + public static Watchdog createDuration( ApiClock clock, java.time.Duration scheduleInterval, ScheduledExecutorService executor) { Watchdog watchdog = new Watchdog(clock, scheduleInterval, executor); watchdog.start(); @@ -113,18 +113,19 @@ private void start() { } /** - * This method is obsolete. Use {@link #watch(ResponseObserver, java.time.Duration, + * This method is obsolete. Use {@link #watchDuration(ResponseObserver, java.time.Duration, * java.time.Duration)} instead. */ @ObsoleteApi("Use watch(ResponseObserver, java.time.Duration, java.time.Duration) instead") - public ResponseObserver watch( + public ResponseObserver watchDuration( ResponseObserver innerObserver, @Nonnull org.threeten.bp.Duration waitTimeout, @Nonnull org.threeten.bp.Duration idleTimeout) { - return watch(innerObserver, toJavaTimeDuration(waitTimeout), toJavaTimeDuration(idleTimeout)); + return watchDuration( + innerObserver, toJavaTimeDuration(waitTimeout), toJavaTimeDuration(idleTimeout)); } /** Wraps the target observer with timing constraints. */ - public ResponseObserver watch( + public ResponseObserver watchDuration( ResponseObserver innerObserver, @Nonnull java.time.Duration waitTimeout, @Nonnull java.time.Duration idleTimeout) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java index c5b5d1a6cc..443bf11dd5 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogServerStreamingCallable.java @@ -66,7 +66,7 @@ public void call( java.time.Duration idleTimeout = MoreObjects.firstNonNull(context.getStreamIdleTimeoutDuration(), java.time.Duration.ZERO); - responseObserver = watchdog.watch(responseObserver, waitTimeout, idleTimeout); + responseObserver = watchdog.watchDuration(responseObserver, waitTimeout, idleTimeout); inner.call(request, responseObserver, context); } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 1e28a6e32a..868a591a3f 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -285,7 +285,7 @@ private void runTest( Credentials credentials = Mockito.mock(Credentials.class); ApiClock clock = Mockito.mock(ApiClock.class); Watchdog watchdog = - Watchdog.create( + Watchdog.createDuration( Mockito.mock(ApiClock.class), java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java index 96aa3e1931..e17cc1517b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientSettingsTest.java @@ -215,7 +215,7 @@ public void testBuilderFromClientContext() throws Exception { FakeCallContext.createDefault().withEndpointContext(endpointContext); Map headers = Collections.singletonMap("spiffykey", "spiffyvalue"); Watchdog watchdog = - Watchdog.create( + Watchdog.createDuration( Mockito.mock(ApiClock.class), java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index 0d6070b056..e472e441d6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -50,7 +50,7 @@ public void testNull() { @Test public void testSameInstance() { Watchdog watchdog = - Watchdog.create( + Watchdog.createDuration( Mockito.mock(ApiClock.class), java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); @@ -62,7 +62,7 @@ public void testSameInstance() { @Test public void testNoModifications() { Watchdog watchdog = - Watchdog.create( + Watchdog.createDuration( Mockito.mock(ApiClock.class), java.time.Duration.ZERO, Mockito.mock(ScheduledExecutorService.class)); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java index 86093789f6..38462f45b5 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/WatchdogTest.java @@ -68,11 +68,11 @@ public class WatchdogTest { @Before public void setUp() { clock = new FakeApiClock(0); - watchdog = Watchdog.create(clock, checkInterval, EXECUTOR); + watchdog = Watchdog.createDuration(clock, checkInterval, EXECUTOR); callable = new MockServerStreamingCallable<>(); innerObserver = new AccumulatingObserver<>(); - callable.call("request", watchdog.watch(innerObserver, waitTime, idleTime)); + callable.call("request", watchdog.watchDuration(innerObserver, waitTime, idleTime)); call = callable.popLastCall(); } @@ -132,7 +132,7 @@ public void testIdleTimeout() throws InterruptedException { public void testTimedOutBeforeStart() throws InterruptedException { MockServerStreamingCallable callable1 = new MockServerStreamingCallable<>(); AccumulatingObserver downstreamObserver1 = new AccumulatingObserver<>(); - ResponseObserver observer = watchdog.watch(downstreamObserver1, waitTime, idleTime); + ResponseObserver observer = watchdog.watchDuration(downstreamObserver1, waitTime, idleTime); clock.incrementNanoTime(idleTime.toNanos() + 1); // This should not remove callable1 from watched list watchdog.run(); @@ -159,7 +159,8 @@ public void testTimedOutBeforeResponse() throws InterruptedException { new MockServerStreamingCallable<>(); AutoFlowControlObserver downstreamObserver = new AutoFlowControlObserver<>(); - autoFlowControlCallable.call("request", watchdog.watch(downstreamObserver, waitTime, idleTime)); + autoFlowControlCallable.call( + "request", watchdog.watchDuration(downstreamObserver, waitTime, idleTime)); MockServerStreamingCall call1 = autoFlowControlCallable.popLastCall(); clock.incrementNanoTime(idleTime.toNanos() + 1); @@ -182,13 +183,13 @@ public void testTimedOutBeforeResponse() throws InterruptedException { public void testMultiple() throws Exception { // Start stream1 AccumulatingObserver downstreamObserver1 = new AccumulatingObserver<>(); - callable.call("request", watchdog.watch(downstreamObserver1, waitTime, idleTime)); + callable.call("request", watchdog.watchDuration(downstreamObserver1, waitTime, idleTime)); MockServerStreamingCall call1 = callable.popLastCall(); downstreamObserver1.controller.get().request(1); // Start stream2 AccumulatingObserver downstreamObserver2 = new AccumulatingObserver<>(); - callable.call("req2", watchdog.watch(downstreamObserver2, waitTime, idleTime)); + callable.call("req2", watchdog.watchDuration(downstreamObserver2, waitTime, idleTime)); MockServerStreamingCall call2 = callable.popLastCall(); downstreamObserver2.controller.get().request(1); @@ -221,7 +222,7 @@ public void testMultiple() throws Exception { public void testWatchdogBeingClosed() { ScheduledFuture future = Mockito.mock(ScheduledFuture.class); ScheduledExecutorService mockExecutor = getMockExecutorService(future); - Watchdog underTest = Watchdog.create(clock, checkInterval, mockExecutor); + Watchdog underTest = Watchdog.createDuration(clock, checkInterval, mockExecutor); assertThat(underTest).isInstanceOf(BackgroundResource.class); underTest.close(); @@ -243,7 +244,7 @@ public void awaitTermination_shouldReturnTrueIfFutureIsDone() throws Exception { TimeUnit timeUnit = TimeUnit.MILLISECONDS; ScheduledFuture future = Mockito.mock(ScheduledFuture.class); ScheduledExecutorService mockExecutor = getMockExecutorService(future); - Watchdog watchdog = Watchdog.create(clock, checkInterval, mockExecutor); + Watchdog watchdog = Watchdog.createDuration(clock, checkInterval, mockExecutor); watchdog.shutdown(); boolean actual = watchdog.awaitTermination(duration, timeUnit); @@ -258,7 +259,7 @@ public void awaitTermination_shouldReturnFalseIfGettingFutureTimedOut() throws E ScheduledFuture future = Mockito.mock(ScheduledFuture.class); Mockito.doThrow(new TimeoutException()).when(future).get(duration, timeUnit); ScheduledExecutorService mockExecutor = getMockExecutorService(future); - Watchdog watchdog = Watchdog.create(clock, checkInterval, mockExecutor); + Watchdog watchdog = Watchdog.createDuration(clock, checkInterval, mockExecutor); boolean actual = watchdog.awaitTermination(duration, timeUnit); @@ -272,7 +273,7 @@ public void awaitTermination_shouldReturnTrueIfFutureIsAlreadyCancelled() throws ScheduledFuture future = Mockito.mock(ScheduledFuture.class); Mockito.doThrow(new CancellationException()).when(future).get(duration, timeUnit); ScheduledExecutorService mockExecutor = getMockExecutorService(future); - Watchdog watchdog = Watchdog.create(clock, checkInterval, mockExecutor); + Watchdog watchdog = Watchdog.createDuration(clock, checkInterval, mockExecutor); boolean actual = watchdog.awaitTermination(duration, timeUnit); @@ -289,7 +290,7 @@ public void awaitTermination_shouldReturnFalseIfGettingFutureThrowsExecutionExce .when(future) .get(duration, timeUnit); ScheduledExecutorService mockExecutor = getMockExecutorService(future); - Watchdog watchdog = Watchdog.create(clock, checkInterval, mockExecutor); + Watchdog watchdog = Watchdog.createDuration(clock, checkInterval, mockExecutor); boolean actual = watchdog.awaitTermination(duration, timeUnit); From ed838ad4d3b905d60e53e62b43c448331cbaeaf8 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Jun 2024 22:04:26 -0400 Subject: [PATCH 117/141] format --- .../google/api/gax/grpc/InstantiatingGrpcChannelProvider.java | 1 - .../api/gax/grpc/InstantiatingGrpcChannelProviderTest.java | 4 ++-- .../com/google/api/gax/batching/ThresholdBatcherTest.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 0c255b3c3c..e662645274 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -35,7 +35,6 @@ import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; -import com.google.api.core.InternalExtensionOnly; import com.google.api.core.ObsoleteApi; import com.google.api.gax.core.ExecutorProvider; import com.google.api.gax.rpc.FixedHeaderProvider; diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index e3936bdd78..01bcf40243 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -29,8 +29,8 @@ */ package com.google.api.gax.grpc; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.GCE_PRODUCTION_NAME_AFTER_2016; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.truth.Truth.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -64,8 +64,8 @@ import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.function.Function; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.stream.Collectors; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java index 70436a3621..f87b772d3b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/ThresholdBatcherTest.java @@ -30,6 +30,8 @@ package com.google.api.gax.batching; import static com.google.common.truth.Truth.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; @@ -37,8 +39,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.core.ApiFutures; import com.google.api.gax.batching.FlowController.FlowControlException; From 5b51530a8aa98da8e1a5c3e70a0f93deb3b07a9e Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Jun 2024 22:47:11 -0400 Subject: [PATCH 118/141] clirr fixes --- gax-java/gax-grpc/clirr-ignored-differences.xml | 9 --------- .../api/gax/grpc/InstantiatingGrpcChannelProvider.java | 6 ++++++ gax-java/gax/clirr-ignored-differences.xml | 5 +++-- .../src/main/java/com/google/api/gax/rpc/Watchdog.java | 7 ++++--- 4 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 gax-java/gax-grpc/clirr-ignored-differences.xml diff --git a/gax-java/gax-grpc/clirr-ignored-differences.xml b/gax-java/gax-grpc/clirr-ignored-differences.xml deleted file mode 100644 index 5af8ca965a..0000000000 --- a/gax-java/gax-grpc/clirr-ignored-differences.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - 7002 - com/google/api/gax/grpc/InstantiatingGrpcChannelProvider$Builder - org.threeten.bp.Duration * - - diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index e662645274..aa3ce38313 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -729,6 +729,12 @@ public Builder setKeepAliveTimeoutDuration(java.time.Duration duration) { return this; } + /** This method is obsolete. Use {@link #getKeepAliveTimeoutDuration()} instead */ + @ObsoleteApi("Use getKeepAliveTimeoutDuration() instead") + public org.threeten.bp.Duration getKeepAliveTimeout() { + return toThreetenDuration(getKeepAliveTimeoutDuration()); + } + /** The time without read activity after sending a keepalive ping. */ public java.time.Duration getKeepAliveTimeoutDuration() { return keepAliveTimeout; diff --git a/gax-java/gax/clirr-ignored-differences.xml b/gax-java/gax/clirr-ignored-differences.xml index 8643386344..a4419f738d 100644 --- a/gax-java/gax/clirr-ignored-differences.xml +++ b/gax-java/gax/clirr-ignored-differences.xml @@ -40,9 +40,10 @@ * set*Duration(*) + 7005 - com/google/api/gax/*/* - * *(*org.threeten.bp.Duration*) + com/google/api/gax/retrying/DirectRetryingExecutor + * sleep(*org.threeten.bp.Duration*) * diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java index 58f1e34628..69ca5d1eca 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/Watchdog.java @@ -84,7 +84,7 @@ public final class Watchdog implements Runnable, BackgroundResource { * ScheduledExecutorService)} instead. */ @ObsoleteApi("Use create(ApiClock, java.time.Duration, ScheduledExecutorService) instead") - public static Watchdog createDuration( + public static Watchdog create( ApiClock clock, org.threeten.bp.Duration scheduleInterval, ScheduledExecutorService executor) { @@ -116,8 +116,9 @@ private void start() { * This method is obsolete. Use {@link #watchDuration(ResponseObserver, java.time.Duration, * java.time.Duration)} instead. */ - @ObsoleteApi("Use watch(ResponseObserver, java.time.Duration, java.time.Duration) instead") - public ResponseObserver watchDuration( + @ObsoleteApi( + "Use watchDuration(ResponseObserver, java.time.Duration, java.time.Duration) instead") + public ResponseObserver watch( ResponseObserver innerObserver, @Nonnull org.threeten.bp.Duration waitTimeout, @Nonnull org.threeten.bp.Duration idleTimeout) { From 709118617a580038d81d9123f2afd34b98af5b13 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Jun 2024 23:06:35 -0400 Subject: [PATCH 119/141] correct import --- .../com/google/api/gax/retrying/TimedAttemptSettingsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java index a8b0d80d1e..af0c1e1b35 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/TimedAttemptSettingsTest.java @@ -31,7 +31,7 @@ import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TimedAttemptSettingsTest { From 3f7ac5772a6123edc54eb878c2f693bebbbec021 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Jun 2024 03:07:17 +0000 Subject: [PATCH 120/141] correct interface usage --- .../v1beta1/it/ITTimeObjectsPropagationTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java index f2aff8da1a..7ac0ceb2cd 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java @@ -17,11 +17,11 @@ public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { org.threeten.bp.Duration.ofMillis(javaTimeCommonValue.toMillis()); RetrySettings javaTimeRetrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(javaTimeCommonValue) - .setMaxRetryDelay(javaTimeCommonValue) - .setInitialRpcTimeout(javaTimeCommonValue) - .setMaxRpcTimeout(javaTimeCommonValue) - .setTotalTimeout(javaTimeCommonValue) + .setInitialRetryDelayDuration(javaTimeCommonValue) + .setMaxRetryDelayDuration(javaTimeCommonValue) + .setInitialRpcTimeoutDuration(javaTimeCommonValue) + .setMaxRpcTimeoutDuration(javaTimeCommonValue) + .setTotalTimeoutDuration(javaTimeCommonValue) .build(); assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRetryDelay()); @@ -33,9 +33,9 @@ public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { @Test public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { - java.time.Duration threetenCommonValue = java.time.Duration.ofMillis(123l); - org.threeten.bp.Duration javaTimeConvertedValue = - org.threeten.bp.Duration.ofMillis(threetenCommonValue.toMillis()); + org.threeten.bp.Duration threetenCommonValue = org.threeten.bp.Duration.ofMillis(123l); + java.time.Duration javaTimeConvertedValue = + java.time.Duration.ofMillis(threetenCommonValue.toMillis()); RetrySettings threetenRetrySettings = RetrySettings.newBuilder() .setInitialRetryDelay(threetenCommonValue) From 21583348b8c765082dbbcc907c1ef94ee3c9d1bd Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Jun 2024 14:49:30 +0000 Subject: [PATCH 121/141] fix junit imports --- .../com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java | 2 +- .../com/google/api/gax/batching/BatchingSettingsTest.java | 2 +- .../com/google/api/gax/rpc/FixedWatchdogProviderTest.java | 2 +- .../java/com/google/api/gax/tracing/MetricsTestUtils.java | 2 +- .../java/com/google/api/gax/util/TimeConversionTestUtils.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java index a761045459..c6aa69d4d8 100644 --- a/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java +++ b/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallOptionsTest.java @@ -32,7 +32,7 @@ import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static com.google.api.gax.util.TimeConversionTestUtils.testInstantMethod; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class HttpJsonCallOptionsTest { private final HttpJsonCallOptions.Builder OPTIONS_BUILDER = HttpJsonCallOptions.newBuilder(); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index 07c3bc5a8e..b344d251aa 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -31,7 +31,7 @@ import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BatchingSettingsTest { diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java index 1c1c547bc3..eb0355d90b 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/FixedWatchdogProviderTest.java @@ -30,7 +30,7 @@ package com.google.api.gax.rpc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.core.ApiClock; import java.util.concurrent.ScheduledExecutorService; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java index 0e04196c21..fd9477becb 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java @@ -29,7 +29,7 @@ */ package com.google.api.gax.tracing; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Method; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index b097fcbb71..b890e3888d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -29,8 +29,8 @@ */ package com.google.api.gax.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.function.Function; From 98fdeb31a3a1cf1b844cdfff395b340e3bc30d84 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 11:15:04 -0400 Subject: [PATCH 122/141] add default behavior to WatchdogProvider --- .../main/java/com/google/api/gax/rpc/WatchdogProvider.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java index e2830ef86e..a31fc7b6f4 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/WatchdogProvider.java @@ -29,6 +29,8 @@ */ package com.google.api.gax.rpc; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.ApiClock; import com.google.api.core.ObsoleteApi; import java.util.concurrent.ScheduledExecutorService; @@ -47,7 +49,9 @@ public interface WatchdogProvider { @ObsoleteApi("Use withCheckIntervalDuration(java.time.Duration) instead") WatchdogProvider withCheckInterval(org.threeten.bp.Duration checkInterval); - WatchdogProvider withCheckIntervalDuration(java.time.Duration checkInterval); + default WatchdogProvider withCheckIntervalDuration(java.time.Duration checkInterval) { + return withCheckInterval(toThreetenDuration(checkInterval)); + } boolean needsExecutor(); From 76048973699525d7ff51cfd763f1947424096674 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Jun 2024 17:21:08 +0000 Subject: [PATCH 123/141] fix IT --- .../it/ITTimeObjectsPropagationTest.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java index 7ac0ceb2cd..f7f801f627 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITTimeObjectsPropagationTest.java @@ -24,11 +24,16 @@ public void testRetrySettings_fromJavaTimeHasEquivalentThreetenValues() { .setTotalTimeoutDuration(javaTimeCommonValue) .build(); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRetryDelay()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRetryDelay()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getInitialRpcTimeout()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getMaxRpcTimeout()); - assertEquals(threetenConvertedValue, javaTimeRetrySettings.getTotalTimeout()); + assertEquals( + threetenConvertedValue.toMillis(), javaTimeRetrySettings.getInitialRetryDelay().toMillis()); + assertEquals( + threetenConvertedValue.toMillis(), javaTimeRetrySettings.getMaxRetryDelay().toMillis()); + assertEquals( + threetenConvertedValue.toMillis(), javaTimeRetrySettings.getInitialRpcTimeout().toMillis()); + assertEquals( + threetenConvertedValue.toMillis(), javaTimeRetrySettings.getMaxRpcTimeout().toMillis()); + assertEquals( + threetenConvertedValue.toMillis(), javaTimeRetrySettings.getTotalTimeout().toMillis()); } @Test @@ -45,10 +50,15 @@ public void testRetrySettings_fromThreetenHasEquivalentJavaTimeValues() { .setTotalTimeout(threetenCommonValue) .build(); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRetryDelay()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRetryDelay()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getInitialRpcTimeout()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getMaxRpcTimeout()); - assertEquals(javaTimeConvertedValue, threetenRetrySettings.getTotalTimeout()); + assertEquals( + javaTimeConvertedValue.toMillis(), threetenRetrySettings.getInitialRetryDelay().toMillis()); + assertEquals( + javaTimeConvertedValue.toMillis(), threetenRetrySettings.getMaxRetryDelay().toMillis()); + assertEquals( + javaTimeConvertedValue.toMillis(), threetenRetrySettings.getInitialRpcTimeout().toMillis()); + assertEquals( + javaTimeConvertedValue.toMillis(), threetenRetrySettings.getMaxRpcTimeout().toMillis()); + assertEquals( + javaTimeConvertedValue.toMillis(), threetenRetrySettings.getTotalTimeout().toMillis()); } } From 59c4dbb0e0dd76fdcd9cb514c075a26c80b26364 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 15:49:43 -0400 Subject: [PATCH 124/141] increase coverate in AttemptCallableTest --- .../api/gax/rpc/AttemptCallableTest.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 1f4556ff05..68c313df89 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -30,12 +30,16 @@ package com.google.api.gax.rpc; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.google.api.core.SettableApiFuture; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.RetryingFuture; import com.google.api.gax.retrying.TimedAttemptSettings; import com.google.api.gax.rpc.testing.FakeCallContext; +import com.google.api.gax.tracing.ApiTracer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -56,7 +60,7 @@ class AttemptCallableTest { @BeforeEach void setUp() { capturedCallContext = ArgumentCaptor.forClass(ApiCallContext.class); - Mockito.when(mockInnerCallable.futureCall(Mockito.anyString(), capturedCallContext.capture())) + when(mockInnerCallable.futureCall(Mockito.anyString(), capturedCallContext.capture())) .thenReturn(SettableApiFuture.create()); currentAttemptSettings = @@ -70,7 +74,7 @@ void setUp() { .setRpcTimeoutDuration(java.time.Duration.ZERO) .build(); - Mockito.when(mockExternalFuture.getAttemptSettings()) + when(mockExternalFuture.getAttemptSettings()) .thenAnswer( new Answer() { @Override @@ -82,8 +86,12 @@ public TimedAttemptSettings answer(InvocationOnMock invocation) throws Throwable @Test void testRpcTimeout() { + FakeCallContext callContext = mock(FakeCallContext.class); + when(callContext.getTimeoutDuration()).thenReturn(null); + when(callContext.withTimeoutDuration(any(java.time.Duration.class))).thenReturn(callContext); + when(callContext.getTracer()).thenReturn(mock(ApiTracer.class)); AttemptCallable callable = - new AttemptCallable<>(mockInnerCallable, "fake-request", FakeCallContext.createDefault()); + new AttemptCallable<>(mockInnerCallable, "fake-request", callContext); callable.setExternalFuture(mockExternalFuture); // Make sure that the rpc timeout is set @@ -91,16 +99,17 @@ void testRpcTimeout() { currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); + callable.call(); - assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(timeout); + Mockito.verify(callContext).withTimeoutDuration(timeout); - // Make sure that subsequent attempts can extend the time out + // Make sure that subsequent attempts can extend the timeout java.time.Duration longerTimeout = java.time.Duration.ofSeconds(20); currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(longerTimeout).build(); callable.call(); - assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); + Mockito.verify(callContext).withTimeoutDuration(longerTimeout); } @Test From 8bbf01f00ccfbe33e301282cb3004000cc5f4e36 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 15:54:52 -0400 Subject: [PATCH 125/141] add tests for BaseApiTracer --- .../api/gax/tracing/BaseApiTracerTest.java | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java new file mode 100644 index 0000000000..871e384069 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java @@ -0,0 +1,163 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.gax.tracing; + + +import org.junit.jupiter.api.Test; + +public class BaseApiTracerTest { + + @Test + public void testInScope() { + BaseApiTracer tracer = new BaseApiTracer(); + ApiTracer.Scope scope = tracer.inScope(); + scope.close(); + // No-op, so nothing to verify. + } + + @Test + public void testOperationSucceeded() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.operationSucceeded(); + // No-op, so nothing to verify. + } + + @Test + public void testOperationCancelled() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.operationCancelled(); + // No-op, so nothing to verify. + } + + @Test + public void testOperationFailed() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.operationFailed(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testConnectionSelected() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.connectionSelected("test-connection"); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptStarted() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptStarted(1); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptStartedWithRequest() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptStarted(new Object(), 1); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptSucceeded() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptSucceeded(); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptCancelled() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptCancelled(); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptFailedDuration() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptFailedDuration(new RuntimeException(), java.time.Duration.ofMillis(100)); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptFailed() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptFailed(new RuntimeException(), org.threeten.bp.Duration.ofMillis(100)); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptFailedRetriesExhausted() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptFailedRetriesExhausted(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptPermanentFailure() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptPermanentFailure(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testLroStartFailed() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.lroStartFailed(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testLroStartSucceeded() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.lroStartSucceeded(); + // No-op, so nothing to verify. + } + + @Test + public void testResponseReceived() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.responseReceived(); + // No-op, so nothing to verify. + } + + @Test + public void testRequestSent() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.requestSent(); + // No-op, so nothing to verify. + } + + @Test + public void testBatchRequestSent() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.batchRequestSent(10, 100); + // No-op, so nothing to verify. + } +} From 038d16b76de6231ccc041f118e011e4261033bb0 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 16:04:54 -0400 Subject: [PATCH 126/141] increase coverage for BasicRetryingFuture --- .../google/api/gax/retrying/BasicRetryingFutureTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java index aaac908c86..5b0c37c3dc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java @@ -30,6 +30,8 @@ package com.google.api.gax.retrying; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import com.google.api.gax.tracing.ApiTracer; import java.lang.reflect.Field; @@ -64,6 +66,9 @@ void testHandleAttemptDoesNotThrowNPEWhenLogLevelLowerThanFiner() throws Excepti RetryingContext retryingContext = mock(RetryingContext.class); ApiTracer tracer = mock(ApiTracer.class); TimedAttemptSettings timedAttemptSettings = mock(TimedAttemptSettings.class); + java.time.Duration testDuration = java.time.Duration.ofMillis(123); + Mockito.when(timedAttemptSettings.getRandomizedRetryDelayDuration()).thenReturn(testDuration); + Mockito.when(timedAttemptSettings.getRetryDelayDuration()).thenReturn(testDuration); Mockito.when(retryingContext.getTracer()).thenReturn(tracer); @@ -91,6 +96,9 @@ void testHandleAttemptDoesNotThrowNPEWhenLogLevelLowerThanFiner() throws Excepti future.handleAttempt(null, null); + Mockito.verify(tracer).attemptFailedDuration(ArgumentMatchers.isNull(), ArgumentMatchers.eq(testDuration)); + Mockito.verify(timedAttemptSettings, times(1)).getRetryDelayDuration(); + Mockito.verify(tracer) .attemptFailedDuration( ArgumentMatchers.any(), ArgumentMatchers.any()); From aa601fd43ea6db049632d968d71c4932e1b0605a Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 16:14:20 -0400 Subject: [PATCH 127/141] increase coverage of BatcherFactory --- .../com/google/api/gax/rpc/BatcherFactoryTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java index bfd95d01c4..8ece5dedde 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/BatcherFactoryTest.java @@ -45,6 +45,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; class BatcherFactoryTest { private ScheduledExecutorService batchingExecutor; @@ -61,12 +62,11 @@ void tearDown() { @Test void testGetPushingBatcher() { - BatchingSettings batchingSettings = - BatchingSettings.newBuilder() - .setDelayThresholdDuration(java.time.Duration.ofSeconds(1)) - .setElementCountThreshold(2L) - .setRequestByteThreshold(1000L) - .build(); + final java.time.Duration delayThreshold = java.time.Duration.ofSeconds(1); + BatchingSettings batchingSettings = Mockito.mock(BatchingSettings.class); + Mockito.when(batchingSettings.getDelayThresholdDuration()).thenReturn(delayThreshold); + Mockito.when(batchingSettings.getElementCountThreshold()).thenReturn(2L); + Mockito.when(batchingSettings.getRequestByteThreshold()).thenReturn(1000L); FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) @@ -86,6 +86,8 @@ void testGetPushingBatcher() { ThresholdBatcher>> batcherBar = batcherFactory.getPushingBatcher(new PartitionKey("bar")); + Mockito.verify(batchingSettings, Mockito.times(2)).getDelayThresholdDuration(); + Truth.assertThat(batcherFoo).isSameInstanceAs(batcherFoo2); Truth.assertThat(batcherFoo).isNotSameInstanceAs(batcherBar); } From ffebe03978fb9366372819d3eaa9c63de14153ea Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 16:32:44 -0400 Subject: [PATCH 128/141] format + increase coverage in BatcherImpl --- .../api/gax/batching/BatcherImplTest.java | 30 ++- .../gax/retrying/BasicRetryingFutureTest.java | 4 +- .../api/gax/rpc/AttemptCallableTest.java | 1 - .../api/gax/tracing/BaseApiTracerTest.java | 253 +++++++++--------- 4 files changed, 155 insertions(+), 133 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java index 7982b90140..3ebcc2c5d0 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java @@ -34,6 +34,10 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.api.core.ApiFuture; @@ -129,6 +133,20 @@ void testResultsAreResolvedAfterFlush() throws Exception { @Test void testSendOutstanding() { final AtomicInteger callableCounter = new AtomicInteger(); + ScheduledExecutorService mockExecutor = mock(ScheduledExecutorService.class); + BatchingSettings mockBatchingSettings = mock(BatchingSettings.class); + java.time.Duration mockDelayThresholdDuration = java.time.Duration.ofSeconds(1000L); + when(mockBatchingSettings.getDelayThresholdDuration()).thenReturn(mockDelayThresholdDuration); + when(mockBatchingSettings.getRequestByteThreshold()).thenReturn(1000L); + when(mockBatchingSettings.getElementCountThreshold()).thenReturn(1000L); + when(mockBatchingSettings.getFlowControlSettings()) + .thenReturn(batchingSettings.getFlowControlSettings()); + when(mockExecutor.scheduleWithFixedDelay( + any(Runnable.class), + eq(mockDelayThresholdDuration.toMillis()), + eq(mockDelayThresholdDuration.toMillis()), + any(TimeUnit.class))) + .thenReturn(mock(ScheduledFuture.class)); underTest = new BatcherImpl<>( @@ -142,8 +160,8 @@ public ApiFuture> futureCall( } }, labeledIntList, - batchingSettings, - EXECUTOR); + mockBatchingSettings, + mockExecutor); // Empty Batcher underTest.sendOutstanding(); @@ -154,6 +172,12 @@ public ApiFuture> futureCall( underTest.add(4); underTest.sendOutstanding(); assertThat(callableCounter.get()).isEqualTo(1); + verify(mockExecutor) + .scheduleWithFixedDelay( + any(Runnable.class), + eq(mockDelayThresholdDuration.toMillis()), + eq(mockDelayThresholdDuration.toMillis()), + any(TimeUnit.class)); } /** Element results are resolved after batch is closed. */ @@ -832,7 +856,7 @@ void testThrottlingBlocking() throws Exception { .build()); ExecutorService executor = Executors.newFixedThreadPool(2); - ApiCallContext callContext = Mockito.mock(ApiCallContext.class); + ApiCallContext callContext = mock(ApiCallContext.class); ArgumentCaptor> key = ArgumentCaptor.forClass(ApiCallContext.Key.class); ArgumentCaptor value = ArgumentCaptor.forClass(Long.class); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java index 5b0c37c3dc..5342f02965 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java @@ -31,7 +31,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import com.google.api.gax.tracing.ApiTracer; import java.lang.reflect.Field; @@ -96,7 +95,8 @@ void testHandleAttemptDoesNotThrowNPEWhenLogLevelLowerThanFiner() throws Excepti future.handleAttempt(null, null); - Mockito.verify(tracer).attemptFailedDuration(ArgumentMatchers.isNull(), ArgumentMatchers.eq(testDuration)); + Mockito.verify(tracer) + .attemptFailedDuration(ArgumentMatchers.isNull(), ArgumentMatchers.eq(testDuration)); Mockito.verify(timedAttemptSettings, times(1)).getRetryDelayDuration(); Mockito.verify(tracer) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index 68c313df89..f06ccdf2c6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -99,7 +99,6 @@ void testRpcTimeout() { currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); - callable.call(); Mockito.verify(callContext).withTimeoutDuration(timeout); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java b/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java index 871e384069..8397efbb7d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/tracing/BaseApiTracerTest.java @@ -29,135 +29,134 @@ */ package com.google.api.gax.tracing; - import org.junit.jupiter.api.Test; public class BaseApiTracerTest { - @Test - public void testInScope() { - BaseApiTracer tracer = new BaseApiTracer(); - ApiTracer.Scope scope = tracer.inScope(); - scope.close(); - // No-op, so nothing to verify. - } - - @Test - public void testOperationSucceeded() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.operationSucceeded(); - // No-op, so nothing to verify. - } - - @Test - public void testOperationCancelled() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.operationCancelled(); - // No-op, so nothing to verify. - } - - @Test - public void testOperationFailed() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.operationFailed(new RuntimeException()); - // No-op, so nothing to verify. - } - - @Test - public void testConnectionSelected() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.connectionSelected("test-connection"); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptStarted() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptStarted(1); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptStartedWithRequest() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptStarted(new Object(), 1); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptSucceeded() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptSucceeded(); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptCancelled() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptCancelled(); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptFailedDuration() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptFailedDuration(new RuntimeException(), java.time.Duration.ofMillis(100)); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptFailed() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptFailed(new RuntimeException(), org.threeten.bp.Duration.ofMillis(100)); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptFailedRetriesExhausted() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptFailedRetriesExhausted(new RuntimeException()); - // No-op, so nothing to verify. - } - - @Test - public void testAttemptPermanentFailure() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.attemptPermanentFailure(new RuntimeException()); - // No-op, so nothing to verify. - } - - @Test - public void testLroStartFailed() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.lroStartFailed(new RuntimeException()); - // No-op, so nothing to verify. - } - - @Test - public void testLroStartSucceeded() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.lroStartSucceeded(); - // No-op, so nothing to verify. - } - - @Test - public void testResponseReceived() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.responseReceived(); - // No-op, so nothing to verify. - } - - @Test - public void testRequestSent() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.requestSent(); - // No-op, so nothing to verify. - } - - @Test - public void testBatchRequestSent() { - BaseApiTracer tracer = new BaseApiTracer(); - tracer.batchRequestSent(10, 100); - // No-op, so nothing to verify. - } + @Test + public void testInScope() { + BaseApiTracer tracer = new BaseApiTracer(); + ApiTracer.Scope scope = tracer.inScope(); + scope.close(); + // No-op, so nothing to verify. + } + + @Test + public void testOperationSucceeded() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.operationSucceeded(); + // No-op, so nothing to verify. + } + + @Test + public void testOperationCancelled() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.operationCancelled(); + // No-op, so nothing to verify. + } + + @Test + public void testOperationFailed() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.operationFailed(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testConnectionSelected() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.connectionSelected("test-connection"); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptStarted() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptStarted(1); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptStartedWithRequest() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptStarted(new Object(), 1); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptSucceeded() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptSucceeded(); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptCancelled() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptCancelled(); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptFailedDuration() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptFailedDuration(new RuntimeException(), java.time.Duration.ofMillis(100)); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptFailed() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptFailed(new RuntimeException(), org.threeten.bp.Duration.ofMillis(100)); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptFailedRetriesExhausted() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptFailedRetriesExhausted(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testAttemptPermanentFailure() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.attemptPermanentFailure(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testLroStartFailed() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.lroStartFailed(new RuntimeException()); + // No-op, so nothing to verify. + } + + @Test + public void testLroStartSucceeded() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.lroStartSucceeded(); + // No-op, so nothing to verify. + } + + @Test + public void testResponseReceived() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.responseReceived(); + // No-op, so nothing to verify. + } + + @Test + public void testRequestSent() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.requestSent(); + // No-op, so nothing to verify. + } + + @Test + public void testBatchRequestSent() { + BaseApiTracer tracer = new BaseApiTracer(); + tracer.batchRequestSent(10, 100); + // No-op, so nothing to verify. + } } From c0957df69c690513510b8051401c02ea980f504f Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 18:44:46 -0400 Subject: [PATCH 129/141] add javadoc for TimeConversionTestUtils --- .../api/gax/util/TimeConversionTestUtils.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java index b890e3888d..bc49bec95e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionTestUtils.java @@ -36,6 +36,21 @@ public class TimeConversionTestUtils { + /** + * Confirms that the behavior of getters and setters of an Instant property (both {@link + * java.time.Instant} and {@link org.threeten.bp.Instant}) is the same. + * + * @param testValue the value in millis to be tested + * @param javaTimeTargetSupplier a supplier of a {@link Target} that is created using an {@link + * java.time.Instant} + * @param threetenTargetSupplier a supplier of a {@link Target} that is created using an {@link + * org.threeten.bp.Instant} + * @param javaTimeGetter a getter of the {@link java.time.Instant} obtained from the instance of + * {@link Target} + * @param threetenGetter a getter of the {{@link org.threeten.bp.Instant} obtained from the + * instance of {@link Target} + * @param the type of the target containing the Instant property + */ public static void testInstantMethod( Long testValue, Function javaTimeTargetSupplier, @@ -66,6 +81,21 @@ public static void testInstantMethod( threetenTester); } + /** + * Confirms that the behavior of getters and setters of a Duration property (both {@link + * java.time.Duration} and {@link org.threeten.bp.Duration}) is the same. + * + * @param testValue the value in millis to be tested + * @param javaTimeTargetSupplier a supplier of a {@link Target} that is created using an {@link + * java.time.Duration} + * @param threetenTargetSupplier a supplier of a {@link Target} that is created using an {@link + * org.threeten.bp.Duration} + * @param javaTimeGetter a getter of the {@link java.time.Duration} obtained from the instance of + * {@link Target} + * @param threetenGetter a getter of the {{@link org.threeten.bp.Duration} obtained from the + * instance of {@link Target} + * @param the type of the target containing the Duration property + */ public static void testDurationMethod( Long testValue, Function javaTimeTargetSupplier, @@ -96,6 +126,11 @@ public static void testDurationMethod( threetenTester); } + /** + * Contains the common implementation of {@link #testInstantMethod(Long, Function, Function, + * Function, Function)} and {@link #testDurationMethod(Long, Function, Function, Function, + * Function)} and performs the corresponding assertions. + */ private static void testTimeObjectMethod( Long testValue, SupplierType targetSupplierValue, From 6359ef48d2a8b1e8a1d5856bd543d558999ff0e3 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 19:37:41 -0400 Subject: [PATCH 130/141] increase coverage in Callables --- .../com/google/api/gax/rpc/CallableTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java index 0bcc1a7b8f..55cb2f3024 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CallableTest.java @@ -32,18 +32,23 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.api.core.ApiClock; import com.google.api.core.ApiFuture; import com.google.api.core.SettableApiFuture; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.testing.FakeCallContext; +import java.util.concurrent.ScheduledExecutorService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; @@ -168,4 +173,30 @@ void testNonRetriedServerStreamingCallableWithRetrySettings() throws Exception { verify(callContextWithRetrySettings).getTimeoutDuration(); verify(callContextWithRetrySettings).withTimeoutDuration(timeout); } + + @Test + void testWatched_usesJavaTimeMethods() { + java.time.Duration timeout = java.time.Duration.ofMillis(5L); + doReturn(callContext).when(callContext).withStreamIdleTimeoutDuration(eq(timeout)); + Watchdog watchdog = + Watchdog.createDuration( + Mockito.mock(ApiClock.class), + java.time.Duration.ZERO, + Mockito.mock(ScheduledExecutorService.class)); + ClientContext clientContext = + ClientContext.newBuilder() + .setStreamWatchdog(watchdog) + .setDefaultCallContext(callContext) + .build(); + ServerStreamingCallSettings callSettings = + ServerStreamingCallSettings.newBuilder() + .setIdleTimeoutDuration(timeout) + .setWaitTimeoutDuration(timeout) + .build(); + ServerStreamingCallable callable = + Callables.retrying(innerServerStreamingCallable, callSettings, clientContext); + Callables.watched(callable, callSettings, clientContext); + verify(callContext, atLeastOnce()).withStreamIdleTimeoutDuration(eq(timeout)); + verify(callContext, atLeastOnce()).withStreamWaitTimeoutDuration(eq(timeout)); + } } From 5167ab12a97002c29be122ee78b6afa0fd35ba3e Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 20:07:15 -0400 Subject: [PATCH 131/141] increase coverage in CheckingAttemptCallable --- .../gax/rpc/CheckingAttemptCallableTest.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java index d7858817af..5d7e905af6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/CheckingAttemptCallableTest.java @@ -30,6 +30,7 @@ package com.google.api.gax.rpc; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.verify; import com.google.api.core.SettableApiFuture; import com.google.api.gax.retrying.RetrySettings; @@ -40,6 +41,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -56,8 +58,6 @@ class CheckingAttemptCallableTest { @BeforeEach void setUp() { capturedCallContext = ArgumentCaptor.forClass(ApiCallContext.class); - Mockito.when(mockInnerCallable.futureCall(Mockito.any(), capturedCallContext.capture())) - .thenReturn(SettableApiFuture.create()); currentAttemptSettings = TimedAttemptSettings.newBuilder() @@ -81,7 +81,9 @@ public TimedAttemptSettings answer(InvocationOnMock invocation) throws Throwable } @Test - void testRpcTimeout() { + void testRpcTimeout_gtZero_succeeds() { + Mockito.when(mockInnerCallable.futureCall(Mockito.any(), capturedCallContext.capture())) + .thenReturn(SettableApiFuture.create()); CheckingAttemptCallable callable = new CheckingAttemptCallable<>(mockInnerCallable, FakeCallContext.createDefault()); callable.setExternalFuture(mockExternalFuture); @@ -102,4 +104,22 @@ void testRpcTimeout() { callable.call(); assertThat(capturedCallContext.getValue().getTimeoutDuration()).isEqualTo(longerTimeout); } + + @Test + void testRpcTimeout_gtZero_callsWithTimeoutDuration() { + FakeCallContext callContext = Mockito.spy(FakeCallContext.createDefault()); + Mockito.doReturn(callContext).when(callContext).withTimeoutDuration(ArgumentMatchers.any()); + CheckingAttemptCallable callable = + new CheckingAttemptCallable<>(Mockito.mock(UnaryCallable.class), callContext); + callable.setExternalFuture(mockExternalFuture); + + // Make sure that the rpc timeout is set + java.time.Duration timeout = java.time.Duration.ofSeconds(10); + currentAttemptSettings = + currentAttemptSettings.toBuilder().setRpcTimeoutDuration(timeout).build(); + + callable.call(); + + verify(callContext).withTimeoutDuration(timeout); + } } From dd9a1b314dd32cd60e84fb79fad7a334a00a80c8 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 6 Jun 2024 20:27:33 -0400 Subject: [PATCH 132/141] add null check in ClientSettings --- .../gax/src/main/java/com/google/api/gax/rpc/StubSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java index d1199b11b5..daeda4c445 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java @@ -648,7 +648,7 @@ public org.threeten.bp.Duration getStreamWatchdogCheckInterval() { @Nonnull public java.time.Duration getStreamWatchdogCheckIntervalDuration() { - return streamWatchdogCheckInterval; + return Preconditions.checkNotNull(streamWatchdogCheckInterval); } @BetaApi("The surface for tracing is not stable yet and may change in the future.") From 1212fa71a1933dd4fbd802c15a3d2d58da717964 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 12 Jun 2024 14:47:29 -0400 Subject: [PATCH 133/141] use manual test in BatchingSettingsTest --- .../gax/batching/BatchingSettingsTest.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index b344d251aa..c12ce651d1 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -29,21 +29,34 @@ */ package com.google.api.gax.batching; -import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; +//import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class BatchingSettingsTest { - private final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); +// private final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); @Test public void testDelayThreshold() { - testDurationMethod( - 123l, - jt -> SETTINGS_BUILDER.setDelayThresholdDuration(jt).build(), - tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), - o -> o.getDelayThresholdDuration(), - o -> o.getDelayThreshold()); + // We are temporarily using a "manual" test to confirm the coverage of this function + final long millis = 123; + java.time.Duration jtd = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration ttd = org.threeten.bp.Duration.ofMillis(millis); + BatchingSettings jtSettings = BatchingSettings.newBuilder().setDelayThresholdDuration(jtd).build(); + BatchingSettings ttSettings = BatchingSettings.newBuilder().setDelayThreshold(ttd).build(); + + assertEquals(jtd, jtSettings.getDelayThresholdDuration()); + assertEquals(ttd, jtSettings.getDelayThreshold()); + assertEquals(jtd, ttSettings.getDelayThresholdDuration()); + assertEquals(ttd, ttSettings.getDelayThreshold()); + + // testDurationMethod( + // 123l, + // jt -> SETTINGS_BUILDER.setDelayThresholdDuration(jt).build(), + // tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), + // o -> o.getDelayThresholdDuration(), + // o -> o.getDelayThreshold()); } } From be1887036317d51cf772fe580506254bee3a5087 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 12 Jun 2024 14:54:16 -0400 Subject: [PATCH 134/141] format --- .../com/google/api/gax/batching/BatchingSettingsTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index c12ce651d1..947322aca7 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -29,14 +29,14 @@ */ package com.google.api.gax.batching; -//import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; +// import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class BatchingSettingsTest { -// private final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); + // private final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); @Test public void testDelayThreshold() { @@ -44,7 +44,8 @@ public void testDelayThreshold() { final long millis = 123; java.time.Duration jtd = java.time.Duration.ofMillis(millis); org.threeten.bp.Duration ttd = org.threeten.bp.Duration.ofMillis(millis); - BatchingSettings jtSettings = BatchingSettings.newBuilder().setDelayThresholdDuration(jtd).build(); + BatchingSettings jtSettings = + BatchingSettings.newBuilder().setDelayThresholdDuration(jtd).build(); BatchingSettings ttSettings = BatchingSettings.newBuilder().setDelayThreshold(ttd).build(); assertEquals(jtd, jtSettings.getDelayThresholdDuration()); From ec6c52ea611c273739b619317c264d403e19037c Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 12 Jun 2024 16:04:39 -0400 Subject: [PATCH 135/141] add tests with same settings builder and different test value --- .../gax/batching/BatchingSettingsTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index 947322aca7..3ff53031a2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -29,29 +29,29 @@ */ package com.google.api.gax.batching; -// import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class BatchingSettingsTest { - // private final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); + private static final BatchingSettings.Builder SETTINGS_BUILDER = BatchingSettings.newBuilder(); @Test public void testDelayThreshold() { - // We are temporarily using a "manual" test to confirm the coverage of this function final long millis = 123; - java.time.Duration jtd = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration ttd = org.threeten.bp.Duration.ofMillis(millis); - BatchingSettings jtSettings = - BatchingSettings.newBuilder().setDelayThresholdDuration(jtd).build(); - BatchingSettings ttSettings = BatchingSettings.newBuilder().setDelayThreshold(ttd).build(); + final long millis2 = 345; + java.time.Duration jtd1 = java.time.Duration.ofMillis(millis); + org.threeten.bp.Duration ttd1 = org.threeten.bp.Duration.ofMillis(millis); + java.time.Duration jtd2 = java.time.Duration.ofMillis(millis2); + org.threeten.bp.Duration ttd2 = org.threeten.bp.Duration.ofMillis(millis2); + BatchingSettings jtSettings = SETTINGS_BUILDER.setDelayThresholdDuration(jtd1).build(); + BatchingSettings ttSettings = SETTINGS_BUILDER.setDelayThreshold(ttd2).build(); - assertEquals(jtd, jtSettings.getDelayThresholdDuration()); - assertEquals(ttd, jtSettings.getDelayThreshold()); - assertEquals(jtd, ttSettings.getDelayThresholdDuration()); - assertEquals(ttd, ttSettings.getDelayThreshold()); + assertEquals(jtd1, jtSettings.getDelayThresholdDuration()); + assertEquals(ttd1, jtSettings.getDelayThreshold()); + assertEquals(jtd2, ttSettings.getDelayThresholdDuration()); + assertEquals(ttd2, ttSettings.getDelayThreshold()); // testDurationMethod( // 123l, From d5ce8b1f3de92dc0060f44b8763b99cc918d3b41 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Jun 2024 22:15:58 -0400 Subject: [PATCH 136/141] chore: Add @{argLine} to prevent overwriting jacoco property --- gax-java/gax/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index f708a0d19b..6a5e36f276 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -103,7 +103,7 @@ org.apache.maven.plugins maven-surefire-plugin - -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n" + @{argLine} -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n" !EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority From aeadeb8237ae564d1737865bb7d950d2c63f711d Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 13 Jun 2024 13:21:23 -0400 Subject: [PATCH 137/141] restore BatchingSettingsTest --- .../gax/batching/BatchingSettingsTest.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java index 3ff53031a2..69dadb5397 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/batching/BatchingSettingsTest.java @@ -29,7 +29,7 @@ */ package com.google.api.gax.batching; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static com.google.api.gax.util.TimeConversionTestUtils.testDurationMethod; import org.junit.jupiter.api.Test; @@ -39,25 +39,11 @@ public class BatchingSettingsTest { @Test public void testDelayThreshold() { - final long millis = 123; - final long millis2 = 345; - java.time.Duration jtd1 = java.time.Duration.ofMillis(millis); - org.threeten.bp.Duration ttd1 = org.threeten.bp.Duration.ofMillis(millis); - java.time.Duration jtd2 = java.time.Duration.ofMillis(millis2); - org.threeten.bp.Duration ttd2 = org.threeten.bp.Duration.ofMillis(millis2); - BatchingSettings jtSettings = SETTINGS_BUILDER.setDelayThresholdDuration(jtd1).build(); - BatchingSettings ttSettings = SETTINGS_BUILDER.setDelayThreshold(ttd2).build(); - - assertEquals(jtd1, jtSettings.getDelayThresholdDuration()); - assertEquals(ttd1, jtSettings.getDelayThreshold()); - assertEquals(jtd2, ttSettings.getDelayThresholdDuration()); - assertEquals(ttd2, ttSettings.getDelayThreshold()); - - // testDurationMethod( - // 123l, - // jt -> SETTINGS_BUILDER.setDelayThresholdDuration(jt).build(), - // tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), - // o -> o.getDelayThresholdDuration(), - // o -> o.getDelayThreshold()); + testDurationMethod( + 123l, + jt -> SETTINGS_BUILDER.setDelayThresholdDuration(jt).build(), + tt -> SETTINGS_BUILDER.setDelayThreshold(tt).build(), + o -> o.getDelayThresholdDuration(), + o -> o.getDelayThreshold()); } } From 468558bfbd7f7aa99ec8a0121e4941fd08d69844 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Thu, 13 Jun 2024 13:22:33 -0400 Subject: [PATCH 138/141] Update gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java Co-authored-by: Lawrence Qiu --- .../java/com/google/api/gax/httpjson/HttpJsonClientCalls.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index c573d786f6..68905396e4 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -60,7 +60,7 @@ public static HttpJsonClientCall newC if (callOptions.getTimeout() == null || httpJsonContext .getTimeoutDuration() - .compareTo(java.time.Duration.ofMillis(callOptions.getTimeout().toMillis())) + .compareTo(java.time.Duration.ofMillis(callOptions.getTimeoutDuration().toMillis())) < 0) { callOptions = callOptions From 82c06792949c8a24e2fb262effa55d43a031fef7 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 13 Jun 2024 13:27:08 -0400 Subject: [PATCH 139/141] use java.time methods in HttpJsonClientCalls --- .../com/google/api/gax/httpjson/HttpJsonClientCalls.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java index 68905396e4..6be4ec7ec6 100644 --- a/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java +++ b/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCalls.java @@ -57,10 +57,11 @@ public static HttpJsonClientCall newC // inside the HttpJsonCallOptions // Note: There is manual conversion between threetenbp's Duration and java.util.Duration // This is temporary here as we plan to migrate to java.util.Duration - if (callOptions.getTimeout() == null + if (callOptions.getTimeoutDuration() == null || httpJsonContext .getTimeoutDuration() - .compareTo(java.time.Duration.ofMillis(callOptions.getTimeoutDuration().toMillis())) + .compareTo( + java.time.Duration.ofMillis(callOptions.getTimeoutDuration().toMillis())) < 0) { callOptions = callOptions From 09e9995a5691a7c46d5ab0a14f6417b6f865debc Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 26 Jun 2024 10:31:34 -0400 Subject: [PATCH 140/141] add tests for TimeConversionUtils --- .../api/gax/util/TimeConversionUtilsTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java new file mode 100644 index 0000000000..ee528bb263 --- /dev/null +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java @@ -0,0 +1,42 @@ +package com.google.api.gax.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +public class TimeConversionUtilsTest { + + final org.threeten.bp.Duration ttDuration = org.threeten.bp.Duration.ofMillis(123); + final org.threeten.bp.Instant ttInstant = org.threeten.bp.Instant.ofEpochMilli(123); + final java.time.Duration jtDuration = java.time.Duration.ofMillis(345); + final java.time.Instant jtInstant = java.time.Instant.ofEpochMilli(345); + + @Test + void testToJavaTimeDuration_validInput_succeeds() { + assertEquals( + ttDuration.toMillis(), TimeConversionUtils.toJavaTimeDuration(ttDuration).toMillis()); + assertNull(TimeConversionUtils.toJavaTimeDuration(null)); + } + + @Test + void testToThreetenTimeDuration_validInput_succeeds() { + assertEquals( + jtDuration.toMillis(), TimeConversionUtils.toThreetenDuration(jtDuration).toMillis()); + assertNull(TimeConversionUtils.toThreetenDuration(null)); + } + + @Test + void testToJavaTimeInstant_validInput_succeeds() { + assertEquals( + ttInstant.toEpochMilli(), TimeConversionUtils.toJavaTimeInstant(ttInstant).toEpochMilli()); + assertNull(TimeConversionUtils.toJavaTimeInstant(null)); + } + + @Test + void testToThreetenTimeInstant_validInput_succeeds() { + assertEquals( + jtInstant.toEpochMilli(), TimeConversionUtils.toThreetenInstant(jtInstant).toEpochMilli()); + assertNull(TimeConversionUtils.toThreetenInstant(null)); + } +} From 57170d015b2466011c5941c23bd6a1289c48f76c Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 27 Jun 2024 13:08:42 -0400 Subject: [PATCH 141/141] add license header --- .../api/gax/util/TimeConversionUtilsTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java index ee528bb263..e288a06bae 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java @@ -1,3 +1,33 @@ +/* + * Copyright 2024 Google LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package com.google.api.gax.util; import static org.junit.jupiter.api.Assertions.assertEquals;