Search in sources :

Example 11 with ReadRowsRequest

use of com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ReadRowsRetryTest method immediateRetryTest.

@Test
public void immediateRetryTest() {
    ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithStatus(Code.UNAVAILABLE));
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(10).respondWithNumberOfRows(7));
    Assert.assertEquals(17, getRowCount(request));
}
Also used : ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest) Test(org.junit.Test)

Example 12 with ReadRowsRequest

use of com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ReadRowsRetryTest method getRowCount.

private int getRowCount(ReadRowsRequest request) {
    ServerStream<ReadRowsResponse> serverStream = client.readRowsCallable().call(request);
    int rowCount = 0;
    for (ReadRowsResponse readRowsResponse : serverStream) {
        rowCount += readRowsResponse.getRowCount();
    }
    return rowCount;
}
Also used : ReadRowsResponse(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsResponse)

Example 13 with ReadRowsRequest

use of com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ReadRowsRetryTest method happyPathTest.

@Test
public void happyPathTest() {
    ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(10).respondWithNumberOfRows(7));
    Assert.assertEquals(17, getRowCount(request));
}
Also used : ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest) Test(org.junit.Test)

Example 14 with ReadRowsRequest

use of com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class ReadRowsRetryTest method errorAtTheVeryEndTest.

@Test
public void errorAtTheVeryEndTest() {
    ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(10).respondWithNumberOfRows(7).respondWithStatus(Code.UNAVAILABLE));
    service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 17).respondWithNumberOfRows(0));
    Assert.assertEquals(17, getRowCount(request));
}
Also used : ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest) Test(org.junit.Test)

Example 15 with ReadRowsRequest

use of com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest in project java-bigquerystorage by googleapis.

the class BigQueryStorageClientTest method readRowsNoRetryForResourceExhaustedWithRetryInfo.

@Test
@SuppressWarnings("all")
public void readRowsNoRetryForResourceExhaustedWithRetryInfo() throws ExecutionException, InterruptedException {
    RetryInfo retryInfo = RetryInfo.newBuilder().setRetryDelay(Duration.newBuilder().setSeconds(123).setNanos(456).build()).build();
    Metadata metadata = new Metadata();
    metadata.put(Metadata.Key.of("google.rpc.retryinfo-bin", new Metadata.BinaryMarshaller<RetryInfo>() {

        @Override
        public byte[] toBytes(RetryInfo value) {
            return value.toByteArray();
        }

        @Override
        public RetryInfo parseBytes(byte[] serialized) {
            try {
                Parser<RetryInfo> parser = (RetryInfo.newBuilder().build()).getParserForType();
                return parser.parseFrom(serialized);
            } catch (Exception e) {
                return null;
            }
        }
    }), retryInfo);
    ApiException exception = new ResourceExhaustedException(new StatusRuntimeException(Status.RESOURCE_EXHAUSTED.withDescription("Try again in a bit"), metadata), GrpcStatusCode.of(Code.RESOURCE_EXHAUSTED), /* retryable = */
    false);
    mockBigQueryStorage.addException(exception);
    long rowCount = 1340416618L;
    ReadRowsResponse expectedResponse = ReadRowsResponse.newBuilder().setRowCount(rowCount).build();
    mockBigQueryStorage.addResponse(expectedResponse);
    ReadRowsRequest request = ReadRowsRequest.newBuilder().build();
    MockStreamObserver<ReadRowsResponse> responseObserver = new MockStreamObserver<>();
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> callable = client.readRowsCallable();
    callable.serverStreamingCall(request, responseObserver);
    List<ReadRowsResponse> actualResponses = responseObserver.future().get();
    Assert.assertEquals(1, actualResponses.size());
    Assert.assertEquals(retryCount, 1);
    Assert.assertEquals(lastRetryStatusCode, Code.RESOURCE_EXHAUSTED);
}
Also used : Metadata(io.grpc.Metadata) ReadRowsRequest(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest) ResourceExhaustedException(com.google.api.gax.rpc.ResourceExhaustedException) InternalException(com.google.api.gax.rpc.InternalException) IOException(java.io.IOException) ApiException(com.google.api.gax.rpc.ApiException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ResourceExhaustedException(com.google.api.gax.rpc.ResourceExhaustedException) ReadRowsResponse(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) RetryInfo(com.google.rpc.RetryInfo) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Aggregations

ReadRowsRequest (com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest)24 ReadRowsResponse (com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsResponse)17 Test (org.junit.Test)17 StreamPosition (com.google.cloud.bigquery.storage.v1beta1.Storage.StreamPosition)9 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)6 ReadSession (com.google.cloud.bigquery.storage.v1beta1.Storage.ReadSession)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 ApiException (com.google.api.gax.rpc.ApiException)4 TableReference (com.google.cloud.bigquery.storage.v1beta1.TableReferenceProto.TableReference)4 InternalException (com.google.api.gax.rpc.InternalException)3 CreateReadSessionRequest (com.google.cloud.bigquery.storage.v1beta1.Storage.CreateReadSessionRequest)3 ExecutionException (java.util.concurrent.ExecutionException)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 ResourceExhaustedException (com.google.api.gax.rpc.ResourceExhaustedException)2 TableReadOptions (com.google.cloud.bigquery.storage.v1beta1.ReadOptions.TableReadOptions)2 AvroRowConsumer (com.google.cloud.bigquery.storage.v1beta1.it.SimpleRowReader.AvroRowConsumer)2 GenericData (org.apache.avro.generic.GenericData)2 ExponentialRetryAlgorithm (com.google.api.gax.retrying.ExponentialRetryAlgorithm)1 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 ScheduledRetryingExecutor (com.google.api.gax.retrying.ScheduledRetryingExecutor)1