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));
}
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;
}
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));
}
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));
}
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);
}
Aggregations