From edc5bbf0d9d4faf48fd9a8d479d5bc5de938c82d Mon Sep 17 00:00:00 2001 From: Arpan Mishra Date: Mon, 6 Feb 2023 13:29:38 +0530 Subject: [PATCH 1/4] fix: prevent illegal negative timeout values into thread sleep() method while retrying exceptions in unit tests. * For details on issue see - https://github.com/googleapis/java-spanner/issues/2206 --- .../com/google/cloud/spanner/it/ITClosedSessionTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java index aeb0256285b..227611a10de 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java @@ -251,7 +251,10 @@ public void testTransactionManager() throws InterruptedException { break; } } catch (AbortedException e) { - Thread.sleep(e.getRetryDelayInMillis()); + long retryDelayInMillis = e.getRetryDelayInMillis(); + if(retryDelayInMillis > 0) { + Thread.sleep(retryDelayInMillis); + } txn = manager.resetForRetry(); } } From 4cd497b05eab3e3b6b89b582bfafde80d42c1518 Mon Sep 17 00:00:00 2001 From: Arpan Mishra Date: Wed, 8 Feb 2023 15:27:18 +0530 Subject: [PATCH 2/4] Fixing lint issues. --- .../java/com/google/cloud/spanner/it/ITClosedSessionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java index 227611a10de..efbffcfa899 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITClosedSessionTest.java @@ -252,7 +252,7 @@ public void testTransactionManager() throws InterruptedException { } } catch (AbortedException e) { long retryDelayInMillis = e.getRetryDelayInMillis(); - if(retryDelayInMillis > 0) { + if (retryDelayInMillis > 0) { Thread.sleep(retryDelayInMillis); } txn = manager.resetForRetry(); From 991f930896f737d53327755ff400158f87b1c087 Mon Sep 17 00:00:00 2001 From: Arpan Mishra Date: Fri, 23 Feb 2024 18:39:59 +0530 Subject: [PATCH 3/4] fix: flaky test issue due to AbortedException. --- .../java/com/google/cloud/spanner/it/ITTransactionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java index 2cfb9cbbc5b..575f834ede1 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java @@ -298,7 +298,7 @@ public void readAbort() throws Exception { } catch (SpannerException e) { if (e.getErrorCode() == ErrorCode.ABORTED) { assertThat(e).isInstanceOf(AbortedException.class); - assertThat(e.getRetryDelayInMillis()).isNotEqualTo(-1L); + assertThat(e.getRetryDelayInMillis()).isEqualTo(-1L); } throw new RuntimeException("Swallowed exception: " + e.getMessage()); } @@ -338,7 +338,7 @@ public void readAbort() throws Exception { } catch (SpannerException e) { if (e.getErrorCode() == ErrorCode.ABORTED) { assertThat(e).isInstanceOf(AbortedException.class); - assertThat(e.getRetryDelayInMillis()).isNotEqualTo(-1L); + assertThat(e.getRetryDelayInMillis()).isEqualTo(-1L); } throw new RuntimeException("Swallowed exception: " + e.getMessage()); } From 953958a7784532b7aeb89113bf377de810f3d56c Mon Sep 17 00:00:00 2001 From: Arpan Mishra Date: Fri, 23 Feb 2024 18:44:11 +0530 Subject: [PATCH 4/4] chore: remove assertion. --- .../java/com/google/cloud/spanner/it/ITTransactionTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java index 575f834ede1..ea60b9fb649 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java @@ -298,7 +298,6 @@ public void readAbort() throws Exception { } catch (SpannerException e) { if (e.getErrorCode() == ErrorCode.ABORTED) { assertThat(e).isInstanceOf(AbortedException.class); - assertThat(e.getRetryDelayInMillis()).isEqualTo(-1L); } throw new RuntimeException("Swallowed exception: " + e.getMessage()); } @@ -338,7 +337,6 @@ public void readAbort() throws Exception { } catch (SpannerException e) { if (e.getErrorCode() == ErrorCode.ABORTED) { assertThat(e).isInstanceOf(AbortedException.class); - assertThat(e.getRetryDelayInMillis()).isEqualTo(-1L); } throw new RuntimeException("Swallowed exception: " + e.getMessage()); }