use of com.google.api.gax.rpc.InternalException in project java-bigquerystorage by googleapis.
the class BigQueryReadClientTest method readRowsRetryingHttp2StreamRstTest.
@Test
@SuppressWarnings("all")
public void readRowsRetryingHttp2StreamRstTest() throws ExecutionException, InterruptedException {
ApiException exception = new InternalException(new StatusRuntimeException(Status.INTERNAL.withDescription("HTTP/2 error code: INTERNAL_ERROR\nReceived Rst Stream")), GrpcStatusCode.of(Code.INTERNAL), /* retryable = */
false);
mockBigQueryRead.addException(exception);
long rowCount = 1340416618L;
ReadRowsResponse expectedResponse = ReadRowsResponse.newBuilder().setRowCount(rowCount).build();
mockBigQueryRead.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.INTERNAL);
}
use of com.google.api.gax.rpc.InternalException in project java-spanner by googleapis.
the class PartitionedDmlTransaction method executeStreamingPartitionedUpdate.
/**
* Executes the {@link Statement} using a partitioned dml transaction with automatic retry if the
* transaction was aborted. The update method uses the ExecuteStreamingSql RPC to execute the
* statement, and will retry the stream if an {@link UnavailableException} is thrown, using the
* last seen resume token if the server returns any.
*/
long executeStreamingPartitionedUpdate(final Statement statement, final Duration timeout, final UpdateOption... updateOptions) {
checkState(isValid, "Partitioned DML has been invalidated by a new operation on the session");
LOGGER.log(Level.FINER, "Starting PartitionedUpdate statement");
ByteString resumeToken = ByteString.EMPTY;
boolean foundStats = false;
long updateCount = 0L;
Stopwatch stopwatch = Stopwatch.createStarted(ticker);
Options options = Options.fromUpdateOptions(updateOptions);
try {
ExecuteSqlRequest request = newTransactionRequestFrom(statement, options);
while (true) {
final Duration remainingTimeout = tryUpdateTimeout(timeout, stopwatch);
try {
ServerStream<PartialResultSet> stream = rpc.executeStreamingPartitionedDml(request, session.getOptions(), remainingTimeout);
for (PartialResultSet rs : stream) {
if (rs.getResumeToken() != null && !rs.getResumeToken().isEmpty()) {
resumeToken = rs.getResumeToken();
}
if (rs.hasStats()) {
foundStats = true;
updateCount += rs.getStats().getRowCountLowerBound();
}
}
break;
} catch (UnavailableException e) {
LOGGER.log(Level.FINER, "Retrying PartitionedDml transaction after UnavailableException", e);
request = resumeOrRestartRequest(resumeToken, statement, request, options);
} catch (InternalException e) {
if (!isRetryableInternalErrorPredicate.apply(e)) {
throw e;
}
LOGGER.log(Level.FINER, "Retrying PartitionedDml transaction after InternalException - EOS", e);
request = resumeOrRestartRequest(resumeToken, statement, request, options);
} catch (AbortedException e) {
LOGGER.log(Level.FINER, "Retrying PartitionedDml transaction after AbortedException", e);
resumeToken = ByteString.EMPTY;
foundStats = false;
updateCount = 0L;
request = newTransactionRequestFrom(statement, options);
}
}
if (!foundStats) {
throw SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "Partitioned DML response missing stats possibly due to non-DML statement as input");
}
LOGGER.log(Level.FINER, "Finished PartitionedUpdate statement");
return updateCount;
} catch (Exception e) {
throw SpannerExceptionFactory.newSpannerException(e);
}
}
use of com.google.api.gax.rpc.InternalException in project java-spanner by googleapis.
the class IsRetryableInternalErrorTest method eosInternalExceptionIsRetryable.
@Test
public void eosInternalExceptionIsRetryable() {
final InternalException e = new InternalException("INTERNAL: Received unexpected EOS on DATA frame from server.", null, GrpcStatusCode.of(Code.INTERNAL), false);
assertThat(predicate.apply(e)).isTrue();
}
use of com.google.api.gax.rpc.InternalException in project java-spanner by googleapis.
the class PartitionedDmlTransactionTest method testExecuteStreamingPartitionedUpdateGenericInternalException.
@Test
public void testExecuteStreamingPartitionedUpdateGenericInternalException() {
PartialResultSet p1 = PartialResultSet.newBuilder().setResumeToken(resumeToken).build();
ServerStream<PartialResultSet> stream1 = mock(ServerStream.class);
Iterator<PartialResultSet> iterator = mock(Iterator.class);
when(iterator.hasNext()).thenReturn(true, true, false);
when(iterator.next()).thenReturn(p1).thenThrow(new InternalException("INTERNAL: Error", null, GrpcStatusCode.of(Code.INTERNAL), false));
when(stream1.iterator()).thenReturn(iterator);
when(rpc.executeStreamingPartitionedDml(Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class))).thenReturn(stream1);
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker);
SpannerException e = assertThrows(SpannerException.class, () -> tx.executeStreamingPartitionedUpdate(Statement.of(sql), Duration.ofMinutes(10)));
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
verify(rpc).beginTransaction(any(BeginTransactionRequest.class), anyMap());
verify(rpc).executeStreamingPartitionedDml(Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class));
}
use of com.google.api.gax.rpc.InternalException in project java-spanner by googleapis.
the class IsRetryableInternalErrorTest method genericInternalExceptionIsNotRetryable.
@Test
public void genericInternalExceptionIsNotRetryable() {
final InternalException e = new InternalException("INTERNAL: Generic.", null, GrpcStatusCode.of(Code.INTERNAL), false);
assertThat(predicate.apply(e)).isFalse();
}
Aggregations