From 46c926e537f387b77a56f9275eb99b4f749ce094 Mon Sep 17 00:00:00 2001 From: BenWhitehead Date: Tue, 25 Apr 2023 14:30:03 -0400 Subject: [PATCH] test: add integration to verify behavior of reader with effective length <= 0 (#1988) StorageReadChannel is able to detect when an effective read length is <= 0 and will return EOF without sending an RPC. If we ever return object metadata along with a read, we will need to amend this behavior so that the metadata can be resolved. --- .../storage/it/ITStorageReadChannelTest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageReadChannelTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageReadChannelTest.java index 317974d47..5c6bb4ef1 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageReadChannelTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageReadChannelTest.java @@ -40,9 +40,14 @@ import com.google.cloud.storage.it.runner.annotations.CrossRun; import com.google.cloud.storage.it.runner.annotations.Inject; import com.google.cloud.storage.it.runner.registry.Generator; +import com.google.cloud.storage.it.runner.registry.ObjectsFixture; +import com.google.common.io.ByteStreams; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; +import java.nio.channels.WritableByteChannel; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -61,6 +66,8 @@ public final class ITStorageReadChannelTest { @Inject public Generator generator; + @Inject public ObjectsFixture objectsFixture; + @Test public void storageReadChannel_getObject_returns() throws Exception { int _512KiB = 512 * 1024; @@ -109,7 +116,6 @@ public void storageReadChannel_getObject_returns() throws Exception { } @Test - // @CrossRun.Exclude(transports = Transport.GRPC) public void storageReadChannel_shouldAllowDisablingBufferingBySettingChunkSize_lteq0() throws IOException { int _512KiB = 512 * 1024; @@ -137,6 +143,21 @@ public void storageReadChannel_shouldAllowDisablingBufferingBySettingChunkSize_l } } + @Test + public void storageReadChannel_attemptToReadZeroBytes() throws IOException { + BlobInfo info1 = objectsFixture.getInfo1(); + try (ReadChannel r = storage.reader(info1.getBlobId()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + WritableByteChannel w = Channels.newChannel(baos)) { + r.setChunkSize(10); + r.seek(10); + r.limit(10); + + ByteStreams.copy(r, w); + assertThat(baos.toByteArray()).isEmpty(); + } + } + @Test public void storageReadChannel_getObject_404() { BlobId id = BlobId.of(bucket.getName(), generator.randomObjectName());