Search in sources :

Example 1 with InternalException

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));
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) BeginTransactionRequest(com.google.spanner.v1.BeginTransactionRequest) Duration(org.threeten.bp.Duration) PartialResultSet(com.google.spanner.v1.PartialResultSet) InternalException(com.google.api.gax.rpc.InternalException) Test(org.junit.Test)

Example 2 with InternalException

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();
}
Also used : InternalException(com.google.api.gax.rpc.InternalException) Test(org.junit.Test)

Example 3 with InternalException

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();
}
Also used : InternalException(com.google.api.gax.rpc.InternalException) Test(org.junit.Test)

Example 4 with InternalException

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();
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.rpc.ApiException) InternalException(com.google.api.gax.rpc.InternalException) Test(org.junit.Test)

Example 5 with InternalException

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());
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) BaseServiceException(com.google.cloud.BaseServiceException) IOException(java.io.IOException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) InternalException(com.google.api.gax.rpc.InternalException) InternalException(com.google.api.gax.rpc.InternalException) Test(org.junit.Test)

Aggregations

InternalException (com.google.api.gax.rpc.InternalException)16 Test (org.junit.Test)15 ApiException (com.google.api.gax.rpc.ApiException)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)6 PartialResultSet (com.google.spanner.v1.PartialResultSet)3 Duration (org.threeten.bp.Duration)3 ReadRowsRequest (com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest)2 ReadRowsResponse (com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsResponse)2 ByteString (com.google.protobuf.ByteString)2 BeginTransactionRequest (com.google.spanner.v1.BeginTransactionRequest)2 AbortedException (com.google.api.gax.rpc.AbortedException)1 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 UnavailableException (com.google.api.gax.rpc.UnavailableException)1 BaseServiceException (com.google.cloud.BaseServiceException)1 Stopwatch (com.google.common.base.Stopwatch)1 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)1 RequestOptions (com.google.spanner.v1.RequestOptions)1 ResultSetStats (com.google.spanner.v1.ResultSetStats)1 TransactionOptions (com.google.spanner.v1.TransactionOptions)1