Refine search
Exception cause = new ResourceManagerException(503, "message"); RetryHelperException exceptionMock = createMock(RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { ResourceManagerException.translateAndThrow(exceptionMock); } catch (BaseServiceException ex) { assertEquals(503, ex.getCode()); assertEquals("message", ex.getMessage()); assertTrue(ex.isRetryable()); } finally { verify(exceptionMock); expect(exceptionMock.getMessage()).andReturn("message").times(1); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try {
public static <V> V runWithRetries( Callable<V> callable, RetrySettings retrySettings, ResultRetryAlgorithm<?> resultRetryAlgorithm, ApiClock clock) throws RetryHelperException { try { // Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm // implementation does not use response at all, so ignoring its type is ok. @SuppressWarnings("unchecked") ResultRetryAlgorithm<V> algorithm = (ResultRetryAlgorithm<V>) resultRetryAlgorithm; return run(callable, new ExponentialRetryAlgorithm(retrySettings, clock), algorithm); } catch (Exception e) { // TODO: remove RetryHelperException, throw InterruptedException or // ExecutionException#getCause() explicitly throw new RetryHelperException(e.getCause()); } }
@Test public void testTranslateAndThrow() throws Exception { BaseServiceException cause = new BaseServiceException(ExceptionData.from(CODE, MESSAGE, REASON, NOT_RETRYABLE)); RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { BaseServiceException.translate(exceptionMock); } catch (BaseServiceException ex) { assertEquals(CODE, ex.getCode()); assertEquals(MESSAGE, ex.getMessage()); assertFalse(ex.isRetryable()); } finally { verify(exceptionMock); } }
/** * Translate RetryHelperException to the BigQueryException that caused the error. This method will * always throw an exception. * * @throws BigQueryException when {@code ex} was caused by a {@code BigQueryException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); }
/** * Translate RetryHelperException to the DnsException that caused the error. This method will * always throw an exception. * * @throws DnsException when {@code ex} was caused by a {@code DnsException} * @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException} */ static DnsException translateAndThrow(RetryHelperException ex) { BaseServiceException.translateAndPropagateIfPossible(ex); throw new DnsException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
protected static void translateAndPropagateIfPossible(RetryHelper.RetryHelperException ex) { if (ex.getCause() instanceof BaseServiceException) { throw (BaseServiceException) ex.getCause(); } if (ex instanceof RetryHelper.RetryInterruptedException) { RetryHelper.RetryInterruptedException.propagate(); } } }
public static <V> V runWithRetries( Callable<V> callable, RetrySettings retrySettings, ResultRetryAlgorithm<?> resultRetryAlgorithm, ApiClock clock) throws RetryHelperException { try { // Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm // implementation does not use response at all, so ignoring its type is ok. @SuppressWarnings("unchecked") ResultRetryAlgorithm<V> algorithm = (ResultRetryAlgorithm<V>) resultRetryAlgorithm; return run(callable, new ExponentialRetryAlgorithm(retrySettings, clock), algorithm); } catch (Exception e) { // TODO: remove RetryHelperException, throw InterruptedException or // ExecutionException#getCause() explicitly throw new RetryHelperException(e.getCause()); } }
@Test public void testTranslateAndThrow() throws Exception { IOException exception = new SocketTimeoutException(); BaseGrpcServiceException cause = new BaseGrpcServiceException(exception, IDEMPOTENT); RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { BaseServiceException.translate(exceptionMock); } catch (BaseServiceException ex) { assertEquals(0, ex.getCode()); assertNull(ex.getMessage()); assertTrue(ex.isRetryable()); } finally { verify(exceptionMock); } } }
/** * Translate RetryHelperException to the DnsException that caused the error. This method will * always throw an exception. * * @throws DnsException when {@code ex} was caused by a {@code DnsException} */ static DnsException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); throw new DnsException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
/** * Translate RetryHelperException to the TranslateException that caused the error. This method * will always throw an exception. * * @throws TranslateException when {@code ex} was caused by a {@code TranslateException} * @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translateAndPropagateIfPossible(ex); throw new TranslateException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
Exception cause = new BigQueryException(503, "message"); RetryHelperException exceptionMock = createMock(RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { BigQueryException.translateAndThrow(exceptionMock); } catch (BaseServiceException ex) { assertEquals(503, ex.getCode()); assertEquals("message", ex.getMessage()); assertTrue(ex.isRetryable()); } finally { verify(exceptionMock); expect(exceptionMock.getMessage()).andReturn("message").times(1); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try {
@Test public void testTranslateAndThrow() throws Exception { BaseServiceException cause = new BaseHttpServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, EMPTY_RETRYABLE_ERRORS); RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { BaseServiceException.translate(exceptionMock); } catch (BaseServiceException ex) { assertEquals(CODE, ex.getCode()); assertEquals(MESSAGE, ex.getMessage()); assertFalse(ex.isRetryable()); } finally { verify(exceptionMock); } } }
/** * Translate RetryHelperException to the DatastoreException that caused the error. This method * will always throw an exception. * * @throws DatastoreException when {@code ex} was caused by a {@code DatastoreException} */ static DatastoreException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); throw new DatastoreException(UNKNOWN_CODE, ex.getMessage(), null, ex.getCause()); }
/** * Translate RetryHelperException to the BigQueryException that caused the error. This method will * always throw an exception. * * @throws BigQueryException when {@code ex} was caused by a {@code BigQueryException} * @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translateAndPropagateIfPossible(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
Exception cause = new DnsException(timeoutException, true); RetryHelperException exceptionMock = createMock(RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { DnsException.translateAndThrow(exceptionMock); } catch (BaseServiceException ex) { assertEquals(DnsException.UNKNOWN_CODE, ex.getCode()); assertNull(ex.getReason()); assertEquals("message", ex.getMessage()); assertEquals(timeoutException, ex.getCause()); assertTrue(ex.isRetryable()); expect(exceptionMock.getMessage()).andReturn("message").times(1); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try {
/** * Translate RetryHelperException to the TranslateException that caused the error. This method * will always throw an exception. * * @throws TranslateException when {@code ex} was caused by a {@code TranslateException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); throw new TranslateException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
/** * Translate RetryHelperException to the ComputeException that caused the error. This method will * always throw an exception. * * @throws ComputeException when {@code ex} was caused by a {@code ComputeException} * @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translateAndPropagateIfPossible(ex); throw new ComputeException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
Exception cause = new TranslateException(500, "message"); RetryHelperException exceptionMock = createMock(RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try { TranslateException.translateAndThrow(exceptionMock); } catch (BaseServiceException ex) { assertEquals(500, ex.getCode()); assertEquals("message", ex.getMessage()); assertTrue(ex.isRetryable()); } finally { verify(exceptionMock); expect(exceptionMock.getMessage()).andReturn("message").times(1); expect(exceptionMock.getCause()).andReturn(cause).times(2); replay(exceptionMock); try {