This repository was archived by the owner on Sep 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
main/java/com/google/api/gax/rpc
test/java/com/google/api/gax/rpc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,9 +63,13 @@ public interface ApiCallContext extends RetryingContext {
6363 * Returns a new ApiCallContext with the given timeout set.
6464 *
6565 * <p>This sets the maximum amount of time a single unary RPC attempt can take. If retries are
66- * enabled, then this can take much longer. Unlike a deadline, timeouts are relative durations
67- * that are measure from the beginning of each RPC attempt. Please note that this will limit the
68- * duration of a server streaming RPC as well.
66+ * enabled, then this can take much longer, as each RPC attempt will have the same constant
67+ * timeout. Unlike a deadline, timeouts are relative durations that are measure from the beginning
68+ * of each RPC attempt. Please note that this limits the duration of a server streaming RPC as
69+ * well.
70+ *
71+ * <p>If a method has default {@link com.google.api.gax.retrying.RetrySettings}, the max attempts
72+ * and/or total timeout is still respected when scheduling each RPC attempt.
6973 */
7074 ApiCallContext withTimeout (@ Nullable Duration timeout );
7175
Original file line number Diff line number Diff line change @@ -69,8 +69,9 @@ public ResponseT call() {
6969 ApiCallContext callContext = originalCallContext ;
7070
7171 try {
72+ // Set the RPC timeout if the caller did not provide their own.
7273 Duration rpcTimeout = externalFuture .getAttemptSettings ().getRpcTimeout ();
73- if (!rpcTimeout .isZero ()) {
74+ if (!rpcTimeout .isZero () && callContext . getTimeout () == null ) {
7475 callContext = callContext .withTimeout (rpcTimeout );
7576 }
7677
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ public void testRpcTimeoutIsNotErased() {
108108 Duration callerTimeout = Duration .ofMillis (10 );
109109 ApiCallContext callerCallContext = FakeCallContext .createDefault ().withTimeout (callerTimeout );
110110
111+ Duration timeout = Duration .ofMillis (5 );
112+ currentAttemptSettings = currentAttemptSettings .toBuilder ().setRpcTimeout (timeout ).build ();
113+
111114 AttemptCallable <String , String > callable =
112115 new AttemptCallable <>(mockInnerCallable , "fake-request" , callerCallContext );
113116 callable .setExternalFuture (mockExternalFuture );
You can’t perform that action at this time.
0 commit comments