Skip to content

Commit

Permalink
test: add integration to verify behavior of reader with effective len…
Browse files Browse the repository at this point in the history
…gth <= 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.
  • Loading branch information
BenWhitehead committed Apr 25, 2023
1 parent e36f8f1 commit 46c926e
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 46c926e

Please sign in to comment.