Search in sources :

Example 1 with UnknownException

use of com.google.api.gax.rpc.UnknownException in project gax-java by googleapis.

the class RetryingTest method testUnknownStatusCode.

@Test
public void testUnknownStatusCode() {
    ImmutableSet<StatusCode.Code> retryable = ImmutableSet.of();
    Mockito.when(callInt.futureCall((Integer) Mockito.any(), (ApiCallContext) Mockito.any())).thenReturn(ApiFutures.<Integer>immediateFailedFuture(new RuntimeException("unknown")));
    UnaryCallSettings<Integer, Integer> callSettings = UnaryCallSettings.<Integer, Integer>newUnaryCallSettingsBuilder().setRetryableCodes(retryable).build();
    UnaryCallable<Integer, Integer> callable = HttpJsonCallableFactory.createUnaryCallable(callInt, callSettings, clientContext);
    UnknownException exception = assertThrows(UnknownException.class, () -> callable.call(1));
    Truth.assertThat(exception).hasMessageThat().isEqualTo("java.lang.RuntimeException: unknown");
}
Also used : UnknownException(com.google.api.gax.rpc.UnknownException) Code(com.google.api.gax.rpc.StatusCode.Code) StatusCode(com.google.api.gax.rpc.StatusCode) Test(org.junit.Test)

Example 2 with UnknownException

use of com.google.api.gax.rpc.UnknownException in project java-bigquerystorage by googleapis.

the class StreamWriterTest method testAppendFailRandomException.

@Test
public void testAppendFailRandomException() throws Exception {
    StreamWriter writer = getTestStreamWriter();
    // Trigger a non-StatusRuntimeException for append operation (although grpc API should not
    // return anything other than StatusRuntimeException)
    IllegalArgumentException illegalArgumentException = new IllegalArgumentException("Illegal argument");
    testBigQueryWrite.addException(illegalArgumentException);
    ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] { "A" });
    UnknownException actualError = assertFutureException(UnknownException.class, appendFuture1);
    assertEquals(Code.UNKNOWN, actualError.getStatusCode().getCode());
    writer.close();
}
Also used : UnknownException(com.google.api.gax.rpc.UnknownException) Test(org.junit.Test)

Aggregations

UnknownException (com.google.api.gax.rpc.UnknownException)2 Test (org.junit.Test)2 StatusCode (com.google.api.gax.rpc.StatusCode)1 Code (com.google.api.gax.rpc.StatusCode.Code)1