Search in sources :

Example 6 with WriteObjectRequest

use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.

the class WatchdogTest method watchOnClientStreamingRPCTimeout.

@Test
public void watchOnClientStreamingRPCTimeout() {
    NoopClientCallStub<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCallStub<>();
    StreamObserver<WriteObjectRequest> timeoutStreamObserver = new StreamObserver<>() {

        @Override
        public void onNext(WriteObjectRequest value) {
            logger.atInfo().log("Sleeping for 10 seconds");
            sleepUninterruptibly(Duration.ofSeconds(10));
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onCompleted() {
        }
    };
    StreamObserver<WriteObjectRequest> watch = watchdog.watch(clientCall, timeoutStreamObserver, waitTime);
    WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
    watch.onNext(value);
    assertThat(clientCall.cancelled).isTrue();
    assertThat(clientCall.cause).isInstanceOf(TimeoutException.class);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) WriteObjectRequest(com.google.storage.v2.WriteObjectRequest) WriteObjectResponse(com.google.storage.v2.WriteObjectResponse) Test(org.junit.Test)

Example 7 with WriteObjectRequest

use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.

the class WatchdogTest method watchPassThroughClientStreamingRPC.

@Test
public void watchPassThroughClientStreamingRPC() {
    ClientCall<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCall<>();
    StreamObserverStub<WriteObjectRequest> streamObserver = new StreamObserverStub<>();
    StreamObserver<WriteObjectRequest> watch = watchdog.watch(clientCall, streamObserver, waitTime);
    assertThat(watchdog).isNotNull();
    assertThat(watchdog.getOpenStreams()).hasSize(1);
    WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
    watch.onNext(value);
    assertThat(streamObserver.getObjects()).containsExactly(value);
    Throwable t = new TimeoutException("Request timeout out");
    watch.onError(t);
    assertThat(streamObserver.getErrors()).containsExactly(t);
    watch.onCompleted();
    assertThat(streamObserver.isCompleted()).isTrue();
    assertThat(watchdog.getOpenStreams().isEmpty()).isTrue();
}
Also used : NoopClientCall(io.grpc.internal.NoopClientCall) WriteObjectRequest(com.google.storage.v2.WriteObjectRequest) WriteObjectResponse(com.google.storage.v2.WriteObjectResponse) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 8 with WriteObjectRequest

use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.

the class WatchdogTest method watchMultipleStreams.

@Test
public void watchMultipleStreams() {
    NoopClientCallStub<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCallStub<>();
    StreamObserver<WriteObjectRequest> timeoutStreamObserver = new StreamObserver<>() {

        @Override
        public void onNext(WriteObjectRequest value) {
            logger.atInfo().log("Sleeping for 10 seconds");
            sleepUninterruptibly(Duration.ofSeconds(10));
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onCompleted() {
        }
    };
    CancellableContext requestContext = Context.current().withCancellation();
    Iterator<ReadObjectResponse> responseIterator = new Iterator<>() {

        @Override
        public boolean hasNext() {
            logger.atInfo().log("Sleeping for 10 seconds");
            sleepUninterruptibly(Duration.ofSeconds(10));
            return true;
        }

        @Override
        public ReadObjectResponse next() {
            return null;
        }
    };
    Iterator<ReadObjectResponse> clientStreamingRPCWatch = watchdog.watch(requestContext, responseIterator, waitTime);
    StreamObserver<WriteObjectRequest> serverStreamingRPCWatch = watchdog.watch(clientCall, timeoutStreamObserver, waitTime);
    assertThat(watchdog).isNotNull();
    assertThat(watchdog.getOpenStreams()).hasSize(2);
    boolean actual = clientStreamingRPCWatch.hasNext();
    WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
    serverStreamingRPCWatch.onNext(value);
    assertThat(actual).isTrue();
    assertThat(requestContext.isCancelled()).isTrue();
    assertThat(clientCall.cancelled).isTrue();
    assertThat(clientCall.cause).isInstanceOf(TimeoutException.class);
    assertThat(watchdog.getOpenStreams().isEmpty()).isTrue();
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ReadObjectResponse(com.google.storage.v2.ReadObjectResponse) CancellableContext(io.grpc.Context.CancellableContext) Iterator(java.util.Iterator) WriteObjectRequest(com.google.storage.v2.WriteObjectRequest) WriteObjectResponse(com.google.storage.v2.WriteObjectResponse) Test(org.junit.Test)

Example 9 with WriteObjectRequest

use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.

the class WatchdogTest method watchOnClientStreamingRPCWithoutTimeout.

@Test
public void watchOnClientStreamingRPCWithoutTimeout() {
    NoopClientCallStub<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCallStub<>();
    StreamObserver<WriteObjectRequest> timeoutStreamObserver = new StreamObserver<>() {

        @Override
        public void onNext(WriteObjectRequest value) {
            logger.atInfo().log("Sleeping for 10 seconds");
            sleepUninterruptibly(Duration.ofSeconds(10));
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onCompleted() {
        }
    };
    StreamObserver<WriteObjectRequest> watch = watchdog.watch(clientCall, timeoutStreamObserver, zeroWaitTime);
    WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
    watch.onNext(value);
    assertThat(clientCall.cancelled).isFalse();
    assertThat(clientCall.cause).isNull();
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) WriteObjectRequest(com.google.storage.v2.WriteObjectRequest) WriteObjectResponse(com.google.storage.v2.WriteObjectResponse) Test(org.junit.Test)

Example 10 with WriteObjectRequest

use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.

the class GoogleCloudStorageGrpcWriteChannelTest method writeSendsMultipleInsertObjectRequestsWithChecksums.

@Test
public void writeSendsMultipleInsertObjectRequestsWithChecksums() throws Exception {
    AsyncWriteChannelOptions options = AsyncWriteChannelOptions.builder().setGrpcChecksumsEnabled(true).build();
    ObjectWriteConditions writeConditions = ObjectWriteConditions.NONE;
    GoogleCloudStorageGrpcWriteChannel writeChannel = newWriteChannel(options, writeConditions, /* requesterPaysProject= */
    null);
    fakeService.setQueryWriteStatusResponses(ImmutableList.of(QueryWriteStatusResponse.newBuilder().setPersistedSize(GCS_MINIMUM_CHUNK_SIZE).build(), QueryWriteStatusResponse.newBuilder().setPersistedSize(2 * GCS_MINIMUM_CHUNK_SIZE).build()).iterator());
    ByteString data = createTestData(GCS_MINIMUM_CHUNK_SIZE * 5 / 2);
    writeChannel.initialize();
    writeChannel.write(data.asReadOnlyByteBuffer());
    writeChannel.close();
    ArgumentCaptor<WriteObjectRequest> requestCaptor = ArgumentCaptor.forClass(WriteObjectRequest.class);
    verify(fakeService, times(1)).startResumableWrite(eq(START_REQUEST), any());
    verify(fakeService.insertRequestObserver, times(1)).onNext(requestCaptor.capture());
    verify(fakeService.insertRequestObserver, atLeast(1)).onCompleted();
}
Also used : AsyncWriteChannelOptions(com.google.cloud.hadoop.util.AsyncWriteChannelOptions) ByteString(com.google.protobuf.ByteString) WriteObjectRequest(com.google.storage.v2.WriteObjectRequest) Test(org.junit.Test)

Aggregations

WriteObjectRequest (com.google.storage.v2.WriteObjectRequest)12 Test (org.junit.Test)10 ByteString (com.google.protobuf.ByteString)7 WriteObjectResponse (com.google.storage.v2.WriteObjectResponse)6 AsyncWriteChannelOptions (com.google.cloud.hadoop.util.AsyncWriteChannelOptions)4 StreamObserver (io.grpc.stub.StreamObserver)4 ApiStreamObserver (com.google.api.gax.rpc.ApiStreamObserver)1 ReadObjectResponse (com.google.storage.v2.ReadObjectResponse)1 StorageClient (com.google.storage.v2.StorageClient)1 StorageGrpc (com.google.storage.v2.StorageGrpc)1 CancellableContext (io.grpc.Context.CancellableContext)1 StatusException (io.grpc.StatusException)1 NoopClientCall (io.grpc.internal.NoopClientCall)1 Iterator (java.util.Iterator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1