use of com.google.api.gax.rpc.InternalException in project java-spanner by googleapis.
the class PartitionedDmlTransactionTest method testExecuteStreamingPartitionedUpdateUnexpectedEOS.
@Test
public void testExecuteStreamingPartitionedUpdateUnexpectedEOS() {
ResultSetStats stats = ResultSetStats.newBuilder().setRowCountLowerBound(1000L).build();
PartialResultSet p1 = PartialResultSet.newBuilder().setResumeToken(resumeToken).build();
PartialResultSet p2 = PartialResultSet.newBuilder().setStats(stats).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: Received unexpected EOS on DATA frame from server.", null, GrpcStatusCode.of(Code.INTERNAL), true));
when(stream1.iterator()).thenReturn(iterator);
ServerStream<PartialResultSet> stream2 = mock(ServerStream.class);
when(stream2.iterator()).thenReturn(ImmutableList.of(p1, p2).iterator());
when(rpc.executeStreamingPartitionedDml(Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class))).thenReturn(stream1);
when(rpc.executeStreamingPartitionedDml(Mockito.eq(executeRequestWithResumeToken), anyMap(), any(Duration.class))).thenReturn(stream2);
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker);
long count = tx.executeStreamingPartitionedUpdate(Statement.of(sql), Duration.ofMinutes(10));
assertThat(count).isEqualTo(1000L);
verify(rpc).beginTransaction(any(BeginTransactionRequest.class), anyMap());
verify(rpc).executeStreamingPartitionedDml(Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class));
verify(rpc).executeStreamingPartitionedDml(Mockito.eq(executeRequestWithResumeToken), anyMap(), any(Duration.class));
}
use of com.google.api.gax.rpc.InternalException in project java-spanner by googleapis.
the class IsRetryableInternalErrorTest method connectionClosedInternalExceptionIsRetryable.
@Test
public void connectionClosedInternalExceptionIsRetryable() {
final InternalException e = new InternalException("INTERNAL: Connection closed with unknown cause.", 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 IsRetryableInternalErrorTest method http2ErrorInternalExceptionIsRetryable.
@Test
public void http2ErrorInternalExceptionIsRetryable() {
final InternalException e = new InternalException("INTERNAL: HTTP/2 error code: INTERNAL_ERROR.", null, GrpcStatusCode.of(Code.INTERNAL), false);
assertThat(predicate.apply(e)).isTrue();
}
use of com.google.api.gax.rpc.InternalException in project java-bigtable by googleapis.
the class ReadRowsRetryTest method retryRstStreamExceptionTest.
@Test
public void retryRstStreamExceptionTest() {
ApiException exception = new InternalException(new StatusRuntimeException(Status.INTERNAL.withDescription("INTERNAL: HTTP/2 error code: INTERNAL_ERROR\nReceived Rst Stream")), GrpcStatusCode.of(Code.INTERNAL), false);
service.expectations.add(RpcExpectation.create().expectRequest("k1").expectRequest(Range.closedOpen("r1", "r3")).respondWithException(Code.INTERNAL, exception));
service.expectations.add(RpcExpectation.create().expectRequest("k1").expectRequest(Range.closedOpen("r1", "r3")).respondWith("k1", "r1", "r2"));
List<String> actualResults = getResults(Query.create(TABLE_ID).rowKey("k1").range("r1", "r3"));
Truth.assertThat(actualResults).containsExactly("k1", "r1", "r2").inOrder();
}
use of com.google.api.gax.rpc.InternalException in project java-core by googleapis.
the class BaseGrpcServiceExceptionTest method testBaseServiceException.
@Test
public void testBaseServiceException() {
BaseGrpcServiceException serviceException = null;
IOException exception = new SocketTimeoutException();
serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT);
assertTrue(serviceException.isRetryable());
assertNull(serviceException.getMessage());
assertEquals(exception, serviceException.getCause());
assertNull(serviceException.getReason());
assertNull(serviceException.getLocation());
assertNull(serviceException.getDebugInfo());
exception = new SocketException();
serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT);
assertTrue(serviceException.isRetryable());
assertNull(serviceException.getMessage());
assertEquals(exception, serviceException.getCause());
assertNull(serviceException.getReason());
assertNull(serviceException.getLocation());
assertNull(serviceException.getDebugInfo());
exception = new IOException("insufficient data written");
serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT);
assertTrue(serviceException.isRetryable());
assertEquals("insufficient data written", serviceException.getMessage());
assertEquals(exception, serviceException.getCause());
assertNull(serviceException.getReason());
assertNull(serviceException.getLocation());
assertNull(serviceException.getDebugInfo());
Exception cause = new IllegalArgumentException("bad arg");
InternalException apiException = new InternalException(MESSAGE, cause, GrpcStatusCode.of(Code.INTERNAL), NOT_RETRYABLE);
serviceException = new BaseGrpcServiceException(apiException);
assertFalse(serviceException.isRetryable());
assertEquals(MESSAGE, serviceException.getMessage());
assertEquals(apiException, serviceException.getCause());
assertEquals(500, serviceException.getCode());
assertEquals(Code.INTERNAL.name(), serviceException.getReason());
assertNull(serviceException.getLocation());
assertNull(serviceException.getDebugInfo());
}
Aggregations