Skip to content

Commit 2968790

Browse files
committed
test: update ITBlobDescriptorFakeTest to account for new backoff handling and messages
Update FakeServer retry config to be shorter. We're running against an in process server, and don't need prod system level backoffs.
1 parent a4d919e commit 2968790

3 files changed

Lines changed: 63 additions & 22 deletions

File tree

google-cloud-storage/src/test/java/com/google/cloud/storage/FakeServer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.storage;
1818

19+
import com.google.api.gax.retrying.RetrySettings;
1920
import com.google.cloud.NoCredentials;
2021
import com.google.cloud.storage.it.GrpcPlainRequestLoggingInterceptor;
2122
import com.google.storage.v2.StorageGrpc;
@@ -24,6 +25,7 @@
2425
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
2526
import java.io.IOException;
2627
import java.net.InetSocketAddress;
28+
import java.time.Duration;
2729
import java.util.Locale;
2830
import java.util.concurrent.TimeUnit;
2931

@@ -63,6 +65,18 @@ static FakeServer of(StorageGrpc.StorageImplBase service) throws IOException {
6365
.setGrpcInterceptorProvider(GrpcPlainRequestLoggingInterceptor.getInterceptorProvider())
6466
.setEnableGrpcClientMetrics(false)
6567
.setAttemptDirectPath(false)
68+
// cut most retry settings by half. we're hitting an in process server.
69+
.setRetrySettings(
70+
RetrySettings.newBuilder()
71+
.setTotalTimeoutDuration(Duration.ofSeconds(25))
72+
.setInitialRetryDelayDuration(Duration.ofMillis(250))
73+
.setRetryDelayMultiplier(1.2)
74+
.setMaxRetryDelayDuration(Duration.ofSeconds(16))
75+
.setMaxAttempts(6)
76+
.setInitialRpcTimeoutDuration(Duration.ofSeconds(25))
77+
.setRpcTimeoutMultiplier(1.0)
78+
.setMaxRpcTimeoutDuration(Duration.ofSeconds(25))
79+
.build())
6680
.build();
6781
return new FakeServer(server, grpcStorageOptions);
6882
}

google-cloud-storage/src/test/java/com/google/cloud/storage/ITBlobDescriptorFakeTest.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.google.api.core.ApiFuture;
2626
import com.google.api.gax.retrying.RetrySettings;
2727
import com.google.api.gax.rpc.AbortedException;
28-
import com.google.api.gax.rpc.ApiExceptions;
2928
import com.google.api.gax.rpc.DataLossException;
3029
import com.google.api.gax.rpc.OutOfRangeException;
3130
import com.google.api.gax.rpc.UnavailableException;
@@ -58,7 +57,6 @@
5857
import io.grpc.stub.StreamObserver;
5958
import java.nio.ByteBuffer;
6059
import java.util.Arrays;
61-
import java.util.List;
6260
import java.util.Map;
6361
import java.util.UUID;
6462
import java.util.concurrent.ExecutionException;
@@ -332,7 +330,6 @@ public void bidiReadObjectError() throws Exception {
332330
BidiReadObjectRequest req2 = read(1, 10, 10);
333331
BidiReadObjectResponse res2 =
334332
BidiReadObjectResponse.newBuilder()
335-
.setMetadata(METADATA)
336333
.addObjectDataRanges(
337334
ObjectRangeData.newBuilder()
338335
.setChecksummedData(content2.asChecksummedData())
@@ -383,7 +380,7 @@ public void bidiReadObjectError() throws Exception {
383380
com.google.rpc.Status grpcStatusDetails =
384381
com.google.rpc.Status.newBuilder()
385382
.setCode(com.google.rpc.Code.UNAVAILABLE_VALUE)
386-
.setMessage("redirect")
383+
.setMessage("fail read_id: 1")
387384
.addDetails(Any.pack(err2))
388385
.build();
389386

@@ -625,18 +622,25 @@ public void onNext(BidiReadObjectRequest request) {
625622

626623
DataLossException dataLossException =
627624
assertThrows(
628-
DataLossException.class, () -> ApiExceptions.callAndTranslateApiException(future));
625+
DataLossException.class, () -> TestUtils.await(future, 5, TimeUnit.SECONDS));
629626

630627
assertThat(dataLossException).isInstanceOf(UncheckedChecksumMismatchException.class);
631628
Throwable[] suppressed = dataLossException.getSuppressed();
632-
List<String> suppressedMessages =
633-
Arrays.stream(suppressed).map(Throwable::getMessage).collect(Collectors.toList());
634-
assertThat(suppressedMessages)
635-
.containsExactly(
636-
"Operation failed to complete within retry limit (attempts: 3, maxAttempts: 3) previous failures follow in order of occurrence",
637-
"Mismatch checksum value. Expected crc32c{0x00000001} actual crc32c{0xe16dcdee}",
638-
"Mismatch checksum value. Expected crc32c{0x00000002} actual crc32c{0xe16dcdee}",
639-
"Asynchronous task failed");
629+
String suppressedMessages =
630+
Arrays.stream(suppressed).map(Throwable::getMessage).collect(Collectors.joining("\n"));
631+
assertAll(
632+
() ->
633+
assertThat(suppressedMessages)
634+
.contains("Operation failed to complete within attempt budget"),
635+
() ->
636+
assertThat(suppressedMessages)
637+
.contains(
638+
"Mismatch checksum value. Expected crc32c{0x00000001} actual crc32c{0xe16dcdee}"),
639+
() ->
640+
assertThat(suppressedMessages)
641+
.contains(
642+
"Mismatch checksum value. Expected crc32c{0x00000002} actual crc32c{0xe16dcdee}"),
643+
() -> assertThat(suppressedMessages).contains("Asynchronous task failed"));
640644
}
641645
}
642646
}
@@ -692,18 +696,20 @@ public void retrySettingsApplicable_objectRangeData_offset_notAligned_gt() throw
692696

693697
OutOfRangeException outOfRangeException =
694698
assertThrows(
695-
OutOfRangeException.class,
696-
() -> ApiExceptions.callAndTranslateApiException(future));
699+
OutOfRangeException.class, () -> TestUtils.await(future, 5, TimeUnit.SECONDS));
697700

698701
assertThat(outOfRangeException).isInstanceOf(OutOfRangeException.class);
699702
Throwable[] suppressed = outOfRangeException.getSuppressed();
700-
List<String> suppressedMessages =
701-
Arrays.stream(suppressed).map(Throwable::getMessage).collect(Collectors.toList());
702-
assertThat(suppressedMessages)
703-
.containsExactly(
704-
"Operation failed to complete within retry limit (attempts: 2, maxAttempts: 2) previous failures follow in order of occurrence",
705-
"position = 10, readRange.read_offset = 11",
706-
"Asynchronous task failed");
703+
String suppressedMessages =
704+
Arrays.stream(suppressed).map(Throwable::getMessage).collect(Collectors.joining("\n"));
705+
assertAll(
706+
() ->
707+
assertThat(suppressedMessages)
708+
.contains("Operation failed to complete within attempt budget"),
709+
() ->
710+
assertThat(suppressedMessages)
711+
.contains("position = 10, readRange.read_offset = 11"),
712+
() -> assertThat(suppressedMessages).contains("Asynchronous task failed"));
707713
}
708714
}
709715
}

google-cloud-storage/src/test/java/com/google/cloud/storage/TestUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static java.util.Objects.requireNonNull;
2020

21+
import com.google.api.core.ApiFuture;
2122
import com.google.api.core.NanoClock;
2223
import com.google.api.gax.grpc.GrpcStatusCode;
2324
import com.google.api.gax.retrying.BasicResultRetryAlgorithm;
@@ -32,6 +33,7 @@
3233
import com.google.common.collect.ImmutableList;
3334
import com.google.common.collect.ImmutableSet;
3435
import com.google.common.io.Files;
36+
import com.google.common.util.concurrent.UncheckedExecutionException;
3537
import com.google.protobuf.Any;
3638
import com.google.protobuf.ByteString;
3739
import com.google.rpc.DebugInfo;
@@ -56,6 +58,9 @@
5658
import java.util.Objects;
5759
import java.util.Optional;
5860
import java.util.concurrent.Callable;
61+
import java.util.concurrent.ExecutionException;
62+
import java.util.concurrent.TimeUnit;
63+
import java.util.concurrent.TimeoutException;
5964
import java.util.function.Function;
6065
import java.util.stream.Collectors;
6166
import java.util.stream.IntStream;
@@ -313,6 +318,22 @@ static String messagesToText(Throwable t) {
313318
return messagesToText(t, "");
314319
}
315320

321+
static <T> T await(ApiFuture<T> future, long timeout, TimeUnit unit) throws TimeoutException {
322+
try {
323+
return future.get(timeout, unit);
324+
} catch (ExecutionException exception) {
325+
if (exception.getCause() instanceof RuntimeException) {
326+
RuntimeException cause = (RuntimeException) exception.getCause();
327+
cause.addSuppressed(new AsyncStorageTaskException());
328+
throw cause;
329+
}
330+
throw new UncheckedExecutionException(exception);
331+
} catch (InterruptedException e) {
332+
Thread.currentThread().interrupt();
333+
throw new RuntimeException(e);
334+
}
335+
}
336+
316337
private static String messagesToText(Throwable t, String indent) {
317338
if (t == null) {
318339
return "";

0 commit comments

Comments
 (0)