Search in sources :

Example 1 with ReadObjectRequest

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;
}
Also used : Context(io.grpc.Context) CancellableContext(io.grpc.Context.CancellableContext) ReadObjectResponse(com.google.storage.v2.ReadObjectResponse) ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) StorageBlockingStub(com.google.storage.v2.StorageGrpc.StorageBlockingStub)

Example 2 with ReadObjectRequest

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));
}
Also used : ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 3 with ReadObjectRequest

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));
}
Also used : ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with ReadObjectRequest

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();
}
Also used : ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with ReadObjectRequest

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();
}
Also used : ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

ReadObjectRequest (com.google.storage.v2.ReadObjectRequest)13 Test (org.junit.Test)9 InputStream (java.io.InputStream)5 ByteBuffer (java.nio.ByteBuffer)5 ReadObjectResponse (com.google.storage.v2.ReadObjectResponse)4 StorageBlockingStub (com.google.storage.v2.StorageGrpc.StorageBlockingStub)3 ByteString (com.google.protobuf.ByteString)2 StorageClient (com.google.storage.v2.StorageClient)1 StorageGrpc (com.google.storage.v2.StorageGrpc)1 Context (io.grpc.Context)1 CancellableContext (io.grpc.Context.CancellableContext)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 Random (java.util.Random)1