Skip to content

Commit 22ed458

Browse files
authored
fix: use millis to prevent rounding errors (#260)
1 parent 3a7a8ad commit 22ed458

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerRetryHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static <T> T runTxWithRetriesOnAborted(Callable<T> callable) {
6363
static <T> T runTxWithRetriesOnAborted(Callable<T> callable, RetrySettings retrySettings) {
6464
try {
6565
return RetryHelper.runWithRetries(
66-
callable, txRetrySettings, new TxRetryAlgorithm<>(), NanoClock.getDefaultClock());
66+
callable, retrySettings, new TxRetryAlgorithm<>(), NanoClock.getDefaultClock());
6767
} catch (RetryHelperException e) {
6868
if (e.getCause() != null) {
6969
Throwables.throwIfUnchecked(e.getCause());

google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerRetryHelperTest.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,18 @@ public Integer call() throws Exception {
188188

189189
@Test
190190
public void testExceptionWithRetryInfo() {
191-
final int RETRY_DELAY_NANOS = 100_000_000;
191+
final int RETRY_DELAY_MILLIS = 100;
192192
Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
193193
Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
194194
Metadata trailers = new Metadata();
195195
RetryInfo retryInfo =
196196
RetryInfo.newBuilder()
197-
.setRetryDelay(Duration.newBuilder().setNanos(RETRY_DELAY_NANOS).build())
197+
.setRetryDelay(
198+
Duration.newBuilder()
199+
.setNanos(
200+
(int)
201+
TimeUnit.NANOSECONDS.convert(RETRY_DELAY_MILLIS, TimeUnit.MILLISECONDS))
202+
.build())
198203
.build();
199204
trailers.put(key, retryInfo);
200205
final SpannerException e =
@@ -214,8 +219,8 @@ public Integer call() throws Exception {
214219
// retry info of the exception.
215220
Stopwatch watch = Stopwatch.createStarted();
216221
assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable)).isEqualTo(2);
217-
long elapsed = watch.elapsed(TimeUnit.NANOSECONDS);
218-
assertThat(elapsed >= RETRY_DELAY_NANOS).isTrue();
222+
long elapsed = watch.elapsed(TimeUnit.MILLISECONDS);
223+
assertThat(elapsed >= RETRY_DELAY_MILLIS).isTrue();
219224
}
220225

221226
private SpannerException abortedWithRetryInfo(int nanos) {

0 commit comments

Comments
 (0)