Skip to content

Commit 140f6c6

Browse files
committed
chore: fix failing tests
1 parent 7b12d01 commit 140f6c6

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
import com.google.api.gax.retrying.ResultRetryAlgorithm;
3434
import com.google.api.services.storage.model.StorageObject;
3535
import com.google.cloud.storage.FakeHttpServer.HttpRequestHandler;
36+
import com.google.cloud.storage.it.ChecksummedTestContent;
3637
import com.google.cloud.storage.it.runner.StorageITRunner;
3738
import com.google.cloud.storage.it.runner.annotations.Backend;
3839
import com.google.cloud.storage.it.runner.annotations.ParallelFriendly;
3940
import com.google.cloud.storage.it.runner.annotations.SingleBackend;
41+
import com.google.common.collect.ImmutableList;
4042
import com.google.common.collect.ImmutableMap;
4143
import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
4244
import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
@@ -791,13 +793,23 @@ public void jsonParseFailure() throws Exception {
791793
}
792794

793795
@Test
794-
public void jsonDeserializationOnlyAttemptedWhenContentPresent() throws Exception {
796+
public void whenContentNotPresentFallBackToHeaders() throws Exception {
795797

798+
ChecksummedTestContent testContent = ChecksummedTestContent.of(new byte[] {'A'});
796799
HttpRequestHandler handler =
797800
req -> {
798801
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(req.protocolVersion(), OK);
799802
resp.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
800-
resp.headers().set("x-goog-stored-content-length", "0");
803+
resp.headers().set("x-goog-generation", "3");
804+
resp.headers().set("x-goog-metageneration", "7");
805+
resp.headers().set("x-goog-stored-content-length", "1");
806+
resp.headers().set("x-goog-stored-content-encoding", "identity");
807+
resp.headers()
808+
.set(
809+
"x-goog-hash",
810+
ImmutableList.of(
811+
"crc32c=" + testContent.getCrc32cBase64(),
812+
"md5=" + testContent.getMd5Base64()));
801813
return resp;
802814
};
803815

@@ -810,13 +822,15 @@ public void jsonDeserializationOnlyAttemptedWhenContentPresent() throws Exceptio
810822
new JsonResumableSessionPutTask(
811823
httpClientContext,
812824
jsonResumableWrite(uploadUrl),
813-
RewindableContent.empty(),
814-
HttpContentRange.of(0));
825+
RewindableContent.of(ByteBuffer.wrap(testContent.getBytes())),
826+
HttpContentRange.of(1));
815827

816828
ResumableOperationResult<@Nullable StorageObject> operationResult = task.call();
817829
StorageObject call = operationResult.getObject();
818-
assertThat(call).isNull();
819-
assertThat(operationResult.getPersistedSize()).isEqualTo(0L);
830+
assertThat(call).isNotNull();
831+
assertThat(call.getCrc32c()).isEqualTo(testContent.getCrc32cBase64());
832+
assertThat(call.getSize()).isEqualTo(BigInteger.ONE);
833+
assertThat(operationResult.getPersistedSize()).isEqualTo(1L);
820834
}
821835
}
822836

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
import com.google.api.client.json.gson.GsonFactory;
2929
import com.google.api.services.storage.model.StorageObject;
3030
import com.google.cloud.storage.FakeHttpServer.HttpRequestHandler;
31+
import com.google.cloud.storage.it.ChecksummedTestContent;
3132
import com.google.cloud.storage.it.runner.StorageITRunner;
3233
import com.google.cloud.storage.it.runner.annotations.Backend;
3334
import com.google.cloud.storage.it.runner.annotations.ParallelFriendly;
3435
import com.google.cloud.storage.it.runner.annotations.SingleBackend;
36+
import com.google.common.collect.ImmutableList;
3537
import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
3638
import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
3739
import io.grpc.netty.shaded.io.netty.handler.codec.http.DefaultFullHttpResponse;
@@ -97,12 +99,23 @@ public void successfulSession() throws Exception {
9799
}
98100

99101
@Test
100-
public void successfulSession_noObject() throws Exception {
102+
public void successfulSession_whenContentNotPresentFallBackToHeaders() throws Exception {
103+
ChecksummedTestContent testContent = ChecksummedTestContent.of(new byte[] {'A'});
101104
HttpRequestHandler handler =
102105
req -> {
103-
DefaultFullHttpResponse response = new DefaultFullHttpResponse(req.protocolVersion(), OK);
104-
response.headers().set("X-Goog-Stored-Content-Length", 0);
105-
return response;
106+
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(req.protocolVersion(), OK);
107+
resp.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
108+
resp.headers().set("x-goog-generation", "3");
109+
resp.headers().set("x-goog-metageneration", "7");
110+
resp.headers().set("x-goog-stored-content-length", "1");
111+
resp.headers().set("x-goog-stored-content-encoding", "identity");
112+
resp.headers()
113+
.set(
114+
"x-goog-hash",
115+
ImmutableList.of(
116+
"crc32c=" + testContent.getCrc32cBase64(),
117+
"md5=" + testContent.getMd5Base64()));
118+
return resp;
106119
};
107120

108121
try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) {
@@ -115,8 +128,10 @@ public void successfulSession_noObject() throws Exception {
115128

116129
ResumableOperationResult<@Nullable StorageObject> result = task.call();
117130
StorageObject object = result.getObject();
118-
assertThat(object).isNull();
119-
assertThat(result.getPersistedSize()).isEqualTo(0L);
131+
assertThat(object).isNotNull();
132+
assertThat(object.getCrc32c()).isEqualTo(testContent.getCrc32cBase64());
133+
assertThat(object.getSize()).isEqualTo(BigInteger.ONE);
134+
assertThat(result.getPersistedSize()).isEqualTo(1L);
120135
}
121136
}
122137

0 commit comments

Comments
 (0)