Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import com.google.api.core.ApiClock;
import com.google.api.core.ApiFuture;
import com.google.api.core.NanoClock;
import com.google.api.gax.retrying.FailingCallable.CustomException;
Expand Down Expand Up @@ -102,6 +103,10 @@ protected abstract RetryingExecutorWithContext<String> getExecutor(
protected abstract RetryAlgorithm<String> getAlgorithm(
RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException);

protected ApiClock getClock() {
return NanoClock.getDefaultClock();
}

protected <T> void busyWaitForInitialResult(RetryingFuture<T> future, java.time.Duration timeout)
throws TimeoutException {
Stopwatch watch = Stopwatch.createStarted();
Expand Down Expand Up @@ -356,7 +361,7 @@ void testPollExceptionByPollAlgorithm(boolean withCustomRetrySettings) throws Ex
useContextRetrySettings
? withCustomRetrySettings ? FAILING_RETRY_SETTINGS : FAST_RETRY_SETTINGS
: retrySettings,
NanoClock.getDefaultClock()));
getClock()));

RetryingExecutorWithContext<String> executor = getExecutor(retryAlgorithm);
FailingCallable callable = new FailingCallable(6, "request", "FAILURE", tracer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,41 @@
*/
package com.google.api.gax.retrying;

import com.google.api.core.CurrentMillisClock;
import com.google.api.core.ApiClock;
import com.google.api.gax.core.FakeApiClock;
import java.time.Duration;

class DirectRetryingExecutorTest extends AbstractRetryingExecutorTest {

// ExponentialRetryAlgorithm and ExponentialPollAlgorithm only compute relative elapsed time
// deltas against firstAttemptStartTimeNanos (clock.nanoTime() - firstAttemptStartTimeNanos)
// and never treat 0L as a special sentinel value.
private final FakeApiClock clock = new FakeApiClock(0L);
Comment thread
lqiu96 marked this conversation as resolved.

@Override
protected ApiClock getClock() {
return clock;
}

@Override
protected RetryingExecutorWithContext<String> getExecutor(RetryAlgorithm<String> retryAlgorithm) {
return new DirectRetryingExecutor<>(retryAlgorithm);
return new DirectRetryingExecutor<String>(retryAlgorithm) {
// Advance the fake clock instead of sleeping the current thread so that retry delays
// are simulated deterministically without wall-clock pauses on slow CI VMs.
@Override
protected void sleep(Duration delay) {
if (!delay.isZero() && !delay.isNegative()) {
clock.incrementNanoTime(delay.toNanos());
}
}
};
}

@Override
protected RetryAlgorithm<String> getAlgorithm(
RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException) {
return new RetryAlgorithm<>(
new TestResultRetryAlgorithm<String>(apocalypseCountDown, apocalypseException),
new ExponentialRetryAlgorithm(retrySettings, CurrentMillisClock.getDefaultClock()));
new ExponentialRetryAlgorithm(retrySettings, clock));
}
}
Loading