Skip to content

Commit 6364aab

Browse files
committed
add retrial exhaustion check
1 parent 9ab23d5 commit 6364aab

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/RetryingTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class RetryingTest {
9797
private AtomicInteger tracerAttempts;
9898
private AtomicInteger tracerAttemptsFailed;
9999
private AtomicBoolean tracerOperationFailed;
100+
private AtomicBoolean tracerFailedRetriesExhausted;
101+
100102
private RecordingScheduler executor;
101103
private FakeApiClock fakeClock;
102104
private ClientContext clientContext;
@@ -125,6 +127,7 @@ void resetClock() {
125127
tracerAttempts = new AtomicInteger();
126128
tracerAttemptsFailed = new AtomicInteger();
127129
tracerOperationFailed = new AtomicBoolean(false);
130+
tracerFailedRetriesExhausted = new AtomicBoolean(false);
128131
fakeClock = new FakeApiClock(System.nanoTime());
129132
executor = RecordingScheduler.create(fakeClock);
130133
clientContext =
@@ -161,6 +164,7 @@ void retry() {
161164
assertThat(tracerAttemptsFailed.get()).isEqualTo(3);
162165
assertThat(tracerAttempts.get()).isEqualTo(4);
163166
assertThat(tracerOperationFailed.get()).isEqualTo(false);
167+
assertThat(tracerFailedRetriesExhausted.get()).isEqualTo(false);
164168

165169
// Capture the argument passed to futureCall
166170
ArgumentCaptor<Integer> argumentCaptor = ArgumentCaptor.forClass(Integer.class);
@@ -223,7 +227,7 @@ void retryMaxAttemptsExceeded() {
223227
assertThrows(ApiException.class, () -> callable.call(initialRequest));
224228
assertThat(tracerAttempts.get()).isEqualTo(2);
225229
assertThat(tracerAttemptsFailed.get()).isEqualTo(1);
226-
assertThat(tracerOperationFailed.get()).isEqualTo(true);
230+
assertThat(tracerFailedRetriesExhausted.get()).isEqualTo(true);
227231
// Capture the argument passed to futureCall
228232
ArgumentCaptor<Integer> argumentCaptor = ArgumentCaptor.forClass(Integer.class);
229233
verify(callInt, atLeastOnce()).futureCall(argumentCaptor.capture(), any(ApiCallContext.class));
@@ -362,7 +366,7 @@ void retryKeepFailing() {
362366
// attempts and that the operation was considered as failed.
363367
assertThat(tracerAttemptsFailed.get()).isGreaterThan(0);
364368
assertThat(tracerAttemptsFailed.get()).isEqualTo(tracerAttempts.get() - 1);
365-
assertThat(tracerOperationFailed.get()).isEqualTo(true);
369+
assertThat(tracerFailedRetriesExhausted.get()).isEqualTo(true);
366370
assertThat(exception).hasCauseThat().isInstanceOf(ApiException.class);
367371
assertThat(exception).hasCauseThat().hasMessageThat().contains("Unavailable");
368372
// Capture the argument passed to futureCall
@@ -467,6 +471,12 @@ public void operationFailed(Throwable error) {
467471
tracerOperationFailed.set(true);
468472
super.operationFailed(error);
469473
}
474+
475+
@Override
476+
public void attemptFailedRetriesExhausted(Throwable error) {
477+
tracerFailedRetriesExhausted.set(true);
478+
super.attemptFailedRetriesExhausted(error);
479+
}
470480
};
471481
ApiTracerFactory tracerFactory = (parent, spanName, operationType) -> tracer;
472482
return tracerFactory;

0 commit comments

Comments
 (0)