Skip to content
Permalink
Browse files
fix: use millis to prevent rounding errors (#260)
  • Loading branch information
olavloite committed Jun 11, 2020
1 parent 3a7a8ad commit 22ed45816098f5e50104935b66bc55297ea7f7b7
@@ -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());
@@ -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 =
@@ -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) {

0 comments on commit 22ed458

Please sign in to comment.