| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -110,51 +110,6 @@ public void emptyObjectHappyPath() throws Exception { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * <h4>S.9</h4> | ||
| * | ||
| * Partial successful append to session | ||
| * | ||
| * <p>The client has sent N bytes, the server confirmed N bytes as committed. The client sends K | ||
| * bytes starting at offset N. The server responds with only N + L with 0 <= L < K bytes as | ||
| * committed. | ||
| */ | ||
| @Test | ||
| public void scenario9() throws Exception { | ||
|
Comment thread
Copy link
Copy Markdown
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis test would verify that GCS ack'ing fewer bytes than were sent was correctly categorized as a failure scenario, however as we are now gracefully handling the partial write case. We no longer need this test for failure categorization.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| HttpRequestHandler handler = | ||
| req -> { | ||
| String contentRangeString = req.headers().get(CONTENT_RANGE); | ||
| HttpContentRange parse = HttpContentRange.parse(contentRangeString); | ||
| long endInclusive = ((HttpContentRange.HasRange<?>) parse).range().endOffsetInclusive(); | ||
| FullHttpResponse resp = | ||
| new DefaultFullHttpResponse(req.protocolVersion(), RESUME_INCOMPLETE); | ||
| ByteRangeSpec range = ByteRangeSpec.explicitClosed(0L, endInclusive - 1); | ||
| resp.headers().set(HttpHeaderNames.RANGE, range.getHttpRangeHeader()); | ||
| return resp; | ||
| }; | ||
|
|
||
| try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { | ||
| URI endpoint = fakeHttpServer.getEndpoint(); | ||
| String uploadUrl = String.format("%s/upload/%s", endpoint.toString(), UUID.randomUUID()); | ||
|
|
||
| AtomicLong confirmedBytes = new AtomicLong(-1L); | ||
|
|
||
| JsonResumableSessionPutTask task = | ||
| new JsonResumableSessionPutTask( | ||
| httpClientContext, | ||
| uploadUrl, | ||
| RewindableContent.empty(), | ||
| HttpContentRange.of(ByteRangeSpec.explicitClosed(0L, 10L))); | ||
|
|
||
| StorageException se = assertThrows(StorageException.class, task::call); | ||
| assertThat(se.getCode()).isEqualTo(503); | ||
| assertThat(confirmedBytes.get()).isEqualTo(-1L); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| import com.google.api.core.ApiFutures; | ||
| import com.google.api.services.storage.model.StorageObject; | ||
| import com.google.cloud.storage.ITUnbufferedResumableUploadTest.ObjectSizes; | ||
| import com.google.cloud.storage.TransportCompatibility.Transport; | ||
| import com.google.cloud.storage.UnbufferedWritableByteChannelSession.UnbufferedWritableByteChannel; | ||
| import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt; | ||
| import com.google.cloud.storage.UnifiedOpts.Opts; | ||
| import com.google.cloud.storage.it.runner.StorageITRunner; | ||
| import com.google.cloud.storage.it.runner.annotations.Backend; | ||
| import com.google.cloud.storage.it.runner.annotations.CrossRun; | ||
| import com.google.cloud.storage.it.runner.annotations.CrossRun.Exclude; | ||
| import com.google.cloud.storage.it.runner.annotations.Inject; | ||
| import com.google.cloud.storage.it.runner.annotations.Parameterized; | ||
| import com.google.cloud.storage.it.runner.annotations.Parameterized.Parameter; | ||
| import com.google.cloud.storage.it.runner.annotations.Parameterized.ParametersProvider; | ||
| import com.google.cloud.storage.it.runner.registry.Generator; | ||
| import com.google.cloud.storage.spi.v1.StorageRpc; | ||
| import com.google.common.collect.ImmutableList; | ||
| import java.io.IOException; | ||
| import java.math.BigInteger; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.TimeoutException; | ||
| import java.util.function.Supplier; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(StorageITRunner.class) | ||
| @CrossRun( | ||
| backends = {Backend.PROD}, | ||
| transports = {Transport.HTTP, Transport.GRPC}) | ||
| @Parameterized(ObjectSizes.class) | ||
| public final class ITUnbufferedResumableUploadTest { | ||
|
|
||
| @Inject public Storage storage; | ||
| @Inject public BucketInfo bucket; | ||
| @Inject public Generator generator; | ||
|
|
||
| @Parameter public int objectSize; | ||
|
|
||
| public static final class ObjectSizes implements ParametersProvider { | ||
|
|
||
| @Override | ||
| public ImmutableList<Integer> parameters() { | ||
| return ImmutableList.of(256 * 1024, 2 * 1024 * 1024); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Exclude(transports = Transport.GRPC) | ||
| public void json() | ||
| throws IOException, ExecutionException, InterruptedException, TimeoutException { | ||
| BlobInfo blobInfo = BlobInfo.newBuilder(bucket, generator.randomObjectName()).build(); | ||
| Opts<ObjectTargetOpt> opts = Opts.empty(); | ||
| final Map<StorageRpc.Option, ?> optionsMap = opts.getRpcOptions(); | ||
| BlobInfo.Builder builder = blobInfo.toBuilder().setMd5(null).setCrc32c(null); | ||
| BlobInfo updated = opts.blobInfoMapper().apply(builder).build(); | ||
|
|
||
| StorageObject encode = Conversions.json().blobInfo().encode(updated); | ||
| HttpStorageOptions options = (HttpStorageOptions) storage.getOptions(); | ||
| Supplier<String> uploadIdSupplier = | ||
| ResumableMedia.startUploadForBlobInfo( | ||
| options, | ||
| updated, | ||
| optionsMap, | ||
| StorageRetryStrategy.getUniformStorageRetryStrategy().getIdempotentHandler()); | ||
| JsonResumableWrite jsonResumableWrite = | ||
| JsonResumableWrite.of(encode, optionsMap, uploadIdSupplier.get(), 0); | ||
|
|
||
| UnbufferedWritableByteChannelSession<StorageObject> session = | ||
| ResumableMedia.http() | ||
| .write() | ||
| .byteChannel(HttpClientContext.from(options.getStorageRpcV1())) | ||
| .resumable() | ||
| .unbuffered() | ||
| .setStartAsync(ApiFutures.immediateFuture(jsonResumableWrite)) | ||
| .build(); | ||
|
|
||
| int additional = 13; | ||
| long size = objectSize + additional; | ||
| ByteBuffer b = DataGenerator.base64Characters().genByteBuffer(size); | ||
|
|
||
| UnbufferedWritableByteChannel open = session.open(); | ||
| int written = open.write(b); | ||
| assertThat(written).isEqualTo(objectSize); | ||
| assertThat(b.remaining()).isEqualTo(additional); | ||
|
|
||
| int writtenAndClose = open.writeAndClose(b); | ||
| assertThat(writtenAndClose).isEqualTo(additional); | ||
|
Comment thread
BenWhitehead marked this conversation as resolved.
|
||
| open.close(); | ||
|
|
||
| StorageObject storageObject = session.getResult().get(2, TimeUnit.SECONDS); | ||
| assertThat(storageObject.getSize()).isEqualTo(BigInteger.valueOf(size)); | ||
| } | ||
| } | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.