From abc3766a833b171b683127850d4976ce0b0c71be Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 6 Aug 2024 16:23:21 -0400 Subject: [PATCH 1/4] fix: adapt to introduction of java.time in gax --- .../com/google/cloud/spanner/CompositeTracer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java index 07d1310e91b..0aff4a87dcf 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java @@ -16,6 +16,8 @@ package com.google.cloud.spanner; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.InternalApi; import com.google.api.gax.tracing.ApiTracer; import com.google.api.gax.tracing.BaseApiTracer; @@ -23,7 +25,6 @@ import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; -import org.threeten.bp.Duration; @InternalApi public class CompositeTracer extends BaseApiTracer { @@ -108,9 +109,14 @@ public void attemptCancelled() { } @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailedDuration(error, toJavaTimeDuration(delay)); + } + + @Override + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { for (ApiTracer child : children) { - child.attemptFailed(error, delay); + child.attemptFailedDuration(error, delay); } } From afeb16c3f25ae6193b3acc326d0afd5361602c84 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 6 Aug 2024 16:45:44 -0400 Subject: [PATCH 2/4] chore: fix duplicate method --- .../java/com/google/cloud/spanner/CompositeTracer.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java index 0aff4a87dcf..318fdce26d4 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java @@ -120,13 +120,6 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) { } } - @Override - public void attemptFailedDuration(Throwable error, java.time.Duration delay) { - for (ApiTracer child : children) { - child.attemptFailedDuration(error, delay); - } - } - @Override public void attemptFailedRetriesExhausted(Throwable error) { for (ApiTracer child : children) { From 09df44be466a6b983f09423f125554014abc7e1f Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 6 Aug 2024 17:03:10 -0400 Subject: [PATCH 3/4] chore: Update failing spanner test --- .../cloud/spanner/CompositeTracerTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java index dfb7b252268..ec85f3532b8 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java @@ -16,6 +16,7 @@ package com.google.cloud.spanner; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -149,12 +150,17 @@ public void testAttemptCancelled() { @Test public void testAttemptFailed() { RuntimeException error = new RuntimeException(); - Duration delay = Duration.ofMillis(10); + Duration delay = org.threeten.bp.Duration.ofMillis(10); compositeTracer.attemptFailed(error, delay); - verify(child1, times(1)).attemptFailed(error, delay); - verify(child2, times(1)).attemptFailed(error, delay); - verify(child3, times(1)).attemptFailed(error, delay); - verify(child4, times(1)).attemptFailed(error, delay); + + // CompositeTracer's attemptFailed calls the attemptFailedDuration method. This was part of + // the java.time migration effort to move away from threetenbp. Verify that each child tracer + // calls attemptFailedDuration once. + java.time.Duration delayDuration = toJavaTimeDuration(delay); + verify(child1, times(1)).attemptFailedDuration(error, delayDuration); + verify(child2, times(1)).attemptFailedDuration(error, delayDuration); + verify(child3, times(1)).attemptFailedDuration(error, delayDuration); + verify(child4, times(1)).attemptFailedDuration(error, delayDuration); } @Test From 05fc166cd6a82bd23d0e1fcd1b5615beb0199a1d Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 6 Aug 2024 17:04:59 -0400 Subject: [PATCH 4/4] chore: Update failing spanner test --- .../test/java/com/google/cloud/spanner/CompositeTracerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java index ec85f3532b8..e300dd6e793 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/CompositeTracerTest.java @@ -150,7 +150,7 @@ public void testAttemptCancelled() { @Test public void testAttemptFailed() { RuntimeException error = new RuntimeException(); - Duration delay = org.threeten.bp.Duration.ofMillis(10); + Duration delay = Duration.ofMillis(10); compositeTracer.attemptFailed(error, delay); // CompositeTracer's attemptFailed calls the attemptFailedDuration method. This was part of