Skip to content
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

fix: use millis to prevent rounding errors #260

Merged
merged 1 commit into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -63,7 +63,7 @@ static <T> T runTxWithRetriesOnAborted(Callable<T> callable) {
static <T> T runTxWithRetriesOnAborted(Callable<T> callable, RetrySettings retrySettings) {
try {
return RetryHelper.runWithRetries(
callable, txRetrySettings, new TxRetryAlgorithm<>(), NanoClock.getDefaultClock());
callable, retrySettings, new TxRetryAlgorithm<>(), NanoClock.getDefaultClock());
} catch (RetryHelperException e) {
if (e.getCause() != null) {
Throwables.throwIfUnchecked(e.getCause());
Expand Down
Expand Up @@ -188,13 +188,18 @@ public Integer call() throws Exception {

@Test
public void testExceptionWithRetryInfo() {
final int RETRY_DELAY_NANOS = 100_000_000;
final int RETRY_DELAY_MILLIS = 100;
Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
Metadata trailers = new Metadata();
RetryInfo retryInfo =
RetryInfo.newBuilder()
.setRetryDelay(Duration.newBuilder().setNanos(RETRY_DELAY_NANOS).build())
.setRetryDelay(
Duration.newBuilder()
.setNanos(
(int)
TimeUnit.NANOSECONDS.convert(RETRY_DELAY_MILLIS, TimeUnit.MILLISECONDS))
.build())
.build();
trailers.put(key, retryInfo);
final SpannerException e =
Expand All @@ -214,8 +219,8 @@ public Integer call() throws Exception {
// retry info of the exception.
Stopwatch watch = Stopwatch.createStarted();
assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable)).isEqualTo(2);
long elapsed = watch.elapsed(TimeUnit.NANOSECONDS);
assertThat(elapsed >= RETRY_DELAY_NANOS).isTrue();
long elapsed = watch.elapsed(TimeUnit.MILLISECONDS);
assertThat(elapsed >= RETRY_DELAY_MILLIS).isTrue();
}

private SpannerException abortedWithRetryInfo(int nanos) {
Expand Down