Skip to content
New issue

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

test: add integration test to verify behavior of reader with effective length <= 0 #1988

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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