use of com.google.storage.v2.ReadObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class GoogleCloudStorageGrpcReadChannel method requestObjectMedia.
private Iterator<ReadObjectResponse> requestObjectMedia(String objectName, long objectGeneration, long offset, OptionalLong bytesToRead) throws StatusRuntimeException {
ReadObjectRequest.Builder requestBuilder = ReadObjectRequest.newBuilder().setBucket(GrpcChannelUtils.toV2BucketName(resourceId.getBucketName())).setObject(objectName).setGeneration(objectGeneration).setReadOffset(offset);
bytesToRead.ifPresent(requestBuilder::setReadLimit);
ReadObjectRequest request = requestBuilder.build();
requestContext = Context.current().withCancellation();
Context toReattach = requestContext.attach();
StorageBlockingStub blockingStub = stub.withDeadlineAfter(readOptions.getGrpcReadTimeoutMillis(), MILLISECONDS);
Iterator<ReadObjectResponse> readObjectResponseIterator;
try {
if (useZeroCopyMarshaller) {
Iterator<ReadObjectResponse> responseIterator = ClientCalls.blockingServerStreamingCall(blockingStub.getChannel(), getObjectMediaMethod, blockingStub.getCallOptions(), request);
readObjectResponseIterator = watchdog.watch(requestContext, responseIterator, Duration.ofMillis(this.gRPCReadMessageTimeout));
} else {
readObjectResponseIterator = watchdog.watch(requestContext, blockingStub.readObject(request), Duration.ofMillis(this.gRPCReadMessageTimeout));
}
} finally {
requestContext.detach(toReattach);
}
return readObjectResponseIterator;
}
use of com.google.storage.v2.ReadObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class ZeroCopyMessageMarshallerTest method testParseBrokenMessageOnSlowPath.
@Test
public void testParseBrokenMessageOnSlowPath() {
InputStream stream = createInputStream(dropLastOneByte(REQUEST.toByteArray()), false);
ZeroCopyMessageMarshaller<ReadObjectRequest> marshaller = createMarshaller();
assertThrows(StatusRuntimeException.class, () -> marshaller.parse(stream));
}
use of com.google.storage.v2.ReadObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class ZeroCopyMessageMarshallerTest method testParseBrokenMessageOnFastPath.
@Test
public void testParseBrokenMessageOnFastPath() {
InputStream stream = createInputStream(dropLastOneByte(REQUEST.toByteArray()), true);
ZeroCopyMessageMarshaller<ReadObjectRequest> marshaller = createMarshaller();
assertThrows(StatusRuntimeException.class, () -> marshaller.parse(stream));
}
use of com.google.storage.v2.ReadObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class ZeroCopyMessageMarshallerTest method testParseOnSlowPath.
@Test
public void testParseOnSlowPath() {
InputStream stream = createInputStream(REQUEST.toByteArray(), false);
ZeroCopyMessageMarshaller<ReadObjectRequest> marshaller = createMarshaller();
ReadObjectRequest request = marshaller.parse(stream);
assertThat(request).isEqualTo(REQUEST);
InputStream stream2 = marshaller.popStream(request);
assertThat(stream2).isNull();
}
use of com.google.storage.v2.ReadObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class ZeroCopyMessageMarshallerTest method testParseOnFastPath.
@Test
public void testParseOnFastPath() throws IOException {
InputStream stream = createInputStream(REQUEST.toByteArray(), true);
ZeroCopyMessageMarshaller<ReadObjectRequest> marshaller = createMarshaller();
ReadObjectRequest request = marshaller.parse(stream);
assertThat(request).isEqualTo(REQUEST);
InputStream stream2 = marshaller.popStream(request);
assertThat(stream2).isNotNull();
stream2.close();
InputStream stream3 = marshaller.popStream(request);
assertThat(stream3).isNull();
}
Aggregations