-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test(showcase): add integration tests for retries #13929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nnicolee
wants to merge
5
commits into
main
Choose a base branch
from
test/showcase-retries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+253
−0
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c543a1
test(showcase): add integration tests for exponential backoff retries…
nnicolee d27e2d0
Merge branch 'main' of github.com:googleapis/google-cloud-java into t…
nnicolee 490cb36
test(showcase): simplify retry client configuration to use SequenceSe…
nnicolee eb5cf39
Merge branch 'main' into test/showcase-retries
nnicolee 51960b2
test(showcase): use lower bounds only for retry delays to prevent fla…
nnicolee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
193 changes: 193 additions & 0 deletions
193
java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITRetries.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.showcase.v1beta1.it; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| import com.google.api.gax.retrying.RetrySettings; | ||
| import com.google.api.gax.rpc.StatusCode; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import com.google.rpc.Status; | ||
| import com.google.showcase.v1beta1.AttemptSequenceRequest; | ||
| import com.google.showcase.v1beta1.CreateSequenceRequest; | ||
| import com.google.showcase.v1beta1.GetSequenceReportRequest; | ||
| import com.google.showcase.v1beta1.Sequence; | ||
| import com.google.showcase.v1beta1.SequenceReport; | ||
| import com.google.showcase.v1beta1.SequenceServiceClient; | ||
| import com.google.showcase.v1beta1.it.util.TestClientInitializer; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ITRetries { | ||
|
|
||
| private static final Sequence STANDARD_SEQUENCE = | ||
| Sequence.newBuilder() | ||
| .addResponses( | ||
| Sequence.Response.newBuilder() | ||
| .setStatus( | ||
| Status.newBuilder() | ||
| .setCode(com.google.rpc.Code.UNAVAILABLE.getNumber()) | ||
| .build()) | ||
| .build()) | ||
| .addResponses( | ||
| Sequence.Response.newBuilder() | ||
| .setStatus( | ||
| Status.newBuilder() | ||
| .setCode(com.google.rpc.Code.UNAVAILABLE.getNumber()) | ||
| .build()) | ||
| .build()) | ||
| .addResponses( | ||
| Sequence.Response.newBuilder() | ||
| .setStatus( | ||
| Status.newBuilder() | ||
| .setCode(com.google.rpc.Code.UNAVAILABLE.getNumber()) | ||
| .build()) | ||
| .build()) | ||
| .addResponses( | ||
| Sequence.Response.newBuilder() | ||
| .setStatus( | ||
| Status.newBuilder().setCode(com.google.rpc.Code.OK.getNumber()).build()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| private static final RetrySettings STANDARD_RETRY_SETTINGS = | ||
| RetrySettings.newBuilder() | ||
| .setInitialRetryDelayDuration(java.time.Duration.ofMillis(100L)) | ||
| .setRetryDelayMultiplier(2.0) | ||
| .setMaxRetryDelayDuration(java.time.Duration.ofMillis(1000L)) | ||
| .setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(1000L)) | ||
| .setRpcTimeoutMultiplier(1.0) | ||
| .setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(1000L)) | ||
| .setTotalTimeoutDuration(java.time.Duration.ofMillis(5000L)) | ||
| .setMaxAttempts(4) | ||
| .setJittered(false) | ||
| .build(); | ||
|
|
||
| private static SequenceServiceClient grpcClient; | ||
| private static SequenceServiceClient httpjsonClient; | ||
|
|
||
| @BeforeAll | ||
| static void createClients() throws Exception { | ||
| grpcClient = TestClientInitializer.createGrpcSequenceClient(); | ||
| httpjsonClient = TestClientInitializer.createHttpJsonSequenceClient(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void destroyClients() throws InterruptedException { | ||
| grpcClient.close(); | ||
| httpjsonClient.close(); | ||
|
|
||
| grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); | ||
| httpjsonClient.awaitTermination( | ||
| TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("deprecation") | ||
| void testGrpc_retryExponentialBackoff() throws Exception { | ||
| // Create a custom client with these retry settings on attemptSequence | ||
| try (SequenceServiceClient retryClient = | ||
| TestClientInitializer.createGrpcSequenceClientWithRetrySettings( | ||
| STANDARD_RETRY_SETTINGS, ImmutableSet.of(StatusCode.Code.UNAVAILABLE))) { | ||
|
|
||
| Sequence createdSequence = | ||
| grpcClient.createSequence( | ||
| CreateSequenceRequest.newBuilder().setSequence(STANDARD_SEQUENCE).build()); | ||
|
|
||
| // 3. Trigger the sequence attempts using the retrying client | ||
| retryClient.attemptSequence( | ||
| AttemptSequenceRequest.newBuilder().setName(createdSequence.getName()).build()); | ||
|
|
||
| // 4. Retrieve the sequence report to inspect delay measurements | ||
| SequenceReport report = | ||
| grpcClient.getSequenceReport( | ||
| GetSequenceReportRequest.newBuilder() | ||
| .setName(createdSequence.getName() + "/sequenceReport") | ||
| .build()); | ||
|
|
||
| // 5. Assert attempts count and delays | ||
| verifySequenceReport(report); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("deprecation") | ||
| void testHttpJson_retryExponentialBackoff() throws Exception { | ||
| // Create a custom client with these retry settings on attemptSequence | ||
| try (SequenceServiceClient retryClient = | ||
| TestClientInitializer.createHttpJsonSequenceClientWithRetrySettings( | ||
| STANDARD_RETRY_SETTINGS, ImmutableSet.of(StatusCode.Code.UNAVAILABLE))) { | ||
|
|
||
| Sequence createdSequence = | ||
| httpjsonClient.createSequence( | ||
| CreateSequenceRequest.newBuilder().setSequence(STANDARD_SEQUENCE).build()); | ||
|
|
||
| // 3. Trigger the sequence attempts using the retrying client | ||
| retryClient.attemptSequence( | ||
| AttemptSequenceRequest.newBuilder().setName(createdSequence.getName()).build()); | ||
|
|
||
| // 4. Retrieve the sequence report to inspect delay measurements | ||
| SequenceReport report = | ||
| httpjsonClient.getSequenceReport( | ||
| GetSequenceReportRequest.newBuilder() | ||
| .setName(createdSequence.getName() + "/sequenceReport") | ||
| .build()); | ||
|
|
||
| // 5. Assert attempts count and delays | ||
| verifySequenceReport(report); | ||
| } | ||
| } | ||
|
|
||
| private void verifySequenceReport(SequenceReport report) { | ||
| List<SequenceReport.Attempt> attempts = report.getAttemptsList(); | ||
| assertThat(attempts).hasSize(4); | ||
|
|
||
| // Verify the status of each attempt | ||
| assertThat(attempts.get(0).getStatus().getCode()) | ||
| .isEqualTo(com.google.rpc.Code.UNAVAILABLE.getNumber()); | ||
| assertThat(attempts.get(1).getStatus().getCode()) | ||
| .isEqualTo(com.google.rpc.Code.UNAVAILABLE.getNumber()); | ||
| assertThat(attempts.get(2).getStatus().getCode()) | ||
| .isEqualTo(com.google.rpc.Code.UNAVAILABLE.getNumber()); | ||
| assertThat(attempts.get(3).getStatus().getCode()).isEqualTo(com.google.rpc.Code.OK.getNumber()); | ||
|
|
||
| // Verify delay intervals are within expected tolerances: | ||
| // Attempt 1 -> 2: ~100ms delay. Range [80ms, 250ms] | ||
| long delay1 = getDelayMs(attempts.get(1)); | ||
| assertThat(delay1).isAtLeast(80L); | ||
| assertThat(delay1).isLessThan(250L); | ||
|
|
||
| // Attempt 2 -> 3: ~200ms delay. Range [180ms, 400ms] | ||
| long delay2 = getDelayMs(attempts.get(2)); | ||
| assertThat(delay2).isAtLeast(180L); | ||
| assertThat(delay2).isLessThan(400L); | ||
|
|
||
| // Attempt 3 -> 4: ~400ms delay. Range [380ms, 700ms] | ||
| long delay3 = getDelayMs(attempts.get(3)); | ||
| assertThat(delay3).isAtLeast(380L); | ||
| assertThat(delay3).isLessThan(700L); | ||
| } | ||
|
|
||
| private long getDelayMs(SequenceReport.Attempt attempt) { | ||
| com.google.protobuf.Duration attemptDelay = attempt.getAttemptDelay(); | ||
| return attemptDelay.getSeconds() * 1000 + attemptDelay.getNanos() / 1_000_000; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.