@Test public void translateException_RuntimeException() throws Exception { Throwable originalException = new RuntimeException("stuff went wrong"); GrpcExceptionCallable<Integer, Integer> exceptionCallable = new GrpcExceptionCallable<>( failingCallable(originalException), Collections.<StatusCode.Code>emptySet()); try { exceptionCallable.call(0); fail("Expected exception to be thrown"); } catch (Throwable throwable) { assertInnerExceptionIsInstanceOf( throwable, UnknownException.class, NOT_RETRYABLE, originalException); } }
@Test public void translateException_StatusRuntimeException_withRetry() throws Exception { Throwable originalException = new StatusRuntimeException(Status.UNAVAILABLE); GrpcExceptionCallable<Integer, Integer> exceptionCallable = new GrpcExceptionCallable<>( failingCallable(originalException), Collections.singleton(Code.UNAVAILABLE)); try { exceptionCallable.call(0); fail("Expected exception to be thrown"); } catch (Throwable throwable) { assertInnerExceptionIsInstanceOf( throwable, UnavailableException.class, IS_RETRYABLE, originalException); } }
@Test public void translateException_StatusException_withRetry() throws Exception { Throwable originalException = new StatusException(Status.UNAVAILABLE); GrpcExceptionCallable<Integer, Integer> exceptionCallable = new GrpcExceptionCallable<>( failingCallable(originalException), Collections.singleton(Code.UNAVAILABLE)); try { exceptionCallable.call(0); fail("Expected exception to be thrown"); } catch (Throwable throwable) { assertInnerExceptionIsInstanceOf( throwable, UnavailableException.class, IS_RETRYABLE, originalException); } }
@Test public void translateException_StatusRuntimeException_noRetry() throws Exception { Throwable originalException = new StatusRuntimeException(Status.INVALID_ARGUMENT); GrpcExceptionCallable<Integer, Integer> exceptionCallable = new GrpcExceptionCallable<>( failingCallable(originalException), Collections.<StatusCode.Code>emptySet()); try { exceptionCallable.call(0); fail("Expected exception to be thrown"); } catch (Throwable throwable) { assertInnerExceptionIsInstanceOf( throwable, InvalidArgumentException.class, NOT_RETRYABLE, originalException); } }
@Test public void translateException_StatusException_noRetry() throws Exception { Throwable originalException = new StatusException(Status.INVALID_ARGUMENT); GrpcExceptionCallable<Integer, Integer> exceptionCallable = new GrpcExceptionCallable<>( failingCallable(originalException), Collections.<StatusCode.Code>emptySet()); try { exceptionCallable.call(0); fail("Expected exception to be thrown"); } catch (Throwable throwable) { assertInnerExceptionIsInstanceOf( throwable, InvalidArgumentException.class, NOT_RETRYABLE, originalException); } }
@Test public void translateException_ApiException() throws Exception { Throwable originalException = new RuntimeException("stuff went wrong"); Throwable apiException = new DataLossException( originalException, GrpcStatusCode.of(Status.Code.UNKNOWN), IS_RETRYABLE); GrpcExceptionCallable<Integer, Integer> exceptionCallable = new GrpcExceptionCallable<>( failingCallable(apiException), Collections.<StatusCode.Code>emptySet()); try { exceptionCallable.call(0); fail("Expected exception to be thrown"); } catch (Throwable throwable) { assertInnerExceptionIsInstanceOf( throwable, DataLossException.class, IS_RETRYABLE, originalException); } }